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 :)
If I define the table as static
- the module loading will indeed fail - this is probably because of the 1.5G limit mentioned in the answer by Andrew Aylett
However, if I do dynamic vmalloc()
calls, I was able to get up to 7680Mb on a host with 8Gb of memory (until the kernel killed some crucial process and my X hanged).
So to answer my questions:
static
Extra credit: just do vmalloc()
This only works in linux kernels newer than 2.6.10 - before that, the vmalloc()
limit was 64 Mb.