diff options
author | Hugh Dickins <hugh.dickins@tiscali.co.uk> | 2009-09-21 20:02:10 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-22 10:17:32 -0400 |
commit | e178dfde3952192cf44eeb0612882f01fc96c0a9 (patch) | |
tree | 874b8dd5c2ebba6889621b14e01b7d503a098e4d | |
parent | b4028260334e1ecf63fb5e0a95d65bb2db02c1ec (diff) |
ksm: move pages_sharing updates
The pages_shared count is incremented and decremented when adding a node
to and removing a node from the stable tree: easy to understand. But the
pages_sharing count was hard to follow, being adjusted in various places:
increment and decrement it when adding to and removing from the stable tree.
And the pages_sharing variable used to include the pages_shared, then those
were subtracted when shown in the pages_sharing sysfs file: now keep it as
an exclusive count of leaves hanging off the stable tree nodes, throughout.
Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Acked-by: Izik Eidus <ieidus@redhat.com>
Acked-by: Andrea Arcangeli <aarcange@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | mm/ksm.c | 24 |
1 files changed, 9 insertions, 15 deletions
@@ -152,7 +152,7 @@ static struct kmem_cache *mm_slot_cache; | |||
152 | /* The number of nodes in the stable tree */ | 152 | /* The number of nodes in the stable tree */ |
153 | static unsigned long ksm_pages_shared; | 153 | static unsigned long ksm_pages_shared; |
154 | 154 | ||
155 | /* The number of page slots sharing those nodes */ | 155 | /* The number of page slots additionally sharing those nodes */ |
156 | static unsigned long ksm_pages_sharing; | 156 | static unsigned long ksm_pages_sharing; |
157 | 157 | ||
158 | /* Limit on the number of unswappable pages used */ | 158 | /* Limit on the number of unswappable pages used */ |
@@ -382,6 +382,7 @@ static void remove_rmap_item_from_tree(struct rmap_item *rmap_item) | |||
382 | &next_item->node, | 382 | &next_item->node, |
383 | &root_stable_tree); | 383 | &root_stable_tree); |
384 | next_item->address |= NODE_FLAG; | 384 | next_item->address |= NODE_FLAG; |
385 | ksm_pages_sharing--; | ||
385 | } else { | 386 | } else { |
386 | rb_erase(&rmap_item->node, &root_stable_tree); | 387 | rb_erase(&rmap_item->node, &root_stable_tree); |
387 | ksm_pages_shared--; | 388 | ksm_pages_shared--; |
@@ -395,10 +396,10 @@ static void remove_rmap_item_from_tree(struct rmap_item *rmap_item) | |||
395 | BUG_ON(next_item->prev != rmap_item); | 396 | BUG_ON(next_item->prev != rmap_item); |
396 | next_item->prev = rmap_item->prev; | 397 | next_item->prev = rmap_item->prev; |
397 | } | 398 | } |
399 | ksm_pages_sharing--; | ||
398 | } | 400 | } |
399 | 401 | ||
400 | rmap_item->next = NULL; | 402 | rmap_item->next = NULL; |
401 | ksm_pages_sharing--; | ||
402 | 403 | ||
403 | } else if (rmap_item->address & NODE_FLAG) { | 404 | } else if (rmap_item->address & NODE_FLAG) { |
404 | unsigned char age; | 405 | unsigned char age; |
@@ -786,8 +787,6 @@ static int try_to_merge_two_pages(struct mm_struct *mm1, unsigned long addr1, | |||
786 | */ | 787 | */ |
787 | if (err) | 788 | if (err) |
788 | break_cow(mm1, addr1); | 789 | break_cow(mm1, addr1); |
789 | else | ||
790 | ksm_pages_sharing += 2; | ||
791 | } | 790 | } |
792 | 791 | ||
793 | put_page(kpage); | 792 | put_page(kpage); |
@@ -816,9 +815,6 @@ static int try_to_merge_with_ksm_page(struct mm_struct *mm1, | |||
816 | err = try_to_merge_one_page(vma, page1, kpage); | 815 | err = try_to_merge_one_page(vma, page1, kpage); |
817 | up_read(&mm1->mmap_sem); | 816 | up_read(&mm1->mmap_sem); |
818 | 817 | ||
819 | if (!err) | ||
820 | ksm_pages_sharing++; | ||
821 | |||
822 | return err; | 818 | return err; |
823 | } | 819 | } |
824 | 820 | ||
@@ -928,13 +924,12 @@ static struct rmap_item *stable_tree_insert(struct page *page, | |||
928 | } | 924 | } |
929 | } | 925 | } |
930 | 926 | ||
931 | ksm_pages_shared++; | ||
932 | |||
933 | rmap_item->address |= NODE_FLAG | STABLE_FLAG; | 927 | rmap_item->address |= NODE_FLAG | STABLE_FLAG; |
934 | rmap_item->next = NULL; | 928 | rmap_item->next = NULL; |
935 | rb_link_node(&rmap_item->node, parent, new); | 929 | rb_link_node(&rmap_item->node, parent, new); |
936 | rb_insert_color(&rmap_item->node, &root_stable_tree); | 930 | rb_insert_color(&rmap_item->node, &root_stable_tree); |
937 | 931 | ||
932 | ksm_pages_shared++; | ||
938 | return rmap_item; | 933 | return rmap_item; |
939 | } | 934 | } |
940 | 935 | ||
@@ -1019,6 +1014,8 @@ static void stable_tree_append(struct rmap_item *rmap_item, | |||
1019 | 1014 | ||
1020 | tree_rmap_item->next = rmap_item; | 1015 | tree_rmap_item->next = rmap_item; |
1021 | rmap_item->address |= STABLE_FLAG; | 1016 | rmap_item->address |= STABLE_FLAG; |
1017 | |||
1018 | ksm_pages_sharing++; | ||
1022 | } | 1019 | } |
1023 | 1020 | ||
1024 | /* | 1021 | /* |
@@ -1043,10 +1040,9 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) | |||
1043 | /* We first start with searching the page inside the stable tree */ | 1040 | /* We first start with searching the page inside the stable tree */ |
1044 | tree_rmap_item = stable_tree_search(page, page2, rmap_item); | 1041 | tree_rmap_item = stable_tree_search(page, page2, rmap_item); |
1045 | if (tree_rmap_item) { | 1042 | if (tree_rmap_item) { |
1046 | if (page == page2[0]) { /* forked */ | 1043 | if (page == page2[0]) /* forked */ |
1047 | ksm_pages_sharing++; | ||
1048 | err = 0; | 1044 | err = 0; |
1049 | } else | 1045 | else |
1050 | err = try_to_merge_with_ksm_page(rmap_item->mm, | 1046 | err = try_to_merge_with_ksm_page(rmap_item->mm, |
1051 | rmap_item->address, | 1047 | rmap_item->address, |
1052 | page, page2[0]); | 1048 | page, page2[0]); |
@@ -1107,7 +1103,6 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item) | |||
1107 | break_cow(tree_rmap_item->mm, | 1103 | break_cow(tree_rmap_item->mm, |
1108 | tree_rmap_item->address); | 1104 | tree_rmap_item->address); |
1109 | break_cow(rmap_item->mm, rmap_item->address); | 1105 | break_cow(rmap_item->mm, rmap_item->address); |
1110 | ksm_pages_sharing -= 2; | ||
1111 | } | 1106 | } |
1112 | } | 1107 | } |
1113 | 1108 | ||
@@ -1475,8 +1470,7 @@ KSM_ATTR_RO(pages_shared); | |||
1475 | static ssize_t pages_sharing_show(struct kobject *kobj, | 1470 | static ssize_t pages_sharing_show(struct kobject *kobj, |
1476 | struct kobj_attribute *attr, char *buf) | 1471 | struct kobj_attribute *attr, char *buf) |
1477 | { | 1472 | { |
1478 | return sprintf(buf, "%lu\n", | 1473 | return sprintf(buf, "%lu\n", ksm_pages_sharing); |
1479 | ksm_pages_sharing - ksm_pages_shared); | ||
1480 | } | 1474 | } |
1481 | KSM_ATTR_RO(pages_sharing); | 1475 | KSM_ATTR_RO(pages_sharing); |
1482 | 1476 | ||