* [PATCH v1 0/2] tools/mm: slabinfo: fix inverted sorting and totals
@ 2026-11-18 6:03 Xuewen Wang
2026-11-18 6:03 ` [PATCH v1 1/2] tools/mm: slabinfo: fix inverted numeric sorting Xuewen Wang
2026-11-18 6:03 ` [PATCH v1 2/2] tools/mm: slabinfo: preserve the average partial object count Xuewen Wang
0 siblings, 2 replies; 5+ messages in thread
From: Xuewen Wang @ 2026-11-18 6:03 UTC (permalink / raw)
To: vbabka, harry, hao.li, cl, rientjes, akpm, david, rppt, mhocko,
surenb, sj
Cc: linux-mm, linux-kernel, Xuewen Wang
From: Xuewen Wang <wangxuewen@kylinos.cn>
This series fixes two independent bugs in slabinfo:
1. Return signed comparison results for unequal numeric sort keys so
that -i correctly reverses size, activity, loss and partial sorting.
2. Keep the per-cache partial-object average instead of overwriting it
with a percentage before printing the PartObjs row.
Validation:
The sorting and totals fixes were additionally verified on live kernels
(v5.10 and v6.6) with root access: "slabinfo -l -S -i" is unsorted before
the sorting fix and ascending after it, with descending output unchanged;
"slabinfo -B -T" reports the PartObjs Average as a percentage (8 and 67)
before the totals fix and as the correct per-cache average
(2362 = 262202/111 and 48867 = 10897410/223) after it. No kernel slab
settings were modified.
Xuewen Wang (2):
tools/mm: slabinfo: fix inverted numeric sorting
tools/mm: slabinfo: preserve the average partial object count
tools/mm/slabinfo.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v1 1/2] tools/mm: slabinfo: fix inverted numeric sorting
2026-11-18 6:03 [PATCH v1 0/2] tools/mm: slabinfo: fix inverted sorting and totals Xuewen Wang
@ 2026-11-18 6:03 ` Xuewen Wang
2026-12-02 18:24 ` Harry Yoo
2026-11-18 6:03 ` [PATCH v1 2/2] tools/mm: slabinfo: preserve the average partial object count Xuewen Wang
1 sibling, 1 reply; 5+ messages in thread
From: Xuewen Wang @ 2026-11-18 6:03 UTC (permalink / raw)
To: vbabka, harry, hao.li, cl, rientjes, akpm, david, rppt, mhocko,
surenb, sj
Cc: linux-mm, linux-kernel, Xuewen Wang
From: Xuewen Wang <wangxuewen@kylinos.cn>
The numeric branches of sort_slabs() return either zero or one for
unequal keys. Negating these values for -i never yields a positive
result, so the sort does not swap entries with different numeric keys.
For example, partial-slab counts 30, 10, 20 remain in that order
with -P -i instead of being sorted as 10, 20, 30.
Return a positive or negative result for unequal numeric keys so that
the existing inversion works for size, activity, loss and partial-slab
sorting. Preserve the alphabetic tie break for equal keys and avoid
subtracting unsigned counters.
Fixes: c09d87517298 ("slub: add slabinfo tool")
Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
---
tools/mm/slabinfo.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/mm/slabinfo.c b/tools/mm/slabinfo.c
index 48d1ee8b0e81..3e62a2fccaeb 100644
--- a/tools/mm/slabinfo.c
+++ b/tools/mm/slabinfo.c
@@ -1075,22 +1075,22 @@ static void sort_slabs(void)
if (slab_size(s1) == slab_size(s2))
result = strcasecmp(s1->name, s2->name);
else
- result = slab_size(s1) < slab_size(s2);
+ result = slab_size(s1) < slab_size(s2) ? 1 : -1;
} else if (sort_active) {
if (slab_activity(s1) == slab_activity(s2))
result = strcasecmp(s1->name, s2->name);
else
- result = slab_activity(s1) < slab_activity(s2);
+ result = slab_activity(s1) < slab_activity(s2) ? 1 : -1;
} else if (sort_loss) {
if (slab_waste(s1) == slab_waste(s2))
result = strcasecmp(s1->name, s2->name);
else
- result = slab_waste(s1) < slab_waste(s2);
+ result = slab_waste(s1) < slab_waste(s2) ? 1 : -1;
} else if (sort_partial) {
if (s1->partial == s2->partial)
result = strcasecmp(s1->name, s2->name);
else
- result = s1->partial < s2->partial;
+ result = s1->partial < s2->partial ? 1 : -1;
} else
result = strcasecmp(s1->name, s2->name);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v1 1/2] tools/mm: slabinfo: fix inverted numeric sorting
2026-11-18 6:03 ` [PATCH v1 1/2] tools/mm: slabinfo: fix inverted numeric sorting Xuewen Wang
@ 2026-12-02 18:24 ` Harry Yoo
0 siblings, 0 replies; 5+ messages in thread
From: Harry Yoo @ 2026-12-02 18:24 UTC (permalink / raw)
To: Xuewen Wang
Cc: vbabka, hao.li, cl, rientjes, akpm, david, rppt, mhocko, surenb,
sj, linux-mm, linux-kernel, Xuewen Wang
On Wed, Nov 18, 2026 at 02:03:16PM +0800, Xuewen Wang wrote:
> From: Xuewen Wang <wangxuewen@kylinos.cn>
>
> The numeric branches of sort_slabs() return either zero or one for
> unequal keys. Negating these values for -i never yields a positive
> result, so the sort does not swap entries with different numeric keys.
> For example, partial-slab counts 30, 10, 20 remain in that order
> with -P -i instead of being sorted as 10, 20, 30.
>
> Return a positive or negative result for unequal numeric keys so that
> the existing inversion works for size, activity, loss and partial-slab
> sorting. Preserve the alphabetic tie break for equal keys and avoid
> subtracting unsigned counters.
>
> Fixes: c09d87517298 ("slub: add slabinfo tool")
> Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
> ---
Looks good to me,
Acked-by: Harry Yoo (Meta) <harry@kernel.org>
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 2/2] tools/mm: slabinfo: preserve the average partial object count
2026-11-18 6:03 [PATCH v1 0/2] tools/mm: slabinfo: fix inverted sorting and totals Xuewen Wang
2026-11-18 6:03 ` [PATCH v1 1/2] tools/mm: slabinfo: fix inverted numeric sorting Xuewen Wang
@ 2026-11-18 6:03 ` Xuewen Wang
2026-12-02 18:25 ` Harry Yoo
1 sibling, 1 reply; 5+ messages in thread
From: Xuewen Wang @ 2026-11-18 6:03 UTC (permalink / raw)
To: vbabka, harry, hao.li, cl, rientjes, akpm, david, rppt, mhocko,
surenb, sj
Cc: linux-mm, linux-kernel, Xuewen Wang
From: Xuewen Wang <wangxuewen@kylinos.cn>
totals() calculates avg_partobj as total_partobj / used_slabs, but then
overwrites it with total_partobj * 100 / total_objects. Consequently,
the PartObjs Average column of -T and -X reports a percentage instead
of an object count per cache.
Remove the second assignment. The aggregate partial-object percentage
is already calculated where it is printed, and avg_ppartobj separately
holds the average per-cache percentage.
Fixes: c09d87517298 ("slub: add slabinfo tool")
Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
---
tools/mm/slabinfo.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/tools/mm/slabinfo.c b/tools/mm/slabinfo.c
index 3e62a2fccaeb..116625bd1110 100644
--- a/tools/mm/slabinfo.c
+++ b/tools/mm/slabinfo.c
@@ -973,7 +973,6 @@ static void totals(void)
/* Per object object sizes */
avg_objsize = total_used / total_objects;
avg_objwaste = total_objwaste / total_objects;
- avg_partobj = total_partobj * 100 / total_objects;
avg_memobj = total_objsize / total_objects;
printf("Slabcache Totals\n");
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v1 2/2] tools/mm: slabinfo: preserve the average partial object count
2026-11-18 6:03 ` [PATCH v1 2/2] tools/mm: slabinfo: preserve the average partial object count Xuewen Wang
@ 2026-12-02 18:25 ` Harry Yoo
0 siblings, 0 replies; 5+ messages in thread
From: Harry Yoo @ 2026-12-02 18:25 UTC (permalink / raw)
To: Xuewen Wang
Cc: vbabka, hao.li, cl, rientjes, akpm, david, rppt, mhocko, surenb,
sj, linux-mm, linux-kernel, Xuewen Wang
On Wed, Nov 18, 2026 at 02:03:17PM +0800, Xuewen Wang wrote:
> From: Xuewen Wang <wangxuewen@kylinos.cn>
>
> totals() calculates avg_partobj as total_partobj / used_slabs, but then
> overwrites it with total_partobj * 100 / total_objects. Consequently,
> the PartObjs Average column of -T and -X reports a percentage instead
> of an object count per cache.
>
> Remove the second assignment. The aggregate partial-object percentage
> is already calculated where it is printed, and avg_ppartobj separately
> holds the average per-cache percentage.
>
> Fixes: c09d87517298 ("slub: add slabinfo tool")
> Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
> ---
Looks good to me,
Acked-by: Harry Yoo (Meta) <harry@kernel.org>
--
Cheers,
Harry / Hyeonggon
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-02 18:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 6:03 [PATCH v1 0/2] tools/mm: slabinfo: fix inverted sorting and totals Xuewen Wang
2026-11-18 6:03 ` [PATCH v1 1/2] tools/mm: slabinfo: fix inverted numeric sorting Xuewen Wang
2026-12-02 18:24 ` Harry Yoo
2026-11-18 6:03 ` [PATCH v1 2/2] tools/mm: slabinfo: preserve the average partial object count Xuewen Wang
2026-12-02 18:25 ` Harry Yoo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox