ANDROID: vendor_hooks: add hooks for slab memory leak debugging

Add hooks and additional fields in vm_struct and track structs
to store and report additional information for slab memory leak
debugging.

Bug: 184928480

Change-Id: I6897a6a98d4eaaea492673cefd4111a7ba741940
Signed-off-by: Liujie Xie <xieliujie@oppo.com>
This commit is contained in:
Liujie Xie
2021-05-11 19:05:32 +08:00
committed by Todd Kjos
parent 70094f39c7
commit 8bc6337823
6 changed files with 23 additions and 0 deletions

View File

@@ -293,3 +293,6 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sd_update_bus_speed_mode);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmc_attach_sd);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sdhci_get_cd);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmc_gpio_cd_irqt);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_vmalloc_stack);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_show_stack_hash);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_track_hash);

View File

@@ -9,6 +9,7 @@
#include <asm/page.h> /* pgprot_t */
#include <linux/rbtree.h>
#include <linux/overflow.h>
#include <linux/android_vendor.h>
#include <asm/vmalloc.h>
@@ -57,6 +58,7 @@ struct vm_struct {
unsigned int nr_pages;
phys_addr_t phys_addr;
const void *caller;
ANDROID_OEM_DATA(1);
};
struct vmap_area {

View File

@@ -78,6 +78,15 @@ DECLARE_HOOK(android_vh_mm_dirty_limits,
unsigned long nr_reclaimable, unsigned long pages_dirtied),
TP_ARGS(gdtc, strictlimit, dirty, bg_thresh,
nr_reclaimable, pages_dirtied));
DECLARE_HOOK(android_vh_save_vmalloc_stack,
TP_PROTO(unsigned long flags, struct vm_struct *vm),
TP_ARGS(flags, vm));
DECLARE_HOOK(android_vh_show_stack_hash,
TP_PROTO(struct seq_file *m, struct vm_struct *v),
TP_ARGS(m, v));
DECLARE_HOOK(android_vh_save_track_hash,
TP_PROTO(unsigned long p),
TP_ARGS(p));
/* macro versions of hooks are no longer required */
#endif /* _TRACE_HOOK_MM_H */

View File

@@ -46,6 +46,7 @@ struct kmem_cache {
#include <linux/kmemleak.h>
#include <linux/random.h>
#include <linux/sched/mm.h>
#include <linux/android_vendor.h>
/*
* State of the slab allocator.
@@ -104,6 +105,9 @@ struct track {
int cpu; /* Was running on cpu */
int pid; /* Pid context */
unsigned long when; /* When did the operation occur */
#ifdef CONFIG_STACKTRACE
ANDROID_OEM_DATA(1);
#endif
};
enum track_item { TRACK_ALLOC, TRACK_FREE };

View File

@@ -37,6 +37,7 @@
#include <linux/random.h>
#include <trace/events/kmem.h>
#include <trace/hooks/mm.h>
#include "internal.h"
@@ -609,6 +610,7 @@ static void set_track(struct kmem_cache *s, void *object,
if (nr_entries < TRACK_ADDRS_COUNT)
p->addrs[nr_entries] = 0;
trace_android_vh_save_track_hash((unsigned long)p);
#endif
p->addr = addr;
p->cpu = smp_processor_id();

View File

@@ -34,6 +34,7 @@
#include <linux/bitops.h>
#include <linux/rbtree_augmented.h>
#include <linux/overflow.h>
#include <trace/hooks/mm.h>
#include <linux/uaccess.h>
#include <asm/tlbflush.h>
@@ -2033,6 +2034,7 @@ static inline void setup_vmalloc_vm_locked(struct vm_struct *vm,
vm->size = va->va_end - va->va_start;
vm->caller = caller;
va->vm = vm;
trace_android_vh_save_vmalloc_stack(flags, vm);
}
static void setup_vmalloc_vm(struct vm_struct *vm, struct vmap_area *va,
@@ -3550,6 +3552,7 @@ static int s_show(struct seq_file *m, void *p)
seq_puts(m, " vpages");
show_numa_info(m, v);
trace_android_vh_show_stack_hash(m, v);
seq_putc(m, '\n');
/*