Index: sys/vm/swap_pager.c =================================================================== --- sys/vm/swap_pager.c +++ sys/vm/swap_pager.c @@ -424,6 +424,11 @@ static int swapoff_one(struct swdevt *sp, struct ucred *cred); /* + * Swap swdevt functions + */ +static bool swp_swdevt_available(struct swdevt *sp, int npages); + +/* * Swap bitmap functions */ static void swp_pager_freeswapspace(daddr_t blk, daddr_t npages); @@ -734,6 +739,16 @@ object->type = OBJT_DEAD; } +static bool +swp_swdevt_available(struct swdevt *sp, int npages) +{ + + if (sp->sw_flags & SW_CLOSING) + return (false); + return (sp->sw_nblks - howmany(BBSIZE, PAGE_SIZE) - sp->sw_used >= + npages ); +} + /************************************************************************ * SWAP PAGER BITMAP ROUTINES * ************************************************************************/ @@ -768,7 +783,7 @@ while (!TAILQ_EMPTY(&swtailq)) { if (sp == NULL) sp = TAILQ_FIRST(&swtailq); - if ((sp->sw_flags & SW_CLOSING) == 0) + if (swp_swdevt_available(sp, npages)) blk = blist_alloc(sp->sw_blist, &npages, mpages); if (blk != SWAPBLK_NONE) break;