Merge branch 'pci/misc'
[linux-2.6-microblaze.git] / mm / migrate.c
index 941b893..5ca5842 100644 (file)
@@ -381,7 +381,7 @@ static int expected_page_refs(struct address_space *mapping, struct page *page)
        int expected_count = 1;
 
        /*
-        * Device public or private pages have an extra refcount as they are
+        * Device private pages have an extra refcount as they are
         * ZONE_DEVICE pages.
         */
        expected_count += is_device_private_page(page);
@@ -503,7 +503,7 @@ int migrate_page_move_mapping(struct address_space *mapping,
                        __dec_lruvec_state(old_lruvec, NR_SHMEM);
                        __inc_lruvec_state(new_lruvec, NR_SHMEM);
                }
-               if (dirty && mapping_cap_account_dirty(mapping)) {
+               if (dirty && mapping_can_writeback(mapping)) {
                        __dec_node_state(oldzone->zone_pgdat, NR_FILE_DIRTY);
                        __dec_zone_state(oldzone, NR_ZONE_WRITE_PENDING);
                        __inc_node_state(newzone->zone_pgdat, NR_FILE_DIRTY);
@@ -668,7 +668,8 @@ void migrate_page_states(struct page *newpage, struct page *page)
 
        copy_page_owner(page, newpage);
 
-       mem_cgroup_migrate(page, newpage);
+       if (!PageHuge(page))
+               mem_cgroup_migrate(page, newpage);
 }
 EXPORT_SYMBOL(migrate_page_states);
 
@@ -1222,16 +1223,11 @@ out:
         * we want to retry.
         */
        if (rc == MIGRATEPAGE_SUCCESS) {
-               put_page(page);
-               if (reason == MR_MEMORY_FAILURE) {
+               if (reason != MR_MEMORY_FAILURE)
                        /*
-                        * Set PG_HWPoison on just freed page
-                        * intentionally. Although it's rather weird,
-                        * it's how HWPoison flag works at the moment.
+                        * We release the page in page_handle_poison.
                         */
-                       if (set_hwpoison_free_buddy_page(page))
-                               num_poisoned_pages_inc();
-               }
+                       put_page(page);
        } else {
                if (rc != -EAGAIN) {
                        if (likely(!__PageMovable(page))) {
@@ -1445,7 +1441,7 @@ retry:
                         * Capture required information that might get lost
                         * during migration.
                         */
-                       is_thp = PageTransHuge(page);
+                       is_thp = PageTransHuge(page) && !PageHuge(page);
                        nr_subpages = thp_nr_pages(page);
                        cond_resched();
 
@@ -1471,7 +1467,7 @@ retry:
                                 * we encounter them after the rest of the list
                                 * is processed.
                                 */
-                               if (PageTransHuge(page) && !PageHuge(page)) {
+                               if (is_thp) {
                                        lock_page(page);
                                        rc = split_huge_page_to_list(page, from);
                                        unlock_page(page);
@@ -1480,8 +1476,7 @@ retry:
                                                nr_thp_split++;
                                                goto retry;
                                        }
-                               }
-                               if (is_thp) {
+
                                        nr_thp_failed++;
                                        nr_failed += nr_subpages;
                                        goto out;
@@ -1869,33 +1864,27 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
        return nr_pages ? -EFAULT : 0;
 }
 
-/*
- * Move a list of pages in the address space of the currently executing
- * process.
- */
-static int kernel_move_pages(pid_t pid, unsigned long nr_pages,
-                            const void __user * __user *pages,
-                            const int __user *nodes,
-                            int __user *status, int flags)
+static struct mm_struct *find_mm_struct(pid_t pid, nodemask_t *mem_nodes)
 {
        struct task_struct *task;
        struct mm_struct *mm;
-       int err;
-       nodemask_t task_nodes;
-
-       /* Check flags */
-       if (flags & ~(MPOL_MF_MOVE|MPOL_MF_MOVE_ALL))
-               return -EINVAL;
 
-       if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE))
-               return -EPERM;
+       /*
+        * There is no need to check if current process has the right to modify
+        * the specified process when they are same.
+        */
+       if (!pid) {
+               mmget(current->mm);
+               *mem_nodes = cpuset_mems_allowed(current);
+               return current->mm;
+       }
 
        /* Find the mm_struct */
        rcu_read_lock();
-       task = pid ? find_task_by_vpid(pid) : current;
+       task = find_task_by_vpid(pid);
        if (!task) {
                rcu_read_unlock();
-               return -ESRCH;
+               return ERR_PTR(-ESRCH);
        }
        get_task_struct(task);
 
@@ -1905,22 +1894,47 @@ static int kernel_move_pages(pid_t pid, unsigned long nr_pages,
         */
        if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) {
                rcu_read_unlock();
-               err = -EPERM;
+               mm = ERR_PTR(-EPERM);
                goto out;
        }
        rcu_read_unlock();
 
-       err = security_task_movememory(task);
-       if (err)
+       mm = ERR_PTR(security_task_movememory(task));
+       if (IS_ERR(mm))
                goto out;
-
-       task_nodes = cpuset_mems_allowed(task);
+       *mem_nodes = cpuset_mems_allowed(task);
        mm = get_task_mm(task);
+out:
        put_task_struct(task);
-
        if (!mm)
+               mm = ERR_PTR(-EINVAL);
+       return mm;
+}
+
+/*
+ * Move a list of pages in the address space of the currently executing
+ * process.
+ */
+static int kernel_move_pages(pid_t pid, unsigned long nr_pages,
+                            const void __user * __user *pages,
+                            const int __user *nodes,
+                            int __user *status, int flags)
+{
+       struct mm_struct *mm;
+       int err;
+       nodemask_t task_nodes;
+
+       /* Check flags */
+       if (flags & ~(MPOL_MF_MOVE|MPOL_MF_MOVE_ALL))
                return -EINVAL;
 
+       if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE))
+               return -EPERM;
+
+       mm = find_mm_struct(pid, &task_nodes);
+       if (IS_ERR(mm))
+               return PTR_ERR(mm);
+
        if (nodes)
                err = do_pages_move(mm, task_nodes, nr_pages, pages,
                                    nodes, status, flags);
@@ -1929,10 +1943,6 @@ static int kernel_move_pages(pid_t pid, unsigned long nr_pages,
 
        mmput(mm);
        return err;
-
-out:
-       put_task_struct(task);
-       return err;
 }
 
 SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
@@ -3077,7 +3087,6 @@ void migrate_vma_finalize(struct migrate_vma *migrate)
 
                remove_migration_ptes(page, newpage, false);
                unlock_page(page);
-               migrate->cpages--;
 
                if (is_zone_device_page(page))
                        put_page(page);