Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern _vstate_assert: Use atomic_load/store_relaxed. Omi...



details:   https://anonhg.NetBSD.org/src/rev/726653cbc30c
branches:  trunk
changeset: 373640:726653cbc30c
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Feb 22 21:44:21 2023 +0000

description:
_vstate_assert: Use atomic_load/store_relaxed.  Omit membar_enter.

Can't find anything this is supposed to pair with.  Pretty sure this
is just an optimistic unlocked test, not actually reliant on memory
ordering.  But as it is unlocked, it needs to be coordinated with
atomic_load/store_relaxed, not ordinary loads or stores, if for no
other reason than to pacify sanitizers.

No need in vnalloc_marker or vcache_alloc because these still have
exclusive access to the vnode at that point.

XXX Should deduplicate the logic in vstate_assert_change and
vstate_change.

diffstat:

 sys/kern/vfs_vnode.c |  21 ++++++++-------------
 1 files changed, 8 insertions(+), 13 deletions(-)

diffs (58 lines):

diff -r 8e9f8aa16e89 -r 726653cbc30c sys/kern/vfs_vnode.c
--- a/sys/kern/vfs_vnode.c      Wed Feb 22 17:00:16 2023 +0000
+++ b/sys/kern/vfs_vnode.c      Wed Feb 22 21:44:21 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnode.c,v 1.147 2022/10/26 23:40:08 riastradh Exp $        */
+/*     $NetBSD: vfs_vnode.c,v 1.148 2023/02/22 21:44:21 riastradh Exp $        */
 
 /*-
  * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc.
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.147 2022/10/26 23:40:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.148 2023/02/22 21:44:21 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -269,17 +269,12 @@
        int refcnt = vrefcnt(vp);
 
        if (!has_lock) {
-               /*
-                * Prevent predictive loads from the CPU, but check the state
-                * without loooking first.
-                *
-                * XXX what does this pair with?
-                */
-               membar_enter();
+               enum vnode_state vstate = atomic_load_relaxed(&vip->vi_state);
+
                if (state == VS_ACTIVE && refcnt > 0 &&
-                   (vip->vi_state == VS_LOADED || vip->vi_state == VS_BLOCKED))
+                   (vstate == VS_LOADED || vstate == VS_BLOCKED))
                        return;
-               if (vip->vi_state == state)
+               if (vstate == state)
                        return;
                mutex_enter((vp)->v_interlock);
        }
@@ -363,7 +358,7 @@
                atomic_and_uint(&vp->v_usecount, ~VUSECOUNT_GATE);
        }
 
-       vip->vi_state = to;
+       atomic_store_relaxed(&vip->vi_state, to);
        if (from == VS_LOADING)
                cv_broadcast(&vcache_cv);
        if (to == VS_LOADED || to == VS_RECLAIMED)
@@ -409,7 +404,7 @@
                atomic_and_uint(&vp->v_usecount, ~VUSECOUNT_GATE);
        }
 
-       vip->vi_state = to;
+       atomic_store_relaxed(&vip->vi_state, to);
        if (from == VS_LOADING)
                cv_broadcast(&vcache_cv);
        if (to == VS_LOADED || to == VS_RECLAIMED)



Home | Main Index | Thread Index | Old Index