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/export.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/hugetlb.h>
36 #include <linux/hugetlb_cgroup.h>
37 #include <linux/gfp.h>
38 #include <linux/balloon_compaction.h>
39 #include <linux/mmu_notifier.h>
41 #include <asm/tlbflush.h>
43 #define CREATE_TRACE_POINTS
44 #include <trace/events/migrate.h>
49 * migrate_prep() needs to be called before we start compiling a list of pages
50 * to be migrated using isolate_lru_page(). If scheduling work on other CPUs is
51 * undesirable, use migrate_prep_local()
53 int migrate_prep(void)
56 * Clear the LRU lists so pages can be isolated.
57 * Note that pages may be moved off the LRU after we have
58 * drained them. Those pages will fail to migrate like other
59 * pages that may be busy.
66 /* Do the necessary work of migrate_prep but not if it involves other CPUs */
67 int migrate_prep_local(void)
75 * Add isolated pages on the list back to the LRU under page lock
76 * to avoid leaking evictable pages back onto unevictable list.
78 void putback_lru_pages(struct list_head
*l
)
83 list_for_each_entry_safe(page
, page2
, l
, lru
) {
85 dec_zone_page_state(page
, NR_ISOLATED_ANON
+
86 page_is_file_cache(page
));
87 putback_lru_page(page
);
92 * Put previously isolated pages back onto the appropriate lists
93 * from where they were once taken off for compaction/migration.
95 * This function shall be used instead of putback_lru_pages(),
96 * whenever the isolated pageset has been built by isolate_migratepages_range()
98 void putback_movable_pages(struct list_head
*l
)
103 list_for_each_entry_safe(page
, page2
, l
, lru
) {
104 if (unlikely(PageHuge(page
))) {
105 putback_active_hugepage(page
);
108 list_del(&page
->lru
);
109 dec_zone_page_state(page
, NR_ISOLATED_ANON
+
110 page_is_file_cache(page
));
111 if (unlikely(isolated_balloon_page(page
)))
112 balloon_page_putback(page
);
114 putback_lru_page(page
);
119 * Restore a potential migration pte to a working pte entry
121 static int remove_migration_pte(struct page
*new, struct vm_area_struct
*vma
,
122 unsigned long addr
, void *old
)
124 struct mm_struct
*mm
= vma
->vm_mm
;
130 if (unlikely(PageHuge(new))) {
131 ptep
= huge_pte_offset(mm
, addr
);
134 ptl
= &mm
->page_table_lock
;
136 pmd
= mm_find_pmd(mm
, addr
);
139 if (pmd_trans_huge(*pmd
))
142 ptep
= pte_offset_map(pmd
, addr
);
145 * Peek to check is_swap_pte() before taking ptlock? No, we
146 * can race mremap's move_ptes(), which skips anon_vma lock.
149 ptl
= pte_lockptr(mm
, pmd
);
154 if (!is_swap_pte(pte
))
157 entry
= pte_to_swp_entry(pte
);
159 if (!is_migration_entry(entry
) ||
160 migration_entry_to_page(entry
) != old
)
164 pte
= pte_mkold(mk_pte(new, vma
->vm_page_prot
));
165 if (pte_swp_soft_dirty(*ptep
))
166 pte
= pte_mksoft_dirty(pte
);
167 if (is_write_migration_entry(entry
))
168 pte
= pte_mkwrite(pte
);
169 #ifdef CONFIG_HUGETLB_PAGE
171 pte
= pte_mkhuge(pte
);
172 pte
= arch_make_huge_pte(pte
, vma
, new, 0);
175 flush_dcache_page(new);
176 set_pte_at(mm
, addr
, ptep
, pte
);
180 hugepage_add_anon_rmap(new, vma
, addr
);
183 } else if (PageAnon(new))
184 page_add_anon_rmap(new, vma
, addr
);
186 page_add_file_rmap(new);
188 /* No need to invalidate - it was non-present before */
189 update_mmu_cache(vma
, addr
, ptep
);
191 pte_unmap_unlock(ptep
, ptl
);
197 * Get rid of all migration entries and replace them by
198 * references to the indicated page.
200 static void remove_migration_ptes(struct page
*old
, struct page
*new)
202 rmap_walk(new, remove_migration_pte
, old
);
206 * Something used the pte of a page under migration. We need to
207 * get to the page and wait until migration is finished.
208 * When we return from this function the fault will be retried.
210 static void __migration_entry_wait(struct mm_struct
*mm
, pte_t
*ptep
,
219 if (!is_swap_pte(pte
))
222 entry
= pte_to_swp_entry(pte
);
223 if (!is_migration_entry(entry
))
226 page
= migration_entry_to_page(entry
);
229 * Once radix-tree replacement of page migration started, page_count
230 * *must* be zero. And, we don't want to call wait_on_page_locked()
231 * against a page without get_page().
232 * So, we use get_page_unless_zero(), here. Even failed, page fault
235 if (!get_page_unless_zero(page
))
237 pte_unmap_unlock(ptep
, ptl
);
238 wait_on_page_locked(page
);
242 pte_unmap_unlock(ptep
, ptl
);
245 void migration_entry_wait(struct mm_struct
*mm
, pmd_t
*pmd
,
246 unsigned long address
)
248 spinlock_t
*ptl
= pte_lockptr(mm
, pmd
);
249 pte_t
*ptep
= pte_offset_map(pmd
, address
);
250 __migration_entry_wait(mm
, ptep
, ptl
);
253 void migration_entry_wait_huge(struct mm_struct
*mm
, pte_t
*pte
)
255 spinlock_t
*ptl
= &(mm
)->page_table_lock
;
256 __migration_entry_wait(mm
, pte
, ptl
);
260 /* Returns true if all buffers are successfully locked */
261 static bool buffer_migrate_lock_buffers(struct buffer_head
*head
,
262 enum migrate_mode mode
)
264 struct buffer_head
*bh
= head
;
266 /* Simple case, sync compaction */
267 if (mode
!= MIGRATE_ASYNC
) {
271 bh
= bh
->b_this_page
;
273 } while (bh
!= head
);
278 /* async case, we cannot block on lock_buffer so use trylock_buffer */
281 if (!trylock_buffer(bh
)) {
283 * We failed to lock the buffer and cannot stall in
284 * async migration. Release the taken locks
286 struct buffer_head
*failed_bh
= bh
;
289 while (bh
!= failed_bh
) {
292 bh
= bh
->b_this_page
;
297 bh
= bh
->b_this_page
;
298 } while (bh
!= head
);
302 static inline bool buffer_migrate_lock_buffers(struct buffer_head
*head
,
303 enum migrate_mode mode
)
307 #endif /* CONFIG_BLOCK */
310 * Replace the page in the mapping.
312 * The number of remaining references must be:
313 * 1 for anonymous pages without a mapping
314 * 2 for pages with a mapping
315 * 3 for pages with a mapping and PagePrivate/PagePrivate2 set.
317 int migrate_page_move_mapping(struct address_space
*mapping
,
318 struct page
*newpage
, struct page
*page
,
319 struct buffer_head
*head
, enum migrate_mode mode
,
322 int expected_count
= 1 + extra_count
;
326 /* Anonymous page without mapping */
327 if (page_count(page
) != expected_count
)
329 return MIGRATEPAGE_SUCCESS
;
332 spin_lock_irq(&mapping
->tree_lock
);
334 pslot
= radix_tree_lookup_slot(&mapping
->page_tree
,
337 expected_count
+= 1 + page_has_private(page
);
338 if (page_count(page
) != expected_count
||
339 radix_tree_deref_slot_protected(pslot
, &mapping
->tree_lock
) != page
) {
340 spin_unlock_irq(&mapping
->tree_lock
);
344 if (!page_freeze_refs(page
, expected_count
)) {
345 spin_unlock_irq(&mapping
->tree_lock
);
350 * In the async migration case of moving a page with buffers, lock the
351 * buffers using trylock before the mapping is moved. If the mapping
352 * was moved, we later failed to lock the buffers and could not move
353 * the mapping back due to an elevated page count, we would have to
354 * block waiting on other references to be dropped.
356 if (mode
== MIGRATE_ASYNC
&& head
&&
357 !buffer_migrate_lock_buffers(head
, mode
)) {
358 page_unfreeze_refs(page
, expected_count
);
359 spin_unlock_irq(&mapping
->tree_lock
);
364 * Now we know that no one else is looking at the page.
366 get_page(newpage
); /* add cache reference */
367 if (PageSwapCache(page
)) {
368 SetPageSwapCache(newpage
);
369 set_page_private(newpage
, page_private(page
));
372 radix_tree_replace_slot(pslot
, newpage
);
375 * Drop cache reference from old page by unfreezing
376 * to one less reference.
377 * We know this isn't the last reference.
379 page_unfreeze_refs(page
, expected_count
- 1);
382 * If moved to a different zone then also account
383 * the page for that zone. Other VM counters will be
384 * taken care of when we establish references to the
385 * new page and drop references to the old page.
387 * Note that anonymous pages are accounted for
388 * via NR_FILE_PAGES and NR_ANON_PAGES if they
389 * are mapped to swap space.
391 __dec_zone_page_state(page
, NR_FILE_PAGES
);
392 __inc_zone_page_state(newpage
, NR_FILE_PAGES
);
393 if (!PageSwapCache(page
) && PageSwapBacked(page
)) {
394 __dec_zone_page_state(page
, NR_SHMEM
);
395 __inc_zone_page_state(newpage
, NR_SHMEM
);
397 spin_unlock_irq(&mapping
->tree_lock
);
399 return MIGRATEPAGE_SUCCESS
;
403 * The expected number of remaining references is the same as that
404 * of migrate_page_move_mapping().
406 int migrate_huge_page_move_mapping(struct address_space
*mapping
,
407 struct page
*newpage
, struct page
*page
)
413 if (page_count(page
) != 1)
415 return MIGRATEPAGE_SUCCESS
;
418 spin_lock_irq(&mapping
->tree_lock
);
420 pslot
= radix_tree_lookup_slot(&mapping
->page_tree
,
423 expected_count
= 2 + page_has_private(page
);
424 if (page_count(page
) != expected_count
||
425 radix_tree_deref_slot_protected(pslot
, &mapping
->tree_lock
) != page
) {
426 spin_unlock_irq(&mapping
->tree_lock
);
430 if (!page_freeze_refs(page
, expected_count
)) {
431 spin_unlock_irq(&mapping
->tree_lock
);
437 radix_tree_replace_slot(pslot
, newpage
);
439 page_unfreeze_refs(page
, expected_count
- 1);
441 spin_unlock_irq(&mapping
->tree_lock
);
442 return MIGRATEPAGE_SUCCESS
;
446 * Copy the page to its new location
448 void migrate_page_copy(struct page
*newpage
, struct page
*page
)
450 if (PageHuge(page
) || PageTransHuge(page
))
451 copy_huge_page(newpage
, page
);
453 copy_highpage(newpage
, page
);
456 SetPageError(newpage
);
457 if (PageReferenced(page
))
458 SetPageReferenced(newpage
);
459 if (PageUptodate(page
))
460 SetPageUptodate(newpage
);
461 if (TestClearPageActive(page
)) {
462 VM_BUG_ON(PageUnevictable(page
));
463 SetPageActive(newpage
);
464 } else if (TestClearPageUnevictable(page
))
465 SetPageUnevictable(newpage
);
466 if (PageChecked(page
))
467 SetPageChecked(newpage
);
468 if (PageMappedToDisk(page
))
469 SetPageMappedToDisk(newpage
);
471 if (PageDirty(page
)) {
472 clear_page_dirty_for_io(page
);
474 * Want to mark the page and the radix tree as dirty, and
475 * redo the accounting that clear_page_dirty_for_io undid,
476 * but we can't use set_page_dirty because that function
477 * is actually a signal that all of the page has become dirty.
478 * Whereas only part of our page may be dirty.
480 if (PageSwapBacked(page
))
481 SetPageDirty(newpage
);
483 __set_page_dirty_nobuffers(newpage
);
486 mlock_migrate_page(newpage
, page
);
487 ksm_migrate_page(newpage
, page
);
489 * Please do not reorder this without considering how mm/ksm.c's
490 * get_ksm_page() depends upon ksm_migrate_page() and PageSwapCache().
492 ClearPageSwapCache(page
);
493 ClearPagePrivate(page
);
494 set_page_private(page
, 0);
497 * If any waiters have accumulated on the new page then
500 if (PageWriteback(newpage
))
501 end_page_writeback(newpage
);
504 /************************************************************
505 * Migration functions
506 ***********************************************************/
508 /* Always fail migration. Used for mappings that are not movable */
509 int fail_migrate_page(struct address_space
*mapping
,
510 struct page
*newpage
, struct page
*page
)
514 EXPORT_SYMBOL(fail_migrate_page
);
517 * Common logic to directly migrate a single page suitable for
518 * pages that do not use PagePrivate/PagePrivate2.
520 * Pages are locked upon entry and exit.
522 int migrate_page(struct address_space
*mapping
,
523 struct page
*newpage
, struct page
*page
,
524 enum migrate_mode mode
)
528 BUG_ON(PageWriteback(page
)); /* Writeback must be complete */
530 rc
= migrate_page_move_mapping(mapping
, newpage
, page
, NULL
, mode
, 0);
532 if (rc
!= MIGRATEPAGE_SUCCESS
)
535 migrate_page_copy(newpage
, page
);
536 return MIGRATEPAGE_SUCCESS
;
538 EXPORT_SYMBOL(migrate_page
);
542 * Migration function for pages with buffers. This function can only be used
543 * if the underlying filesystem guarantees that no other references to "page"
546 int buffer_migrate_page(struct address_space
*mapping
,
547 struct page
*newpage
, struct page
*page
, enum migrate_mode mode
)
549 struct buffer_head
*bh
, *head
;
552 if (!page_has_buffers(page
))
553 return migrate_page(mapping
, newpage
, page
, mode
);
555 head
= page_buffers(page
);
557 rc
= migrate_page_move_mapping(mapping
, newpage
, page
, head
, mode
, 0);
559 if (rc
!= MIGRATEPAGE_SUCCESS
)
563 * In the async case, migrate_page_move_mapping locked the buffers
564 * with an IRQ-safe spinlock held. In the sync case, the buffers
565 * need to be locked now
567 if (mode
!= MIGRATE_ASYNC
)
568 BUG_ON(!buffer_migrate_lock_buffers(head
, mode
));
570 ClearPagePrivate(page
);
571 set_page_private(newpage
, page_private(page
));
572 set_page_private(page
, 0);
578 set_bh_page(bh
, newpage
, bh_offset(bh
));
579 bh
= bh
->b_this_page
;
581 } while (bh
!= head
);
583 SetPagePrivate(newpage
);
585 migrate_page_copy(newpage
, page
);
591 bh
= bh
->b_this_page
;
593 } while (bh
!= head
);
595 return MIGRATEPAGE_SUCCESS
;
597 EXPORT_SYMBOL(buffer_migrate_page
);
601 * Writeback a page to clean the dirty state
603 static int writeout(struct address_space
*mapping
, struct page
*page
)
605 struct writeback_control wbc
= {
606 .sync_mode
= WB_SYNC_NONE
,
609 .range_end
= LLONG_MAX
,
614 if (!mapping
->a_ops
->writepage
)
615 /* No write method for the address space */
618 if (!clear_page_dirty_for_io(page
))
619 /* Someone else already triggered a write */
623 * A dirty page may imply that the underlying filesystem has
624 * the page on some queue. So the page must be clean for
625 * migration. Writeout may mean we loose the lock and the
626 * page state is no longer what we checked for earlier.
627 * At this point we know that the migration attempt cannot
630 remove_migration_ptes(page
, page
);
632 rc
= mapping
->a_ops
->writepage(page
, &wbc
);
634 if (rc
!= AOP_WRITEPAGE_ACTIVATE
)
635 /* unlocked. Relock */
638 return (rc
< 0) ? -EIO
: -EAGAIN
;
642 * Default handling if a filesystem does not provide a migration function.
644 static int fallback_migrate_page(struct address_space
*mapping
,
645 struct page
*newpage
, struct page
*page
, enum migrate_mode mode
)
647 if (PageDirty(page
)) {
648 /* Only writeback pages in full synchronous migration */
649 if (mode
!= MIGRATE_SYNC
)
651 return writeout(mapping
, page
);
655 * Buffers may be managed in a filesystem specific way.
656 * We must have no buffers or drop them.
658 if (page_has_private(page
) &&
659 !try_to_release_page(page
, GFP_KERNEL
))
662 return migrate_page(mapping
, newpage
, page
, mode
);
666 * Move a page to a newly allocated page
667 * The page is locked and all ptes have been successfully removed.
669 * The new page will have replaced the old page if this function
674 * MIGRATEPAGE_SUCCESS - success
676 static int move_to_new_page(struct page
*newpage
, struct page
*page
,
677 int remap_swapcache
, enum migrate_mode mode
)
679 struct address_space
*mapping
;
683 * Block others from accessing the page when we get around to
684 * establishing additional references. We are the only one
685 * holding a reference to the new page at this point.
687 if (!trylock_page(newpage
))
690 /* Prepare mapping for the new page.*/
691 newpage
->index
= page
->index
;
692 newpage
->mapping
= page
->mapping
;
693 if (PageSwapBacked(page
))
694 SetPageSwapBacked(newpage
);
696 mapping
= page_mapping(page
);
698 rc
= migrate_page(mapping
, newpage
, page
, mode
);
699 else if (mapping
->a_ops
->migratepage
)
701 * Most pages have a mapping and most filesystems provide a
702 * migratepage callback. Anonymous pages are part of swap
703 * space which also has its own migratepage callback. This
704 * is the most common path for page migration.
706 rc
= mapping
->a_ops
->migratepage(mapping
,
707 newpage
, page
, mode
);
709 rc
= fallback_migrate_page(mapping
, newpage
, page
, mode
);
711 if (rc
!= MIGRATEPAGE_SUCCESS
) {
712 newpage
->mapping
= NULL
;
715 remove_migration_ptes(page
, newpage
);
716 page
->mapping
= NULL
;
719 unlock_page(newpage
);
724 static int __unmap_and_move(struct page
*page
, struct page
*newpage
,
725 int force
, enum migrate_mode mode
)
728 int remap_swapcache
= 1;
729 struct mem_cgroup
*mem
;
730 struct anon_vma
*anon_vma
= NULL
;
732 if (!trylock_page(page
)) {
733 if (!force
|| mode
== MIGRATE_ASYNC
)
737 * It's not safe for direct compaction to call lock_page.
738 * For example, during page readahead pages are added locked
739 * to the LRU. Later, when the IO completes the pages are
740 * marked uptodate and unlocked. However, the queueing
741 * could be merging multiple pages for one bio (e.g.
742 * mpage_readpages). If an allocation happens for the
743 * second or third page, the process can end up locking
744 * the same page twice and deadlocking. Rather than
745 * trying to be clever about what pages can be locked,
746 * avoid the use of lock_page for direct compaction
749 if (current
->flags
& PF_MEMALLOC
)
755 /* charge against new page */
756 mem_cgroup_prepare_migration(page
, newpage
, &mem
);
758 if (PageWriteback(page
)) {
760 * Only in the case of a full synchronous migration is it
761 * necessary to wait for PageWriteback. In the async case,
762 * the retry loop is too short and in the sync-light case,
763 * the overhead of stalling is too much
765 if (mode
!= MIGRATE_SYNC
) {
771 wait_on_page_writeback(page
);
774 * By try_to_unmap(), page->mapcount goes down to 0 here. In this case,
775 * we cannot notice that anon_vma is freed while we migrates a page.
776 * This get_anon_vma() delays freeing anon_vma pointer until the end
777 * of migration. File cache pages are no problem because of page_lock()
778 * File Caches may use write_page() or lock_page() in migration, then,
779 * just care Anon page here.
781 if (PageAnon(page
) && !PageKsm(page
)) {
783 * Only page_lock_anon_vma_read() understands the subtleties of
784 * getting a hold on an anon_vma from outside one of its mms.
786 anon_vma
= page_get_anon_vma(page
);
791 } else if (PageSwapCache(page
)) {
793 * We cannot be sure that the anon_vma of an unmapped
794 * swapcache page is safe to use because we don't
795 * know in advance if the VMA that this page belonged
796 * to still exists. If the VMA and others sharing the
797 * data have been freed, then the anon_vma could
798 * already be invalid.
800 * To avoid this possibility, swapcache pages get
801 * migrated but are not remapped when migration
810 if (unlikely(balloon_page_movable(page
))) {
812 * A ballooned page does not need any special attention from
813 * physical to virtual reverse mapping procedures.
814 * Skip any attempt to unmap PTEs or to remap swap cache,
815 * in order to avoid burning cycles at rmap level, and perform
816 * the page migration right away (proteced by page lock).
818 rc
= balloon_page_migrate(newpage
, page
, mode
);
823 * Corner case handling:
824 * 1. When a new swap-cache page is read into, it is added to the LRU
825 * and treated as swapcache but it has no rmap yet.
826 * Calling try_to_unmap() against a page->mapping==NULL page will
827 * trigger a BUG. So handle it here.
828 * 2. An orphaned page (see truncate_complete_page) might have
829 * fs-private metadata. The page can be picked up due to memory
830 * offlining. Everywhere else except page reclaim, the page is
831 * invisible to the vm, so the page can not be migrated. So try to
832 * free the metadata, so the page can be freed.
834 if (!page
->mapping
) {
835 VM_BUG_ON(PageAnon(page
));
836 if (page_has_private(page
)) {
837 try_to_free_buffers(page
);
843 /* Establish migration ptes or remove ptes */
844 try_to_unmap(page
, TTU_MIGRATION
|TTU_IGNORE_MLOCK
|TTU_IGNORE_ACCESS
);
847 if (!page_mapped(page
))
848 rc
= move_to_new_page(newpage
, page
, remap_swapcache
, mode
);
850 if (rc
&& remap_swapcache
)
851 remove_migration_ptes(page
, page
);
853 /* Drop an anon_vma reference if we took one */
855 put_anon_vma(anon_vma
);
858 mem_cgroup_end_migration(mem
, page
, newpage
,
859 (rc
== MIGRATEPAGE_SUCCESS
||
860 rc
== MIGRATEPAGE_BALLOON_SUCCESS
));
867 * Obtain the lock on page, remove all ptes and migrate the page
868 * to the newly allocated page in newpage.
870 static int unmap_and_move(new_page_t get_new_page
, unsigned long private,
871 struct page
*page
, int force
, enum migrate_mode mode
)
875 struct page
*newpage
= get_new_page(page
, private, &result
);
880 if (page_count(page
) == 1) {
881 /* page was freed from under us. So we are done. */
885 if (unlikely(PageTransHuge(page
)))
886 if (unlikely(split_huge_page(page
)))
889 rc
= __unmap_and_move(page
, newpage
, force
, mode
);
891 if (unlikely(rc
== MIGRATEPAGE_BALLOON_SUCCESS
)) {
893 * A ballooned page has been migrated already.
894 * Now, it's the time to wrap-up counters,
895 * handle the page back to Buddy and return.
897 dec_zone_page_state(page
, NR_ISOLATED_ANON
+
898 page_is_file_cache(page
));
899 balloon_page_free(page
);
900 return MIGRATEPAGE_SUCCESS
;
905 * A page that has been migrated has all references
906 * removed and will be freed. A page that has not been
907 * migrated will have kepts its references and be
910 list_del(&page
->lru
);
911 dec_zone_page_state(page
, NR_ISOLATED_ANON
+
912 page_is_file_cache(page
));
913 putback_lru_page(page
);
916 * Move the new page to the LRU. If migration was not successful
917 * then this will free the page.
919 putback_lru_page(newpage
);
924 *result
= page_to_nid(newpage
);
930 * Counterpart of unmap_and_move_page() for hugepage migration.
932 * This function doesn't wait the completion of hugepage I/O
933 * because there is no race between I/O and migration for hugepage.
934 * Note that currently hugepage I/O occurs only in direct I/O
935 * where no lock is held and PG_writeback is irrelevant,
936 * and writeback status of all subpages are counted in the reference
937 * count of the head page (i.e. if all subpages of a 2MB hugepage are
938 * under direct I/O, the reference of the head page is 512 and a bit more.)
939 * This means that when we try to migrate hugepage whose subpages are
940 * doing direct I/O, some references remain after try_to_unmap() and
941 * hugepage migration fails without data corruption.
943 * There is also no race when direct I/O is issued on the page under migration,
944 * because then pte is replaced with migration swap entry and direct I/O code
945 * will wait in the page fault for migration to complete.
947 static int unmap_and_move_huge_page(new_page_t get_new_page
,
948 unsigned long private, struct page
*hpage
,
949 int force
, enum migrate_mode mode
)
953 struct page
*new_hpage
= get_new_page(hpage
, private, &result
);
954 struct anon_vma
*anon_vma
= NULL
;
957 * Movability of hugepages depends on architectures and hugepage size.
958 * This check is necessary because some callers of hugepage migration
959 * like soft offline and memory hotremove don't walk through page
960 * tables or check whether the hugepage is pmd-based or not before
963 if (!hugepage_migration_support(page_hstate(hpage
)))
971 if (!trylock_page(hpage
)) {
972 if (!force
|| mode
!= MIGRATE_SYNC
)
978 anon_vma
= page_get_anon_vma(hpage
);
980 try_to_unmap(hpage
, TTU_MIGRATION
|TTU_IGNORE_MLOCK
|TTU_IGNORE_ACCESS
);
982 if (!page_mapped(hpage
))
983 rc
= move_to_new_page(new_hpage
, hpage
, 1, mode
);
986 remove_migration_ptes(hpage
, hpage
);
989 put_anon_vma(anon_vma
);
992 hugetlb_cgroup_migrate(hpage
, new_hpage
);
997 putback_active_hugepage(hpage
);
1003 *result
= page_to_nid(new_hpage
);
1009 * migrate_pages - migrate the pages specified in a list, to the free pages
1010 * supplied as the target for the page migration
1012 * @from: The list of pages to be migrated.
1013 * @get_new_page: The function used to allocate free pages to be used
1014 * as the target of the page migration.
1015 * @private: Private data to be passed on to get_new_page()
1016 * @mode: The migration mode that specifies the constraints for
1017 * page migration, if any.
1018 * @reason: The reason for page migration.
1020 * The function returns after 10 attempts or if no pages are movable any more
1021 * because the list has become empty or no retryable pages exist any more.
1022 * The caller should call putback_lru_pages() to return pages to the LRU
1023 * or free list only if ret != 0.
1025 * Returns the number of pages that were not migrated, or an error code.
1027 int migrate_pages(struct list_head
*from
, new_page_t get_new_page
,
1028 unsigned long private, enum migrate_mode mode
, int reason
)
1032 int nr_succeeded
= 0;
1036 int swapwrite
= current
->flags
& PF_SWAPWRITE
;
1040 current
->flags
|= PF_SWAPWRITE
;
1042 for(pass
= 0; pass
< 10 && retry
; pass
++) {
1045 list_for_each_entry_safe(page
, page2
, from
, lru
) {
1049 rc
= unmap_and_move_huge_page(get_new_page
,
1050 private, page
, pass
> 2, mode
);
1052 rc
= unmap_and_move(get_new_page
, private,
1053 page
, pass
> 2, mode
);
1061 case MIGRATEPAGE_SUCCESS
:
1065 /* Permanent failure */
1071 rc
= nr_failed
+ retry
;
1074 count_vm_events(PGMIGRATE_SUCCESS
, nr_succeeded
);
1076 count_vm_events(PGMIGRATE_FAIL
, nr_failed
);
1077 trace_mm_migrate_pages(nr_succeeded
, nr_failed
, mode
, reason
);
1080 current
->flags
&= ~PF_SWAPWRITE
;
1087 * Move a list of individual pages
1089 struct page_to_node
{
1096 static struct page
*new_page_node(struct page
*p
, unsigned long private,
1099 struct page_to_node
*pm
= (struct page_to_node
*)private;
1101 while (pm
->node
!= MAX_NUMNODES
&& pm
->page
!= p
)
1104 if (pm
->node
== MAX_NUMNODES
)
1107 *result
= &pm
->status
;
1110 return alloc_huge_page_node(page_hstate(compound_head(p
)),
1113 return alloc_pages_exact_node(pm
->node
,
1114 GFP_HIGHUSER_MOVABLE
| GFP_THISNODE
, 0);
1118 * Move a set of pages as indicated in the pm array. The addr
1119 * field must be set to the virtual address of the page to be moved
1120 * and the node number must contain a valid target node.
1121 * The pm array ends with node = MAX_NUMNODES.
1123 static int do_move_page_to_node_array(struct mm_struct
*mm
,
1124 struct page_to_node
*pm
,
1128 struct page_to_node
*pp
;
1129 LIST_HEAD(pagelist
);
1131 down_read(&mm
->mmap_sem
);
1134 * Build a list of pages to migrate
1136 for (pp
= pm
; pp
->node
!= MAX_NUMNODES
; pp
++) {
1137 struct vm_area_struct
*vma
;
1141 vma
= find_vma(mm
, pp
->addr
);
1142 if (!vma
|| pp
->addr
< vma
->vm_start
|| !vma_migratable(vma
))
1145 page
= follow_page(vma
, pp
->addr
, FOLL_GET
|FOLL_SPLIT
);
1147 err
= PTR_ERR(page
);
1155 /* Use PageReserved to check for zero page */
1156 if (PageReserved(page
))
1160 err
= page_to_nid(page
);
1162 if (err
== pp
->node
)
1164 * Node already in the right place
1169 if (page_mapcount(page
) > 1 &&
1173 if (PageHuge(page
)) {
1174 isolate_huge_page(page
, &pagelist
);
1178 err
= isolate_lru_page(page
);
1180 list_add_tail(&page
->lru
, &pagelist
);
1181 inc_zone_page_state(page
, NR_ISOLATED_ANON
+
1182 page_is_file_cache(page
));
1186 * Either remove the duplicate refcount from
1187 * isolate_lru_page() or drop the page ref if it was
1196 if (!list_empty(&pagelist
)) {
1197 err
= migrate_pages(&pagelist
, new_page_node
,
1198 (unsigned long)pm
, MIGRATE_SYNC
, MR_SYSCALL
);
1200 putback_movable_pages(&pagelist
);
1203 up_read(&mm
->mmap_sem
);
1208 * Migrate an array of page address onto an array of nodes and fill
1209 * the corresponding array of status.
1211 static int do_pages_move(struct mm_struct
*mm
, nodemask_t task_nodes
,
1212 unsigned long nr_pages
,
1213 const void __user
* __user
*pages
,
1214 const int __user
*nodes
,
1215 int __user
*status
, int flags
)
1217 struct page_to_node
*pm
;
1218 unsigned long chunk_nr_pages
;
1219 unsigned long chunk_start
;
1223 pm
= (struct page_to_node
*)__get_free_page(GFP_KERNEL
);
1230 * Store a chunk of page_to_node array in a page,
1231 * but keep the last one as a marker
1233 chunk_nr_pages
= (PAGE_SIZE
/ sizeof(struct page_to_node
)) - 1;
1235 for (chunk_start
= 0;
1236 chunk_start
< nr_pages
;
1237 chunk_start
+= chunk_nr_pages
) {
1240 if (chunk_start
+ chunk_nr_pages
> nr_pages
)
1241 chunk_nr_pages
= nr_pages
- chunk_start
;
1243 /* fill the chunk pm with addrs and nodes from user-space */
1244 for (j
= 0; j
< chunk_nr_pages
; j
++) {
1245 const void __user
*p
;
1249 if (get_user(p
, pages
+ j
+ chunk_start
))
1251 pm
[j
].addr
= (unsigned long) p
;
1253 if (get_user(node
, nodes
+ j
+ chunk_start
))
1257 if (node
< 0 || node
>= MAX_NUMNODES
)
1260 if (!node_state(node
, N_MEMORY
))
1264 if (!node_isset(node
, task_nodes
))
1270 /* End marker for this chunk */
1271 pm
[chunk_nr_pages
].node
= MAX_NUMNODES
;
1273 /* Migrate this chunk */
1274 err
= do_move_page_to_node_array(mm
, pm
,
1275 flags
& MPOL_MF_MOVE_ALL
);
1279 /* Return status information */
1280 for (j
= 0; j
< chunk_nr_pages
; j
++)
1281 if (put_user(pm
[j
].status
, status
+ j
+ chunk_start
)) {
1289 free_page((unsigned long)pm
);
1295 * Determine the nodes of an array of pages and store it in an array of status.
1297 static void do_pages_stat_array(struct mm_struct
*mm
, unsigned long nr_pages
,
1298 const void __user
**pages
, int *status
)
1302 down_read(&mm
->mmap_sem
);
1304 for (i
= 0; i
< nr_pages
; i
++) {
1305 unsigned long addr
= (unsigned long)(*pages
);
1306 struct vm_area_struct
*vma
;
1310 vma
= find_vma(mm
, addr
);
1311 if (!vma
|| addr
< vma
->vm_start
)
1314 page
= follow_page(vma
, addr
, 0);
1316 err
= PTR_ERR(page
);
1321 /* Use PageReserved to check for zero page */
1322 if (!page
|| PageReserved(page
))
1325 err
= page_to_nid(page
);
1333 up_read(&mm
->mmap_sem
);
1337 * Determine the nodes of a user array of pages and store it in
1338 * a user array of status.
1340 static int do_pages_stat(struct mm_struct
*mm
, unsigned long nr_pages
,
1341 const void __user
* __user
*pages
,
1344 #define DO_PAGES_STAT_CHUNK_NR 16
1345 const void __user
*chunk_pages
[DO_PAGES_STAT_CHUNK_NR
];
1346 int chunk_status
[DO_PAGES_STAT_CHUNK_NR
];
1349 unsigned long chunk_nr
;
1351 chunk_nr
= nr_pages
;
1352 if (chunk_nr
> DO_PAGES_STAT_CHUNK_NR
)
1353 chunk_nr
= DO_PAGES_STAT_CHUNK_NR
;
1355 if (copy_from_user(chunk_pages
, pages
, chunk_nr
* sizeof(*chunk_pages
)))
1358 do_pages_stat_array(mm
, chunk_nr
, chunk_pages
, chunk_status
);
1360 if (copy_to_user(status
, chunk_status
, chunk_nr
* sizeof(*status
)))
1365 nr_pages
-= chunk_nr
;
1367 return nr_pages
? -EFAULT
: 0;
1371 * Move a list of pages in the address space of the currently executing
1374 SYSCALL_DEFINE6(move_pages
, pid_t
, pid
, unsigned long, nr_pages
,
1375 const void __user
* __user
*, pages
,
1376 const int __user
*, nodes
,
1377 int __user
*, status
, int, flags
)
1379 const struct cred
*cred
= current_cred(), *tcred
;
1380 struct task_struct
*task
;
1381 struct mm_struct
*mm
;
1383 nodemask_t task_nodes
;
1386 if (flags
& ~(MPOL_MF_MOVE
|MPOL_MF_MOVE_ALL
))
1389 if ((flags
& MPOL_MF_MOVE_ALL
) && !capable(CAP_SYS_NICE
))
1392 /* Find the mm_struct */
1394 task
= pid
? find_task_by_vpid(pid
) : current
;
1399 get_task_struct(task
);
1402 * Check if this process has the right to modify the specified
1403 * process. The right exists if the process has administrative
1404 * capabilities, superuser privileges or the same
1405 * userid as the target process.
1407 tcred
= __task_cred(task
);
1408 if (!uid_eq(cred
->euid
, tcred
->suid
) && !uid_eq(cred
->euid
, tcred
->uid
) &&
1409 !uid_eq(cred
->uid
, tcred
->suid
) && !uid_eq(cred
->uid
, tcred
->uid
) &&
1410 !capable(CAP_SYS_NICE
)) {
1417 err
= security_task_movememory(task
);
1421 task_nodes
= cpuset_mems_allowed(task
);
1422 mm
= get_task_mm(task
);
1423 put_task_struct(task
);
1429 err
= do_pages_move(mm
, task_nodes
, nr_pages
, pages
,
1430 nodes
, status
, flags
);
1432 err
= do_pages_stat(mm
, nr_pages
, pages
, status
);
1438 put_task_struct(task
);
1443 * Call migration functions in the vma_ops that may prepare
1444 * memory in a vm for migration. migration functions may perform
1445 * the migration for vmas that do not have an underlying page struct.
1447 int migrate_vmas(struct mm_struct
*mm
, const nodemask_t
*to
,
1448 const nodemask_t
*from
, unsigned long flags
)
1450 struct vm_area_struct
*vma
;
1453 for (vma
= mm
->mmap
; vma
&& !err
; vma
= vma
->vm_next
) {
1454 if (vma
->vm_ops
&& vma
->vm_ops
->migrate
) {
1455 err
= vma
->vm_ops
->migrate(vma
, to
, from
, flags
);
1463 #ifdef CONFIG_NUMA_BALANCING
1465 * Returns true if this is a safe migration target node for misplaced NUMA
1466 * pages. Currently it only checks the watermarks which crude
1468 static bool migrate_balanced_pgdat(struct pglist_data
*pgdat
,
1469 unsigned long nr_migrate_pages
)
1472 for (z
= pgdat
->nr_zones
- 1; z
>= 0; z
--) {
1473 struct zone
*zone
= pgdat
->node_zones
+ z
;
1475 if (!populated_zone(zone
))
1478 if (!zone_reclaimable(zone
))
1481 /* Avoid waking kswapd by allocating pages_to_migrate pages. */
1482 if (!zone_watermark_ok(zone
, 0,
1483 high_wmark_pages(zone
) +
1492 static struct page
*alloc_misplaced_dst_page(struct page
*page
,
1496 int nid
= (int) data
;
1497 struct page
*newpage
;
1499 newpage
= alloc_pages_exact_node(nid
,
1500 (GFP_HIGHUSER_MOVABLE
| GFP_THISNODE
|
1501 __GFP_NOMEMALLOC
| __GFP_NORETRY
|
1505 page_nid_xchg_last(newpage
, page_nid_last(page
));
1511 * page migration rate limiting control.
1512 * Do not migrate more than @pages_to_migrate in a @migrate_interval_millisecs
1513 * window of time. Default here says do not migrate more than 1280M per second.
1514 * If a node is rate-limited then PTE NUMA updates are also rate-limited. However
1515 * as it is faults that reset the window, pte updates will happen unconditionally
1516 * if there has not been a fault since @pteupdate_interval_millisecs after the
1517 * throttle window closed.
1519 static unsigned int migrate_interval_millisecs __read_mostly
= 100;
1520 static unsigned int pteupdate_interval_millisecs __read_mostly
= 1000;
1521 static unsigned int ratelimit_pages __read_mostly
= 128 << (20 - PAGE_SHIFT
);
1523 /* Returns true if NUMA migration is currently rate limited */
1524 bool migrate_ratelimited(int node
)
1526 pg_data_t
*pgdat
= NODE_DATA(node
);
1528 if (time_after(jiffies
, pgdat
->numabalancing_migrate_next_window
+
1529 msecs_to_jiffies(pteupdate_interval_millisecs
)))
1532 if (pgdat
->numabalancing_migrate_nr_pages
< ratelimit_pages
)
1538 /* Returns true if the node is migrate rate-limited after the update */
1539 bool numamigrate_update_ratelimit(pg_data_t
*pgdat
, unsigned long nr_pages
)
1541 bool rate_limited
= false;
1544 * Rate-limit the amount of data that is being migrated to a node.
1545 * Optimal placement is no good if the memory bus is saturated and
1546 * all the time is being spent migrating!
1548 spin_lock(&pgdat
->numabalancing_migrate_lock
);
1549 if (time_after(jiffies
, pgdat
->numabalancing_migrate_next_window
)) {
1550 pgdat
->numabalancing_migrate_nr_pages
= 0;
1551 pgdat
->numabalancing_migrate_next_window
= jiffies
+
1552 msecs_to_jiffies(migrate_interval_millisecs
);
1554 if (pgdat
->numabalancing_migrate_nr_pages
> ratelimit_pages
)
1555 rate_limited
= true;
1557 pgdat
->numabalancing_migrate_nr_pages
+= nr_pages
;
1558 spin_unlock(&pgdat
->numabalancing_migrate_lock
);
1560 return rate_limited
;
1563 int numamigrate_isolate_page(pg_data_t
*pgdat
, struct page
*page
)
1567 VM_BUG_ON(compound_order(page
) && !PageTransHuge(page
));
1569 /* Avoid migrating to a node that is nearly full */
1570 if (!migrate_balanced_pgdat(pgdat
, 1UL << compound_order(page
)))
1573 if (isolate_lru_page(page
))
1577 * migrate_misplaced_transhuge_page() skips page migration's usual
1578 * check on page_count(), so we must do it here, now that the page
1579 * has been isolated: a GUP pin, or any other pin, prevents migration.
1580 * The expected page count is 3: 1 for page's mapcount and 1 for the
1581 * caller's pin and 1 for the reference taken by isolate_lru_page().
1583 if (PageTransHuge(page
) && page_count(page
) != 3) {
1584 putback_lru_page(page
);
1588 page_lru
= page_is_file_cache(page
);
1589 mod_zone_page_state(page_zone(page
), NR_ISOLATED_ANON
+ page_lru
,
1590 hpage_nr_pages(page
));
1593 * Isolating the page has taken another reference, so the
1594 * caller's reference can be safely dropped without the page
1595 * disappearing underneath us during migration.
1601 bool pmd_trans_migrating(pmd_t pmd
)
1603 struct page
*page
= pmd_page(pmd
);
1604 return PageLocked(page
);
1607 void wait_migrate_huge_page(struct anon_vma
*anon_vma
, pmd_t
*pmd
)
1609 struct page
*page
= pmd_page(*pmd
);
1610 wait_on_page_locked(page
);
1614 * Attempt to migrate a misplaced page to the specified destination
1615 * node. Caller is expected to have an elevated reference count on
1616 * the page that will be dropped by this function before returning.
1618 int migrate_misplaced_page(struct page
*page
, int node
)
1620 pg_data_t
*pgdat
= NODE_DATA(node
);
1623 LIST_HEAD(migratepages
);
1626 * Don't migrate pages that are mapped in multiple processes.
1627 * TODO: Handle false sharing detection instead of this hammer
1629 if (page_mapcount(page
) != 1)
1633 * Rate-limit the amount of data that is being migrated to a node.
1634 * Optimal placement is no good if the memory bus is saturated and
1635 * all the time is being spent migrating!
1637 if (numamigrate_update_ratelimit(pgdat
, 1))
1640 isolated
= numamigrate_isolate_page(pgdat
, page
);
1644 list_add(&page
->lru
, &migratepages
);
1645 nr_remaining
= migrate_pages(&migratepages
, alloc_misplaced_dst_page
,
1646 node
, MIGRATE_ASYNC
, MR_NUMA_MISPLACED
);
1648 putback_lru_pages(&migratepages
);
1651 count_vm_numa_event(NUMA_PAGE_MIGRATE
);
1652 BUG_ON(!list_empty(&migratepages
));
1659 #endif /* CONFIG_NUMA_BALANCING */
1661 #if defined(CONFIG_NUMA_BALANCING) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
1663 * Migrates a THP to a given target node. page must be locked and is unlocked
1666 int migrate_misplaced_transhuge_page(struct mm_struct
*mm
,
1667 struct vm_area_struct
*vma
,
1668 pmd_t
*pmd
, pmd_t entry
,
1669 unsigned long address
,
1670 struct page
*page
, int node
)
1672 pg_data_t
*pgdat
= NODE_DATA(node
);
1674 struct page
*new_page
= NULL
;
1675 struct mem_cgroup
*memcg
= NULL
;
1676 int page_lru
= page_is_file_cache(page
);
1677 unsigned long mmun_start
= address
& HPAGE_PMD_MASK
;
1678 unsigned long mmun_end
= mmun_start
+ HPAGE_PMD_SIZE
;
1682 * Don't migrate pages that are mapped in multiple processes.
1683 * TODO: Handle false sharing detection instead of this hammer
1685 if (page_mapcount(page
) != 1)
1689 * Rate-limit the amount of data that is being migrated to a node.
1690 * Optimal placement is no good if the memory bus is saturated and
1691 * all the time is being spent migrating!
1693 if (numamigrate_update_ratelimit(pgdat
, HPAGE_PMD_NR
))
1696 new_page
= alloc_pages_node(node
,
1697 (GFP_TRANSHUGE
| GFP_THISNODE
) & ~__GFP_WAIT
, HPAGE_PMD_ORDER
);
1701 page_nid_xchg_last(new_page
, page_nid_last(page
));
1703 isolated
= numamigrate_isolate_page(pgdat
, page
);
1709 if (mm_tlb_flush_pending(mm
))
1710 flush_tlb_range(vma
, mmun_start
, mmun_end
);
1712 /* Prepare a page as a migration target */
1713 __set_page_locked(new_page
);
1714 SetPageSwapBacked(new_page
);
1716 /* anon mapping, we can simply copy page->mapping to the new page: */
1717 new_page
->mapping
= page
->mapping
;
1718 new_page
->index
= page
->index
;
1719 migrate_page_copy(new_page
, page
);
1720 WARN_ON(PageLRU(new_page
));
1722 /* Recheck the target PMD */
1723 mmu_notifier_invalidate_range_start(mm
, mmun_start
, mmun_end
);
1724 spin_lock(&mm
->page_table_lock
);
1725 if (unlikely(!pmd_same(*pmd
, entry
) || page_count(page
) != 2)) {
1727 spin_unlock(&mm
->page_table_lock
);
1728 mmu_notifier_invalidate_range_end(mm
, mmun_start
, mmun_end
);
1730 /* Reverse changes made by migrate_page_copy() */
1731 if (TestClearPageActive(new_page
))
1732 SetPageActive(page
);
1733 if (TestClearPageUnevictable(new_page
))
1734 SetPageUnevictable(page
);
1735 mlock_migrate_page(page
, new_page
);
1737 unlock_page(new_page
);
1738 put_page(new_page
); /* Free it */
1740 /* Retake the callers reference and putback on LRU */
1742 putback_lru_page(page
);
1743 mod_zone_page_state(page_zone(page
),
1744 NR_ISOLATED_ANON
+ page_lru
, -HPAGE_PMD_NR
);
1750 * Traditional migration needs to prepare the memcg charge
1751 * transaction early to prevent the old page from being
1752 * uncharged when installing migration entries. Here we can
1753 * save the potential rollback and start the charge transfer
1754 * only when migration is already known to end successfully.
1756 mem_cgroup_prepare_migration(page
, new_page
, &memcg
);
1759 entry
= mk_pmd(new_page
, vma
->vm_page_prot
);
1760 entry
= pmd_mkhuge(entry
);
1761 entry
= maybe_pmd_mkwrite(pmd_mkdirty(entry
), vma
);
1764 * Clear the old entry under pagetable lock and establish the new PTE.
1765 * Any parallel GUP will either observe the old page blocking on the
1766 * page lock, block on the page table lock or observe the new page.
1767 * The SetPageUptodate on the new page and page_add_new_anon_rmap
1768 * guarantee the copy is visible before the pagetable update.
1770 flush_cache_range(vma
, mmun_start
, mmun_end
);
1771 page_add_new_anon_rmap(new_page
, vma
, mmun_start
);
1772 pmdp_clear_flush(vma
, mmun_start
, pmd
);
1773 set_pmd_at(mm
, mmun_start
, pmd
, entry
);
1774 flush_tlb_range(vma
, mmun_start
, mmun_end
);
1775 update_mmu_cache_pmd(vma
, address
, &entry
);
1777 if (page_count(page
) != 2) {
1778 set_pmd_at(mm
, mmun_start
, pmd
, orig_entry
);
1779 flush_tlb_range(vma
, mmun_start
, mmun_end
);
1780 update_mmu_cache_pmd(vma
, address
, &entry
);
1781 page_remove_rmap(new_page
);
1785 page_remove_rmap(page
);
1788 * Finish the charge transaction under the page table lock to
1789 * prevent split_huge_page() from dividing up the charge
1790 * before it's fully transferred to the new page.
1792 mem_cgroup_end_migration(memcg
, page
, new_page
, true);
1793 spin_unlock(&mm
->page_table_lock
);
1794 mmu_notifier_invalidate_range_end(mm
, mmun_start
, mmun_end
);
1796 unlock_page(new_page
);
1798 put_page(page
); /* Drop the rmap reference */
1799 put_page(page
); /* Drop the LRU isolation reference */
1801 count_vm_events(PGMIGRATE_SUCCESS
, HPAGE_PMD_NR
);
1802 count_vm_numa_events(NUMA_PAGE_MIGRATE
, HPAGE_PMD_NR
);
1804 mod_zone_page_state(page_zone(page
),
1805 NR_ISOLATED_ANON
+ page_lru
,
1810 count_vm_events(PGMIGRATE_FAIL
, HPAGE_PMD_NR
);
1812 spin_lock(&mm
->page_table_lock
);
1813 if (pmd_same(*pmd
, entry
)) {
1814 entry
= pmd_mknonnuma(entry
);
1815 set_pmd_at(mm
, mmun_start
, pmd
, entry
);
1816 update_mmu_cache_pmd(vma
, address
, &entry
);
1818 spin_unlock(&mm
->page_table_lock
);
1825 #endif /* CONFIG_NUMA_BALANCING */
1827 #endif /* CONFIG_NUMA */