Commit 3fe2011f authored by Mel Gorman's avatar Mel Gorman Committed by Linus Torvalds

mm: migration: allow the migration of PageSwapCache pages

PageAnon pages that are unmapped may or may not have an anon_vma so are
not currently migrated.  However, a swap cache page can be migrated and
fits this description.  This patch identifies page swap caches and allows
them to be migrated but ensures that no attempt to made to remap the pages
would would potentially try to access an already freed anon_vma.
Signed-off-by: default avatarMel Gorman <mel@csn.ul.ie>
Reviewed-by: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Reviewed-by: default avatarMinchan Kim <minchan.kim@gmail.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 67b9509b
...@@ -485,7 +485,8 @@ static int fallback_migrate_page(struct address_space *mapping, ...@@ -485,7 +485,8 @@ static int fallback_migrate_page(struct address_space *mapping,
* < 0 - error code * < 0 - error code
* == 0 - success * == 0 - success
*/ */
static int move_to_new_page(struct page *newpage, struct page *page) static int move_to_new_page(struct page *newpage, struct page *page,
int remap_swapcache)
{ {
struct address_space *mapping; struct address_space *mapping;
int rc; int rc;
...@@ -520,10 +521,12 @@ static int move_to_new_page(struct page *newpage, struct page *page) ...@@ -520,10 +521,12 @@ static int move_to_new_page(struct page *newpage, struct page *page)
else else
rc = fallback_migrate_page(mapping, newpage, page); rc = fallback_migrate_page(mapping, newpage, page);
if (!rc) if (rc) {
remove_migration_ptes(page, newpage);
else
newpage->mapping = NULL; newpage->mapping = NULL;
} else {
if (remap_swapcache)
remove_migration_ptes(page, newpage);
}
unlock_page(newpage); unlock_page(newpage);
...@@ -540,6 +543,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private, ...@@ -540,6 +543,7 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
int rc = 0; int rc = 0;
int *result = NULL; int *result = NULL;
struct page *newpage = get_new_page(page, private, &result); struct page *newpage = get_new_page(page, private, &result);
int remap_swapcache = 1;
int rcu_locked = 0; int rcu_locked = 0;
int charge = 0; int charge = 0;
struct mem_cgroup *mem = NULL; struct mem_cgroup *mem = NULL;
...@@ -601,19 +605,34 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private, ...@@ -601,19 +605,34 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
rcu_read_lock(); rcu_read_lock();
rcu_locked = 1; rcu_locked = 1;
/* /* Determine how to safely use anon_vma */
* If the page has no mappings any more, just bail. An if (!page_mapped(page)) {
* unmapped anon page is likely to be freed soon but worse, if (!PageSwapCache(page))
* it's possible its anon_vma disappeared between when
* the page was isolated and when we reached here while
* the RCU lock was not held
*/
if (!page_mapped(page))
goto rcu_unlock; goto rcu_unlock;
/*
* We cannot be sure that the anon_vma of an unmapped
* swapcache page is safe to use because we don't
* know in advance if the VMA that this page belonged
* to still exists. If the VMA and others sharing the
* data have been freed, then the anon_vma could
* already be invalid.
*
* To avoid this possibility, swapcache pages get
* migrated but are not remapped when migration
* completes
*/
remap_swapcache = 0;
} else {
/*
* Take a reference count on the anon_vma if the
* page is mapped so that it is guaranteed to
* exist when the page is remapped later
*/
anon_vma = page_anon_vma(page); anon_vma = page_anon_vma(page);
atomic_inc(&anon_vma->external_refcount); atomic_inc(&anon_vma->external_refcount);
} }
}
/* /*
* Corner case handling: * Corner case handling:
...@@ -647,9 +666,9 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private, ...@@ -647,9 +666,9 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
skip_unmap: skip_unmap:
if (!page_mapped(page)) if (!page_mapped(page))
rc = move_to_new_page(newpage, page); rc = move_to_new_page(newpage, page, remap_swapcache);
if (rc) if (rc && remap_swapcache)
remove_migration_ptes(page, page); remove_migration_ptes(page, page);
rcu_unlock: rcu_unlock:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment