Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK()
authormpi <mpi@openbsd.org>
Thu, 4 Mar 2021 09:00:03 +0000 (09:00 +0000)
committermpi <mpi@openbsd.org>
Thu, 4 Mar 2021 09:00:03 +0000 (09:00 +0000)
ok kettenis@

sys/uvm/uvm_anon.c
sys/uvm/uvm_aobj.c
sys/uvm/uvm_km.c
sys/uvm/uvm_pdaemon.c
sys/uvm/uvm_swap.c
sys/uvm/uvmexp.h

index b643214..2ae8dac 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uvm_anon.c,v 1.51 2021/01/19 13:21:36 mpi Exp $       */
+/*     $OpenBSD: uvm_anon.c,v 1.52 2021/03/04 09:00:03 mpi Exp $       */
 /*     $NetBSD: uvm_anon.c,v 1.10 2000/11/25 06:27:59 chs Exp $        */
 
 /*
@@ -120,9 +120,9 @@ uvm_anfree_list(struct vm_anon *anon, struct pglist *pgl)
                }
        } else {
                if (anon->an_swslot != 0) {
-                       /* this page is no longer only in swap. */
+                       /* This page is no longer only in swap. */
                        KASSERT(uvmexp.swpgonly > 0);
-                       uvmexp.swpgonly--;
+                       atomic_dec_int(&uvmexp.swpgonly);
                }
        }
        anon->an_lock = NULL;
index 5567ec9..d6f0b8c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uvm_aobj.c,v 1.90 2021/01/11 18:51:09 mpi Exp $       */
+/*     $OpenBSD: uvm_aobj.c,v 1.91 2021/03/04 09:00:03 mpi Exp $       */
 /*     $NetBSD: uvm_aobj.c,v 1.39 2001/02/18 21:19:08 chs Exp $        */
 
 /*
@@ -381,7 +381,7 @@ uao_free(struct uvm_aobj *aobj)
                                         * this page is no longer
                                         * only in swap.
                                         */
-                                       uvmexp.swpgonly--;
+                                       atomic_dec_int(&uvmexp.swpgonly);
                                }
 
                                next = LIST_NEXT(elt, list);
@@ -400,7 +400,7 @@ uao_free(struct uvm_aobj *aobj)
                        if (slot) {
                                uvm_swap_free(slot, 1);
                                /* this page is no longer only in swap. */
-                               uvmexp.swpgonly--;
+                               atomic_dec_int(&uvmexp.swpgonly);
                        }
                }
                free(aobj->u_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int));
@@ -1549,6 +1549,6 @@ uao_dropswap_range(struct uvm_object *uobj, voff_t start, voff_t end)
         */
        if (swpgonlydelta > 0) {
                KASSERT(uvmexp.swpgonly >= swpgonlydelta);
-               uvmexp.swpgonly -= swpgonlydelta;
+               atomic_add_int(&uvmexp.swpgonly, -swpgonlydelta);
        }
 }
index 1b8c185..ba39b27 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uvm_km.c,v 1.139 2020/12/15 22:14:42 mpi Exp $        */
+/*     $OpenBSD: uvm_km.c,v 1.140 2021/03/04 09:00:03 mpi Exp $        */
 /*     $NetBSD: uvm_km.c,v 1.42 2001/01/14 02:10:01 thorpej Exp $      */
 
 /* 
@@ -242,6 +242,7 @@ uvm_km_pgremove(struct uvm_object *uobj, vaddr_t start, vaddr_t end)
        struct vm_page *pp;
        voff_t curoff;
        int slot;
+       int swpgonlydelta = 0;
 
        KASSERT(uobj->pgops == &aobj_pager);
 
@@ -262,9 +263,14 @@ uvm_km_pgremove(struct uvm_object *uobj, vaddr_t start, vaddr_t end)
                        uvm_pagefree(pp);
                        uvm_unlock_pageq();
                } else if (slot != 0) {
-                       uvmexp.swpgonly--;
+                       swpgonlydelta++;
                }
        }
+
+       if (swpgonlydelta > 0) {
+               KASSERT(uvmexp.swpgonly >= swpgonlydelta);
+               atomic_add_int(&uvmexp.swpgonly, -swpgonlydelta);
+       }
 }
 
 
index 5892059..875e820 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uvm_pdaemon.c,v 1.89 2021/03/01 09:13:33 mpi Exp $    */
+/*     $OpenBSD: uvm_pdaemon.c,v 1.90 2021/03/04 09:00:03 mpi Exp $    */
 /*     $NetBSD: uvm_pdaemon.c,v 1.23 2000/08/20 10:24:14 bjh21 Exp $   */
 
 /* 
@@ -491,7 +491,7 @@ uvmpd_scan_inactive(struct pglist *pglst)
                        if (p->pg_flags & PG_CLEAN) {
                                if (p->pg_flags & PQ_SWAPBACKED) {
                                        /* this page now lives only in swap */
