Skip to contentSkip to conversation

tools/mm/page_owner_sort: Fix timestamp comparison for stable sorting

PATCH Applied Kaushlendra Kumar 1 participant 1 message Dec 9, 2025 Memory management

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 tools/mm/page_owner_sort.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
tools/mm/page_owner_sort.c +5 -1
index 880e36df0c11..82d6f6b31348 100644
@@ -183,7 +183,11 @@ static int compare_ts(const void *p1, const void *p2)
 {
 	const struct block_list *l1 = p1, *l2 = p2;
 
-	return l1->ts_nsec < l2->ts_nsec ? -1 : 1;
+	if (l1->ts_nsec < l2->ts_nsec)
+		return -1;
+	if (l1->ts_nsec > l2->ts_nsec)
+		return 1;
+	return 0;
 }
 
 static int compare_cull_condition(const void *p1, const void *p2)
Signature · 1 line
2.34.1