lsmod , /proc/modules and slabinfo , /proc/meminfo does NOT give how much memory my kernel module is using
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. Iam not able to see the increase in "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. 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.
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.
Sample output showing how much memory are drm modules using:
cat /proc/modules |grep ^drm|awk '{print $1 " " $2}'
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. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.