I have a problem loading a kernel module, there is a large data structure, around the size of 2Gb of memory - whether I preallocate the table (so that it shows in .bss when I do size -A module.ko
or try to vmalloc()
it at load time, the module loading fails with insmod: error inserting 'module.ko': -1 Cannot allocate memory
.
I tried debugging the problem on usermode linux, but I get a bunch of segfaults (that can be continued in gdb, but end up with a console message overflow in relocation type 10 val <value in the ball park of 6G>
and 'module' likely not compiled with -mcmodel=kernel
. I assume that with Kbuild
the -mcmodel
should be right, right?
So the questions are:
-mcmodel=large
for a kernel module and expect it to work?I've tried this on debian squeeze, 64-bit, 2.6.32-5-amd64 (host) with 8Gb of memory and 2.6.32 in uml with 4G memory, so this should not be an ordinary out of memory problem.
Extra credit for working around the limit, if such limit exists :)
As for your first question - the limit on the module itself is 64 megabytes. The module loader will reject to load a module that exceeds this size. From kernel/module.c:
if (len > 64 * 1024 * 1024 || (hdr = vmalloc(len)) == NULL)
return ERR_PTR(-ENOMEM);
This is true both for 2.6.32 and for the newer kernels too, up to 3.3.
EDIT: In kernel version 3.4, the 64 Mb limit was removed. Now the actual limit depends only on how much memory vmalloc()
can allocate.
Remember that kernel-space memory is different from user-space memory -- on 32-bit Linux, the kernel has only 1Gb address space. There's a log more space address space for the kernel on 64-bit Linux, but kernel documentation suggests that only 1536MB is available for modules.
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