mempolicy.c (eb42c75878e4d13941dcbcf2ef1027c257b099a6) mempolicy.c (76aac0e9a17742e60d408be1a706e9aaad370891)
1/*
2 * Simple NUMA memory policy for the Linux kernel.
3 *
4 * Copyright 2003,2004 Andi Kleen, SuSE Labs.
5 * (C) Copyright 2005 Christoph Lameter, Silicon Graphics, Inc.
6 * Subject to the GNU Public License, version 2.
7 *
8 * NUMA policy allows the user to give hints in which node(s) memory should

--- 475 unchanged lines hidden (view full) ---

484 */
485static struct vm_area_struct *
486check_range(struct mm_struct *mm, unsigned long start, unsigned long end,
487 const nodemask_t *nodes, unsigned long flags, void *private)
488{
489 int err;
490 struct vm_area_struct *first, *vma, *prev;
491
1/*
2 * Simple NUMA memory policy for the Linux kernel.
3 *
4 * Copyright 2003,2004 Andi Kleen, SuSE Labs.
5 * (C) Copyright 2005 Christoph Lameter, Silicon Graphics, Inc.
6 * Subject to the GNU Public License, version 2.
7 *
8 * NUMA policy allows the user to give hints in which node(s) memory should

--- 475 unchanged lines hidden (view full) ---

484 */
485static struct vm_area_struct *
486check_range(struct mm_struct *mm, unsigned long start, unsigned long end,
487 const nodemask_t *nodes, unsigned long flags, void *private)
488{
489 int err;
490 struct vm_area_struct *first, *vma, *prev;
491
492 if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
492
493
494 err = migrate_prep();
495 if (err)
496 return ERR_PTR(err);
497 }
498
493 first = find_vma(mm, start);
494 if (!first)
495 return ERR_PTR(-EFAULT);
496 prev = NULL;
497 for (vma = first; vma && vma->vm_start < end; vma = vma->vm_next) {
498 if (!(flags & MPOL_MF_DISCONTIG_OK)) {
499 if (!vma->vm_next && vma->vm_end < end)
500 return ERR_PTR(-EFAULT);

--- 297 unchanged lines hidden (view full) ---

798 * layout as much as possible.
799 *
800 * Returns the number of page that could not be moved.
801 */
802int do_migrate_pages(struct mm_struct *mm,
803 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags)
804{
805 int busy = 0;
499 first = find_vma(mm, start);
500 if (!first)
501 return ERR_PTR(-EFAULT);
502 prev = NULL;
503 for (vma = first; vma && vma->vm_start < end; vma = vma->vm_next) {
504 if (!(flags & MPOL_MF_DISCONTIG_OK)) {
505 if (!vma->vm_next && vma->vm_end < end)
506 return ERR_PTR(-EFAULT);

--- 297 unchanged lines hidden (view full) ---

804 * layout as much as possible.
805 *
806 * Returns the number of page that could not be moved.
807 */
808int do_migrate_pages(struct mm_struct *mm,
809 const nodemask_t *from_nodes, const nodemask_t *to_nodes, int flags)
810{
811 int busy = 0;
806 int err;
812 int err = 0;
807 nodemask_t tmp;
808
813 nodemask_t tmp;
814
809 err = migrate_prep();
810 if (err)
811 return err;
812
813 down_read(&mm->mmap_sem);
814
815 err = migrate_vmas(mm, from_nodes, to_nodes, flags);
816 if (err)
817 goto out;
818
819/*
820 * Find a 'source' bit set in 'tmp' whose corresponding 'dest'

--- 146 unchanged lines hidden (view full) ---

967 */
968 if (!new)
969 flags |= MPOL_MF_DISCONTIG_OK;
970
971 pr_debug("mbind %lx-%lx mode:%d flags:%d nodes:%lx\n",
972 start, start + len, mode, mode_flags,
973 nmask ? nodes_addr(*nmask)[0] : -1);
974
815 down_read(&mm->mmap_sem);
816
817 err = migrate_vmas(mm, from_nodes, to_nodes, flags);
818 if (err)
819 goto out;
820
821/*
822 * Find a 'source' bit set in 'tmp' whose corresponding 'dest'

--- 146 unchanged lines hidden (view full) ---

969 */
970 if (!new)
971 flags |= MPOL_MF_DISCONTIG_OK;
972
973 pr_debug("mbind %lx-%lx mode:%d flags:%d nodes:%lx\n",
974 start, start + len, mode, mode_flags,
975 nmask ? nodes_addr(*nmask)[0] : -1);
976
975 if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) {
976
977 err = migrate_prep();
978 if (err)
979 return err;
980 }
981 down_write(&mm->mmap_sem);
982 vma = check_range(mm, start, end, nmask,
983 flags | MPOL_MF_INVERT, &pagelist);
984
985 err = PTR_ERR(vma);
986 if (!IS_ERR(vma)) {
987 int nr_failed = 0;
988

--- 125 unchanged lines hidden (view full) ---

1114 const unsigned long __user *old_nodes,
1115 const unsigned long __user *new_nodes)
1116{
1117 struct mm_struct *mm;
1118 struct task_struct *task;
1119 nodemask_t old;
1120 nodemask_t new;
1121 nodemask_t task_nodes;
977 down_write(&mm->mmap_sem);
978 vma = check_range(mm, start, end, nmask,
979 flags | MPOL_MF_INVERT, &pagelist);
980
981 err = PTR_ERR(vma);
982 if (!IS_ERR(vma)) {
983 int nr_failed = 0;
984

--- 125 unchanged lines hidden (view full) ---

1110 const unsigned long __user *old_nodes,
1111 const unsigned long __user *new_nodes)
1112{
1113 struct mm_struct *mm;
1114 struct task_struct *task;
1115 nodemask_t old;
1116 nodemask_t new;
1117 nodemask_t task_nodes;
1118 uid_t uid, euid;
1122 int err;
1123
1124 err = get_nodes(&old, old_nodes, maxnode);
1125 if (err)
1126 return err;
1127
1128 err = get_nodes(&new, new_nodes, maxnode);
1129 if (err)

--- 13 unchanged lines hidden (view full) ---

1143 return -EINVAL;
1144
1145 /*
1146 * Check if this process has the right to modify the specified
1147 * process. The right exists if the process has administrative
1148 * capabilities, superuser privileges or the same
1149 * userid as the target process.
1150 */
1119 int err;
1120
1121 err = get_nodes(&old, old_nodes, maxnode);
1122 if (err)
1123 return err;
1124
1125 err = get_nodes(&new, new_nodes, maxnode);
1126 if (err)

--- 13 unchanged lines hidden (view full) ---

1140 return -EINVAL;
1141
1142 /*
1143 * Check if this process has the right to modify the specified
1144 * process. The right exists if the process has administrative
1145 * capabilities, superuser privileges or the same
1146 * userid as the target process.
1147 */
1151 if ((current->euid != task->suid) && (current->euid != task->uid) &&
1152 (current->uid != task->suid) && (current->uid != task->uid) &&
1148 uid = current_uid();
1149 euid = current_euid();
1150 if (euid != task->suid && euid != task->uid &&
1151 uid != task->suid && uid != task->uid &&
1153 !capable(CAP_SYS_NICE)) {
1154 err = -EPERM;
1155 goto out;
1156 }
1157
1158 task_nodes = cpuset_mems_allowed(task);
1159 /* Is the user allowed to access the target nodes? */
1160 if (!nodes_subset(new, task_nodes) && !capable(CAP_SYS_NICE)) {

--- 1180 unchanged lines hidden ---
1152 !capable(CAP_SYS_NICE)) {
1153 err = -EPERM;
1154 goto out;
1155 }
1156
1157 task_nodes = cpuset_mems_allowed(task);
1158 /* Is the user allowed to access the target nodes? */
1159 if (!nodes_subset(new, task_nodes) && !capable(CAP_SYS_NICE)) {

--- 1180 unchanged lines hidden ---