Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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,

like image 307
resultsway Avatar asked Mar 07 '13 21:03

resultsway


People also ask

How can I see my kernel memory usage?

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.

How much RAM does Linux kernel need?

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.

Is kernel space in RAM?

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.

How much memory Linux is using?

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.


1 Answers

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.

like image 94
blu3g3 Avatar answered Oct 22 '22 11:10

blu3g3