Skip to content

Commit 11bc82d

Browse files
aarcange-rhtorvalds
authored andcommitted
mm: compaction: Use async migration for __GFP_NO_KSWAPD and enforce no writeback
__GFP_NO_KSWAPD allocations are usually very expensive and not mandatory to succeed as they have graceful fallback. Waiting for I/O in those, tends to be overkill in terms of latencies, so we can reduce their latency by disabling sync migrate. Unfortunately, even with async migration it's still possible for the process to be blocked waiting for a request slot (e.g. get_request_wait in the block layer) when ->writepage is called. To prevent __GFP_NO_KSWAPD blocking, this patch prevents ->writepage being called on dirty page cache for asynchronous migration. Addresses https://bugzilla.kernel.org/show_bug.cgi?id=31142 [mel@csn.ul.ie: Avoid writebacks for NFS, retry locked pages, use bool] Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Mel Gorman <mel@csn.ul.ie> Cc: Arthur Marsh <arthur.marsh@internode.on.net> Cc: Clemens Ladisch <cladisch@googlemail.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Minchan Kim <minchan.kim@gmail.com> Reported-by: Alex Villacis Lasso <avillaci@ceibo.fiec.espol.edu.ec> Tested-by: Alex Villacis Lasso <avillaci@ceibo.fiec.espol.edu.ec> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b2eef8c commit 11bc82d

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

‎mm/migrate.c‎

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ static int fallback_migrate_page(struct address_space *mapping,
564564
* == 0 - success
565565
*/
566566
static int move_to_new_page(struct page *newpage, struct page *page,
567-
int remap_swapcache)
567+
int remap_swapcache, bool sync)
568568
{
569569
struct address_space *mapping;
570570
int rc;
@@ -586,18 +586,28 @@ static int move_to_new_page(struct page *newpage, struct page *page,
586586
mapping = page_mapping(page);
587587
if (!mapping)
588588
rc = migrate_page(mapping, newpage, page);
589-
else if (mapping->a_ops->migratepage)
589+
else {
590590
/*
591-
* Most pages have a mapping and most filesystems
592-
* should provide a migration function. Anonymous
593-
* pages are part of swap space which also has its
594-
* own migration function. This is the most common
595-
* path for page migration.
591+
* Do not writeback pages if !sync and migratepage is
592+
* not pointing to migrate_page() which is nonblocking
593+
* (swapcache/tmpfs uses migratepage = migrate_page).
596594
*/
597-
rc = mapping->a_ops->migratepage(mapping,
598-
newpage, page);
599-
else
600-
rc = fallback_migrate_page(mapping, newpage, page);
595+
if (PageDirty(page) && !sync &&
596+
mapping->a_ops->migratepage != migrate_page)
597+
rc = -EBUSY;
598+
else if (mapping->a_ops->migratepage)
599+
/*
600+
* Most pages have a mapping and most filesystems
601+
* should provide a migration function. Anonymous
602+
* pages are part of swap space which also has its
603+
* own migration function. This is the most common
604+
* path for page migration.
605+
*/
606+
rc = mapping->a_ops->migratepage(mapping,
607+
newpage, page);
608+
else
609+
rc = fallback_migrate_page(mapping, newpage, page);
610+
}
601611

602612
if (rc) {
603613
newpage->mapping = NULL;
@@ -641,7 +651,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
641651
rc = -EAGAIN;
642652

643653
if (!trylock_page(page)) {
644-
if (!force)
654+
if (!force || !sync)
645655
goto move_newpage;
646656

647657
/*
@@ -686,7 +696,15 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
686696
BUG_ON(charge);
687697

688698
if (PageWriteback(page)) {
689-
if (!force || !sync)
699+
/*
700+
* For !sync, there is no point retrying as the retry loop
701+
* is expected to be too short for PageWriteback to be cleared
702+
*/
703+
if (!sync) {
704+
rc = -EBUSY;
705+
goto uncharge;
706+
}
707+
if (!force)
690708
goto uncharge;
691709
wait_on_page_writeback(page);
692710
}
@@ -757,7 +775,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
757775

758776
skip_unmap:
759777
if (!page_mapped(page))
760-
rc = move_to_new_page(newpage, page, remap_swapcache);
778+
rc = move_to_new_page(newpage, page, remap_swapcache, sync);
761779

762780
if (rc && remap_swapcache)
763781
remove_migration_ptes(page, page);
@@ -850,7 +868,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
850868
try_to_unmap(hpage, TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS);
851869

852870
if (!page_mapped(hpage))
853-
rc = move_to_new_page(new_hpage, hpage, 1);
871+
rc = move_to_new_page(new_hpage, hpage, 1, sync);
854872

855873
if (rc)
856874
remove_migration_ptes(hpage, hpage);

‎mm/page_alloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
21032103
sync_migration);
21042104
if (page)
21052105
goto got_pg;
2106-
sync_migration = true;
2106+
sync_migration = !(gfp_mask & __GFP_NO_KSWAPD);
21072107

21082108
/* Try direct reclaim and then allocating */
21092109
page = __alloc_pages_direct_reclaim(gfp_mask, order,

0 commit comments

Comments
 (0)