mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-09 23:39:18 +00:00
mm: migrate: simplify the logic for handling permanent failure
When unmap_and_move{_huge_page}() returns !-EAGAIN and !MIGRATEPAGE_SUCCESS, the page would be put back to LRU or proper list if it is non-LRU movable page. But, the callers always call putback_movable_pages() to put the failed pages back later on, so it seems not very efficient to put every single page back immediately, and the code looks convoluted. Put the failed page on a separate list, then splice the list to migrate list when all pages are tried. It is the caller's responsibility to call putback_movable_pages() to handle failures. This also makes the code simpler and more readable. After the change the rules are: * Success: non hugetlb page will be freed, hugetlb page will be put back * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list * Other errno: put on ret_pages list then splice to from list The from list would be empty iff all pages are migrated successfully, it was not so before. This has no impact to current existing callsites. Link: https://lkml.kernel.org/r/20201113205359.556831-3-shy828301@gmail.com Signed-off-by: Yang Shi <shy828301@gmail.com> Reviewed-by: Zi Yan <ziy@nvidia.com> Cc: Jan Kara <jack@suse.cz> Cc: Matthew Wilcox <willy@infradead.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Michal Hocko <mhocko@suse.com> Cc: Song Liu <songliubraving@fb.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
d12b8951ad
commit
dd4ae78a21
72
mm/migrate.c
72
mm/migrate.c
@ -1168,7 +1168,8 @@ static int unmap_and_move(new_page_t get_new_page,
|
|||||||
free_page_t put_new_page,
|
free_page_t put_new_page,
|
||||||
unsigned long private, struct page *page,
|
unsigned long private, struct page *page,
|
||||||
int force, enum migrate_mode mode,
|
int force, enum migrate_mode mode,
|
||||||
enum migrate_reason reason)
|
enum migrate_reason reason,
|
||||||
|
struct list_head *ret)
|
||||||
{
|
{
|
||||||
int rc = MIGRATEPAGE_SUCCESS;
|
int rc = MIGRATEPAGE_SUCCESS;
|
||||||
struct page *newpage = NULL;
|
struct page *newpage = NULL;
|
||||||
@ -1205,15 +1206,6 @@ out:
|
|||||||
* migrated will have kept its references and be restored.
|
* migrated will have kept its references and be restored.
|
||||||
*/
|
*/
|
||||||
list_del(&page->lru);
|
list_del(&page->lru);
|
||||||
|
|
||||||
/*
|
|
||||||
* Compaction can migrate also non-LRU pages which are
|
|
||||||
* not accounted to NR_ISOLATED_*. They can be recognized
|
|
||||||
* as __PageMovable
|
|
||||||
*/
|
|
||||||
if (likely(!__PageMovable(page)))
|
|
||||||
mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON +
|
|
||||||
page_is_file_lru(page), -thp_nr_pages(page));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1222,27 +1214,24 @@ out:
|
|||||||
* we want to retry.
|
* we want to retry.
|
||||||
*/
|
*/
|
||||||
if (rc == MIGRATEPAGE_SUCCESS) {
|
if (rc == MIGRATEPAGE_SUCCESS) {
|
||||||
|
/*
|
||||||
|
* Compaction can migrate also non-LRU pages which are
|
||||||
|
* not accounted to NR_ISOLATED_*. They can be recognized
|
||||||
|
* as __PageMovable
|
||||||
|
*/
|
||||||
|
if (likely(!__PageMovable(page)))
|
||||||
|
mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON +
|
||||||
|
page_is_file_lru(page), -thp_nr_pages(page));
|
||||||
|
|
||||||
if (reason != MR_MEMORY_FAILURE)
|
if (reason != MR_MEMORY_FAILURE)
|
||||||
/*
|
/*
|
||||||
* We release the page in page_handle_poison.
|
* We release the page in page_handle_poison.
|
||||||
*/
|
*/
|
||||||
put_page(page);
|
put_page(page);
|
||||||
} else {
|
} else {
|
||||||
if (rc != -EAGAIN) {
|
if (rc != -EAGAIN)
|
||||||
if (likely(!__PageMovable(page))) {
|
list_add_tail(&page->lru, ret);
|
||||||
putback_lru_page(page);
|
|
||||||
goto put_new;
|
|
||||||
}
|
|
||||||
|
|
||||||
lock_page(page);
|
|
||||||
if (PageMovable(page))
|
|
||||||
putback_movable_page(page);
|
|
||||||
else
|
|
||||||
__ClearPageIsolated(page);
|
|
||||||
unlock_page(page);
|
|
||||||
put_page(page);
|
|
||||||
}
|
|
||||||
put_new:
|
|
||||||
if (put_new_page)
|
if (put_new_page)
|
||||||
put_new_page(newpage, private);
|
put_new_page(newpage, private);
|
||||||
else
|
else
|
||||||
@ -1273,7 +1262,8 @@ put_new:
|
|||||||
static int unmap_and_move_huge_page(new_page_t get_new_page,
|
static int unmap_and_move_huge_page(new_page_t get_new_page,
|
||||||
free_page_t put_new_page, unsigned long private,
|
free_page_t put_new_page, unsigned long private,
|
||||||
struct page *hpage, int force,
|
struct page *hpage, int force,
|
||||||
enum migrate_mode mode, int reason)
|
enum migrate_mode mode, int reason,
|
||||||
|
struct list_head *ret)
|
||||||
{
|
{
|
||||||
int rc = -EAGAIN;
|
int rc = -EAGAIN;
|
||||||
int page_was_mapped = 0;
|
int page_was_mapped = 0;
|
||||||
@ -1289,7 +1279,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page,
|
|||||||
* kicking migration.
|
* kicking migration.
|
||||||
*/
|
*/
|
||||||
if (!hugepage_migration_supported(page_hstate(hpage))) {
|
if (!hugepage_migration_supported(page_hstate(hpage))) {
|
||||||
putback_active_hugepage(hpage);
|
list_move_tail(&hpage->lru, ret);
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1374,8 +1364,10 @@ put_anon:
|
|||||||
out_unlock:
|
out_unlock:
|
||||||
unlock_page(hpage);
|
unlock_page(hpage);
|
||||||
out:
|
out:
|
||||||
if (rc != -EAGAIN)
|
if (rc == MIGRATEPAGE_SUCCESS)
|
||||||
putback_active_hugepage(hpage);
|
putback_active_hugepage(hpage);
|
||||||
|
else if (rc != -EAGAIN && rc != MIGRATEPAGE_SUCCESS)
|
||||||
|
list_move_tail(&hpage->lru, ret);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If migration was not successful and there's a freeing callback, use
|
* If migration was not successful and there's a freeing callback, use
|
||||||
@ -1406,8 +1398,8 @@ out:
|
|||||||
*
|
*
|
||||||
* The function returns after 10 attempts or if no pages are movable any more
|
* The function returns after 10 attempts or if no pages are movable any more
|
||||||
* because the list has become empty or no retryable pages exist any more.
|
* because the list has become empty or no retryable pages exist any more.
|
||||||
* The caller should call putback_movable_pages() to return pages to the LRU
|
* It is caller's responsibility to call putback_movable_pages() to return pages
|
||||||
* or free list only if ret != 0.
|
* to the LRU or free list only if ret != 0.
|
||||||
*
|
*
|
||||||
* Returns the number of pages that were not migrated, or an error code.
|
* Returns the number of pages that were not migrated, or an error code.
|
||||||
*/
|
*/
|
||||||
@ -1428,6 +1420,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
|
|||||||
struct page *page2;
|
struct page *page2;
|
||||||
int swapwrite = current->flags & PF_SWAPWRITE;
|
int swapwrite = current->flags & PF_SWAPWRITE;
|
||||||
int rc, nr_subpages;
|
int rc, nr_subpages;
|
||||||
|
LIST_HEAD(ret_pages);
|
||||||
|
|
||||||
if (!swapwrite)
|
if (!swapwrite)
|
||||||
current->flags |= PF_SWAPWRITE;
|
current->flags |= PF_SWAPWRITE;
|
||||||
@ -1450,12 +1443,21 @@ retry:
|
|||||||
if (PageHuge(page))
|
if (PageHuge(page))
|
||||||
rc = unmap_and_move_huge_page(get_new_page,
|
rc = unmap_and_move_huge_page(get_new_page,
|
||||||
put_new_page, private, page,
|
put_new_page, private, page,
|
||||||
pass > 2, mode, reason);
|
pass > 2, mode, reason,
|
||||||
|
&ret_pages);
|
||||||
else
|
else
|
||||||
rc = unmap_and_move(get_new_page, put_new_page,
|
rc = unmap_and_move(get_new_page, put_new_page,
|
||||||
private, page, pass > 2, mode,
|
private, page, pass > 2, mode,
|
||||||
reason);
|
reason, &ret_pages);
|
||||||
|
/*
|
||||||
|
* The rules are:
|
||||||
|
* Success: non hugetlb page will be freed, hugetlb
|
||||||
|
* page will be put back
|
||||||
|
* -EAGAIN: stay on the from list
|
||||||
|
* -ENOMEM: stay on the from list
|
||||||
|
* Other errno: put on ret_pages list then splice to
|
||||||
|
* from list
|
||||||
|
*/
|
||||||
switch(rc) {
|
switch(rc) {
|
||||||
case -ENOMEM:
|
case -ENOMEM:
|
||||||
/*
|
/*
|
||||||
@ -1521,6 +1523,12 @@ retry:
|
|||||||
nr_thp_failed += thp_retry;
|
nr_thp_failed += thp_retry;
|
||||||
rc = nr_failed;
|
rc = nr_failed;
|
||||||
out:
|
out:
|
||||||
|
/*
|
||||||
|
* Put the permanent failure page back to migration list, they
|
||||||
|
* will be put back to the right list by the caller.
|
||||||
|
*/
|
||||||
|
list_splice(&ret_pages, from);
|
||||||
|
|
||||||
count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
|
count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded);
|
||||||
count_vm_events(PGMIGRATE_FAIL, nr_failed);
|
count_vm_events(PGMIGRATE_FAIL, nr_failed);
|
||||||
count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded);
|
count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user