]> Gentwo Git Trees - linux/.git/commit
mm/slub: Fix cmp_loc_by_count() to return 0 when counts are equal
authorKuan-Wei Chiu <visitorckw@gmail.com>
Tue, 26 Aug 2025 06:23:14 +0000 (14:23 +0800)
committerVlastimil Babka <vbabka@suse.cz>
Wed, 10 Sep 2025 20:52:33 +0000 (22:52 +0200)
commite1c4350327b39c9cad27b6c5779b3754384f26c8
tree056473b86b8d5c54e82ecc920f0d639202191941
parent850470a8413a8a78e772c4f6bd9fe81ec6bd5b0f
mm/slub: Fix cmp_loc_by_count() to return 0 when counts are equal

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>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slub.c