[英]how much memory is my kernel module using?
lsmod , /proc/modules and slabinfo , /proc/meminfo does NOT give how much memory my kernel module is using lsmod,/ proc / modules和slabinfo,/ proc / meminfo不会给我的内核模块使用多少内存
is there a way to find this out ? 有没有办法找到这个?
btw, I wrote a small test program basically, a device driver that takes ioctl call to alloc 1MB and I send this ioctl message every second from my application so my drive does kmalloc every second. 顺便说一句,我基本上写了一个小测试程序,一个设备驱动程序,它接受ioctl调用以分配1MB,我每秒从我的应用程序发送这个ioctl消息,所以我的驱动器每秒都会执行kmalloc。 Iam not able to see the increase in "cat /proc/meminfo | grep Slab "
我无法看到“cat / proc / meminfo | grep Slab”的增加
-- snip --- - 剪断---
int device_ioctl(
struct file *file,
unsigned int ioctl_num,
unsigned long ioctl_param)
{
/*
* Switch according to the ioctl called
*/
printk ( "<l> inside ioctl %d IOCTL_ALLOC_MSG = %d\n", ioctl_num,IOCTL_ALLOC_MSG );
switch (ioctl_num) {
case IOCTL_ALLOC_MSG:
allocfunc(); // kmalloc 1MB // printk in this function is OK
break;
case IOCTL_DEALLOC_MSG:
deallocfunc();
break;
}
return 0;
}
Application/user space 应用/用户空间
while ( !stop )
{
ret_val = ioctl(memfile, IOCTL_ALLOC_MSG);
if (ret_val < 0) {
printf("ioctl failed. Return code: %d, meaning: %s\n", ret_val, strerror(errno));
return -1;
}
sleep ( 10 );
}
I dont see the growth of memory in slabinfo. 我看不到slabinfo中记忆的增长。 I know linux does cache->slabs->pages->objects but there must be some way in user land to determine the memory size of a particular kernel module.
我知道linux会执行cache-> slabs-> pages-> objects,但是在用户区中必须有一些方法来确定特定内核模块的内存大小。
Thanks, 谢谢,
I'm not sure if it will be ok for you, but you can get the amount of memory that a module has taken with 'cat /proc/modules' , the second column is the size in bytes that the module in the first column is using. 我不确定它是否适合您,但是您可以获得模块使用'cat / proc / modules'获取的内存量,第二列是第一列中模块的大小(以字节为单位)正在使用。
Sample output showing how much memory are drm modules using: 示例输出显示drm模块使用的内存量:
cat /proc/modules |grep ^drm|awk '{print $1 " " $2}' cat / proc / modules | grep ^ drm | awk'{print $ 1“”$ 2}“
drm_kms_helper 49394 drm 286028 drm_kms_helper 49394 drm 286028
Hope that helps. 希望有所帮助。
Assuming there isn't a way to do this directly (which there might be, for all I know) .... 假设没有办法直接这样做(据我所知,可能存在)....
You could use LTTng to trace your kernel events. 您可以使用LTTng来跟踪内核事件。 If there's no handy event already there, you should create a new trace even every time your module allocates memory.
如果那里没有任何方便的事件,即使每次模块分配内存,也应该创建一个新的跟踪。
You can then analyse the trace and draw a graph of how your memory use grows and shrinks over time. 然后,您可以分析跟踪并绘制内存使用量随时间增长和缩小的图表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.