aboutsummaryrefslogtreecommitdiffstats
path: root/mm/migrate.c
diff options
context:
space:
mode:
authorChristoph Lameter <clameter@sgi.com>2006-06-23 05:03:53 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-23 10:42:53 -0400
commit95a402c3847cc16f4ba03013cd01404fa0f14c2e (patch)
tree0fd9b3379f70cc99b2325bccaa150089abf6c8b3 /mm/migrate.c
parentaaa994b300a172afafab47938804836b923e5ef7 (diff)
[PATCH] page migration: use allocator function for migrate_pages()
Instead of passing a list of new pages, pass a function to allocate a new page. This allows the correct placement of MPOL_INTERLEAVE pages during page migration. It also further simplifies the callers of migrate pages. migrate_pages() becomes similar to migrate_pages_to() so drop migrate_pages_to(). The batching of new page allocations becomes unnecessary. Signed-off-by: Christoph Lameter <clameter@sgi.com> Cc: Hugh Dickins <hugh@veritas.com> Cc: Jes Sorensen <jes@trained-monkey.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Lee Schermerhorn <lee.schermerhorn@hp.com> Cc: Andi Kleen <ak@muc.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm/migrate.c')
-rw-r--r--mm/migrate.c115
1 files changed, 32 insertions, 83 deletions
diff --git a/mm/migrate.c b/mm/migrate.c
index d3a1810a4c9f..251a8d158257 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -28,9 +28,6 @@
28 28
29#include "internal.h" 29#include "internal.h"
30 30
31/* The maximum number of pages to take off the LRU for migration */
32#define MIGRATE_CHUNK_SIZE 256
33
34#define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru)) 31#define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))
35 32
36/* 33/*
@@ -587,18 +584,23 @@ static int move_to_new_page(struct page *newpage, struct page *page)
587 * Obtain the lock on page, remove all ptes and migrate the page 584 * Obtain the lock on page, remove all ptes and migrate the page
588 * to the newly allocated page in newpage. 585 * to the newly allocated page in newpage.
589 */ 586 */
590static int unmap_and_move(struct page *newpage, struct page *page, int force) 587static int unmap_and_move(new_page_t get_new_page, unsigned long private,
588 struct page *page, int force)
591{ 589{
592 int rc = 0; 590 int rc = 0;
591 struct page *newpage = get_new_page(page, private);
592
593 if (!newpage)
594 return -ENOMEM;
593 595
594 if (page_count(page) == 1) 596 if (page_count(page) == 1)
595 /* page was freed from under us. So we are done. */ 597 /* page was freed from under us. So we are done. */
596 goto ret; 598 goto move_newpage;
597 599
598 rc = -EAGAIN; 600 rc = -EAGAIN;
599 if (TestSetPageLocked(page)) { 601 if (TestSetPageLocked(page)) {
600 if (!force) 602 if (!force)
601 goto ret; 603 goto move_newpage;
602 lock_page(page); 604 lock_page(page);
603 } 605 }
604 606
@@ -622,7 +624,7 @@ static int unmap_and_move(struct page *newpage, struct page *page, int force)
622 remove_migration_ptes(page, page); 624 remove_migration_ptes(page, page);
623unlock: 625unlock:
624 unlock_page(page); 626 unlock_page(page);
625ret: 627
626 if (rc != -EAGAIN) { 628 if (rc != -EAGAIN) {
627 /* 629 /*
628 * A page that has been migrated has all references 630 * A page that has been migrated has all references
@@ -632,29 +634,33 @@ ret:
632 */ 634 */
633 list_del(&page->lru); 635 list_del(&page->lru);
634 move_to_lru(page); 636 move_to_lru(page);
635
636 list_del(&newpage->lru);
637 move_to_lru(newpage);
638 } 637 }
638
639move_newpage:
640 /*
641 * Move the new page to the LRU. If migration was not successful
642 * then this will free the page.
643 */
644 move_to_lru(newpage);
639 return rc; 645 return rc;
640} 646}
641 647
642/* 648/*
643 * migrate_pages 649 * migrate_pages
644 * 650 *
645 * Two lists are passed to this function. The first list 651 * The function takes one list of pages to migrate and a function
646 * contains the pages isolated from the LRU to be migrated. 652 * that determines from the page to be migrated and the private data
647 * The second list contains new pages that the isolated pages 653 * the target of the move and allocates the page.
648 * can be moved to.
649 * 654 *
650 * The function returns after 10 attempts or if no pages 655 * The function returns after 10 attempts or if no pages
651 * are movable anymore because to has become empty 656 * are movable anymore because to has become empty
652 * or no retryable pages exist anymore. All pages will be 657 * or no retryable pages exist anymore. All pages will be
653 * retruned to the LRU or freed. 658 * retruned to the LRU or freed.
654 * 659 *
655 * Return: Number of pages not migrated. 660 * Return: Number of pages not migrated or error code.
656 */ 661 */
657int migrate_pages(struct list_head *from, struct list_head *to) 662int migrate_pages(struct list_head *from,
663 new_page_t get_new_page, unsigned long private)
658{ 664{
659 int retry = 1; 665 int retry = 1;
660 int nr_failed = 0; 666 int nr_failed = 0;
@@ -671,15 +677,14 @@ int migrate_pages(struct list_head *from, struct list_head *to)
671 retry = 0; 677 retry = 0;
672 678
673 list_for_each_entry_safe(page, page2, from, lru) { 679 list_for_each_entry_safe(page, page2, from, lru) {
674
675 if (list_empty(to))
676 break;
677
678 cond_resched(); 680 cond_resched();
679 681
680 rc = unmap_and_move(lru_to_page(to), page, pass > 2); 682 rc = unmap_and_move(get_new_page, private,
683 page, pass > 2);
681 684
682 switch(rc) { 685 switch(rc) {
686 case -ENOMEM:
687 goto out;
683 case -EAGAIN: 688 case -EAGAIN:
684 retry++; 689 retry++;
685 break; 690 break;
@@ -692,72 +697,16 @@ int migrate_pages(struct list_head *from, struct list_head *to)
692 } 697 }
693 } 698 }
694 } 699 }
695 700 rc = 0;
701out:
696 if (!swapwrite) 702 if (!swapwrite)
697 current->flags &= ~PF_SWAPWRITE; 703 current->flags &= ~PF_SWAPWRITE;
698 704
699 putback_lru_pages(from); 705 putback_lru_pages(from);
700 return nr_failed + retry;
701}
702 706
703/* 707 if (rc)
704 * Migrate the list 'pagelist' of pages to a certain destination. 708 return rc;
705 *
706 * Specify destination with either non-NULL vma or dest_node >= 0
707 * Return the number of pages not migrated or error code
708 */
709int migrate_pages_to(struct list_head *pagelist,
710 struct vm_area_struct *vma, int dest)
711{
712 LIST_HEAD(newlist);
713 int err = 0;
714 unsigned long offset = 0;
715 int nr_pages;
716 int nr_failed = 0;
717 struct page *page;
718 struct list_head *p;
719
720redo:
721 nr_pages = 0;
722 list_for_each(p, pagelist) {
723 if (vma) {
724 /*
725 * The address passed to alloc_page_vma is used to
726 * generate the proper interleave behavior. We fake
727 * the address here by an increasing offset in order
728 * to get the proper distribution of pages.
729 *
730 * No decision has been made as to which page
731 * a certain old page is moved to so we cannot
732 * specify the correct address.
733 */
734 page = alloc_page_vma(GFP_HIGHUSER, vma,
735 offset + vma->vm_start);
736 offset += PAGE_SIZE;
737 }
738 else
739 page = alloc_pages_node(dest, GFP_HIGHUSER, 0);
740
741 if (!page) {
742 err = -ENOMEM;
743 goto out;
744 }
745 list_add_tail(&page->lru, &newlist);
746 nr_pages++;
747 if (nr_pages > MIGRATE_CHUNK_SIZE)
748 break;
749 }
750 err = migrate_pages(pagelist, &newlist);
751
752 if (err >= 0) {
753 nr_failed += err;
754 if (list_empty(&newlist) && !list_empty(pagelist))
755 goto redo;
756 }
757out:
758 709
759 /* Calculate number of leftover pages */ 710 return nr_failed + retry;
760 list_for_each(p, pagelist)
761 nr_failed++;
762 return nr_failed;
763} 711}
712