From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: vbabka@suse.cz, akpm@linux-foundation.org
Cc: cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev,
harry.yoo@oracle.com, glittao@gmail.com, jserv@ccns.ncku.edu.tw,
chuang@cs.nycu.edu.tw, cfmc.cs13@nycu.edu.tw,
jhcheng.cs13@nycu.edu.tw, c.yuanhaur@wustl.edu,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Kuan-Wei Chiu <visitorckw@gmail.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>
Subject: [PATCH v2 1/2] mm/slub: Fix cmp_loc_by_count() to return 0 when counts are equal
Date: Tue, 26 Aug 2025 14:23:14 +0800 [thread overview]
Message-ID: <20250826062315.644520-2-visitorckw@gmail.com> (raw)
In-Reply-To: <20250826062315.644520-1-visitorckw@gmail.com>
The comparison function cmp_loc_by_count() used for sorting stack trace
locations in debugfs currently returns -1 if a->count > b->count and 1
otherwise. This breaks the antisymmetry property required by sort(),
because when two counts are equal, both cmp(a, b) and cmp(b, a) return
1.
This can lead to undefined or incorrect ordering results. Fix it by
updating the comparison logic to explicitly handle the case when counts
are equal, and use cmp_int() to ensure the comparison function adheres
to the required mathematical properties of antisymmetry.
Fixes: 553c0369b3e1 ("mm/slub: sort debugfs output by frequency of stack traces")
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
---
mm/slub.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 30003763d224..081816ff89ab 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -7716,10 +7716,7 @@ static int cmp_loc_by_count(const void *a, const void *b, const void *data)
struct location *loc1 = (struct location *)a;
struct location *loc2 = (struct location *)b;
- if (loc1->count > loc2->count)
- return -1;
- else
- return 1;
+ return cmp_int(loc2->count, loc1->count);
}
static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos)
--
2.34.1
next prev parent reply other threads:[~2025-08-26 6:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 6:23 [PATCH v2 0/2] mm/slub: Fix debugfs stack trace sorting and simplify sort call Kuan-Wei Chiu
2025-08-26 6:23 ` Kuan-Wei Chiu [this message]
2025-08-29 2:13 ` [PATCH v2 1/2] mm/slub: Fix cmp_loc_by_count() to return 0 when counts are equal Harry Yoo
2025-08-26 6:23 ` [PATCH v2 2/2] mm/slub: Replace sort_r() with sort() for debugfs stack trace sorting Kuan-Wei Chiu
2025-08-29 2:14 ` Harry Yoo
2025-08-27 9:55 ` [PATCH v2 0/2] mm/slub: Fix debugfs stack trace sorting and simplify sort call Vlastimil Babka
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=20250826062315.644520-2-visitorckw@gmail.com \
--to=visitorckw@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=c.yuanhaur@wustl.edu \
--cc=cfmc.cs13@nycu.edu.tw \
--cc=chuang@cs.nycu.edu.tw \
--cc=cl@gentwo.org \
--cc=glittao@gmail.com \
--cc=harry.yoo@oracle.com \
--cc=jhcheng.cs13@nycu.edu.tw \
--cc=joshua.hahnjy@gmail.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=vbabka@suse.cz \
/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;
as well as URLs for NNTP newsgroup(s).