From 100162ab54da80a549e589c3b574423c3391f086 Mon Sep 17 00:00:00 2001 From: kib Date: Wed, 6 Sep 2017 16:16:11 +0000 Subject: [PATCH] In swp_pager_meta_build(), handle a race with other thread allocating swapblk for our index while we dropped the object lock. Noted by: jeff Reviewed by: alc, markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/vm/swap_pager.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index ec5f3f81e1e2..a5f064ae41e2 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -1726,7 +1726,7 @@ static void swp_pager_meta_build(vm_object_t object, vm_pindex_t pindex, daddr_t swapblk) { static volatile int swblk_zone_exhausted, swpctrie_zone_exhausted; - struct swblk *sb; + struct swblk *sb, *sb1; vm_pindex_t modpi, rdpi; int error, i; @@ -1776,6 +1776,15 @@ swp_pager_meta_build(vm_object_t object, vm_pindex_t pindex, daddr_t swapblk) } else VM_WAIT; VM_OBJECT_WLOCK(object); + sb = SWAP_PCTRIE_LOOKUP(&object->un_pager.swp.swp_blks, + rdpi); + if (sb != NULL) + /* + * Somebody swapped out a nearby page, + * allocating swblk at the rdpi index, + * while we dropped the object lock. + */ + goto allocated; } for (;;) { error = SWAP_PCTRIE_INSERT( @@ -1797,8 +1806,16 @@ swp_pager_meta_build(vm_object_t object, vm_pindex_t pindex, daddr_t swapblk) } else VM_WAIT; VM_OBJECT_WLOCK(object); + sb1 = SWAP_PCTRIE_LOOKUP(&object->un_pager.swp.swp_blks, + rdpi); + if (sb1 != NULL) { + uma_zfree(swblk_zone, sb); + sb = sb1; + goto allocated; + } } } +allocated: MPASS(sb->p == rdpi); modpi = pindex % SWAP_META_PAGES;