[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tip-15jgtv7g5i9emxs6jz0gapab@git.kernel.org>
Date: Fri, 18 May 2012 03:27:16 -0700
From: tip-bot for Lee Schermerhorn <lee.schermerhorn@...com>
To: linux-tip-commits@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, hpa@...or.com, mingo@...nel.org,
torvalds@...ux-foundation.org, a.p.zijlstra@...llo.nl,
pjt@...gle.com, lee.schermerhorn@...com, cl@...ux.com,
riel@...hat.com, akpm@...ux-foundation.org, bharata.rao@...il.com,
aarcange@...hat.com, suresh.b.siddha@...el.com, danms@...ibm.com,
tglx@...utronix.de
Subject: [tip:sched/numa] mm: Handle misplaced anon pages
Commit-ID: 65699050e8aae41078c9c73f61f6fae26e07e461
Gitweb: http://git.kernel.org/tip/65699050e8aae41078c9c73f61f6fae26e07e461
Author: Lee Schermerhorn <lee.schermerhorn@...com>
AuthorDate: Thu, 12 Jan 2012 12:05:17 +0100
Committer: Ingo Molnar <mingo@...nel.org>
CommitDate: Fri, 18 May 2012 08:16:18 +0200
mm: Handle misplaced anon pages
This patch simply hooks the anon page fault handler [do_swap_page()]
to check for and migrate misplaced pages if enabled and page won't
be "COWed".
This introduces can_reuse_swap_page() since reuse_swap_page() does
delete_from_swap_cache() which messes our migration path (since that
assumes its still a swapcache page).
Signed-off-by: Lee Schermerhorn <lee.schermerhorn@...com>
[ removed the retry loops after lock_page on a swapcache which tried
to fixup the wreckage caused by ignoring the page count on migate;
added can_reuse_swap_page(); moved the migrate-on-fault enabled
test into check_migrate_misplaced_page() ]
Signed-off-by: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Suresh Siddha <suresh.b.siddha@...el.com>
Cc: Paul Turner <pjt@...gle.com>
Cc: Dan Smith <danms@...ibm.com>
Cc: Bharata B Rao <bharata.rao@...il.com>
Cc: Christoph Lameter <cl@...ux.com>
Cc: Rik van Riel <riel@...hat.com>
Cc: Andrea Arcangeli <aarcange@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Link: http://lkml.kernel.org/n/tip-15jgtv7g5i9emxs6jz0gapab@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
include/linux/swap.h | 4 +++-
mm/memory.c | 17 +++++++++++++++++
mm/swapfile.c | 13 +++++++++++++
3 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index b1fd5c7..0c23738 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -352,6 +352,7 @@ extern unsigned int count_swap_pages(int, int);
extern sector_t map_swap_page(struct page *, struct block_device **);
extern sector_t swapdev_block(int, pgoff_t);
extern int reuse_swap_page(struct page *);
+extern int can_reuse_swap_page(struct page *);
extern int try_to_free_swap(struct page *);
struct backing_dev_info;
@@ -462,7 +463,8 @@ static inline void delete_from_swap_cache(struct page *page)
{
}
-#define reuse_swap_page(page) (page_mapcount(page) == 1)
+#define reuse_swap_page(page) (page_mapcount(page) == 1)
+#define can_reuse_swap_page(page) (page_mapcount(page) == 1)
static inline int try_to_free_swap(struct page *page)
{
diff --git a/mm/memory.c b/mm/memory.c
index 6105f47..08a3489 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -57,6 +57,7 @@
#include <linux/swapops.h>
#include <linux/elf.h>
#include <linux/gfp.h>
+#include <linux/mempolicy.h> /* check_migrate_misplaced_page() */
#include <asm/io.h>
#include <asm/pgalloc.h>
@@ -2974,6 +2975,22 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
}
/*
+ * No sense in migrating a page that will be "COWed" as the new
+ * new page will be allocated according to effective mempolicy.
+ */
+ if ((flags & FAULT_FLAG_WRITE) && can_reuse_swap_page(page)) {
+ /*
+ * check for misplacement and migrate, if necessary/possible,
+ * here and now. Note that if we're racing with another thread,
+ * we may end up discarding the migrated page after locking
+ * the page table and checking the pte below. However, we
+ * don't want to hold the page table locked over migration, so
+ * we'll live with that [unlikely, one hopes] possibility.
+ */
+ page = check_migrate_misplaced_page(page, vma, address);
+ }
+
+ /*
* Back out if somebody else already faulted in this pte.
*/
page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
diff --git a/mm/swapfile.c b/mm/swapfile.c
index fafc26d..c5952c0 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -640,6 +640,19 @@ int reuse_swap_page(struct page *page)
return count <= 1;
}
+int can_reuse_swap_page(struct page *page)
+{
+ int count;
+
+ VM_BUG_ON(!PageLocked(page));
+ if (unlikely(PageKsm(page)))
+ return 0;
+ count = page_mapcount(page);
+ if (count <= 1 && PageSwapCache(page))
+ count += page_swapcount(page);
+ return count <= 1;
+}
+
/*
* If swap is getting full, or if there are no more mappings of this page,
* then try_to_free_swap is called to free its swap space.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists