mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-01 12:04:08 +00:00
mm: extract do_pages_move() out of sys_move_pages()
To prepare the chunking, move the sys_move_pages() code that is used when nodes!=NULL into do_pages_move(). And rename do_move_pages() into do_move_page_to_node_array(). Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr> Acked-by: Christoph Lameter <cl@linux-foundation.org> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
2f007e74bb
commit
5e9a0f023b
1 changed files with 86 additions and 66 deletions
148
mm/migrate.c
148
mm/migrate.c
|
@ -826,8 +826,10 @@ static struct page *new_page_node(struct page *p, unsigned long private,
|
||||||
* Move a set of pages as indicated in the pm array. The addr
|
* Move a set of pages as indicated in the pm array. The addr
|
||||||
* field must be set to the virtual address of the page to be moved
|
* field must be set to the virtual address of the page to be moved
|
||||||
* and the node number must contain a valid target node.
|
* and the node number must contain a valid target node.
|
||||||
|
* The pm array ends with node = MAX_NUMNODES.
|
||||||
*/
|
*/
|
||||||
static int do_move_pages(struct mm_struct *mm, struct page_to_node *pm,
|
static int do_move_page_to_node_array(struct mm_struct *mm,
|
||||||
|
struct page_to_node *pm,
|
||||||
int migrate_all)
|
int migrate_all)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -905,6 +907,81 @@ set_status:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Migrate an array of page address onto an array of nodes and fill
|
||||||
|
* the corresponding array of status.
|
||||||
|
*/
|
||||||
|
static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
|
||||||
|
unsigned long nr_pages,
|
||||||
|
const void __user * __user *pages,
|
||||||
|
const int __user *nodes,
|
||||||
|
int __user *status, int flags)
|
||||||
|
{
|
||||||
|
struct page_to_node *pm = NULL;
|
||||||
|
nodemask_t task_nodes;
|
||||||
|
int err = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
task_nodes = cpuset_mems_allowed(task);
|
||||||
|
|
||||||
|
/* Limit nr_pages so that the multiplication may not overflow */
|
||||||
|
if (nr_pages >= ULONG_MAX / sizeof(struct page_to_node) - 1) {
|
||||||
|
err = -E2BIG;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
pm = vmalloc((nr_pages + 1) * sizeof(struct page_to_node));
|
||||||
|
if (!pm) {
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get parameters from user space and initialize the pm
|
||||||
|
* array. Return various errors if the user did something wrong.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < nr_pages; i++) {
|
||||||
|
const void __user *p;
|
||||||
|
|
||||||
|
err = -EFAULT;
|
||||||
|
if (get_user(p, pages + i))
|
||||||
|
goto out_pm;
|
||||||
|
|
||||||
|
pm[i].addr = (unsigned long)p;
|
||||||
|
if (nodes) {
|
||||||
|
int node;
|
||||||
|
|
||||||
|
if (get_user(node, nodes + i))
|
||||||
|
goto out_pm;
|
||||||
|
|
||||||
|
err = -ENODEV;
|
||||||
|
if (!node_state(node, N_HIGH_MEMORY))
|
||||||
|
goto out_pm;
|
||||||
|
|
||||||
|
err = -EACCES;
|
||||||
|
if (!node_isset(node, task_nodes))
|
||||||
|
goto out_pm;
|
||||||
|
|
||||||
|
pm[i].node = node;
|
||||||
|
} else
|
||||||
|
pm[i].node = 0; /* anything to not match MAX_NUMNODES */
|
||||||
|
}
|
||||||
|
/* End marker */
|
||||||
|
pm[nr_pages].node = MAX_NUMNODES;
|
||||||
|
|
||||||
|
err = do_move_page_to_node_array(mm, pm, flags & MPOL_MF_MOVE_ALL);
|
||||||
|
if (err >= 0)
|
||||||
|
/* Return status information */
|
||||||
|
for (i = 0; i < nr_pages; i++)
|
||||||
|
if (put_user(pm[i].status, status + i))
|
||||||
|
err = -EFAULT;
|
||||||
|
|
||||||
|
out_pm:
|
||||||
|
vfree(pm);
|
||||||
|
out:
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine the nodes of an array of pages and store it in an array of status.
|
* Determine the nodes of an array of pages and store it in an array of status.
|
||||||
*/
|
*/
|
||||||
|
@ -963,12 +1040,9 @@ asmlinkage long sys_move_pages(pid_t pid, unsigned long nr_pages,
|
||||||
const int __user *nodes,
|
const int __user *nodes,
|
||||||
int __user *status, int flags)
|
int __user *status, int flags)
|
||||||
{
|
{
|
||||||
int err = 0;
|
|
||||||
int i;
|
|
||||||
struct task_struct *task;
|
struct task_struct *task;
|
||||||
nodemask_t task_nodes;
|
|
||||||
struct mm_struct *mm;
|
struct mm_struct *mm;
|
||||||
struct page_to_node *pm = NULL;
|
int err;
|
||||||
|
|
||||||
/* Check flags */
|
/* Check flags */
|
||||||
if (flags & ~(MPOL_MF_MOVE|MPOL_MF_MOVE_ALL))
|
if (flags & ~(MPOL_MF_MOVE|MPOL_MF_MOVE_ALL))
|
||||||
|
@ -1000,75 +1074,21 @@ asmlinkage long sys_move_pages(pid_t pid, unsigned long nr_pages,
|
||||||
(current->uid != task->suid) && (current->uid != task->uid) &&
|
(current->uid != task->suid) && (current->uid != task->uid) &&
|
||||||
!capable(CAP_SYS_NICE)) {
|
!capable(CAP_SYS_NICE)) {
|
||||||
err = -EPERM;
|
err = -EPERM;
|
||||||
goto out2;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = security_task_movememory(task);
|
err = security_task_movememory(task);
|
||||||
if (err)
|
if (err)
|
||||||
goto out2;
|
|
||||||
|
|
||||||
if (!nodes) {
|
|
||||||
err = do_pages_stat(mm, nr_pages, pages, status);
|
|
||||||
goto out2;
|
|
||||||
}
|
|
||||||
|
|
||||||
task_nodes = cpuset_mems_allowed(task);
|
|
||||||
|
|
||||||
/* Limit nr_pages so that the multiplication may not overflow */
|
|
||||||
if (nr_pages >= ULONG_MAX / sizeof(struct page_to_node) - 1) {
|
|
||||||
err = -E2BIG;
|
|
||||||
goto out2;
|
|
||||||
}
|
|
||||||
|
|
||||||
pm = vmalloc((nr_pages + 1) * sizeof(struct page_to_node));
|
|
||||||
if (!pm) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto out2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get parameters from user space and initialize the pm
|
|
||||||
* array. Return various errors if the user did something wrong.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < nr_pages; i++) {
|
|
||||||
const void __user *p;
|
|
||||||
|
|
||||||
err = -EFAULT;
|
|
||||||
if (get_user(p, pages + i))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
pm[i].addr = (unsigned long)p;
|
|
||||||
if (nodes) {
|
if (nodes) {
|
||||||
int node;
|
err = do_pages_move(mm, task, nr_pages, pages, nodes, status,
|
||||||
|
flags);
|
||||||
if (get_user(node, nodes + i))
|
} else {
|
||||||
goto out;
|
err = do_pages_stat(mm, nr_pages, pages, status);
|
||||||
|
|
||||||
err = -ENODEV;
|
|
||||||
if (!node_state(node, N_HIGH_MEMORY))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
err = -EACCES;
|
|
||||||
if (!node_isset(node, task_nodes))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
pm[i].node = node;
|
|
||||||
} else
|
|
||||||
pm[i].node = 0; /* anything to not match MAX_NUMNODES */
|
|
||||||
}
|
}
|
||||||
/* End marker */
|
|
||||||
pm[nr_pages].node = MAX_NUMNODES;
|
|
||||||
|
|
||||||
err = do_move_pages(mm, pm, flags & MPOL_MF_MOVE_ALL);
|
|
||||||
if (err >= 0)
|
|
||||||
/* Return status information */
|
|
||||||
for (i = 0; i < nr_pages; i++)
|
|
||||||
if (put_user(pm[i].status, status + i))
|
|
||||||
err = -EFAULT;
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
vfree(pm);
|
|
||||||
out2:
|
|
||||||
mmput(mm);
|
mmput(mm);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue