Skip to content

Commit c661b07

Browse files
awhitcroftLinus Torvalds
authored andcommitted
synchronous lumpy reclaim: wait for page writeback when directly reclaiming contiguous areas
Lumpy reclaim works by selecting a lead page from the LRU list and then selecting pages for reclaim from the order-aligned area of pages. In the situation were all pages in that region are inactive and not referenced by any process over time, it works well. In the situation where there is even light load on the system, the pages may not free quickly. Out of a area of 1024 pages, maybe only 950 of them are freed when the allocation attempt occurs because lumpy reclaim returned early. This patch alters the behaviour of direct reclaim for large contiguous blocks. The first attempt to call shrink_page_list() is asynchronous but if it fails, the pages are submitted a second time and the calling process waits for the IO to complete. This may stall allocators waiting for contiguous memory but that should be expected behaviour for high-order users. It is preferable behaviour to potentially queueing unnecessary areas for IO. Note that kswapd will not stall in this fashion. [apw@shadowen.org: update to version 2] [apw@shadowen.org: update to version 3] Signed-off-by: Mel Gorman <mel@csn.ul.ie> Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e9187bd commit c661b07

1 file changed

Lines changed: 60 additions & 8 deletions

File tree

‎mm/vmscan.c‎

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ static void handle_write_error(struct address_space *mapping,
271271
unlock_page(page);
272272
}
273273

274+
/* Request for sync pageout. */
275+
enum pageout_io {
276+
PAGEOUT_IO_ASYNC,
277+
PAGEOUT_IO_SYNC,
278+
};
279+
274280
/* possible outcome of pageout() */
275281
typedef enum {
276282
/* failed to write page out, page is locked */
@@ -287,7 +293,8 @@ typedef enum {
287293
* pageout is called by shrink_page_list() for each dirty page.
288294
* Calls ->writepage().
289295
*/
290-
static pageout_t pageout(struct page *page, struct address_space *mapping)
296+
static pageout_t pageout(struct page *page, struct address_space *mapping,
297+
enum pageout_io sync_writeback)
291298
{
292299
/*
293300
* If the page is dirty, only perform writeback if that write
@@ -346,6 +353,15 @@ static pageout_t pageout(struct page *page, struct address_space *mapping)
346353
ClearPageReclaim(page);
347354
return PAGE_ACTIVATE;
348355
}
356+
357+
/*
358+
* Wait on writeback if requested to. This happens when
359+
* direct reclaiming a large contiguous area and the
360+
* first attempt to free a range of pages fails.
361+
*/
362+
if (PageWriteback(page) && sync_writeback == PAGEOUT_IO_SYNC)
363+
wait_on_page_writeback(page);
364+
349365
if (!PageWriteback(page)) {
350366
/* synchronous write or broken a_ops? */
351367
ClearPageReclaim(page);
@@ -423,7 +439,8 @@ int remove_mapping(struct address_space *mapping, struct page *page)
423439
* shrink_page_list() returns the number of reclaimed pages
424440
*/
425441
static unsigned long shrink_page_list(struct list_head *page_list,
426-
struct scan_control *sc)
442+
struct scan_control *sc,
443+
enum pageout_io sync_writeback)
427444
{
428445
LIST_HEAD(ret_pages);
429446
struct pagevec freed_pvec;
@@ -458,8 +475,23 @@ static unsigned long shrink_page_list(struct list_head *page_list,
458475
if (page_mapped(page) || PageSwapCache(page))
459476
sc->nr_scanned++;
460477

461-
if (PageWriteback(page))
462-
goto keep_locked;
478+
may_enter_fs = (sc->gfp_mask & __GFP_FS) ||
479+
(PageSwapCache(page) && (sc->gfp_mask & __GFP_IO));
480+
481+
if (PageWriteback(page)) {
482+
/*
483+
* Synchronous reclaim is performed in two passes,
484+
* first an asynchronous pass over the list to
485+
* start parallel writeback, and a second synchronous
486+
* pass to wait for the IO to complete. Wait here
487+
* for any page for which writeback has already
488+
* started.
489+
*/
490+
if (sync_writeback == PAGEOUT_IO_SYNC && may_enter_fs)
491+
wait_on_page_writeback(page);
492+
else
493+
goto keep_locked;
494+
}
463495

464496
referenced = page_referenced(page, 1);
465497
/* In active use or really unfreeable? Activate it. */
@@ -478,8 +510,6 @@ static unsigned long shrink_page_list(struct list_head *page_list,
478510
#endif /* CONFIG_SWAP */
479511

480512
mapping = page_mapping(page);
481-
may_enter_fs = (sc->gfp_mask & __GFP_FS) ||
482-
(PageSwapCache(page) && (sc->gfp_mask & __GFP_IO));
483513

484514
/*
485515
* The page is mapped into the page tables of one or more
@@ -505,7 +535,7 @@ static unsigned long shrink_page_list(struct list_head *page_list,
505535
goto keep_locked;
506536

507537
/* Page is dirty, try to write it out here */
508-
switch(pageout(page, mapping)) {
538+
switch (pageout(page, mapping, sync_writeback)) {
509539
case PAGE_KEEP:
510540
goto keep_locked;
511541
case PAGE_ACTIVATE:
@@ -786,7 +816,29 @@ static unsigned long shrink_inactive_list(unsigned long max_scan,
786816
spin_unlock_irq(&zone->lru_lock);
787817

788818
nr_scanned += nr_scan;
789-
nr_freed = shrink_page_list(&page_list, sc);
819+
nr_freed = shrink_page_list(&page_list, sc, PAGEOUT_IO_ASYNC);
820+
821+
/*
822+
* If we are direct reclaiming for contiguous pages and we do
823+
* not reclaim everything in the list, try again and wait
824+
* for IO to complete. This will stall high-order allocations
825+
* but that should be acceptable to the caller
826+
*/
827+
if (nr_freed < nr_taken && !current_is_kswapd() &&
828+
sc->order > PAGE_ALLOC_COSTLY_ORDER) {
829+
congestion_wait(WRITE, HZ/10);
830+
831+
/*
832+
* The attempt at page out may have made some
833+
* of the pages active, mark them inactive again.
834+
*/
835+
nr_active = clear_active_flags(&page_list);
836+
count_vm_events(PGDEACTIVATE, nr_active);
837+
838+
nr_freed += shrink_page_list(&page_list, sc,
839+
PAGEOUT_IO_SYNC);
840+
}
841+
790842
nr_reclaimed += nr_freed;
791843
local_irq_disable();
792844
if (current_is_kswapd()) {

0 commit comments

Comments
 (0)