问题描述
我想检查刚刚完成的内核驱动程序模块是否存在内存泄漏问题.但是我不知道如何在内核空间中做到这一点.我认为动态内存分配非常难以处理.任何人都有调试内核空间中此类内存问题的经验吗?或者,我可以使用哪个工具来衡量特定内核模块的动态内存使用情况?
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?
推荐答案
在内核模块中跟踪分配和释放内存确实很困难,但是您仍然有一些便利.这是研究内核空间内存泄漏的几种工具和方法.
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).它收集有关内核结构的信息.与模块无关.但这可能还是很有帮助的.
/proc/slabinfo (slabtop). It collects information about kernel structures. Not really about a module one. But it still might be very helpful.
Kmem和ftrace .只是链接:
https://www.kernel.org/doc/Documentation/跟踪/事件-kmem.txt
http://elinux.org/Kernel_dynamic_memory_analysis
捕获每个kmalloc,kfree等事件,并与它们一起产生相关信息.(c)
- /proc/modules(lsmod).除了提供有关模块加载时使用多少内存的信息外,没有什么特别的.实际上,这只是一个模块的大小.
- /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.
这篇关于测量某个Linux驱动程序模块的内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!