[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250604031758.4150209-2-xialonglong@kylinos.cn>
Date: Wed, 4 Jun 2025 11:17:54 +0800
From: Longlong Xia <xialonglong@...inos.cn>
To: akpm@...ux-foundation.org,
xu.xin16@....com.cn
Cc: linux-mm@...ck.org,
linux-kernel@...r.kernel.org,
Longlong Xia <xialonglong@...inos.cn>
Subject: [PATCH 1/2] mm/ksm: calculate ksm_process_profit more accurately
The general_profit_show() only considers ksm_pages_sharing,
whereas ksm_process_profit() accounts for both ksm_pages_sharing
and ksm_pages_shared for each process. This discrepancy leads to
the sum of ksm_process_profit() across all processes not being equal
to general_profit_show().
Fixes: 7609385337a4 ("ksm: count ksm merging pages for each process")
Signed-off-by: Longlong Xia <xialonglong@...inos.cn>
---
mm/ksm.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 8583fb91ef13..fa4e1618b671 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -824,12 +824,10 @@ static void remove_node_from_stable_tree(struct ksm_stable_node *stable_node)
hlist_for_each_entry(rmap_item, &stable_node->hlist, hlist) {
if (rmap_item->hlist.next) {
ksm_pages_sharing--;
+ rmap_item->mm->ksm_merging_pages--;
trace_ksm_remove_rmap_item(stable_node->kpfn, rmap_item, rmap_item->mm);
- } else {
+ } else
ksm_pages_shared--;
- }
-
- rmap_item->mm->ksm_merging_pages--;
VM_BUG_ON(stable_node->rmap_hlist_len <= 0);
stable_node->rmap_hlist_len--;
@@ -976,13 +974,12 @@ static void remove_rmap_item_from_tree(struct ksm_rmap_item *rmap_item)
folio_unlock(folio);
folio_put(folio);
- if (!hlist_empty(&stable_node->hlist))
+ if (!hlist_empty(&stable_node->hlist)) {
ksm_pages_sharing--;
- else
+ rmap_item->mm->ksm_merging_pages--;
+ } else
ksm_pages_shared--;
- rmap_item->mm->ksm_merging_pages--;
-
VM_BUG_ON(stable_node->rmap_hlist_len <= 0);
stable_node->rmap_hlist_len--;
@@ -2202,12 +2199,11 @@ static void stable_tree_append(struct ksm_rmap_item *rmap_item,
rmap_item->address |= STABLE_FLAG;
hlist_add_head(&rmap_item->hlist, &stable_node->hlist);
- if (rmap_item->hlist.next)
+ if (rmap_item->hlist.next) {
ksm_pages_sharing++;
- else
+ rmap_item->mm->ksm_merging_pages++;
+ } else
ksm_pages_shared++;
-
- rmap_item->mm->ksm_merging_pages++;
}
/*
--
2.43.0
Powered by blists - more mailing lists