11

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

size chardev.ko

text    data     bss     dec     hex   filename
172     448    1024016 1024636  fa27c chardev.ko

lsmod

Module  Size    Used by    Tainted: P
chardev 1025040 0 - Live   0xc009d000
4
  • If you've done measurements, you should probably provide them. Commented Mar 19, 2009 at 15:04
  • Please document the question more. Commented Mar 19, 2009 at 15:18
  • Yes, please list the modules. It would also be helpful to know what kind of debugging is configured in your kernel, it might just be debug overhead. Commented Mar 20, 2009 at 6:07
  • 1
    The lsmod will list values in page sizes. size lists them to whatever the ELF sections are aligned to. You can't allocate less than a page in the kernel. This difference in size is not really that great 1025040-1024636=404 bytes. Commented Jan 22, 2013 at 15:39

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yea this seems to be the case.
1

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

1 Comment

It did not give any size information .Here is the o/p # cat /proc/kallsyms | grep chardev 00000000 a chardev.c [chardev] c009d058 r $LC0 [chardev] c009d400 b p [chardev] c009d000 t cleanup_module [chardev] c009d008 t init_module [chardev]
0

Without more information, I'm tempted to guess that its debug overhead. I say tempted because I don't have your kernel configuration.

2 Comments

@tinkertim Will not the debug overhead be coming in both size and lsmod?
@AIB, I think the size of _init depends on debugging, but only _after the module is inserted. I might be incorrect, I'm actually trying to look it up now :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.