Commit 7ca8783a authored by Wei Yang's avatar Wei Yang Committed by Linus Torvalds

mm/migrate.c: wrap do_move_pages_to_node() and store_status()

Usually, do_move_pages_to_node() and store_status() are used in
combination.  We have three similar call sites.

Let's provide a wrapper for both function calls -
move_pages_and_store_status - to make the calling code easier to maintain
and fix (as noted by Yang Shi, the return value handling of
do_move_pages_to_node() has a flaw).

[david@redhat.com rephrase changelog]
Signed-off-by: default avatarWei Yang <richardw.yang@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarDavid Hildenbrand <david@redhat.com>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Link: http://lkml.kernel.org/r/20200214003017.25558-3-richardw.yang@linux.intel.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4afdacec
...@@ -1602,6 +1602,29 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, ...@@ -1602,6 +1602,29 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr,
return err; return err;
} }
static int move_pages_and_store_status(struct mm_struct *mm, int node,
struct list_head *pagelist, int __user *status,
int start, int i, unsigned long nr_pages)
{
int err;
err = do_move_pages_to_node(mm, pagelist, node);
if (err) {
/*
* Positive err means the number of failed
* pages to migrate. Since we are going to
* abort and return the number of non-migrated
* pages, so need to incude the rest of the
* nr_pages that have not been attempted as
* well.
*/
if (err > 0)
err += nr_pages - i - 1;
return err;
}
return store_status(status, start, node, i - start);
}
/* /*
* Migrate an array of page address onto an array of nodes and fill * Migrate an array of page address onto an array of nodes and fill
* the corresponding array of status. * the corresponding array of status.
...@@ -1645,21 +1668,8 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, ...@@ -1645,21 +1668,8 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
current_node = node; current_node = node;
start = i; start = i;
} else if (node != current_node) { } else if (node != current_node) {
err = do_move_pages_to_node(mm, &pagelist, current_node); err = move_pages_and_store_status(mm, current_node,
if (err) { &pagelist, status, start, i, nr_pages);
/*
* Positive err means the number of failed
* pages to migrate. Since we are going to
* abort and return the number of non-migrated
* pages, so need to incude the rest of the
* nr_pages that have not been attempted as
* well.
*/
if (err > 0)
err += nr_pages - i - 1;
goto out;
}
err = store_status(status, start, current_node, i - start);
if (err) if (err)
goto out; goto out;
start = i; start = i;
...@@ -1688,13 +1698,8 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, ...@@ -1688,13 +1698,8 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
if (err) if (err)
goto out_flush; goto out_flush;
err = do_move_pages_to_node(mm, &pagelist, current_node); err = move_pages_and_store_status(mm, current_node, &pagelist,
if (err) { status, start, i, nr_pages);
if (err > 0)
err += nr_pages - i - 1;
goto out;
}
err = store_status(status, start, current_node, i - start);
if (err) if (err)
goto out; goto out;
current_node = NUMA_NO_NODE; current_node = NUMA_NO_NODE;
...@@ -1704,16 +1709,8 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes, ...@@ -1704,16 +1709,8 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,
return err; return err;
/* Make sure we do not overwrite the existing error */ /* Make sure we do not overwrite the existing error */
err1 = do_move_pages_to_node(mm, &pagelist, current_node); err1 = move_pages_and_store_status(mm, current_node, &pagelist,
/* status, start, i, nr_pages);
* Don't have to report non-attempted pages here since:
* - If the above loop is done gracefully all pages have been
* attempted.
* - If the above loop is aborted it means a fatal error
* happened, should return ret.
*/
if (!err1)
err1 = store_status(status, start, current_node, i - start);
if (err >= 0) if (err >= 0)
err = err1; err = err1;
out: out:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment