From c4a864ba38a189859dcf0af4cf9fb01aabd6a92c Mon Sep 17 00:00:00 2001 From: mpi Date: Thu, 4 Mar 2021 09:00:03 +0000 Subject: [PATCH] Modify `uvmexp.swpgonly' atomically, required for uvm_fault() w/o KERNEL_LOCK() ok kettenis@ --- sys/uvm/uvm_anon.c | 6 +++--- sys/uvm/uvm_aobj.c | 8 ++++---- sys/uvm/uvm_km.c | 10 ++++++++-- sys/uvm/uvm_pdaemon.c | 6 +++--- sys/uvm/uvm_swap.c | 6 +++--- sys/uvm/uvmexp.h | 5 +++-- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/sys/uvm/uvm_anon.c b/sys/uvm/uvm_anon.c index b64321410da..2ae8dacc482 100644 --- a/sys/uvm/uvm_anon.c +++ b/sys/uvm/uvm_anon.c @@ -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; diff --git a/sys/uvm/uvm_aobj.c b/sys/uvm/uvm_aobj.c index 5567ec9773a..d6f0b8cb597 100644 --- a/sys/uvm/uvm_aobj.c +++ b/sys/uvm/uvm_aobj.c @@ -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); } } diff --git a/sys/uvm/uvm_km.c b/sys/uvm/uvm_km.c index 1b8c1857f27..ba39b274d10 100644 --- a/sys/uvm/uvm_km.c +++ b/sys/uvm/uvm_km.c @@ -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); + } } diff --git a/sys/uvm/uvm_pdaemon.c b/sys/uvm/uvm_pdaemon.c index 5892059354a..875e82056cc 100644 --- a/sys/uvm/uvm_pdaemon.c +++ b/sys/uvm/uvm_pdaemon.c @@ -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... */ diff --git a/sys/uvm/uvm_swap.c b/sys/uvm/uvm_swap.c index 0b5aa3191c2..cc9786e482e 100644 --- a/sys/uvm/uvm_swap.c +++ b/sys/uvm/uvm_swap.c @@ -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); diff --git a/sys/uvm/uvmexp.h b/sys/uvm/uvmexp.h index 0e3129e3513..90533813dff 100644 --- a/sys/uvm/uvmexp.h +++ b/sys/uvm/uvmexp.h @@ -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 */ -- 2.20.1