I want to check whether the kernel driver module which I just finished has a memory leak problem. But I don't know how to do it in kernel space. Dynamic memory allocation is very hard to handle I think. Anyone has the experience in debugging such memory problem in kernel space? Or, which tool can I use to measure the dynamic memory usage of a specific kernel module?
Best How To :
It's really hard to track allocation and freeing memory in a kernel module, but you have some facilities still. Here are a couple tools and approaches to investigate memory leakage in kernel space.
/proc/slabinfo (slabtop). It collects information about kernel structures. Not really about a module one. But it still might be very helpful.
Kmem and ftrace. Just links:
Trap each kmalloc, kfree, etc. event and produce relevant information with them.(c)
- /proc/modules (lsmod). Nothing special except information how much memory a module uses when it's loaded. In fact it's just the size of a module.