ANDROID: vendor_hooks: add hook to record slab alloc and free

Add hook to record slab usage for calling slab_alloc_node and
slab_free check for memory leaks.

Bug: 379598560
Bug: 341216009
Change-Id: Ibb5f77b8244096fc999190244d197b7a40e6591c
Signed-off-by: Dezhi Huang <huangdezhi@hihonor.com>
(cherry picked from commit d5c66ad281a72e29802ae72fec0526e58a151377)
This commit is contained in:
Dezhi Huang
2024-05-17 16:05:48 +08:00
committed by zhengwei
parent defe0024cf
commit eb0102684f
3 changed files with 13 additions and 0 deletions

View File

@@ -192,6 +192,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_unreserve_highatomic_bypass);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rmqueue_bulk_bypass);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ra_tuning_max_page);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_tune_mmap_readaround);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_slab_alloc_node);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_slab_free);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_selinux_avc_insert);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_selinux_avc_node_delete);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_selinux_avc_node_replace);

View File

@@ -123,6 +123,12 @@ DECLARE_HOOK(android_vh_show_smap,
TP_PROTO(struct seq_file *m, unsigned long writeback,
unsigned long same, unsigned long huge),
TP_ARGS(m, writeback, same, huge));
DECLARE_HOOK(android_vh_slab_alloc_node,
TP_PROTO(void *object, unsigned long addr, struct kmem_cache *s),
TP_ARGS(object, addr, s));
DECLARE_HOOK(android_vh_slab_free,
TP_PROTO(unsigned long addr, struct kmem_cache *s),
TP_ARGS(addr, s));
DECLARE_HOOK(android_vh_meminfo_cache_adjust,
TP_PROTO(unsigned long *cached),
TP_ARGS(cached));

View File

@@ -3420,6 +3420,8 @@ redo:
out:
slab_post_alloc_hook(s, objcg, gfpflags, 1, &object, init);
trace_android_vh_slab_alloc_node(object, addr, s);
return object;
}
@@ -3683,6 +3685,9 @@ static __always_inline void slab_free(struct kmem_cache *s, struct slab *slab,
*/
if (slab_free_freelist_hook(s, &head, &tail, &cnt))
do_slab_free(s, slab, head, tail, cnt, addr);
trace_android_vh_slab_free(addr, s);
}
#ifdef CONFIG_KASAN_GENERIC