Skip to content

Commit 8ea9fb9

Browse files
oglittatehcaster
authored andcommitted
mm/slub: distinguish and print stack traces in debugfs files
Aggregate objects in slub cache by unique stack trace in addition to caller address when producing contents of debugfs files alloc_traces and free_traces in debugfs. Also add the stack traces to the debugfs output. This makes it much more useful to e.g. debug memory leaks. 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>
1 parent 5cf909c commit 8ea9fb9

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

mm/slub.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5064,6 +5064,7 @@ EXPORT_SYMBOL(validate_slab_cache);
50645064
*/
50655065

50665066
struct location {
5067+
depot_stack_handle_t handle;
50675068
unsigned long count;
50685069
unsigned long addr;
50695070
long long sum_time;
@@ -5116,9 +5117,13 @@ static int add_location(struct loc_track *t, struct kmem_cache *s,
51165117
{
51175118
long start, end, pos;
51185119
struct location *l;
5119-
unsigned long caddr;
5120+
unsigned long caddr, chandle;
51205121
unsigned long age = jiffies - track->when;
5122+
depot_stack_handle_t handle = 0;
51215123

5124+
#ifdef CONFIG_STACKDEPOT
5125+
handle = READ_ONCE(track->handle);
5126+
#endif
51225127
start = -1;
51235128
end = t->count;
51245129

@@ -5133,7 +5138,8 @@ static int add_location(struct loc_track *t, struct kmem_cache *s,
51335138
break;
51345139

51355140
caddr = t->loc[pos].addr;
5136-
if (track->addr == caddr) {
5141+
chandle = t->loc[pos].handle;
5142+
if ((track->addr == caddr) && (handle == chandle)) {
51375143

51385144
l = &t->loc[pos];
51395145
l->count++;
@@ -5158,6 +5164,8 @@ static int add_location(struct loc_track *t, struct kmem_cache *s,
51585164

51595165
if (track->addr < caddr)
51605166
end = pos;
5167+
else if (track->addr == caddr && handle < chandle)
5168+
end = pos;
51615169
else
51625170
start = pos;
51635171
}
@@ -5180,6 +5188,7 @@ static int add_location(struct loc_track *t, struct kmem_cache *s,
51805188
l->max_time = age;
51815189
l->min_pid = track->pid;
51825190
l->max_pid = track->pid;
5191+
l->handle = handle;
51835192
cpumask_clear(to_cpumask(l->cpus));
51845193
cpumask_set_cpu(track->cpu, to_cpumask(l->cpus));
51855194
nodes_clear(l->nodes);
@@ -6089,6 +6098,21 @@ static int slab_debugfs_show(struct seq_file *seq, void *v)
60896098
seq_printf(seq, " nodes=%*pbl",
60906099
nodemask_pr_args(&l->nodes));
60916100

6101+
#ifdef CONFIG_STACKDEPOT
6102+
{
6103+
depot_stack_handle_t handle;
6104+
unsigned long *entries;
6105+
unsigned int nr_entries, j;
6106+
6107+
handle = READ_ONCE(l->handle);
6108+
if (handle) {
6109+
nr_entries = stack_depot_fetch(handle, &entries);
6110+
seq_puts(seq, "\n");
6111+
for (j = 0; j < nr_entries; j++)
6112+
seq_printf(seq, " %pS\n", (void *)entries[j]);
6113+
}
6114+
}
6115+
#endif
60926116
seq_puts(seq, "\n");
60936117
}
60946118

0 commit comments

Comments
 (0)