Measure memory usage of a certain Linux driver module

13.3k views Asked by At

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?

1

There are 1 answers

0
Anton Glukhov On BEST ANSWER

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.

  1. /proc/slabinfo (slabtop). It collects information about kernel structures. Not really about a module one. But it still might be very helpful.

  2. Kmem and ftrace. Just links:

https://www.kernel.org/doc/Documentation/trace/events-kmem.txt

http://elinux.org/Kernel_dynamic_memory_analysis

Trap each kmalloc, kfree, etc. event and produce relevant information with them.(c)

  1. /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.