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 #include <asm/tlbflush.h>
41 #define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))
44 * migrate_prep() needs to be called before we start compiling a list of pages
45 * to be migrated using isolate_lru_page(). If scheduling work on other CPUs is
46 * undesirable, use migrate_prep_local()
48 int migrate_prep(void)
51 * Clear the LRU lists so pages can be isolated.
52 * Note that pages may be moved off the LRU after we have
53 * drained them. Those pages will fail to migrate like other
54 * pages that may be busy.
61 /* Do the necessary work of migrate_prep but not if it involves other CPUs */
62 int migrate_prep_local(void)
70 * Add isolated pages on the list back to the LRU under page lock
71 * to avoid leaking evictable pages back onto unevictable list.
73 void putback_lru_pages(struct list_head
*l
)
78 list_for_each_entry_safe(page
, page2
, l
, lru
) {
80 dec_zone_page_state(page
, NR_ISOLATED_ANON
+
81 page_is_file_cache(page
));
82 putback_lru_page(page
);
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;
559 struct mem_cgroup
*mem
= NULL
;
560 struct anon_vma
*anon_vma
= NULL
;
565 if (page_count(page
) == 1) {
566 /* page was freed from under us. So we are done. */
570 /* prepare cgroup just returns 0 or -ENOMEM */
573 if (!trylock_page(page
)) {
580 * Only memory hotplug's offline_pages() caller has locked out KSM,
581 * and can safely migrate a KSM page. The other cases have skipped
582 * PageKsm along with PageReserved - but it is only now when we have
583 * the page lock that we can be certain it will not go KSM beneath us
584 * (KSM will not upgrade a page from PageAnon to PageKsm when it sees
585 * its pagecount raised, but only here do we take the page lock which
588 if (PageKsm(page
) && !offlining
) {
593 /* charge against new page */
594 charge
= mem_cgroup_prepare_migration(page
, newpage
, &mem
);
595 if (charge
== -ENOMEM
) {
601 if (PageWriteback(page
)) {
604 wait_on_page_writeback(page
);
607 * By try_to_unmap(), page->mapcount goes down to 0 here. In this case,
608 * we cannot notice that anon_vma is freed while we migrates a page.
609 * This get_anon_vma() delays freeing anon_vma pointer until the end
610 * of migration. File cache pages are no problem because of page_lock()
611 * File Caches may use write_page() or lock_page() in migration, then,
612 * just care Anon page here.
614 if (PageAnon(page
)) {
616 * Only page_lock_anon_vma() understands the subtleties of
617 * getting a hold on an anon_vma from outside one of its mms.
619 anon_vma
= page_lock_anon_vma(page
);
622 * Take a reference count on the anon_vma if the
623 * page is mapped so that it is guaranteed to
624 * exist when the page is remapped later
626 get_anon_vma(anon_vma
);
627 page_unlock_anon_vma(anon_vma
);
628 } else if (PageSwapCache(page
)) {
630 * We cannot be sure that the anon_vma of an unmapped
631 * swapcache page is safe to use because we don't
632 * know in advance if the VMA that this page belonged
633 * to still exists. If the VMA and others sharing the
634 * data have been freed, then the anon_vma could
635 * already be invalid.
637 * To avoid this possibility, swapcache pages get
638 * migrated but are not remapped when migration
648 * Corner case handling:
649 * 1. When a new swap-cache page is read into, it is added to the LRU
650 * and treated as swapcache but it has no rmap yet.
651 * Calling try_to_unmap() against a page->mapping==NULL page will
652 * trigger a BUG. So handle it here.
653 * 2. An orphaned page (see truncate_complete_page) might have
654 * fs-private metadata. The page can be picked up due to memory
655 * offlining. Everywhere else except page reclaim, the page is
656 * invisible to the vm, so the page can not be migrated. So try to
657 * free the metadata, so the page can be freed.
659 if (!page
->mapping
) {
660 VM_BUG_ON(PageAnon(page
));
661 if (page_has_private(page
)) {
662 try_to_free_buffers(page
);
668 /* Establish migration ptes or remove ptes */
669 try_to_unmap(page
, TTU_MIGRATION
|TTU_IGNORE_MLOCK
|TTU_IGNORE_ACCESS
);
672 if (!page_mapped(page
))
673 rc
= move_to_new_page(newpage
, page
, remap_swapcache
);
675 if (rc
&& remap_swapcache
)
676 remove_migration_ptes(page
, page
);
678 /* Drop an anon_vma reference if we took one */
680 drop_anon_vma(anon_vma
);
684 mem_cgroup_end_migration(mem
, page
, newpage
);
690 * A page that has been migrated has all references
691 * removed and will be freed. A page that has not been
692 * migrated will have kepts its references and be
695 list_del(&page
->lru
);
696 dec_zone_page_state(page
, NR_ISOLATED_ANON
+
697 page_is_file_cache(page
));
698 putback_lru_page(page
);
704 * Move the new page to the LRU. If migration was not successful
705 * then this will free the page.
707 putback_lru_page(newpage
);
713 *result
= page_to_nid(newpage
);
721 * The function takes one list of pages to migrate and a function
722 * that determines from the page to be migrated and the private data
723 * the target of the move and allocates the page.
725 * The function returns after 10 attempts or if no pages
726 * are movable anymore because to has become empty
727 * or no retryable pages exist anymore. All pages will be
728 * returned to the LRU or freed.
730 * Return: Number of pages not migrated or error code.
732 int migrate_pages(struct list_head
*from
,
733 new_page_t get_new_page
, unsigned long private, int offlining
)
740 int swapwrite
= current
->flags
& PF_SWAPWRITE
;
744 current
->flags
|= PF_SWAPWRITE
;
746 for(pass
= 0; pass
< 10 && retry
; pass
++) {
749 list_for_each_entry_safe(page
, page2
, from
, lru
) {
752 rc
= unmap_and_move(get_new_page
, private,
753 page
, pass
> 2, offlining
);
764 /* Permanent failure */
773 current
->flags
&= ~PF_SWAPWRITE
;
775 putback_lru_pages(from
);
780 return nr_failed
+ retry
;
785 * Move a list of individual pages
787 struct page_to_node
{
794 static struct page
*new_page_node(struct page
*p
, unsigned long private,
797 struct page_to_node
*pm
= (struct page_to_node
*)private;
799 while (pm
->node
!= MAX_NUMNODES
&& pm
->page
!= p
)
802 if (pm
->node
== MAX_NUMNODES
)
805 *result
= &pm
->status
;
807 return alloc_pages_exact_node(pm
->node
,
808 GFP_HIGHUSER_MOVABLE
| GFP_THISNODE
, 0);
812 * Move a set of pages as indicated in the pm array. The addr
813 * field must be set to the virtual address of the page to be moved
814 * and the node number must contain a valid target node.
815 * The pm array ends with node = MAX_NUMNODES.
817 static int do_move_page_to_node_array(struct mm_struct
*mm
,
818 struct page_to_node
*pm
,
822 struct page_to_node
*pp
;
825 down_read(&mm
->mmap_sem
);
828 * Build a list of pages to migrate
830 for (pp
= pm
; pp
->node
!= MAX_NUMNODES
; pp
++) {
831 struct vm_area_struct
*vma
;
835 vma
= find_vma(mm
, pp
->addr
);
836 if (!vma
|| !vma_migratable(vma
))
839 page
= follow_page(vma
, pp
->addr
, FOLL_GET
);
849 /* Use PageReserved to check for zero page */
850 if (PageReserved(page
) || PageKsm(page
))
854 err
= page_to_nid(page
);
858 * Node already in the right place
863 if (page_mapcount(page
) > 1 &&
867 err
= isolate_lru_page(page
);
869 list_add_tail(&page
->lru
, &pagelist
);
870 inc_zone_page_state(page
, NR_ISOLATED_ANON
+
871 page_is_file_cache(page
));
875 * Either remove the duplicate refcount from
876 * isolate_lru_page() or drop the page ref if it was
885 if (!list_empty(&pagelist
))
886 err
= migrate_pages(&pagelist
, new_page_node
,
887 (unsigned long)pm
, 0);
889 up_read(&mm
->mmap_sem
);
894 * Migrate an array of page address onto an array of nodes and fill
895 * the corresponding array of status.
897 static int do_pages_move(struct mm_struct
*mm
, struct task_struct
*task
,
898 unsigned long nr_pages
,
899 const void __user
* __user
*pages
,
900 const int __user
*nodes
,
901 int __user
*status
, int flags
)
903 struct page_to_node
*pm
;
904 nodemask_t task_nodes
;
905 unsigned long chunk_nr_pages
;
906 unsigned long chunk_start
;
909 task_nodes
= cpuset_mems_allowed(task
);
912 pm
= (struct page_to_node
*)__get_free_page(GFP_KERNEL
);
919 * Store a chunk of page_to_node array in a page,
920 * but keep the last one as a marker
922 chunk_nr_pages
= (PAGE_SIZE
/ sizeof(struct page_to_node
)) - 1;
924 for (chunk_start
= 0;
925 chunk_start
< nr_pages
;
926 chunk_start
+= chunk_nr_pages
) {
929 if (chunk_start
+ chunk_nr_pages
> nr_pages
)
930 chunk_nr_pages
= nr_pages
- chunk_start
;
932 /* fill the chunk pm with addrs and nodes from user-space */
933 for (j
= 0; j
< chunk_nr_pages
; j
++) {
934 const void __user
*p
;
938 if (get_user(p
, pages
+ j
+ chunk_start
))
940 pm
[j
].addr
= (unsigned long) p
;
942 if (get_user(node
, nodes
+ j
+ chunk_start
))
946 if (node
< 0 || node
>= MAX_NUMNODES
)
949 if (!node_state(node
, N_HIGH_MEMORY
))
953 if (!node_isset(node
, task_nodes
))
959 /* End marker for this chunk */
960 pm
[chunk_nr_pages
].node
= MAX_NUMNODES
;
962 /* Migrate this chunk */
963 err
= do_move_page_to_node_array(mm
, pm
,
964 flags
& MPOL_MF_MOVE_ALL
);
968 /* Return status information */
969 for (j
= 0; j
< chunk_nr_pages
; j
++)
970 if (put_user(pm
[j
].status
, status
+ j
+ chunk_start
)) {
978 free_page((unsigned long)pm
);
984 * Determine the nodes of an array of pages and store it in an array of status.
986 static void do_pages_stat_array(struct mm_struct
*mm
, unsigned long nr_pages
,
987 const void __user
**pages
, int *status
)
991 down_read(&mm
->mmap_sem
);
993 for (i
= 0; i
< nr_pages
; i
++) {
994 unsigned long addr
= (unsigned long)(*pages
);
995 struct vm_area_struct
*vma
;
999 vma
= find_vma(mm
, addr
);
1003 page
= follow_page(vma
, addr
, 0);
1005 err
= PTR_ERR(page
);
1010 /* Use PageReserved to check for zero page */
1011 if (!page
|| PageReserved(page
) || PageKsm(page
))
1014 err
= page_to_nid(page
);
1022 up_read(&mm
->mmap_sem
);
1026 * Determine the nodes of a user array of pages and store it in
1027 * a user array of status.
1029 static int do_pages_stat(struct mm_struct
*mm
, unsigned long nr_pages
,
1030 const void __user
* __user
*pages
,
1033 #define DO_PAGES_STAT_CHUNK_NR 16
1034 const void __user
*chunk_pages
[DO_PAGES_STAT_CHUNK_NR
];
1035 int chunk_status
[DO_PAGES_STAT_CHUNK_NR
];
1038 unsigned long chunk_nr
;
1040 chunk_nr
= nr_pages
;
1041 if (chunk_nr
> DO_PAGES_STAT_CHUNK_NR
)
1042 chunk_nr
= DO_PAGES_STAT_CHUNK_NR
;
1044 if (copy_from_user(chunk_pages
, pages
, chunk_nr
* sizeof(*chunk_pages
)))
1047 do_pages_stat_array(mm
, chunk_nr
, chunk_pages
, chunk_status
);
1049 if (copy_to_user(status
, chunk_status
, chunk_nr
* sizeof(*status
)))
1054 nr_pages
-= chunk_nr
;
1056 return nr_pages
? -EFAULT
: 0;
1060 * Move a list of pages in the address space of the currently executing
1063 SYSCALL_DEFINE6(move_pages
, pid_t
, pid
, unsigned long, nr_pages
,
1064 const void __user
* __user
*, pages
,
1065 const int __user
*, nodes
,
1066 int __user
*, status
, int, flags
)
1068 const struct cred
*cred
= current_cred(), *tcred
;
1069 struct task_struct
*task
;
1070 struct mm_struct
*mm
;
1074 if (flags
& ~(MPOL_MF_MOVE
|MPOL_MF_MOVE_ALL
))
1077 if ((flags
& MPOL_MF_MOVE_ALL
) && !capable(CAP_SYS_NICE
))
1080 /* Find the mm_struct */
1081 read_lock(&tasklist_lock
);
1082 task
= pid
? find_task_by_vpid(pid
) : current
;
1084 read_unlock(&tasklist_lock
);
1087 mm
= get_task_mm(task
);
1088 read_unlock(&tasklist_lock
);
1094 * Check if this process has the right to modify the specified
1095 * process. The right exists if the process has administrative
1096 * capabilities, superuser privileges or the same
1097 * userid as the target process.
1100 tcred
= __task_cred(task
);
1101 if (cred
->euid
!= tcred
->suid
&& cred
->euid
!= tcred
->uid
&&
1102 cred
->uid
!= tcred
->suid
&& cred
->uid
!= tcred
->uid
&&
1103 !capable(CAP_SYS_NICE
)) {
1110 err
= security_task_movememory(task
);
1115 err
= do_pages_move(mm
, task
, nr_pages
, pages
, nodes
, status
,
1118 err
= do_pages_stat(mm
, nr_pages
, pages
, status
);
1127 * Call migration functions in the vma_ops that may prepare
1128 * memory in a vm for migration. migration functions may perform
1129 * the migration for vmas that do not have an underlying page struct.
1131 int migrate_vmas(struct mm_struct
*mm
, const nodemask_t
*to
,
1132 const nodemask_t
*from
, unsigned long flags
)
1134 struct vm_area_struct
*vma
;
1137 for (vma
= mm
->mmap
; vma
&& !err
; vma
= vma
->vm_next
) {
1138 if (vma
->vm_ops
&& vma
->vm_ops
->migrate
) {
1139 err
= vma
->vm_ops
->migrate(vma
, to
, from
, flags
);