Index: swap_pager.c =================================================================== --- swap_pager.c +++ swap_pager.c @@ -1678,6 +1678,9 @@ /* * SWP_PAGER_FORCE_PAGEIN() - force a swap block to be paged in * + * Returns the number of pages that are paged in. The maximum number of + * pages this function can page in at a time is SWB_NPAGES. + * * This routine dissociates the page at the given index within an object * from its backing store, paging it in if it does not reside in memory. * If the page is paged in, it is marked dirty and placed in the laundry @@ -1688,36 +1691,41 @@ * We also attempt to swap in all other pages in the swap block. * However, we only guarantee that the one at the specified index is * paged in. - * - * XXX - The code to page the whole block in doesn't work, so we - * revert to the one-by-one behavior for now. Sigh. */ -static void +static int swp_pager_force_pagein(vm_object_t object, vm_pindex_t pindex) { - vm_page_t m; + vm_page_t ma[SWB_NPAGES]; + int i, j, npages; - vm_object_pip_add(object, 1); - m = vm_page_grab(object, pindex, VM_ALLOC_NORMAL); - if (m->valid == VM_PAGE_BITS_ALL) { - vm_object_pip_wakeup(object); - swp_pager_force_dirty(m); - vm_pager_page_unswapped(m); - return; + if (swap_pager_haspage(object, pindex, NULL, &npages)) + npages += 1; /* plus the current page */ + else + npages = 1; /* we didn't find extra pages to page in together */ + npages = vm_page_grab_pages(object, pindex, VM_ALLOC_NORMAL, ma, + npages); + vm_object_pip_add(object, npages); + for (i = j = 0;; i++) { + if (i < npages && ma[i]->valid != VM_PAGE_BITS_ALL) + continue; + if (j < i && swap_pager_getpages(object, &ma[j], i - j, NULL, + NULL) != VM_PAGER_OK) + panic("swp_pager_force_pagein: read from swap failed " + "for page %p", ma[i]); + while (j < i) + swp_pager_force_launder(ma[j++]); + if (i == npages) + break; + swp_pager_force_dirty(ma[j++]); } - - if (swap_pager_getpages(object, &m, 1, NULL, NULL) != VM_PAGER_OK) - panic("swap_pager_force_pagein: read from swap failed");/*XXX*/ - vm_object_pip_wakeup(object); - swp_pager_force_launder(m); - vm_pager_page_unswapped(m); + return (npages); } /* * swap_pager_swapoff_object: * * Page in all of the pages that have been paged out for an object - * from a given swap device. + * from a swap device. */ static void swap_pager_swapoff_object(struct swdevt *sp, vm_object_t object) @@ -1726,16 +1734,25 @@ vm_pindex_t pi; int i; - for (pi = 0; (sb = SWAP_PCTRIE_LOOKUP_GE( - &object->un_pager.swp.swp_blks, pi)) != NULL; ) { + for (pi = 0, i = 0; (sb = SWAP_PCTRIE_LOOKUP_GE( + &object->un_pager.swp.swp_blks, pi)) != NULL; + i %= SWAP_META_PAGES) { pi = sb->p + SWAP_META_PAGES; - for (i = 0; i < SWAP_META_PAGES; i++) { - if (sb->d[i] == SWAPBLK_NONE) - continue; - if (swp_pager_isondev(sb->d[i], sp)) - swp_pager_force_pagein(object, sb->p + i); + /* + * A single swp_pager_force_pagein() call can + * page-in more than pages on a sb->d[] array. + * If last page-in handled more than a sb->d[] block, + * we skip blocks and advance to the next one. + */ + while (i < SWAP_META_PAGES) { + if (swp_pager_isondev(sb->d[i], sp)) { + i += swp_pager_force_pagein(object, + sb->p + i); + } else + i++; } } + KASSERT(i == 0, ("Paged-in %d more pages than we had known", i)); } /*