Skip to content

Commit 7013803

Browse files
kaushlenakpm00
authored andcommitted
tools/mm/page_owner_sort: fix timestamp comparison for stable sorting
The ternary operator in compare_ts() returns 1 when timestamps are equal, causing unstable sorting behavior. Replace with explicit three-way comparison that returns 0 for equal timestamps, ensuring stable qsort ordering and consistent output. Link: https://lkml.kernel.org/r/20251209044552.3396468-1-kaushlendra.kumar@intel.com Fixes: 8f9c447 ("tools/vm/page_owner_sort.c: support sorting pid and time") Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com> Cc: Chongxi Zhao <zhaochongxi2019@email.szu.edu.cn> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 632b874 commit 7013803

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

tools/mm/page_owner_sort.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ static int compare_ts(const void *p1, const void *p2)
181181
{
182182
const struct block_list *l1 = p1, *l2 = p2;
183183

184-
return l1->ts_nsec < l2->ts_nsec ? -1 : 1;
184+
if (l1->ts_nsec < l2->ts_nsec)
185+
return -1;
186+
if (l1->ts_nsec > l2->ts_nsec)
187+
return 1;
188+
return 0;
185189
}
186190

187191
static int compare_cull_condition(const void *p1, const void *p2)

0 commit comments

Comments
 (0)