-                                       uvmexp.swpgonly++;
+                                       atomic_inc_int(&uvmexp.swpgonly);
                                }
 
                                /* zap all mappings with pmap_page_protect... */
@@ -994,7 +994,7 @@ uvmpd_drop(struct pglist *pglst)
                        if (p->pg_flags & PG_CLEAN) {
                                if (p->pg_flags & PQ_SWAPBACKED) {
                                        /* this page now lives only in swap */
-                                       uvmexp.swpgonly++;
+                                       atomic_inc_int(&uvmexp.swpgonly);
                                }
 
                                /* zap all mappings with pmap_page_protect... */
index 0b5aa31..cc9786e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uvm_swap.c,v 1.148 2020/12/14 13:29:18 mpi Exp $      */
+/*     $OpenBSD: uvm_swap.c,v 1.149 2021/03/04 09:00:03 mpi Exp $      */
 /*     $NetBSD: uvm_swap.c,v 1.40 2000/11/17 11:39:39 mrg Exp $        */
 
 /*
@@ -1574,14 +1574,14 @@ uvm_swap_get(struct vm_page *page, int swslot, int flags)
 
        KERNEL_LOCK();
        /* this page is (about to be) no longer only in swap. */
-       uvmexp.swpgonly--;
+       atomic_dec_int(&uvmexp.swpgonly);
 
        result = uvm_swap_io(&page, swslot, 1, B_READ |
            ((flags & PGO_SYNCIO) ? 0 : B_ASYNC));
 
        if (result != VM_PAGER_OK && result != VM_PAGER_PEND) {
                /* oops, the read failed so it really is still only in swap. */
-               uvmexp.swpgonly++;
+               atomic_inc_int(&uvmexp.swpgonly);
        }
        KERNEL_UNLOCK();
        return (result);
index 0e3129e..9053381 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: uvmexp.h,v 1.8 2020/12/28 14:01:23 mpi Exp $  */
+/*     $OpenBSD: uvmexp.h,v 1.9 2021/03/04 09:00:03 mpi Exp $  */
 
 #ifndef        _UVM_UVMEXP_
 #define        _UVM_UVMEXP_
@@ -41,6 +41,7 @@
  * other than the vm system.
  *
  *  Locks used to protect struct members in this file:
+ *     a       atomic operations
  *     I       immutable after creation
  *     K       kernel lock
  *     F       uvm_lock_fpageq
@@ -82,7 +83,7 @@ struct uvmexp {
        int nswapdev;   /* number of configured swap devices in system */
        int swpages;    /* [K] number of PAGE_SIZE'ed swap pages */
        int swpginuse;  /* number of swap pages in use */
-       int swpgonly;   /* [K] number of swap pages in use, not also in RAM */
+       int swpgonly;   /* [a] number of swap pages in use, not also in RAM */
        int nswget;     /* number of swap pages moved from disk to RAM */
        int nanon;      /* XXX number total of anon's in system */
        int unused05;   /* formerly nanonneeded */