The branch stable/13 has been updated by mjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4bddcc418971bf21fb5e760248045f8a222a9a80

commit 4bddcc418971bf21fb5e760248045f8a222a9a80
Author:     Mateusz Guzik <m...@freebsd.org>
AuthorDate: 2023-09-16 15:41:12 +0000
Commit:     Mateusz Guzik <m...@freebsd.org>
CommitDate: 2023-10-04 12:05:58 +0000

    vfs: stabilize freevnodes_old
    
    In face of parallel callers.
    
    (cherry picked from commit ef89b78bb1f60484cc743fa590d623ad896ca8e9)
---
 sys/kern/vfs_subr.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index b125438923bf..37554858173f 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1545,21 +1545,22 @@ vfs_freevnodes_dec(void)
 static u_long
 vnlru_read_freevnodes(void)
 {
-       long slop, rfreevnodes;
+       long slop, rfreevnodes, rfreevnodes_old;
        int cpu;
 
        rfreevnodes = atomic_load_long(&freevnodes);
+       rfreevnodes_old = atomic_load_long(&freevnodes_old);
 
-       if (rfreevnodes > freevnodes_old)
-               slop = rfreevnodes - freevnodes_old;
+       if (rfreevnodes > rfreevnodes_old)
+               slop = rfreevnodes - rfreevnodes_old;
        else
-               slop = freevnodes_old - rfreevnodes;
+               slop = rfreevnodes_old - rfreevnodes;
        if (slop < VNLRU_FREEVNODES_SLOP)
                return (rfreevnodes >= 0 ? rfreevnodes : 0);
-       freevnodes_old = rfreevnodes;
        CPU_FOREACH(cpu) {
-               freevnodes_old += cpuid_to_pcpu[cpu]->pc_vfs_freevnodes;
+               rfreevnodes += cpuid_to_pcpu[cpu]->pc_vfs_freevnodes;
        }
+       atomic_store_long(&freevnodes_old, rfreevnodes);
        return (freevnodes_old >= 0 ? freevnodes_old : 0);
 }
 

Reply via email to