Introduce a new helper to check global variables that will need to be protected from concurrent access.
The name is taken from NetBSD in order to reduce the difference between our trees. Diff below introduces a syntax change in uvmpd_scan() where the boolean test "<" becomes "!=". This shouldn't matter because `uvmexp.swpgonly' must always be smaller than `uvmexp.swpages'. Ok? Index: uvm/uvm_fault.c =================================================================== RCS file: /cvs/src/sys/uvm/uvm_fault.c,v retrieving revision 1.101 diff -u -p -r1.101 uvm_fault.c --- uvm/uvm_fault.c 24 Sep 2020 09:51:07 -0000 1.101 +++ uvm/uvm_fault.c 25 Sep 2020 08:28:51 -0000 @@ -881,7 +881,6 @@ ReFault: /* check for out of RAM */ if (anon == NULL || pg == NULL) { uvmfault_unlockall(&ufi, amap, NULL, oanon); - KASSERT(uvmexp.swpgonly <= uvmexp.swpages); if (anon == NULL) uvmexp.fltnoanon++; else { @@ -889,7 +888,7 @@ ReFault: uvmexp.fltnoram++; } - if (uvmexp.swpgonly == uvmexp.swpages) + if (uvm_swapisfull()) return (ENOMEM); /* out of RAM, wait for more */ @@ -942,8 +941,7 @@ ReFault: * as the map may change while we're asleep. */ uvmfault_unlockall(&ufi, amap, NULL, oanon); - KASSERT(uvmexp.swpgonly <= uvmexp.swpages); - if (uvmexp.swpgonly == uvmexp.swpages) { + if (uvm_swapisfull()) { /* XXX instrumentation */ return (ENOMEM); } @@ -1137,7 +1135,6 @@ Case2: /* unlock and fail ... */ uvmfault_unlockall(&ufi, amap, uobj, NULL); - KASSERT(uvmexp.swpgonly <= uvmexp.swpages); if (anon == NULL) uvmexp.fltnoanon++; else { @@ -1145,7 +1142,7 @@ Case2: uvmexp.fltnoram++; } - if (uvmexp.swpgonly == uvmexp.swpages) + if (uvm_swapisfull()) return (ENOMEM); /* out of RAM, wait for more */ @@ -1191,11 +1188,10 @@ Case2: if (amap_add(&ufi.entry->aref, ufi.orig_rvaddr - ufi.entry->start, anon, 0)) { uvmfault_unlockall(&ufi, amap, NULL, oanon); - KASSERT(uvmexp.swpgonly <= uvmexp.swpages); uvm_anfree(anon); uvmexp.fltnoamap++; - if (uvmexp.swpgonly == uvmexp.swpages) + if (uvm_swapisfull()) return (ENOMEM); amap_populate(&ufi.entry->aref, @@ -1225,8 +1221,7 @@ Case2: atomic_clearbits_int(&pg->pg_flags, PG_BUSY|PG_FAKE|PG_WANTED); UVM_PAGE_OWN(pg, NULL); uvmfault_unlockall(&ufi, amap, uobj, NULL); - KASSERT(uvmexp.swpgonly <= uvmexp.swpages); - if (uvmexp.swpgonly == uvmexp.swpages) { + if (uvm_swapisfull()) { /* XXX instrumentation */ return (ENOMEM); } Index: uvm/uvm_pdaemon.c =================================================================== RCS file: /cvs/src/sys/uvm/uvm_pdaemon.c,v retrieving revision 1.86 diff -u -p -r1.86 uvm_pdaemon.c --- uvm/uvm_pdaemon.c 4 Apr 2020 22:08:02 -0000 1.86 +++ uvm/uvm_pdaemon.c 25 Sep 2020 08:28:52 -0000 @@ -522,9 +522,7 @@ uvmpd_scan_inactive(struct pglist *pglst * reactivate it so that we eventually cycle * all pages thru the inactive queue. */ - KASSERT(uvmexp.swpgonly <= uvmexp.swpages); - if ((p->pg_flags & PQ_SWAPBACKED) && - uvmexp.swpgonly == uvmexp.swpages) { + if ((p->pg_flags & PQ_SWAPBACKED) && uvm_swapisfull()) { dirtyreacts++; uvm_pageactivate(p); continue; @@ -879,7 +877,7 @@ uvmpd_scan(void) swap_shortage = 0; if (uvmexp.free < uvmexp.freetarg && uvmexp.swpginuse == uvmexp.swpages && - uvmexp.swpgonly < uvmexp.swpages && + !uvm_swapisfull() && pages_freed == 0) { swap_shortage = uvmexp.freetarg - uvmexp.free; } Index: uvm/uvm_swap.c =================================================================== RCS file: /cvs/src/sys/uvm/uvm_swap.c,v retrieving revision 1.146 diff -u -p -r1.146 uvm_swap.c --- uvm/uvm_swap.c 20 Jan 2020 23:21:57 -0000 1.146 +++ uvm/uvm_swap.c 25 Sep 2020 08:28:52 -0000 @@ -1441,6 +1441,21 @@ ReTry: /* XXXMRG */ } /* + * uvm_swapisfull: return true if all of available swap is allocated + * and in use. + */ +int +uvm_swapisfull(void) +{ + int result; + + KASSERT(uvmexp.swpgonly <= uvmexp.swpages); + result = (uvmexp.swpgonly == uvmexp.swpages); + + return result; +} + +/* * uvm_swap_markbad: keep track of swap ranges where we've had i/o errors * * => we lock uvm.swap_data_lock Index: uvm/uvm_swap.h =================================================================== RCS file: /cvs/src/sys/uvm/uvm_swap.h,v retrieving revision 1.17 diff -u -p -r1.17 uvm_swap.h --- uvm/uvm_swap.h 5 Dec 2019 12:46:54 -0000 1.17 +++ uvm/uvm_swap.h 25 Sep 2020 08:28:52 -0000 @@ -41,6 +41,7 @@ int uvm_swap_put(int, struct vm_page * int uvm_swap_alloc(int *, boolean_t); void uvm_swap_free(int, int); void uvm_swap_markbad(int, int); +int uvm_swapisfull(void); void uvm_swap_freepages(struct vm_page **, int); #ifdef HIBERNATE int uvm_hibswap(dev_t, u_long *, u_long *);