git: 54291f7d6506 - main - swap_pager: Reduce the scope of the object lock in putpages

From: Alan Cox <alc_at_FreeBSD.org>
Date: Tue, 19 Jul 2022 03:36:19 UTC
The branch main has been updated by alc:

URL: https://cgit.FreeBSD.org/src/commit/?id=54291f7d6506e6c6087433c5bbdb2224b6cef23b

commit 54291f7d6506e6c6087433c5bbdb2224b6cef23b
Author:     Alan Cox <alc@FreeBSD.org>
AuthorDate: 2022-07-19 03:28:07 +0000
Commit:     Alan Cox <alc@FreeBSD.org>
CommitDate: 2022-07-19 03:35:49 +0000

    swap_pager: Reduce the scope of the object lock in putpages
    
    We don't need to hold the object lock while allocating swap space, so
    don't.
    
    Reviewed by:    dougm, kib, markj
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D35839
---
 sys/vm/swap_pager.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c
index c20360975c4b..67cc3bf017d2 100644
--- a/sys/vm/swap_pager.c
+++ b/sys/vm/swap_pager.c
@@ -1506,10 +1506,8 @@ swap_pager_putpages(vm_object_t object, vm_page_t *ma, int count,
 		}
 
 		/* Get a block of swap of size up to size n. */
-		VM_OBJECT_WLOCK(object);
 		blk = swp_pager_getswapspace(&n);
 		if (blk == SWAPBLK_NONE) {
-			VM_OBJECT_WUNLOCK(object);
 			mtx_lock(&swbuf_mtx);
 			if (++nsw_wcount_async == 1)
 				wakeup(&nsw_wcount_async);
@@ -1518,6 +1516,7 @@ swap_pager_putpages(vm_object_t object, vm_page_t *ma, int count,
 				rtvals[i + j] = VM_PAGER_FAIL;
 			continue;
 		}
+		VM_OBJECT_WLOCK(object);
 		for (j = 0; j < n; ++j) {
 			mreq = ma[i + j];
 			vm_page_aflag_clear(mreq, PGA_SWAP_FREE);