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,
Entering cat /proc/meminfo in your terminal opens the /proc/meminfo file. This is a virtual file that reports the amount of available and used memory. It contains real-time information about the system's memory usage as well as the buffers and shared memory used by the kernel.
Memory Requirements Linux requires very little memory to run compared to other advanced operating systems. You should have at the very least 8 MB of RAM; however, it's strongly suggested that you have at least 16 MB. The more memory you have, the faster the system will run.
The code for managing all this hardware – all the shared resources, as well as process scheduling and memory management – is located in main memory and belongs to the oper- ating system. This part of the main memory is what is commonly referred to as kernel space.
The simplest way to check the RAM memory usage is to display the contents of the /proc/meminfo virtual file. This file is used by the free , top , ps , and other system information commands. The information from the /proc/meminfo file can be parsed and used in shell scripts.
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}'
Example answer:
drm_kms_helper 49394
drm 286028
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With