Skip to content

Commit 0dabec9

Browse files
Minchan Kimtorvalds
authored andcommitted
mm: migration: clean up unmap_and_move()
unmap_and_move() is one a big messy function. Clean it up. Signed-off-by: Minchan Kim <minchan.kim@gmail.com> Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Rik van Riel <riel@redhat.com> Cc: Michal Hocko <mhocko@suse.cz> Cc: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f80c067 commit 0dabec9

1 file changed

Lines changed: 40 additions & 35 deletions

File tree

‎mm/migrate.c‎

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -621,38 +621,18 @@ static int move_to_new_page(struct page *newpage, struct page *page,
621621
return rc;
622622
}
623623

624-
/*
625-
* Obtain the lock on page, remove all ptes and migrate the page
626-
* to the newly allocated page in newpage.
627-
*/
628-
static int unmap_and_move(new_page_t get_new_page, unsigned long private,
629-
struct page *page, int force, bool offlining, bool sync)
624+
static int __unmap_and_move(struct page *page, struct page *newpage,
625+
int force, bool offlining, bool sync)
630626
{
631-
int rc = 0;
632-
int *result = NULL;
633-
struct page *newpage = get_new_page(page, private, &result);
627+
int rc = -EAGAIN;
634628
int remap_swapcache = 1;
635629
int charge = 0;
636630
struct mem_cgroup *mem;
637631
struct anon_vma *anon_vma = NULL;
638632

639-
if (!newpage)
640-
return -ENOMEM;
641-
642-
if (page_count(page) == 1) {
643-
/* page was freed from under us. So we are done. */
644-
goto move_newpage;
645-
}
646-
if (unlikely(PageTransHuge(page)))
647-
if (unlikely(split_huge_page(page)))
648-
goto move_newpage;
649-
650-
/* prepare cgroup just returns 0 or -ENOMEM */
651-
rc = -EAGAIN;
652-
653633
if (!trylock_page(page)) {
654634
if (!force || !sync)
655-
goto move_newpage;
635+
goto out;
656636

657637
/*
658638
* It's not safe for direct compaction to call lock_page.
@@ -668,7 +648,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
668648
* altogether.
669649
*/
670650
if (current->flags & PF_MEMALLOC)
671-
goto move_newpage;
651+
goto out;
672652

673653
lock_page(page);
674654
}
@@ -785,27 +765,52 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
785765
mem_cgroup_end_migration(mem, page, newpage, rc == 0);
786766
unlock:
787767
unlock_page(page);
768+
out:
769+
return rc;
770+
}
788771

789-
move_newpage:
772+
/*
773+
* Obtain the lock on page, remove all ptes and migrate the page
774+
* to the newly allocated page in newpage.
775+
*/
776+
static int unmap_and_move(new_page_t get_new_page, unsigned long private,
777+
struct page *page, int force, bool offlining, bool sync)
778+
{
779+
int rc = 0;
780+
int *result = NULL;
781+
struct page *newpage = get_new_page(page, private, &result);
782+
783+
if (!newpage)
784+
return -ENOMEM;
785+
786+
if (page_count(page) == 1) {
787+
/* page was freed from under us. So we are done. */
788+
goto out;
789+
}
790+
791+
if (unlikely(PageTransHuge(page)))
792+
if (unlikely(split_huge_page(page)))
793+
goto out;
794+
795+
rc = __unmap_and_move(page, newpage, force, offlining, sync);
796+
out:
790797
if (rc != -EAGAIN) {
791-
/*
792-
* A page that has been migrated has all references
793-
* removed and will be freed. A page that has not been
794-
* migrated will have kepts its references and be
795-
* restored.
796-
*/
797-
list_del(&page->lru);
798+
/*
799+
* A page that has been migrated has all references
800+
* removed and will be freed. A page that has not been
801+
* migrated will have kepts its references and be
802+
* restored.
803+
*/
804+
list_del(&page->lru);
798805
dec_zone_page_state(page, NR_ISOLATED_ANON +
799806
page_is_file_cache(page));
800807
putback_lru_page(page);
801808
}
802-
803809
/*
804810
* Move the new page to the LRU. If migration was not successful
805811
* then this will free the page.
806812
*/
807813
putback_lru_page(newpage);
808-
809814
if (result) {
810815
if (rc)
811816
*result = rc;

0 commit comments

Comments
 (0)