linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Longlong Xia <xialonglong@kylinos.cn>
To: akpm@linux-foundation.org, xu.xin16@zte.com.cn
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Longlong Xia <xialonglong@kylinos.cn>
Subject: [PATCH 1/2] mm/ksm: calculate ksm_process_profit more accurately
Date: Wed,  4 Jun 2025 11:17:54 +0800	[thread overview]
Message-ID: <20250604031758.4150209-2-xialonglong@kylinos.cn> (raw)
In-Reply-To: <20250604031758.4150209-1-xialonglong@kylinos.cn>

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@kylinos.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



  reply	other threads:[~2025-06-04 13:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-04  3:17 [PATCH 0/2] " Longlong Xia
2025-06-04  3:17 ` Longlong Xia [this message]
2025-06-04  3:45   ` [PATCH 1/2] " xu.xin16
2025-06-17 15:52   ` David Hildenbrand
2025-06-04  3:17 ` [PATCH 2/2] mm/ksm: Rename ksm_merging_pages to ksm_process_sharing Longlong Xia
2025-06-17 15:51   ` David Hildenbrand
2025-06-17 15:48 ` [PATCH 0/2] mm/ksm: calculate ksm_process_profit more accurately David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250604031758.4150209-2-xialonglong@kylinos.cn \
    --to=xialonglong@kylinos.cn \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=xu.xin16@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox