From a3a61e4ffea7f5d87b792e02917d0acb134e36fd Mon Sep 17 00:00:00 2001 From: mpi Date: Thu, 12 May 2022 12:48:36 +0000 Subject: [PATCH] Introduce uvm_pagedequeue() to reduce code duplication. ok kettenis@ --- sys/uvm/uvm_page.c | 60 ++++++++++++++++++---------------------------- sys/uvm/uvm_page.h | 3 ++- 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/sys/uvm/uvm_page.c b/sys/uvm/uvm_page.c index 03e1299784a..0523a5e11a8 100644 --- a/sys/uvm/uvm_page.c +++ b/sys/uvm/uvm_page.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_page.c,v 1.165 2022/05/04 14:58:26 mpi Exp $ */ +/* $OpenBSD: uvm_page.c,v 1.166 2022/05/12 12:48:36 mpi Exp $ */ /* $NetBSD: uvm_page.c,v 1.44 2000/11/27 08:40:04 chs Exp $ */ /* @@ -987,16 +987,7 @@ uvm_pageclean(struct vm_page *pg) /* * now remove the page from the queues */ - if (pg->pg_flags & PQ_ACTIVE) { - TAILQ_REMOVE(&uvm.page_active, pg, pageq); - flags_to_clear |= PQ_ACTIVE; - uvmexp.active--; - } - if (pg->pg_flags & PQ_INACTIVE) { - TAILQ_REMOVE(&uvm.page_inactive, pg, pageq); - flags_to_clear |= PQ_INACTIVE; - uvmexp.inactive--; - } + uvm_pagedequeue(pg); /* * if the page was wired, unwire it now. @@ -1243,16 +1234,7 @@ uvm_pagewire(struct vm_page *pg) MUTEX_ASSERT_LOCKED(&uvm.pageqlock); if (pg->wire_count == 0) { - if (pg->pg_flags & PQ_ACTIVE) { - TAILQ_REMOVE(&uvm.page_active, pg, pageq); - atomic_clearbits_int(&pg->pg_flags, PQ_ACTIVE); - uvmexp.active--; - } - if (pg->pg_flags & PQ_INACTIVE) { - TAILQ_REMOVE(&uvm.page_inactive, pg, pageq); - atomic_clearbits_int(&pg->pg_flags, PQ_INACTIVE); - uvmexp.inactive--; - } + uvm_pagedequeue(pg); uvmexp.wired++; } pg->wire_count++; @@ -1324,28 +1306,32 @@ uvm_pageactivate(struct vm_page *pg) KASSERT(uvm_page_owner_locked_p(pg)); MUTEX_ASSERT_LOCKED(&uvm.pageqlock); + uvm_pagedequeue(pg); + if (pg->wire_count == 0) { + TAILQ_INSERT_TAIL(&uvm.page_active, pg, pageq); + atomic_setbits_int(&pg->pg_flags, PQ_ACTIVE); + uvmexp.active++; + + } +} + +/* + * uvm_pagedequeue: remove a page from any paging queue + */ +void +uvm_pagedequeue(struct vm_page *pg) +{ + if (pg->pg_flags & PQ_ACTIVE) { + TAILQ_REMOVE(&uvm.page_active, pg, pageq); + atomic_clearbits_int(&pg->pg_flags, PQ_ACTIVE); + uvmexp.active--; + } if (pg->pg_flags & PQ_INACTIVE) { TAILQ_REMOVE(&uvm.page_inactive, pg, pageq); atomic_clearbits_int(&pg->pg_flags, PQ_INACTIVE); uvmexp.inactive--; } - if (pg->wire_count == 0) { - /* - * if page is already active, remove it from list so we - * can put it at tail. if it wasn't active, then mark - * it active and bump active count - */ - if (pg->pg_flags & PQ_ACTIVE) - TAILQ_REMOVE(&uvm.page_active, pg, pageq); - else { - atomic_setbits_int(&pg->pg_flags, PQ_ACTIVE); - uvmexp.active++; - } - - TAILQ_INSERT_TAIL(&uvm.page_active, pg, pageq); - } } - /* * uvm_pagezero: zero fill a page */ diff --git a/sys/uvm/uvm_page.h b/sys/uvm/uvm_page.h index e1f1016b71f..eab5cc4c6af 100644 --- a/sys/uvm/uvm_page.h +++ b/sys/uvm/uvm_page.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_page.h,v 1.67 2022/01/29 06:25:33 aoyama Exp $ */ +/* $OpenBSD: uvm_page.h,v 1.68 2022/05/12 12:48:36 mpi Exp $ */ /* $NetBSD: uvm_page.h,v 1.19 2000/12/28 08:24:55 chs Exp $ */ /* @@ -224,6 +224,7 @@ boolean_t uvm_page_physget(paddr_t *); #endif void uvm_pageactivate(struct vm_page *); +void uvm_pagedequeue(struct vm_page *); vaddr_t uvm_pageboot_alloc(vsize_t); void uvm_pagecopy(struct vm_page *, struct vm_page *); void uvm_pagedeactivate(struct vm_page *); -- 2.20.1