2 * Memory Migration functionality - linux/mm/migration.c
4 * Copyright (C) 2006 Silicon Graphics, Inc., Christoph Lameter
6 * Page migration was first developed in the context of the memory hotplug
7 * project. The main authors of the migration code are:
9 * IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
10 * Hirokazu Takahashi <taka@valinux.co.jp>
11 * Dave Hansen <haveblue@us.ibm.com>
15 #include <linux/migrate.h>
16 #include <linux/module.h>
17 #include <linux/swap.h>
18 #include <linux/swapops.h>
19 #include <linux/pagemap.h>
20 #include <linux/buffer_head.h>
21 #include <linux/mm_inline.h>
22 #include <linux/nsproxy.h>
23 #include <linux/pagevec.h>
24 #include <linux/ksm.h>
25 #include <linux/rmap.h>
26 #include <linux/topology.h>
27 #include <linux/cpu.h>
28 #include <linux/cpuset.h>
29 #include <linux/writeback.h>
30 #include <linux/mempolicy.h>
31 #include <linux/vmalloc.h>
32 #include <linux/security.h>
33 #include <linux/memcontrol.h>
34 #include <linux/syscalls.h>
35 #include <linux/gfp.h>
39 #define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))
42 * migrate_prep() needs to be called before we start compiling a list of pages
43 * to be migrated using isolate_lru_page(). If scheduling work on other CPUs is
44 * undesirable, use migrate_prep_local()
46 int migrate_prep(void)
49 * Clear the LRU lists so pages can be isolated.
50 * Note that pages may be moved off the LRU after we have
51 * drained them. Those pages will fail to migrate like other
52 * pages that may be busy.
59 /* Do the necessary work of migrate_prep but not if it involves other CPUs */
60 int migrate_prep_local(void)
66 EXPORT_SYMBOL(migrate_prep);
69 * Add isolated pages on the list back to the LRU under page lock
70 * to avoid leaking evictable pages back onto unevictable list.
72 void putback_lru_pages(struct list_head *l)
77 list_for_each_entry_safe(page, page2, l, lru) {
79 dec_zone_page_state(page, NR_ISOLATED_ANON +
80 page_is_file_cache(page));
81 putback_lru_page(page);
84 EXPORT_SYMBOL(putback_lru_pages);
87 * Restore a potential migration pte to a working pte entry
89 static int remove_migration_pte(struct page *new, struct vm_area_struct *vma,
90 unsigned long addr, void *old)
92 struct mm_struct *mm = vma->vm_mm;
100 pgd = pgd_offset(mm, addr);
101 if (!pgd_present(*pgd))
104 pud = pud_offset(pgd, addr);
105 if (!pud_present(*pud))
108 pmd = pmd_offset(pud, addr);
109 if (!pmd_present(*pmd))
112 ptep = pte_offset_map(pmd, addr);
114 if (!is_swap_pte(*ptep)) {
119 ptl = pte_lockptr(mm, pmd);
122 if (!is_swap_pte(pte))
125 entry = pte_to_swp_entry(pte);
127 if (!is_migration_entry(entry) ||
128 migration_entry_to_page(entry) != old)
132 pte = pte_mkold(mk_pte(new, vma->vm_page_prot));
133 if (is_write_migration_entry(entry))
134 pte = pte_mkwrite(pte);
135 flush_cache_page(vma, addr, pte_pfn(pte));
136 set_pte_at(mm, addr, ptep, pte);
139 page_add_anon_rmap(new, vma, addr);
141 page_add_file_rmap(new);
143 /* No need to invalidate - it was non-present before */
144 update_mmu_cache(vma, addr, ptep);
146 pte_unmap_unlock(ptep, ptl);
152 * Get rid of all migration entries and replace them by
153 * references to the indicated page.
155 static void remove_migration_ptes(struct page *old, struct page *new)
157 rmap_walk(new, remove_migration_pte, old);
161 * Something used the pte of a page under migration. We need to
162 * get to the page and wait until migration is finished.
163 * When we return from this function the fault will be retried.
165 * This function is called from do_swap_page().
167 void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd,
168 unsigned long address)
175 ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
177 if (!is_swap_pte(pte))
180 entry = pte_to_swp_entry(pte);
181 if (!is_migration_entry(entry))
184 page = migration_entry_to_page(entry);
187 * Once radix-tree replacement of page migration started, page_count
188 * *must* be zero. And, we don't want to call wait_on_page_locked()
189 * against a page without get_page().
190 * So, we use get_page_unless_zero(), here. Even failed, page fault
193 if (!get_page_unless_zero(page))
195 pte_unmap_unlock(ptep, ptl);
196 wait_on_page_locked(page);
200 pte_unmap_unlock(ptep, ptl);
204 * Replace the page in the mapping.
206 * The number of remaining references must be:
207 * 1 for anonymous pages without a mapping
208 * 2 for pages with a mapping
209 * 3 for pages with a mapping and PagePrivate/PagePrivate2 set.
211 static int migrate_page_move_mapping(struct address_space *mapping,
212 struct page *newpage, struct page *page)
218 /* Anonymous page without mapping */
219 if (page_count(page) != 1)
224 spin_lock_irq(&mapping->tree_lock);
226 pslot = radix_tree_lookup_slot(&mapping->page_tree,
229 expected_count = 2 + page_has_private(page);
230 if (page_count(page) != expected_count ||
231 (struct page *)radix_tree_deref_slot(pslot) != page) {
232 spin_unlock_irq(&mapping->tree_lock);
236 if (!page_freeze_refs(page, expected_count)) {
237 spin_unlock_irq(&mapping->tree_lock);
242 * Now we know that no one else is looking at the page.
244 get_page(newpage); /* add cache reference */
245 if (PageSwapCache(page)) {
246 SetPageSwapCache(newpage);
247 set_page_private(newpage, page_private(page));
250 radix_tree_replace_slot(pslot, newpage);
252 page_unfreeze_refs(page, expected_count);
254 * Drop cache reference from old page.
255 * We know this isn't the last reference.
260 * If moved to a different zone then also account
261 * the page for that zone. Other VM counters will be
262 * taken care of when we establish references to the
263 * new page and drop references to the old page.
265 * Note that anonymous pages are accounted for
266 * via NR_FILE_PAGES and NR_ANON_PAGES if they
267 * are mapped to swap space.
269 __dec_zone_page_state(page, NR_FILE_PAGES);
270 __inc_zone_page_state(newpage, NR_FILE_PAGES);
271 if (PageSwapBacked(page)) {
272 __dec_zone_page_state(page, NR_SHMEM);
273 __inc_zone_page_state(newpage, NR_SHMEM);
275 spin_unlock_irq(&mapping->tree_lock);
281 * Copy the page to its new location
283 static void migrate_page_copy(struct page *newpage, struct page *page)
285 copy_highpage(newpage, page);
288 SetPageError(newpage);
289 if (PageReferenced(page))
290 SetPageReferenced(newpage);
291 if (PageUptodate(page))
292 SetPageUptodate(newpage);
293 if (TestClearPageActive(page)) {
294 VM_BUG_ON(PageUnevictable(page));
295 SetPageActive(newpage);
296 } else if (TestClearPageUnevictable(page))
297 SetPageUnevictable(newpage);
298 if (PageChecked(page))
299 SetPageChecked(newpage);
300 if (PageMappedToDisk(page))
301 SetPageMappedToDisk(newpage);
303 if (PageDirty(page)) {
304 clear_page_dirty_for_io(page);
306 * Want to mark the page and the radix tree as dirty, and
307 * redo the accounting that clear_page_dirty_for_io undid,
308 * but we can't use set_page_dirty because that function
309 * is actually a signal that all of the page has become dirty.
310 * Wheras only part of our page may be dirty.
312 __set_page_dirty_nobuffers(newpage);
315 mlock_migrate_page(newpage, page);
316 ksm_migrate_page(newpage, page);
318 ClearPageSwapCache(page);
319 ClearPagePrivate(page);
320 set_page_private(page, 0);
321 page->mapping = NULL;
324 * If any waiters have accumulated on the new page then
327 if (PageWriteback(newpage))
328 end_page_writeback(newpage);
331 /************************************************************
332 * Migration functions
333 ***********************************************************/
335 /* Always fail migration. Used for mappings that are not movable */
336 int fail_migrate_page(struct address_space *mapping,
337 struct page *newpage, struct page *page)
341 EXPORT_SYMBOL(fail_migrate_page);
344 * Common logic to directly migrate a single page suitable for
345 * pages that do not use PagePrivate/PagePrivate2.
347 * Pages are locked upon entry and exit.
349 int migrate_page(struct address_space *mapping,
350 struct page *newpage, struct page *page)
354 BUG_ON(PageWriteback(page)); /* Writeback must be complete */
356 rc = migrate_page_move_mapping(mapping, newpage, page);
361 migrate_page_copy(newpage, page);
364 EXPORT_SYMBOL(migrate_page);
368 * Migration function for pages with buffers. This function can only be used
369 * if the underlying filesystem guarantees that no other references to "page"
372 int buffer_migrate_page(struct address_space *mapping,
373 struct page *newpage, struct page *page)
375 struct buffer_head *bh, *head;
378 if (!page_has_buffers(page))
379 return migrate_page(mapping, newpage, page);
381 head = page_buffers(page);
383 rc = migrate_page_move_mapping(mapping, newpage, page);
392 bh = bh->b_this_page;
394 } while (bh != head);
396 ClearPagePrivate(page);
397 set_page_private(newpage, page_private(page));
398 set_page_private(page, 0);
404 set_bh_page(bh, newpage, bh_offset(bh));
405 bh = bh->b_this_page;
407 } while (bh != head);
409 SetPagePrivate(newpage);
411 migrate_page_copy(newpage, page);
417 bh = bh->b_this_page;
419 } while (bh != head);
423 EXPORT_SYMBOL(buffer_migrate_page);
427 * Writeback a page to clean the dirty state
429 static int writeout(struct address_space *mapping, struct page *page)
431 struct writeback_control wbc = {
432 .sync_mode = WB_SYNC_NONE,
435 .range_end = LLONG_MAX,
441 if (!mapping->a_ops->writepage)
442 /* No write method for the address space */
445 if (!clear_page_dirty_for_io(page))
446 /* Someone else already triggered a write */
450 * A dirty page may imply that the underlying filesystem has
451 * the page on some queue. So the page must be clean for
452 * migration. Writeout may mean we loose the lock and the
453 * page state is no longer what we checked for earlier.
454 * At this point we know that the migration attempt cannot
457 remove_migration_ptes(page, page);
459 rc = mapping->a_ops->writepage(page, &wbc);
461 if (rc != AOP_WRITEPAGE_ACTIVATE)
462 /* unlocked. Relock */
465 return (rc < 0) ? -EIO : -EAGAIN;
469 * Default handling if a filesystem does not provide a migration function.
471 static int fallback_migrate_page(struct address_space *mapping,
472 struct page *newpage, struct page *page)
475 return writeout(mapping, page);
478 * Buffers may be managed in a filesystem specific way.
479 * We must have no buffers or drop them.
481 if (page_has_private(page) &&
482 !try_to_release_page(page, GFP_KERNEL))
485 return migrate_page(mapping, newpage, page);
489 * Move a page to a newly allocated page
490 * The page is locked and all ptes have been successfully removed.
492 * The new page will have replaced the old page if this function
499 static int move_to_new_page(struct page *newpage, struct page *page,
502 struct address_space *mapping;
506 * Block others from accessing the page when we get around to
507 * establishing additional references. We are the only one
508 * holding a reference to the new page at this point.
510 if (!trylock_page(newpage))
513 /* Prepare mapping for the new page.*/
514 newpage->index = page->index;
515 newpage->mapping = page->mapping;
516 if (PageSwapBacked(page))
517 SetPageSwapBacked(newpage);
519 mapping = page_mapping(page);
521 rc = migrate_page(mapping, newpage, page);
522 else if (mapping->a_ops->migratepage)
524 * Most pages have a mapping and most filesystems
525 * should provide a migration function. Anonymous
526 * pages are part of swap space which also has its
527 * own migration function. This is the most common
528 * path for page migration.
530 rc = mapping->a_ops->migratepage(mapping,
533 rc = fallback_migrate_page(mapping, newpage, page);
536 newpage->mapping = NULL;
539 remove_migration_ptes(page, newpage);
542 unlock_page(newpage);
548 * Obtain the lock on page, remove all ptes and migrate the page
549 * to the newly allocated page in newpage.
551 static int unmap_and_move(new_page_t get_new_page, unsigned long private,
552 struct page *page, int force, int offlining)
556 struct page *newpage = get_new_page(page, private, &result);
557 int remap_swapcache = 1;
560 struct mem_cgroup *mem = NULL;
561 struct anon_vma *anon_vma = NULL;
566 if (page_count(page) == 1) {
567 /* page was freed from under us. So we are done. */
571 /* prepare cgroup just returns 0 or -ENOMEM */
574 if (!trylock_page(page)) {
581 * Only memory hotplug's offline_pages() caller has locked out KSM,
582 * and can safely migrate a KSM page. The other cases have skipped
583 * PageKsm along with PageReserved - but it is only now when we have
584 * the page lock that we can be certain it will not go KSM beneath us
585 * (KSM will not upgrade a page from PageAnon to PageKsm when it sees
586 * its pagecount raised, but only here do we take the page lock which
589 if (PageKsm(page) && !offlining) {
594 /* charge against new page */
595 charge = mem_cgroup_prepare_migration(page, newpage, &mem);
596 if (charge == -ENOMEM) {
602 if (PageWriteback(page)) {
605 wait_on_page_writeback(page);
608 * By try_to_unmap(), page->mapcount goes down to 0 here. In this case,
609 * we cannot notice that anon_vma is freed while we migrates a page.
610 * This rcu_read_lock() delays freeing anon_vma pointer until the end
611 * of migration. File cache pages are no problem because of page_lock()
612 * File Caches may use write_page() or lock_page() in migration, then,
613 * just care Anon page here.
615 if (PageAnon(page)) {
619 /* Determine how to safely use anon_vma */
620 if (!page_mapped(page)) {
621 if (!PageSwapCache(page))
625 * We cannot be sure that the anon_vma of an unmapped
626 * swapcache page is safe to use because we don't
627 * know in advance if the VMA that this page belonged
628 * to still exists. If the VMA and others sharing the
629 * data have been freed, then the anon_vma could
630 * already be invalid.
632 * To avoid this possibility, swapcache pages get
633 * migrated but are not remapped when migration
639 * Take a reference count on the anon_vma if the
640 * page is mapped so that it is guaranteed to
641 * exist when the page is remapped later
643 anon_vma = page_anon_vma(page);
644 atomic_inc(&anon_vma->external_refcount);
649 * Corner case handling:
650 * 1. When a new swap-cache page is read into, it is added to the LRU
651 * and treated as swapcache but it has no rmap yet.
652 * Calling try_to_unmap() against a page->mapping==NULL page will
653 * trigger a BUG. So handle it here.
654 * 2. An orphaned page (see truncate_complete_page) might have
655 * fs-private metadata. The page can be picked up due to memory
656 * offlining. Everywhere else except page reclaim, the page is
657 * invisible to the vm, so the page can not be migrated. So try to
658 * free the metadata, so the page can be freed.
660 if (!page->mapping) {
661 if (!PageAnon(page) && page_has_private(page)) {
663 * Go direct to try_to_free_buffers() here because
664 * a) that's what try_to_release_page() would do anyway
665 * b) we may be under rcu_read_lock() here, so we can't
666 * use GFP_KERNEL which is what try_to_release_page()
667 * needs to be effective.
669 try_to_free_buffers(page);
675 /* Establish migration ptes or remove ptes */
676 try_to_unmap(page, TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS);
679 if (!page_mapped(page))
680 rc = move_to_new_page(newpage, page, remap_swapcache);
682 if (rc && remap_swapcache)
683 remove_migration_ptes(page, page);
686 /* Drop an anon_vma reference if we took one */
687 if (anon_vma && atomic_dec_and_lock(&anon_vma->external_refcount, &anon_vma->lock)) {
688 int empty = list_empty(&anon_vma->head);
689 spin_unlock(&anon_vma->lock);
691 anon_vma_free(anon_vma);
698 mem_cgroup_end_migration(mem, page, newpage);
704 * A page that has been migrated has all references
705 * removed and will be freed. A page that has not been
706 * migrated will have kepts its references and be
709 list_del(&page->lru);
710 if (PageMemError(page)) {
713 * A page with a memory error that has
714 * been migrated will not be moved to
720 * The page failed to migrate and will not
721 * be added to the bad page list. Clearing
722 * the error bit will allow another attempt
723 * to migrate if it gets another correctable
726 ClearPageMemError(page);
729 dec_zone_page_state(page, NR_ISOLATED_ANON +
730 page_is_file_cache(page));
731 putback_lru_page(page);
737 * Move the new page to the LRU. If migration was not successful
738 * then this will free the page.
740 putback_lru_page(newpage);
746 *result = page_to_nid(newpage);
754 * The function takes one list of pages to migrate and a function
755 * that determines from the page to be migrated and the private data
756 * the target of the move and allocates the page.
758 * The function returns after 10 attempts or if no pages
759 * are movable anymore because to has become empty
760 * or no retryable pages exist anymore. All pages will be
761 * returned to the LRU or freed.
763 * Return: Number of pages not migrated or error code.
765 int migrate_pages(struct list_head *from,
766 new_page_t get_new_page, unsigned long private, int offlining)
773 int swapwrite = current->flags & PF_SWAPWRITE;
777 current->flags |= PF_SWAPWRITE;
779 for(pass = 0; pass < 10 && retry; pass++) {
782 list_for_each_entry_safe(page, page2, from, lru) {
785 rc = unmap_and_move(get_new_page, private,
786 page, pass > 2, offlining);
797 /* Permanent failure */
805 list_for_each_entry_safe(page, page2, from, lru)
806 if (PageMemError(page))
808 * The page failed to migrate. Clearing
809 * the error bit will allow another attempt
810 * to migrate if it gets another correctable
813 ClearPageMemError(page);
817 current->flags &= ~PF_SWAPWRITE;
819 putback_lru_pages(from);
824 return nr_failed + retry;
826 EXPORT_SYMBOL(migrate_pages);
830 * Move a list of individual pages
832 struct page_to_node {
839 static struct page *new_page_node(struct page *p, unsigned long private,
842 struct page_to_node *pm = (struct page_to_node *)private;
844 while (pm->node != MAX_NUMNODES && pm->page != p)
847 if (pm->node == MAX_NUMNODES)
850 *result = &pm->status;
852 return alloc_pages_exact_node(pm->node,
853 GFP_HIGHUSER_MOVABLE | GFP_THISNODE, 0);
857 * Move a set of pages as indicated in the pm array. The addr
858 * field must be set to the virtual address of the page to be moved
859 * and the node number must contain a valid target node.
860 * The pm array ends with node = MAX_NUMNODES.
862 static int do_move_page_to_node_array(struct mm_struct *mm,
863 struct page_to_node *pm,
867 struct page_to_node *pp;
870 down_read(&mm->mmap_sem);
873 * Build a list of pages to migrate
875 for (pp = pm; pp->node != MAX_NUMNODES; pp++) {
876 struct vm_area_struct *vma;
880 vma = find_vma(mm, pp->addr);
881 if (!vma || !vma_migratable(vma))
884 page = follow_page(vma, pp->addr, FOLL_GET);
894 /* Use PageReserved to check for zero page */
895 if (PageReserved(page) || PageKsm(page))
899 err = page_to_nid(page);
903 * Node already in the right place
908 if (page_mapcount(page) > 1 &&
912 err = isolate_lru_page(page);
914 list_add_tail(&page->lru, &pagelist);
915 inc_zone_page_state(page, NR_ISOLATED_ANON +
916 page_is_file_cache(page));
920 * Either remove the duplicate refcount from
921 * isolate_lru_page() or drop the page ref if it was
930 if (!list_empty(&pagelist))
931 err = migrate_pages(&pagelist, new_page_node,
932 (unsigned long)pm, 0);
934 up_read(&mm->mmap_sem);
939 * Migrate an array of page address onto an array of nodes and fill
940 * the corresponding array of status.
942 static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
943 unsigned long nr_pages,
944 const void __user * __user *pages,
945 const int __user *nodes,
946 int __user *status, int flags)
948 struct page_to_node *pm;
949 nodemask_t task_nodes;
950 unsigned long chunk_nr_pages;
951 unsigned long chunk_start;
954 task_nodes = cpuset_mems_allowed(task);
957 pm = (struct page_to_node *)__get_free_page(GFP_KERNEL);
964 * Store a chunk of page_to_node array in a page,
965 * but keep the last one as a marker
967 chunk_nr_pages = (PAGE_SIZE / sizeof(struct page_to_node)) - 1;
969 for (chunk_start = 0;
970 chunk_start < nr_pages;
971 chunk_start += chunk_nr_pages) {
974 if (chunk_start + chunk_nr_pages > nr_pages)
975 chunk_nr_pages = nr_pages - chunk_start;
977 /* fill the chunk pm with addrs and nodes from user-space */
978 for (j = 0; j < chunk_nr_pages; j++) {
979 const void __user *p;
983 if (get_user(p, pages + j + chunk_start))
985 pm[j].addr = (unsigned long) p;
987 if (get_user(node, nodes + j + chunk_start))
991 if (node < 0 || node >= MAX_NUMNODES)
994 if (!node_state(node, N_HIGH_MEMORY))
998 if (!node_isset(node, task_nodes))
1004 /* End marker for this chunk */
1005 pm[chunk_nr_pages].node = MAX_NUMNODES;
1007 /* Migrate this chunk */
1008 err = do_move_page_to_node_array(mm, pm,
1009 flags & MPOL_MF_MOVE_ALL);
1013 /* Return status information */
1014 for (j = 0; j < chunk_nr_pages; j++)
1015 if (put_user(pm[j].status, status + j + chunk_start)) {
1023 free_page((unsigned long)pm);
1029 * Determine the nodes of an array of pages and store it in an array of status.
1031 static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages,
1032 const void __user **pages, int *status)
1036 down_read(&mm->mmap_sem);
1038 for (i = 0; i < nr_pages; i++) {
1039 unsigned long addr = (unsigned long)(*pages);
1040 struct vm_area_struct *vma;
1044 vma = find_vma(mm, addr);
1048 page = follow_page(vma, addr, 0);
1050 err = PTR_ERR(page);
1055 /* Use PageReserved to check for zero page */
1056 if (!page || PageReserved(page) || PageKsm(page))
1059 err = page_to_nid(page);
1067 up_read(&mm->mmap_sem);
1071 * Determine the nodes of a user array of pages and store it in
1072 * a user array of status.
1074 static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
1075 const void __user * __user *pages,
1078 #define DO_PAGES_STAT_CHUNK_NR 16
1079 const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR];
1080 int chunk_status[DO_PAGES_STAT_CHUNK_NR];
1083 unsigned long chunk_nr;
1085 chunk_nr = nr_pages;
1086 if (chunk_nr > DO_PAGES_STAT_CHUNK_NR)
1087 chunk_nr = DO_PAGES_STAT_CHUNK_NR;
1089 if (copy_from_user(chunk_pages, pages, chunk_nr * sizeof(*chunk_pages)))
1092 do_pages_stat_array(mm, chunk_nr, chunk_pages, chunk_status);
1094 if (copy_to_user(status, chunk_status, chunk_nr * sizeof(*status)))
1099 nr_pages -= chunk_nr;
1101 return nr_pages ? -EFAULT : 0;
1105 * Move a list of pages in the address space of the currently executing
1108 SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
1109 const void __user * __user *, pages,
1110 const int __user *, nodes,
1111 int __user *, status, int, flags)
1113 const struct cred *cred = current_cred(), *tcred;
1114 struct task_struct *task;
1115 struct mm_struct *mm;
1119 if (flags & ~(MPOL_MF_MOVE|MPOL_MF_MOVE_ALL))
1122 if ((flags & MPOL_MF_MOVE_ALL) && !capable(CAP_SYS_NICE))
1125 /* Find the mm_struct */
1126 read_lock(&tasklist_lock);
1127 task = pid ? find_task_by_vpid(pid) : current;
1129 read_unlock(&tasklist_lock);
1132 mm = get_task_mm(task);
1133 read_unlock(&tasklist_lock);
1139 * Check if this process has the right to modify the specified
1140 * process. The right exists if the process has administrative
1141 * capabilities, superuser privileges or the same
1142 * userid as the target process.
1145 tcred = __task_cred(task);
1146 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
1147 cred->uid != tcred->suid && cred->uid != tcred->uid &&
1148 !capable(CAP_SYS_NICE)) {
1155 err = security_task_movememory(task);
1160 err = do_pages_move(mm, task, nr_pages, pages, nodes, status,
1163 err = do_pages_stat(mm, nr_pages, pages, status);
1172 * Call migration functions in the vma_ops that may prepare
1173 * memory in a vm for migration. migration functions may perform
1174 * the migration for vmas that do not have an underlying page struct.
1176 int migrate_vmas(struct mm_struct *mm, const nodemask_t *to,
1177 const nodemask_t *from, unsigned long flags)
1179 struct vm_area_struct *vma;
1182 for (vma = mm->mmap; vma && !err; vma = vma->vm_next) {
1183 if (vma->vm_ops && vma->vm_ops->migrate) {
1184 err = vma->vm_ops->migrate(vma, to, from, flags);