Index: miscfs/genfs/genfs_io.c =================================================================== RCS file: /cvsroot/src/sys/miscfs/genfs/genfs_io.c,v retrieving revision 1.88 diff -u -p -r1.88 genfs_io.c --- miscfs/genfs/genfs_io.c 27 Feb 2020 22:12:54 -0000 1.88 +++ miscfs/genfs/genfs_io.c 8 Mar 2020 18:45:41 -0000 @@ -524,9 +506,6 @@ out: if (i < ridx || i >= ridx + orignmempages || async) { UVMHIST_LOG(ubchist, "unbusy pg %#jx offset 0x%jx", (uintptr_t)pg, pg->offset,0,0); - if (pg->flags & PG_WANTED) { - wakeup(pg); - } if (pg->flags & PG_FAKE) { KASSERT(overwrite); uvm_pagezero(pg); @@ -537,8 +516,9 @@ out: } uvm_pagelock(pg); uvm_pageenqueue(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); - pg->flags &= ~(PG_WANTED|PG_BUSY|PG_FAKE); + pg->flags &= ~PG_FAKE; UVM_PAGE_OWN(pg, NULL); } else if (memwrite && !overwrite && uvm_pagegetdirty(pg) == UVM_PAGE_STATUS_CLEAN) { @@ -1095,8 +1074,7 @@ retry: continue; } nextoff = pg->offset; /* visit this page again */ - pg->flags |= PG_WANTED; - UVM_UNLOCK_AND_WAIT_RW(pg, slock, 0, "genput", 0); + uvm_pagewait(pg, slock, "genput"); /* * as we dropped the object lock, our cached pages can * be stale. Index: kern/kern_synch.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_synch.c,v retrieving revision 1.342 diff -u -p -r1.342 kern_synch.c --- kern/kern_synch.c 23 Feb 2020 16:27:09 -0000 1.342 +++ kern/kern_synch.c 8 Mar 2020 18:49:28 -0000 @@ -220,46 +221,6 @@ mtsleep(wchan_t ident, pri_t priority, c } /* - * XXXAD Temporary - for use of UVM only. PLEASE DO NOT USE ELSEWHERE. - * Will go once there is a better solution, eg waits interlocked by - * pg->interlock. To wake an LWP sleeping with this, you need to hold a - * write lock. - */ -int -rwtsleep(wchan_t ident, pri_t priority, const char *wmesg, int timo, - krwlock_t *rw) -{ - struct lwp *l = curlwp; - sleepq_t *sq; - kmutex_t *mp; - int error; - krw_t op; - - KASSERT((l->l_pflag & LP_INTR) == 0); - KASSERT(ident != &lbolt); - - if (sleepq_dontsleep(l)) { - (void)sleepq_abort(NULL, (priority & PNORELOCK) != 0); - if ((priority & PNORELOCK) != 0) - rw_exit(rw); - return 0; - } - - l->l_kpriority = true; - sq = sleeptab_lookup(&sleeptab, ident, &mp); - sleepq_enter(sq, l, mp); - sleepq_enqueue(sq, ident, wmesg, &sleep_syncobj); - op = rw_lock_op(rw); - rw_exit(rw); - error = sleepq_block(timo, priority & PCATCH); - - if ((priority & PNORELOCK) == 0) - rw_enter(rw, op); - - return error; -} - -/* * General sleep call for situations where a wake-up is not expected. */ int Index: rump/librump/rumpkern/ltsleep.c =================================================================== RCS file: /cvsroot/src/sys/rump/librump/rumpkern/ltsleep.c,v retrieving revision 1.35 diff -u -p -r1.35 ltsleep.c --- rump/librump/rumpkern/ltsleep.c 23 Feb 2020 15:46:42 -0000 1.35 +++ rump/librump/rumpkern/ltsleep.c 8 Mar 2020 18:49:29 -0000 @@ -151,21 +151,6 @@ mtsleep(wchan_t ident, pri_t prio, const return rv; } -int -rwtsleep(wchan_t ident, pri_t prio, const char *wmesg, int timo, krwlock_t *lock) -{ - krw_t op = rw_write_held(lock) ? RW_WRITER : RW_READER; - int rv; - - mutex_spin_enter(&qlock); - rw_exit(lock); - rv = sleeper(ident, timo, true); - if ((prio & PNORELOCK) == 0) - rw_enter(lock, op); - - return rv; -} - void wakeup(wchan_t ident) { Index: rump/librump/rumpkern/vm.c =================================================================== RCS file: /cvsroot/src/sys/rump/librump/rumpkern/vm.c,v retrieving revision 1.184 diff -u -p -r1.184 vm.c --- rump/librump/rumpkern/vm.c 23 Feb 2020 15:46:42 -0000 1.184 +++ rump/librump/rumpkern/vm.c 8 Mar 2020 18:45:41 -0000 @@ -213,8 +213,12 @@ uvm_pagefree(struct vm_page *pg) KASSERT(rw_write_held(uobj->vmobjlock)); - if (pg->flags & PG_WANTED) + mutex_enter(&pg->interlock); + if (pg->pqflags & PQ_WANTED) { + pg->pqflags &= ~PQ_WANTED; wakeup(pg); + } + mutex_exit(&pg->interlock); uobj->uo_npages--; pg2 = radix_tree_remove_node(&uobj->uo_pages, pg->offset >> PAGE_SHIFT); @@ -669,13 +673,44 @@ uvm_page_unbusy(struct vm_page **pgs, in continue; KASSERT(pg->flags & PG_BUSY); - if (pg->flags & PG_WANTED) + mutex_enter(&pg->interlock); + if (pg->pqflags & PQ_WANTED) { + pg->pqflags &= ~PQ_WANTED; wakeup(pg); + } + mutex_exit(&pg->interlock); if (pg->flags & PG_RELEASED) uvm_pagefree(pg); else - pg->flags &= ~(PG_WANTED|PG_BUSY); + pg->flags &= ~PG_BUSY; + } +} + +void +uvm_pagewait(struct vm_page *pg, krwlock_t *lock, const char *wmesg) +{ + + KASSERT(rw_lock_held(lock)); + KASSERT((pg->flags & PG_BUSY) != 0); + + mutex_enter(&pg->interlock); + pg->pqflags |= PQ_WANTED; + rw_exit(lock); + UVM_UNLOCK_AND_WAIT(pg, &pg->interlock, false, wmesg, 0); +} + +void +uvm_pageunbusy(struct vm_page *pg) +{ + + KASSERT((pg->flags & PG_BUSY) != 0); + KASSERT(mutex_owned(&pg->interlock)); + + if ((pg->pqflags & PQ_WANTED) != 0) { + wakeup(pg); + pg->pqflags &= ~PQ_WANTED; } + pg->flags &= ~PG_BUSY; } void Index: sys/proc.h =================================================================== RCS file: /cvsroot/src/sys/sys/proc.h,v retrieving revision 1.359 diff -u -p -r1.359 proc.h --- sys/proc.h 23 Feb 2020 15:46:42 -0000 1.359 +++ sys/proc.h 8 Mar 2020 18:45:41 -0000 @@ -513,7 +513,6 @@ void fixjobc(struct proc *, struct pgrp int tsleep(wchan_t, pri_t, const char *, int); int mtsleep(wchan_t, pri_t, const char *, int, kmutex_t *); -int rwtsleep(wchan_t, pri_t, const char *, int, krwlock_t *); void wakeup(wchan_t); int kpause(const char *, bool, int, kmutex_t *); void exit1(struct lwp *, int, int) __dead; Index: ufs/lfs/lfs_pages.c =================================================================== RCS file: /cvsroot/src/sys/ufs/lfs/lfs_pages.c,v retrieving revision 1.22 diff -u -p -r1.22 lfs_pages.c --- ufs/lfs/lfs_pages.c 23 Feb 2020 15:46:42 -0000 1.22 +++ ufs/lfs/lfs_pages.c 8 Mar 2020 18:45:41 -0000 @@ -167,8 +167,7 @@ wait_for_page(struct vnode *vp, struct v lastpg = pg; #endif - pg->flags |= PG_WANTED; - UVM_UNLOCK_AND_WAIT_RW(pg, vp->v_uobj.vmobjlock, 0, "lfsput", 0); + uvm_pagewait(pg, vp->v_uobj.vmobjlock, "lfsput"); rw_enter(vp->v_uobj.vmobjlock, RW_WRITER); } @@ -349,9 +348,9 @@ check_dirty(struct lfs *fs, struct vnode pg->flags |= PG_DELWRI; } } - if (pg->flags & PG_WANTED) - wakeup(pg); - pg->flags &= ~(PG_WANTED|PG_BUSY); + uvm_pagelock(pg); + uvm_pageunbusy(pg); + uvm_pageunlock(pg); UVM_PAGE_OWN(pg, NULL); } @@ -495,9 +495,7 @@ retry: pg = uvm_pagelookup(&vp->v_uobj, off); KASSERT(pg != NULL); while (pg->flags & PG_BUSY) { - pg->flags |= PG_WANTED; - UVM_UNLOCK_AND_WAIT_RW(pg, vp->v_uobj.vmobjlock, 0, - "lfsput2", 0); + uvm_pagewait(pg, vp->v_uobj.vmobjlock, "lfsput2"); rw_enter(vp->v_uobj.vmobjlock, RW_WRITER); } uvm_pagelock(pg); Index: ufs/lfs/lfs_vfsops.c =================================================================== RCS file: /cvsroot/src/sys/ufs/lfs/lfs_vfsops.c,v retrieving revision 1.374 diff -u -p -r1.374 lfs_vfsops.c --- ufs/lfs/lfs_vfsops.c 23 Feb 2020 15:46:42 -0000 1.374 +++ ufs/lfs/lfs_vfsops.c 8 Mar 2020 18:45:41 -0000 @@ -2277,7 +2277,6 @@ lfs_gop_write(struct vnode *vp, struct v DLOG((DLOG_PAGE, "pg[%d]->loan_count = %d\n", i, pg->loan_count)); } - /* uvm_pageunbusy takes care of PG_BUSY, PG_WANTED */ uvm_page_unbusy(pgs, npages); mutex_exit(vp->v_interlock); return EAGAIN; Index: uvm/uvm.h =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm.h,v retrieving revision 1.75 diff -u -p -r1.75 uvm.h --- uvm/uvm.h 23 Feb 2020 15:46:43 -0000 1.75 +++ uvm/uvm.h 8 Mar 2020 18:45:41 -0000 @@ -174,13 +174,6 @@ do { \ msg, timo, slock); \ } while (/*CONSTCOND*/ 0) -/* XXX temporary */ -#define UVM_UNLOCK_AND_WAIT_RW(event, slock, intr, msg, timo) \ -do { \ - (void) rwtsleep(event, PVM | PNORELOCK | (intr ? PCATCH : 0), \ - msg, timo, slock); \ -} while (/*CONSTCOND*/ 0) - void uvm_kick_pdaemon(void); /* Index: uvm/uvm_amap.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_amap.c,v retrieving revision 1.116 diff -u -p -r1.116 uvm_amap.c --- uvm/uvm_amap.c 24 Feb 2020 12:38:57 -0000 1.116 +++ uvm/uvm_amap.c 8 Mar 2020 18:45:41 -0000 @@ -1056,9 +1056,7 @@ ReStart: */ if (pg->flags & PG_BUSY) { - pg->flags |= PG_WANTED; - UVM_UNLOCK_AND_WAIT_RW(pg, amap->am_lock, false, - "cownow", 0); + uvm_pagewait(pg, amap->am_lock, "cownow"); goto ReStart; } @@ -1097,8 +1095,9 @@ ReStart: amap->am_anon[slot] = nanon; /* - * Drop PG_BUSY on new page. Since its owner was locked all - * this time - it cannot be PG_RELEASED or PG_WANTED. + * Drop PG_BUSY on new page. Since its owner was write + * locked all this time - it cannot be PG_RELEASED or + * waited on. */ uvm_pagelock(npg); uvm_pageactivate(npg); Index: uvm/uvm_anon.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_anon.c,v retrieving revision 1.74 diff -u -p -r1.74 uvm_anon.c --- uvm/uvm_anon.c 24 Feb 2020 12:38:57 -0000 1.74 +++ uvm/uvm_anon.c 8 Mar 2020 18:45:41 -0000 @@ -358,12 +358,8 @@ uvm_anon_pagein(struct vm_amap *amap, st uvm_pagelock(pg); uvm_pagedeactivate(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); - if (pg->flags & PG_WANTED) { - pg->flags &= ~PG_WANTED; - wakeup(pg); - } - rw_exit(anon->an_lock); if (uobj) { rw_exit(uobj->vmobjlock); Index: uvm/uvm_aobj.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_aobj.c,v retrieving revision 1.136 diff -u -p -r1.136 uvm_aobj.c --- uvm/uvm_aobj.c 24 Feb 2020 12:38:57 -0000 1.136 +++ uvm/uvm_aobj.c 8 Mar 2020 18:45:41 -0000 @@ -621,9 +621,7 @@ uao_detach(struct uvm_object *uobj) uvm_page_array_advance(&a); pmap_page_protect(pg, VM_PROT_NONE); if (pg->flags & PG_BUSY) { - pg->flags |= PG_WANTED; - UVM_UNLOCK_AND_WAIT_RW(pg, uobj->vmobjlock, false, - "uao_det", 0); + uvm_pagewait(pg, uobj->vmobjlock, "uao_det"); uvm_page_array_clear(&a); rw_enter(uobj->vmobjlock, RW_WRITER); continue; @@ -715,9 +713,7 @@ uao_put(struct uvm_object *uobj, voff_t */ if (pg->flags & PG_BUSY) { - pg->flags |= PG_WANTED; - UVM_UNLOCK_AND_WAIT_RW(pg, uobj->vmobjlock, 0, - "uao_put", 0); + uvm_pagewait(pg, uobj->vmobjlock, "uao_put"); uvm_page_array_clear(&a); rw_enter(uobj->vmobjlock, RW_WRITER); continue; @@ -964,12 +960,10 @@ gotpage: /* page is there, see if we need to wait on it */ if ((ptmp->flags & PG_BUSY) != 0) { - ptmp->flags |= PG_WANTED; UVMHIST_LOG(pdhist, "sleeping, ptmp->flags %#jx\n", ptmp->flags,0,0,0); - UVM_UNLOCK_AND_WAIT_RW(ptmp, uobj->vmobjlock, - false, "uao_get", 0); + uvm_pagewait(ptmp, uobj->vmobjlock, "uao_get"); rw_enter(uobj->vmobjlock, RW_WRITER); continue; } @@ -1038,8 +1032,10 @@ gotpage: if (error != 0) { UVMHIST_LOG(pdhist, "<- done (error=%jd)", error,0,0,0); - if (ptmp->flags & PG_WANTED) - wakeup(ptmp); + + uvm_pagelock(ptmp); + uvm_pageunbusy(ptmp); + uvm_pageunlock(ptmp); /* * remove the swap slot from the aobj @@ -1308,12 +1304,10 @@ uao_pagein_page(struct uvm_aobj *aobj, i */ uvm_pagelock(pg); uvm_pageenqueue(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); - if (pg->flags & PG_WANTED) { - wakeup(pg); - } - pg->flags &= ~(PG_WANTED|PG_BUSY|PG_FAKE); + pg->flags &= ~(PG_FAKE); uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_DIRTY); UVM_PAGE_OWN(pg, NULL); Index: uvm/uvm_bio.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_bio.c,v retrieving revision 1.104 diff -u -p -r1.104 uvm_bio.c --- uvm/uvm_bio.c 23 Feb 2020 15:46:43 -0000 1.104 +++ uvm/uvm_bio.c 8 Mar 2020 18:45:41 -0000 @@ -236,9 +236,6 @@ ubc_fault_page(const struct uvm_faultinf KASSERT(rw_write_held(pg->uobject->vmobjlock)); - if (pg->flags & PG_WANTED) { - wakeup(pg); - } KASSERT((pg->flags & PG_FAKE) == 0); if (pg->flags & PG_RELEASED) { uvm_pagefree(pg); @@ -286,8 +283,8 @@ ubc_fault_page(const struct uvm_faultinf uvm_pagelock(pg); uvm_pageactivate(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); - pg->flags &= ~(PG_BUSY|PG_WANTED); UVM_PAGE_OWN(pg, NULL); return error; Index: uvm/uvm_fault.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_fault.c,v retrieving revision 1.217 diff -u -p -r1.217 uvm_fault.c --- uvm/uvm_fault.c 24 Feb 2020 12:38:57 -0000 1.217 +++ uvm/uvm_fault.c 8 Mar 2020 18:45:41 -0000 @@ -329,7 +329,6 @@ uvmfault_anonget(struct uvm_faultinfo *u UVMHIST_LOG(maphist, "<- OK",0,0,0,0); return 0; } - pg->flags |= PG_WANTED; cpu_count(CPU_COUNT_FLTPGWAIT, 1); /* @@ -342,16 +341,13 @@ uvmfault_anonget(struct uvm_faultinfo *u uvmfault_unlockall(ufi, amap, NULL); UVMHIST_LOG(maphist, " unlock+wait on uobj",0, 0,0,0); - UVM_UNLOCK_AND_WAIT_RW(pg, - pg->uobject->vmobjlock, - false, "anonget1", 0); + uvm_pagewait(pg, pg->uobject->vmobjlock, "anonget1"); } else { /* Owner of page is anon. */ uvmfault_unlockall(ufi, NULL, NULL); UVMHIST_LOG(maphist, " unlock+wait on anon",0, 0,0,0); - UVM_UNLOCK_AND_WAIT_RW(pg, anon->an_lock, - false, "anonget2", 0); + uvm_pagewait(pg, anon->an_lock, "anonget2"); } } else { #if defined(VMSWAP) @@ -420,9 +416,6 @@ uvmfault_anonget(struct uvm_faultinfo *u if (we_own) { #if defined(VMSWAP) - if (pg->flags & PG_WANTED) { - wakeup(pg); - } if (error) { /* @@ -486,8 +479,9 @@ released: uvm_pagelock(pg); uvm_pageactivate(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); - pg->flags &= ~(PG_WANTED|PG_BUSY|PG_FAKE); + pg->flags &= ~PG_FAKE; uvm_pagemarkdirty(pg, UVM_PAGE_STATUS_UNKNOWN); UVM_PAGE_OWN(pg, NULL); #else @@ -1745,7 +1739,7 @@ uvm_fault_lower( * - at this point uobjpage can not be NULL * - at this point uobjpage can not be PG_RELEASED (since we checked * for it above) - * - at this point uobjpage could be PG_WANTED (handle later) + * - at this point uobjpage could be waited on (handle later) */ KASSERT(uobjpage != NULL); @@ -1858,12 +1852,11 @@ uvm_fault_lower_neighbor( * Since this page isn't the page that's actually faulting, * ignore pmap_enter() failures; it's not critical that we * enter these right now. - * NOTE: page can't be PG_WANTED or PG_RELEASED because we've + * NOTE: page can't be PG_RELEASED because we've * held the lock the whole time we've had the handle. */ KASSERT((pg->flags & PG_PAGEOUT) == 0); KASSERT((pg->flags & PG_RELEASED) == 0); - KASSERT((pg->flags & PG_WANTED) == 0); KASSERT(!UVM_OBJ_IS_CLEAN(pg->uobject) || uvm_pagegetdirty(pg) == UVM_PAGE_STATUS_CLEAN); pg->flags &= ~(PG_BUSY); @@ -1995,11 +1988,10 @@ uvm_fault_lower_io( UVMHIST_LOG(maphist, " wasn't able to relock after fault: retry", 0,0,0,0); - if (pg->flags & PG_WANTED) { - wakeup(pg); - } if ((pg->flags & PG_RELEASED) == 0) { - pg->flags &= ~(PG_BUSY | PG_WANTED); + uvm_pagelock(pg); + uvm_pageunbusy(pg); + uvm_pageunlock(pg); UVM_PAGE_OWN(pg, NULL); } else { cpu_count(CPU_COUNT_FLTPGRELE, 1); @@ -2100,9 +2092,9 @@ uvm_fault_lower_direct_loan( * drop ownership of page, it can't be released */ - if (uobjpage->flags & PG_WANTED) - wakeup(uobjpage); - uobjpage->flags &= ~(PG_BUSY|PG_WANTED); + uvm_pagelock(uobjpage); + uvm_pageunbusy(uobjpage); + uvm_pageunlock(uobjpage); UVM_PAGE_OWN(uobjpage, NULL); uvmfault_unlockall(ufi, amap, uobj); @@ -2182,11 +2174,9 @@ uvm_fault_lower_promote( * since we still hold the object lock. */ - if (uobjpage->flags & PG_WANTED) { - /* still have the obj lock */ - wakeup(uobjpage); - } - uobjpage->flags &= ~(PG_BUSY|PG_WANTED); + uvm_pagelock(uobjpage); + uvm_pageunbusy(uobjpage); + uvm_pageunlock(uobjpage); UVM_PAGE_OWN(uobjpage, NULL); UVMHIST_LOG(maphist, @@ -2274,18 +2264,16 @@ uvm_fault_lower_enter( uvm_pagelock(pg); uvm_pageenqueue(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); - if (pg->flags & PG_WANTED) - wakeup(pg); - /* * note that pg can't be PG_RELEASED since we did not drop * the object lock since the last time we checked. */ KASSERT((pg->flags & PG_RELEASED) == 0); - pg->flags &= ~(PG_BUSY|PG_FAKE|PG_WANTED); + pg->flags &= ~PG_FAKE; UVM_PAGE_OWN(pg, NULL); uvmfault_unlockall(ufi, amap, uobj); @@ -2308,9 +2296,10 @@ uvm_fault_lower_enter( * lock since the last time we checked. */ KASSERT((pg->flags & PG_RELEASED) == 0); - if (pg->flags & PG_WANTED) - wakeup(pg); - pg->flags &= ~(PG_BUSY|PG_FAKE|PG_WANTED); + uvm_pagelock(pg); + uvm_pageunbusy(pg); + uvm_pageunlock(pg); + pg->flags &= ~PG_FAKE; UVM_PAGE_OWN(pg, NULL); pmap_update(ufi->orig_map->pmap); Index: uvm/uvm_km.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_km.c,v retrieving revision 1.156 diff -u -p -r1.156 uvm_km.c --- uvm/uvm_km.c 24 Feb 2020 12:38:57 -0000 1.156 +++ uvm/uvm_km.c 8 Mar 2020 18:45:41 -0000 @@ -456,9 +456,7 @@ uvm_km_pgremove(vaddr_t startva, vaddr_t nextoff = curoff + PAGE_SIZE; pg = uvm_pagelookup(uobj, curoff); if (pg != NULL && pg->flags & PG_BUSY) { - pg->flags |= PG_WANTED; - UVM_UNLOCK_AND_WAIT_RW(pg, uobj->vmobjlock, 0, - "km_pgrm", 0); + uvm_pagewait(pg, uobj->vmobjlock, "km_pgrm"); rw_enter(uobj->vmobjlock, RW_WRITER); nextoff = curoff; continue; @@ -569,7 +567,7 @@ uvm_km_check_empty(struct vm_map *map, v * - we can recurse when allocating radix_node for * kernel_object. */ - if (rw_tryenter(uvm_kernel_object->vmobjlock, RW_WRITER)) { + if (rw_tryenter(uvm_kernel_object->vmobjlock, RW_READER)) { struct vm_page *pg; pg = uvm_pagelookup(uvm_kernel_object, Index: uvm/uvm_loan.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_loan.c,v retrieving revision 1.96 diff -u -p -r1.96 uvm_loan.c --- uvm/uvm_loan.c 24 Feb 2020 21:06:11 -0000 1.96 +++ uvm/uvm_loan.c 8 Mar 2020 18:45:41 -0000 @@ -705,9 +705,6 @@ uvm_loanuobj(struct uvm_faultinfo *ufi, */ if (locked == false) { - if (pg->flags & PG_WANTED) { - wakeup(pg); - } if (pg->flags & PG_RELEASED) { uvm_pagefree(pg); rw_exit(uobj->vmobjlock); @@ -715,8 +712,8 @@ uvm_loanuobj(struct uvm_faultinfo *ufi, } uvm_pagelock(pg); uvm_pageactivate(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); - pg->flags &= ~(PG_BUSY|PG_WANTED); UVM_PAGE_OWN(pg, NULL); rw_exit(uobj->vmobjlock); return (0); @@ -754,10 +751,9 @@ uvm_loanuobj(struct uvm_faultinfo *ufi, /* XXX: locking */ anon = pg->uanon; anon->an_ref++; - if (pg->flags & PG_WANTED) { - wakeup(pg); - } - pg->flags &= ~(PG_WANTED|PG_BUSY); + uvm_pagelock(pg); + uvm_pageunbusy(pg); + uvm_pageunlock(pg); UVM_PAGE_OWN(pg, NULL); rw_exit(uobj->vmobjlock); **output = anon; @@ -787,11 +783,8 @@ uvm_loanuobj(struct uvm_faultinfo *ufi, anon->an_page = pg; anon->an_lock = /* TODO: share amap lock */ uvm_pageactivate(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); - if (pg->flags & PG_WANTED) { - wakeup(pg); - } - pg->flags &= ~(PG_WANTED|PG_BUSY); UVM_PAGE_OWN(pg, NULL); rw_exit(uobj->vmobjlock); rw_exit(&anon->an_lock); @@ -804,10 +797,9 @@ fail: /* * unlock everything and bail out. */ - if (pg->flags & PG_WANTED) { - wakeup(pg); - } - pg->flags &= ~(PG_WANTED|PG_BUSY); + uvm_pagelock(pg); + uvm_pageunbusy(pg); + uvm_pageunlock(pg); UVM_PAGE_OWN(pg, NULL); uvmfault_unlockall(ufi, amap, uobj, NULL); if (anon) { @@ -863,10 +855,11 @@ again: } /* got a zero'd page. */ - pg->flags &= ~(PG_WANTED|PG_BUSY|PG_FAKE); + pg->flags &= ~PG_FAKE; pg->flags |= PG_RDONLY; uvm_pagelock(pg); uvm_pageactivate(pg); + uvm_pageunbusy(pg); uvm_pageunlock(pg); UVM_PAGE_OWN(pg, NULL); } @@ -1133,10 +1126,7 @@ uvm_loanbreak(struct vm_page *uobjpage) pg->flags &= ~PG_FAKE; KASSERT(uvm_pagegetdirty(pg) == UVM_PAGE_STATUS_DIRTY); pmap_page_protect(uobjpage, VM_PROT_NONE); - if (uobjpage->flags & PG_WANTED) - wakeup(uobjpage); /* uobj still locked */ - uobjpage->flags &= ~(PG_WANTED|PG_BUSY); UVM_PAGE_OWN(uobjpage, NULL); /* @@ -1146,6 +1136,7 @@ uvm_loanbreak(struct vm_page *uobjpage) */ uvm_pagelock2(uobjpage, pg); + uvm_pageunbusy(uobjpage); if (uobjpage->uanon == NULL) uvm_pagedequeue(uobjpage); Index: uvm/uvm_page.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_page.c,v retrieving revision 1.230 diff -u -p -r1.230 uvm_page.c --- uvm/uvm_page.c 3 Mar 2020 08:13:44 -0000 1.230 +++ uvm/uvm_page.c 8 Mar 2020 18:45:41 -0000 @@ -1572,10 +1572,11 @@ uvm_pagefree(struct vm_page *pg) pg->uanon->an_page = NULL; pg->uanon = NULL; } - if (pg->flags & PG_WANTED) { + if (pg->pqflags & PQ_WANTED) { wakeup(pg); } - pg->flags &= ~(PG_WANTED|PG_BUSY|PG_RELEASED|PG_PAGER1); + pg->pqflags &= ~PQ_WANTED; + pg->flags &= ~(PG_BUSY|PG_RELEASED|PG_PAGER1); #ifdef UVM_PAGE_TRKOWN pg->owner_tag = NULL; #endif @@ -1621,6 +1622,14 @@ uvm_pagefree(struct vm_page *pg) } if (locked) { /* + * wake anyone waiting on the page. + */ + if ((pg->pqflags & PQ_WANTED) != 0) { + pg->pqflags &= ~PQ_WANTED; + wakeup(pg); + } + + /* * now remove the page from the queues. */ uvm_pagedequeue(pg); @@ -1691,10 +1700,6 @@ uvm_page_unbusy(struct vm_page **pgs, in KASSERT(uvm_page_owner_locked_p(pg, true)); KASSERT(pg->flags & PG_BUSY); KASSERT((pg->flags & PG_PAGEOUT) == 0); - if (pg->flags & PG_WANTED) { - /* XXXAD thundering herd problem. */ - wakeup(pg); - } if (pg->flags & PG_RELEASED) { UVMHIST_LOG(ubchist, "releasing pg %#jx", (uintptr_t)pg, 0, 0, 0); @@ -1706,12 +1711,59 @@ uvm_page_unbusy(struct vm_page **pgs, in UVMHIST_LOG(ubchist, "unbusying pg %#jx", (uintptr_t)pg, 0, 0, 0); KASSERT((pg->flags & PG_FAKE) == 0); - pg->flags &= ~(PG_WANTED|PG_BUSY); + uvm_pagelock(pg); + uvm_pageunbusy(pg); + uvm_pageunlock(pg); UVM_PAGE_OWN(pg, NULL); } } } +/* + * uvm_pagewait: wait for a busy page + * + * => page must be known PG_BUSY + * => object must be read or write locked + * => object will be unlocked on return + */ + +void +uvm_pagewait(struct vm_page *pg, krwlock_t *lock, const char *wmesg) +{ + + KASSERT(rw_lock_held(lock)); + KASSERT((pg->flags & PG_BUSY) != 0); + KASSERT(uvm_page_owner_locked_p(pg, false)); + + mutex_enter(&pg->interlock); + pg->pqflags |= PQ_WANTED; + rw_exit(lock); + UVM_UNLOCK_AND_WAIT(pg, &pg->interlock, false, wmesg, 0); +} + +/* + * uvm_pageunbusy: unbusy a single page + * + * => page must be known PG_BUSY + * => object must be write locked + * => page interlock must be held + */ + +void +uvm_pageunbusy(struct vm_page *pg) +{ + + KASSERT((pg->flags & PG_BUSY) != 0); + KASSERT(uvm_page_owner_locked_p(pg, true)); + KASSERT(mutex_owned(&pg->interlock)); + + if ((pg->pqflags & PQ_WANTED) != 0) { + wakeup(pg); + pg->pqflags &= ~PQ_WANTED; + } + pg->flags &= ~PG_BUSY; +} + #if defined(UVM_PAGE_TRKOWN) /* * uvm_page_own: set or release page ownership @@ -1727,7 +1779,6 @@ uvm_page_own(struct vm_page *pg, const c { KASSERT((pg->flags & (PG_PAGEOUT|PG_RELEASED)) == 0); - KASSERT((pg->flags & PG_WANTED) == 0); KASSERT(uvm_page_owner_locked_p(pg, true)); /* gain ownership? */ Index: uvm/uvm_page.h =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_page.h,v retrieving revision 1.99 diff -u -p -r1.99 uvm_page.h --- uvm/uvm_page.h 6 Mar 2020 02:46:17 -0000 1.99 +++ uvm/uvm_page.h 8 Mar 2020 18:45:41 -0000 @@ -209,13 +209,8 @@ struct vm_page { * PG_BUSY: * Page is long-term locked, usually because of I/O (transfer from the * page memory to the backing store) is in progress. LWP attempting - * to access the page shall set PG_WANTED and wait. - * - * PG_WANTED: - * Indicates that the page, which is currently PG_BUSY, is wanted by - * some other LWP. The page owner (i.e. LWP which set PG_BUSY) is - * responsible to clear both flags and wake up any waiters once it has - * released the long-term lock (PG_BUSY). + * to access the page shall set PQ_WANTED and wait. PG_BUSY may only + * be set with a write lock held on the object. * * PG_PAGEOUT: * Indicates that the page is being paged-out in preparation for @@ -251,7 +246,6 @@ struct vm_page { #define PG_CLEAN 0x00000001 /* page is known clean */ #define PG_DIRTY 0x00000002 /* page is known dirty */ #define PG_BUSY 0x00000004 /* page is locked */ -#define PG_WANTED 0x00000008 /* someone is waiting for page */ #define PG_PAGEOUT 0x00000010 /* page to be freed for pagedaemon */ #define PG_RELEASED 0x00000020 /* page to be freed when unbusied */ #define PG_FAKE 0x00000040 /* page is not yet initialized */ @@ -272,7 +266,7 @@ struct vm_page { #define PG_SWAPBACKED (PG_ANON|PG_AOBJ) #define UVM_PGFLAGBITS \ - "\20\1CLEAN\2DIRTY\3BUSY\4WANTED" \ + "\20\1CLEAN\2DIRTY\3BUSY" \ "\5PAGEOUT\6RELEASED\7FAKE\10RDONLY" \ "\11ZERO\12TABLED\13AOBJ\14ANON" \ "\15FILE\16READAHEAD\17FREE\20MARKER" \ @@ -281,7 +275,21 @@ struct vm_page { /* * Flags stored in pg->pqflags, which is protected by pg->interlock. * - * PQ_PRIVATE is for uvmpdpol to do whatever it wants with. + * PQ_PRIVATE: + * ... is for uvmpdpol to do whatever it wants with. + * + * PQ_INTENT_SET: + * Indicates that the intent set on the page has not yet been realized. + * + * PQ_INTENT_QUEUED: + * Indicates that the page is, or will soon be, on a per-CPU queue for + * the intent to be realized. + * + * PQ_WANTED: + * Indicates that the page, which is currently PG_BUSY, is wanted by + * some other LWP. The page owner (i.e. LWP which set PG_BUSY) is + * responsible to clear both flags and wake up any waiters once it has + * released the long-term lock (PG_BUSY). */ #define PQ_INTENT_A 0x00000000 /* intend activation */ @@ -292,11 +300,13 @@ struct vm_page { #define PQ_INTENT_SET 0x00000004 /* not realized yet */ #define PQ_INTENT_QUEUED 0x00000008 /* queued for processing */ #define PQ_PRIVATE 0x00000ff0 /* private for pdpolicy */ +#define PQ_WANTED 0x00001000 /* someone is waiting for page */ #define UVM_PQFLAGBITS \ "\20\1INTENT_0\2INTENT_1\3INTENT_SET\4INTENT_QUEUED" \ "\5PRIVATE1\6PRIVATE2\7PRIVATE3\10PRIVATE4" \ - "\11PRIVATE5\12PRIVATE6\13PRIVATE7\14PRIVATE8" + "\11PRIVATE5\12PRIVATE6\13PRIVATE7\14PRIVATE8" \ + "\15WANTED" /* * physical memory layout structure @@ -363,6 +373,8 @@ void uvm_pagemarkdirty(struct vm_page *, bool uvm_pagecheckdirty(struct vm_page *, bool); bool uvm_pagereadonly_p(struct vm_page *); bool uvm_page_locked_p(struct vm_page *); +void uvm_pageunbusy(struct vm_page *); +void uvm_pagewait(struct vm_page *, krwlock_t *, const char *); int uvm_page_lookup_freelist(struct vm_page *); Index: uvm/uvm_vnode.c =================================================================== RCS file: /cvsroot/src/sys/uvm/uvm_vnode.c,v retrieving revision 1.108 diff -u -p -r1.108 uvm_vnode.c --- uvm/uvm_vnode.c 3 Mar 2020 13:32:44 -0000 1.108 +++ uvm/uvm_vnode.c 8 Mar 2020 18:45:41 -0000 @@ -335,11 +356,9 @@ uvn_findpage(struct uvm_object *uobj, vo UVMHIST_LOG(ubchist, "nowait",0,0,0,0); goto skip; } - pg->flags |= PG_WANTED; UVMHIST_LOG(ubchist, "wait %#jx (color %ju)", (uintptr_t)pg, VM_PGCOLOR(pg), 0, 0); - UVM_UNLOCK_AND_WAIT_RW(pg, uobj->vmobjlock, 0, - "uvnfp2", 0); + uvm_pagewait(pg, uobj->vmobjlock, "uvnfp2"); uvm_page_array_clear(a); rw_enter(uobj->vmobjlock, RW_WRITER); continue;