Skip to content

Commit e548eaa

Browse files
maninder42paulmckrcu
authored andcommitted
mm/slub: Add Support for free path information of an object
This commit adds enables a stack dump for the last free of an object: slab kmalloc-64 start c8ab0140 data offset 64 pointer offset 0 size 64 allocated at meminfo_proc_show+0x40/0x4fc [ 20.192078] meminfo_proc_show+0x40/0x4fc [ 20.192263] seq_read_iter+0x18c/0x4c4 [ 20.192430] proc_reg_read_iter+0x84/0xac [ 20.192617] generic_file_splice_read+0xe8/0x17c [ 20.192816] splice_direct_to_actor+0xb8/0x290 [ 20.193008] do_splice_direct+0xa0/0xe0 [ 20.193185] do_sendfile+0x2d0/0x438 [ 20.193345] sys_sendfile64+0x12c/0x140 [ 20.193523] ret_fast_syscall+0x0/0x58 [ 20.193695] 0xbeeacde4 [ 20.193822] Free path: [ 20.193935] meminfo_proc_show+0x5c/0x4fc [ 20.194115] seq_read_iter+0x18c/0x4c4 [ 20.194285] proc_reg_read_iter+0x84/0xac [ 20.194475] generic_file_splice_read+0xe8/0x17c [ 20.194685] splice_direct_to_actor+0xb8/0x290 [ 20.194870] do_splice_direct+0xa0/0xe0 [ 20.195014] do_sendfile+0x2d0/0x438 [ 20.195174] sys_sendfile64+0x12c/0x140 [ 20.195336] ret_fast_syscall+0x0/0x58 [ 20.195491] 0xbeeacde4 Acked-by: Vlastimil Babka <vbabka@suse.cz> Co-developed-by: Vaneet Narang <v.narang@samsung.com> Signed-off-by: Vaneet Narang <v.narang@samsung.com> Signed-off-by: Maninder Singh <maninder1.s@samsung.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent 0cbc124 commit e548eaa

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

mm/slab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ struct kmem_obj_info {
640640
struct kmem_cache *kp_slab_cache;
641641
void *kp_ret;
642642
void *kp_stack[KS_ADDRS_COUNT];
643+
void *kp_free_stack[KS_ADDRS_COUNT];
643644
};
644645
void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page);
645646
#endif

mm/slab_common.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ EXPORT_SYMBOL_GPL(kmem_valid_obj);
564564
* depends on the type of object and on how much debugging is enabled.
565565
* For a slab-cache object, the fact that it is a slab object is printed,
566566
* and, if available, the slab name, return address, and stack trace from
567-
* the allocation of that object.
567+
* the allocation and last free path of that object.
568568
*
569569
* This function will splat if passed a pointer to a non-slab object.
570570
* If you are not sure what type of object you have, you should instead
@@ -609,6 +609,16 @@ void kmem_dump_obj(void *object)
609609
break;
610610
pr_info(" %pS\n", kp.kp_stack[i]);
611611
}
612+
613+
if (kp.kp_free_stack[0])
614+
pr_cont(" Free path:\n");
615+
616+
for (i = 0; i < ARRAY_SIZE(kp.kp_free_stack); i++) {
617+
if (!kp.kp_free_stack[i])
618+
break;
619+
pr_info(" %pS\n", kp.kp_free_stack[i]);
620+
}
621+
612622
}
613623
EXPORT_SYMBOL_GPL(kmem_dump_obj);
614624
#endif

mm/slub.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,6 +4011,13 @@ void kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct page *page)
40114011
if (!kpp->kp_stack[i])
40124012
break;
40134013
}
4014+
4015+
trackp = get_track(s, objp, TRACK_FREE);
4016+
for (i = 0; i < KS_ADDRS_COUNT && i < TRACK_ADDRS_COUNT; i++) {
4017+
kpp->kp_free_stack[i] = (void *)trackp->addrs[i];
4018+
if (!kpp->kp_free_stack[i])
4019+
break;
4020+
}
40144021
#endif
40154022
#endif
40164023
}

mm/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ int __weak memcmp_pages(struct page *page1, struct page *page2)
983983
* depends on the type of object and on how much debugging is enabled.
984984
* For example, for a slab-cache object, the slab name is printed, and,
985985
* if available, the return address and stack trace from the allocation
986-
* of that object.
986+
* and last free path of that object.
987987
*/
988988
void mem_dump_obj(void *object)
989989
{

0 commit comments

Comments
 (0)