While trying to estimate the amount of memory consumed by a kernel module (usually device drivers),I tried using the size utility which gave the size of the static memory areas of the .ko ( .bss, .data, .text etc). So I was expecting the sum of these values to be exactly equal to the output given by the lsmod command immediately after inserting the module.
No dynamic memory allocation(kmalloc or vmalloc) is performed in the init() function to ensure that it isn't causing the difference.So why is there a mismatch?
Curiously the mismatch was found to be a fixed amount most of the time!!
The command outputs are listed below
text data bss dec hex filename
172 448 1024016 1024636 fa27c chardev.ko
Module Size Used by Tainted: P
chardev 1025040 0 - Live 0xc009d000
Paged Kernel Memory Virtual memory is used to take off some load from the RAM, making the RAM available for other applications. It uses your hard disk space by creating a filein your root folder named pagefile. sys. Similar to RAM, a portion of the pagefile.
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.
A 32-bit processor can address a maximum of 4GB of memory. Linux kernels split the 4GB address space between user processes and the kernel; under the most common configuration, the first 3GB of the 32-bit range are given over to user space, and the kernel gets the final 1GB starting at 0xc0000000.
The Windows kernel-mode memory manager component manages physical memory for the operating system. This memory is primarily in the form of random access memory (RAM). The memory manager manages memory by performing the following major tasks: Managing the allocation and deallocation of memory virtually and dynamically.
You mention that no allocation is done in the init function, but does that take into account calls such as register_chrdev(9) which allocate memory internally for the device instance? The comment that it is a constant difference makes me wonder if this might be the cause.
May be the functions used by the module are counted into the module size ? Try
cat /proc/kallsyms | grep module_name
The difference between the two size is 404. Text + data + 404 = 1024. May be this is some kind of granularity problem ? I don't know how the size is calculated inside the kernel...
However, kernel code and data are allocated using dynamic memory. And kmalloc uses pre-allocated block of memory, so it is quite likely that there is some rounding up when code and data sections are allocated.
Try to increment the size of the data sections and see if the lsmod reported size change
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