From: mpi Date: Mon, 1 Aug 2022 14:15:46 +0000 (+0000) Subject: Introduce and use uvm_pagewait() where PG_WANTED is set. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5b4619ea1bd10245593be657f96db18a630d6689;p=openbsd Introduce and use uvm_pagewait() where PG_WANTED is set. No change in behavior. ok kn@, semarie@, kettenis@ --- diff --git a/sys/uvm/uvm_amap.c b/sys/uvm/uvm_amap.c index 39c58fde83a..d2154808797 100644 --- a/sys/uvm/uvm_amap.c +++ b/sys/uvm/uvm_amap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_amap.c,v 1.90 2021/08/30 16:59:17 mpi Exp $ */ +/* $OpenBSD: uvm_amap.c,v 1.91 2022/08/01 14:15:46 mpi Exp $ */ /* $NetBSD: uvm_amap.c,v 1.27 2000/11/25 06:27:59 chs Exp $ */ /* @@ -781,9 +781,7 @@ ReStart: * it and then restart. */ if (pg->pg_flags & PG_BUSY) { - atomic_setbits_int(&pg->pg_flags, PG_WANTED); - rwsleep_nsec(pg, amap->am_lock, PVM | PNORELOCK, - "cownow", INFSLP); + uvm_pagewait(pg, amap->am_lock, "cownow"); goto ReStart; } diff --git a/sys/uvm/uvm_aobj.c b/sys/uvm/uvm_aobj.c index 1c85448f0e8..5e7098adbb2 100644 --- a/sys/uvm/uvm_aobj.c +++ b/sys/uvm/uvm_aobj.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_aobj.c,v 1.105 2022/07/24 11:00:22 mpi Exp $ */ +/* $OpenBSD: uvm_aobj.c,v 1.106 2022/08/01 14:15:46 mpi Exp $ */ /* $NetBSD: uvm_aobj.c,v 1.39 2001/02/18 21:19:08 chs Exp $ */ /* @@ -835,9 +835,8 @@ uao_detach(struct uvm_object *uobj) while ((pg = RBT_ROOT(uvm_objtree, &uobj->memt)) != NULL) { pmap_page_protect(pg, PROT_NONE); if (pg->pg_flags & PG_BUSY) { - atomic_setbits_int(&pg->pg_flags, PG_WANTED); - rwsleep_nsec(pg, uobj->vmobjlock, PVM, "uao_det", - INFSLP); + uvm_pagewait(pg, uobj->vmobjlock, "uao_det"); + rw_enter(uobj->vmobjlock, RW_WRITE); continue; } uao_dropswap(&aobj->u_obj, pg->offset >> PAGE_SHIFT); @@ -909,9 +908,8 @@ uao_flush(struct uvm_object *uobj, voff_t start, voff_t stop, int flags) /* Make sure page is unbusy, else wait for it. */ if (pg->pg_flags & PG_BUSY) { - atomic_setbits_int(&pg->pg_flags, PG_WANTED); - rwsleep_nsec(pg, uobj->vmobjlock, PVM, "uaoflsh", - INFSLP); + uvm_pagewait(pg, uobj->vmobjlock, "uaoflsh"); + rw_enter(uobj->vmobjlock, RW_WRITE); curoff -= PAGE_SIZE; continue; } @@ -1147,9 +1145,8 @@ uao_get(struct uvm_object *uobj, voff_t offset, struct vm_page **pps, /* page is there, see if we need to wait on it */ if ((ptmp->pg_flags & PG_BUSY) != 0) { - atomic_setbits_int(&ptmp->pg_flags, PG_WANTED); - rwsleep_nsec(ptmp, uobj->vmobjlock, PVM, - "uao_get", INFSLP); + uvm_pagewait(ptmp, uobj->vmobjlock, "uao_get"); + rw_enter(uobj->vmobjlock, RW_WRITE); continue; /* goto top of pps while loop */ } diff --git a/sys/uvm/uvm_km.c b/sys/uvm/uvm_km.c index 1f1396e33d8..d5dcc878466 100644 --- a/sys/uvm/uvm_km.c +++ b/sys/uvm/uvm_km.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_km.c,v 1.150 2022/06/07 12:07:45 kettenis Exp $ */ +/* $OpenBSD: uvm_km.c,v 1.151 2022/08/01 14:15:46 mpi Exp $ */ /* $NetBSD: uvm_km.c,v 1.42 2001/01/14 02:10:01 thorpej Exp $ */ /* @@ -255,9 +255,8 @@ uvm_km_pgremove(struct uvm_object *uobj, vaddr_t startva, vaddr_t endva) for (curoff = start ; curoff < end ; curoff += PAGE_SIZE) { pp = uvm_pagelookup(uobj, curoff); if (pp && pp->pg_flags & PG_BUSY) { - atomic_setbits_int(&pp->pg_flags, PG_WANTED); - rwsleep_nsec(pp, uobj->vmobjlock, PVM, "km_pgrm", - INFSLP); + uvm_pagewait(pp, uobj->vmobjlock, "km_pgrm"); + rw_enter(uobj->vmobjlock, RW_WRITE); curoff -= PAGE_SIZE; /* loop back to us */ continue; } diff --git a/sys/uvm/uvm_page.c b/sys/uvm/uvm_page.c index f4ad82de86b..4af64e2d4ca 100644 --- a/sys/uvm/uvm_page.c +++ b/sys/uvm/uvm_page.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_page.c,v 1.168 2022/07/24 11:00:22 mpi Exp $ */ +/* $OpenBSD: uvm_page.c,v 1.169 2022/08/01 14:15:46 mpi Exp $ */ /* $NetBSD: uvm_page.c,v 1.44 2000/11/27 08:40:04 chs Exp $ */ /* @@ -1087,6 +1087,23 @@ uvm_page_unbusy(struct vm_page **pgs, int npgs) } } +/* + * uvm_pagewait: wait for a busy page + * + * => page must be known PG_BUSY + * => object must be locked + * => object will be unlocked on return + */ +void +uvm_pagewait(struct vm_page *pg, struct rwlock *lock, const char *wmesg) +{ + KASSERT(rw_lock_held(lock)); + KASSERT((pg->pg_flags & PG_BUSY) != 0); + + atomic_setbits_int(&pg->pg_flags, PG_WANTED); + rwsleep_nsec(pg, lock, PVM | PNORELOCK, wmesg, INFSLP); +} + #if defined(UVM_PAGE_TRKOWN) /* * uvm_page_own: set or release page ownership diff --git a/sys/uvm/uvm_page.h b/sys/uvm/uvm_page.h index eab5cc4c6af..b70ec7d3bfb 100644 --- a/sys/uvm/uvm_page.h +++ b/sys/uvm/uvm_page.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_page.h,v 1.68 2022/05/12 12:48:36 mpi Exp $ */ +/* $OpenBSD: uvm_page.h,v 1.69 2022/08/01 14:15:46 mpi Exp $ */ /* $NetBSD: uvm_page.h,v 1.19 2000/12/28 08:24:55 chs Exp $ */ /* @@ -233,7 +233,7 @@ void uvm_pagefree(struct vm_page *); void uvm_page_unbusy(struct vm_page **, int); struct vm_page *uvm_pagelookup(struct uvm_object *, voff_t); void uvm_pageunwire(struct vm_page *); -void uvm_pagewait(struct vm_page *, int); +void uvm_pagewait(struct vm_page *, struct rwlock *, const char *); void uvm_pagewake(struct vm_page *); void uvm_pagewire(struct vm_page *); void uvm_pagezero(struct vm_page *); diff --git a/sys/uvm/uvm_vnode.c b/sys/uvm/uvm_vnode.c index b35e864670c..8c1657cbe86 100644 --- a/sys/uvm/uvm_vnode.c +++ b/sys/uvm/uvm_vnode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_vnode.c,v 1.125 2022/07/07 13:52:20 mpi Exp $ */ +/* $OpenBSD: uvm_vnode.c,v 1.126 2022/08/01 14:15:46 mpi Exp $ */ /* $NetBSD: uvm_vnode.c,v 1.36 2000/11/24 20:34:01 chs Exp $ */ /* @@ -684,11 +684,10 @@ uvn_flush(struct uvm_object *uobj, voff_t start, voff_t stop, int flags) } } else if (flags & PGO_FREE) { if (pp->pg_flags & PG_BUSY) { - atomic_setbits_int(&pp->pg_flags, - PG_WANTED); uvm_unlock_pageq(); - rwsleep_nsec(pp, uobj->vmobjlock, PVM, - "uvn_flsh", INFSLP); + uvm_pagewait(pp, uobj->vmobjlock, + "uvn_flsh"); + rw_enter(uobj->vmobjlock, RW_WRITE); uvm_lock_pageq(); curoff -= PAGE_SIZE; continue; @@ -1054,9 +1053,8 @@ uvn_get(struct uvm_object *uobj, voff_t offset, struct vm_page **pps, /* page is there, see if we need to wait on it */ if ((ptmp->pg_flags & PG_BUSY) != 0) { - atomic_setbits_int(&ptmp->pg_flags, PG_WANTED); - rwsleep_nsec(ptmp, uobj->vmobjlock, PVM, - "uvn_get", INFSLP); + uvm_pagewait(ptmp, uobj->vmobjlock, "uvn_get"); + rw_enter(uobj->vmobjlock, RW_WRITE); continue; /* goto top of pps while loop */ }