Skip to content

Commit 553c036

Browse files
oglittatehcaster
authored andcommitted
mm/slub: sort debugfs output by frequency of stack traces
Sort the output of debugfs alloc_traces and free_traces by the frequency of allocation/freeing stack traces. Most frequently used stack traces will be printed first, e.g. for easier memory leak debugging. Signed-off-by: Oliver Glitta <glittao@gmail.com> Signed-off-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-and-tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Acked-by: David Rientjes <rientjes@google.com>
1 parent 8ea9fb9 commit 553c036

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

mm/slub.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <linux/memcontrol.h>
3939
#include <linux/random.h>
4040
#include <kunit/test.h>
41+
#include <linux/sort.h>
4142

4243
#include <linux/debugfs.h>
4344
#include <trace/events/kmem.h>
@@ -6137,6 +6138,17 @@ static void *slab_debugfs_next(struct seq_file *seq, void *v, loff_t *ppos)
61376138
return NULL;
61386139
}
61396140

6141+
static int cmp_loc_by_count(const void *a, const void *b, const void *data)
6142+
{
6143+
struct location *loc1 = (struct location *)a;
6144+
struct location *loc2 = (struct location *)b;
6145+
6146+
if (loc1->count > loc2->count)
6147+
return -1;
6148+
else
6149+
return 1;
6150+
}
6151+
61406152
static void *slab_debugfs_start(struct seq_file *seq, loff_t *ppos)
61416153
{
61426154
struct loc_track *t = seq->private;
@@ -6198,6 +6210,10 @@ static int slab_debug_trace_open(struct inode *inode, struct file *filep)
61986210
spin_unlock_irqrestore(&n->list_lock, flags);
61996211
}
62006212

6213+
/* Sort locations by count */
6214+
sort_r(t->loc, t->count, sizeof(struct location),
6215+
cmp_loc_by_count, NULL, NULL);
6216+
62016217
bitmap_free(obj_map);
62026218
return 0;
62036219
}

0 commit comments

Comments
 (0)