aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorHugh Dickins <hugh.dickins@tiscali.co.uk>2009-12-14 20:59:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-15 11:53:19 -0500
commit08beca44dfb0ab008e365163df70dbd302ae1508 (patch)
tree33f3ddf5460e139bd7fd37e8c08026a7d852c3da /include/linux
parent7b6ba2c7d3baf8cd9f888e05563dcc32e368baab (diff)
ksm: stable_node point to page and back
Add a pointer to the ksm page into struct stable_node, holding a reference to the page while the node exists. Put a pointer to the stable_node into the ksm page's ->mapping. Then we don't need get_ksm_page() while traversing the stable tree: the page to compare against is sure to be present and correct, even if it's no longer visible through any of its existing rmap_items. And we can handle the forked ksm page case more efficiently: no need to memcmp our way through the tree to find its match. Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk> Cc: Izik Eidus <ieidus@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/ksm.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/include/linux/ksm.h b/include/linux/ksm.h
index 1401a313fa77..ef55ce14a2ce 100644
--- a/include/linux/ksm.h
+++ b/include/linux/ksm.h
@@ -12,6 +12,8 @@
12#include <linux/sched.h> 12#include <linux/sched.h>
13#include <linux/vmstat.h> 13#include <linux/vmstat.h>
14 14
15struct stable_node;
16
15#ifdef CONFIG_KSM 17#ifdef CONFIG_KSM
16int ksm_madvise(struct vm_area_struct *vma, unsigned long start, 18int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
17 unsigned long end, int advice, unsigned long *vm_flags); 19 unsigned long end, int advice, unsigned long *vm_flags);
@@ -34,7 +36,8 @@ static inline void ksm_exit(struct mm_struct *mm)
34/* 36/*
35 * A KSM page is one of those write-protected "shared pages" or "merged pages" 37 * A KSM page is one of those write-protected "shared pages" or "merged pages"
36 * which KSM maps into multiple mms, wherever identical anonymous page content 38 * which KSM maps into multiple mms, wherever identical anonymous page content
37 * is found in VM_MERGEABLE vmas. It's a PageAnon page, with NULL anon_vma. 39 * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
40 * anon_vma, but to that page's node of the stable tree.
38 */ 41 */
39static inline int PageKsm(struct page *page) 42static inline int PageKsm(struct page *page)
40{ 43{
@@ -42,15 +45,22 @@ static inline int PageKsm(struct page *page)
42 (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM); 45 (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
43} 46}
44 47
45/* 48static inline struct stable_node *page_stable_node(struct page *page)
46 * But we have to avoid the checking which page_add_anon_rmap() performs. 49{
47 */ 50 return PageKsm(page) ? page_rmapping(page) : NULL;
51}
52
53static inline void set_page_stable_node(struct page *page,
54 struct stable_node *stable_node)
55{
56 page->mapping = (void *)stable_node +
57 (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
58}
59
48static inline void page_add_ksm_rmap(struct page *page) 60static inline void page_add_ksm_rmap(struct page *page)
49{ 61{
50 if (atomic_inc_and_test(&page->_mapcount)) { 62 if (atomic_inc_and_test(&page->_mapcount))
51 page->mapping = (void *) (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
52 __inc_zone_page_state(page, NR_ANON_PAGES); 63 __inc_zone_page_state(page, NR_ANON_PAGES);
53 }
54} 64}
55#else /* !CONFIG_KSM */ 65#else /* !CONFIG_KSM */
56 66