To determine how large a memory allocation can be made from within the kernel, via the “usual suspects” – the kmalloc and vmalloc kernel memory allocation APIs, in a single call.
Lets answer this question using two approaches: one, reading the source, and two, trying it out empirically on the system.
(Kernel source from kernel ver 3.0.2; tried out on kernel ver 2.6.35 on an x86 PC and 188.8.131.52 on the (ARM) BeagleBoard).
For the impatient:
The upper limit (number of bytes that can be allocated in a single kmalloc request), is a function of:
- the processor – really, the page size – and
- the number of buddy system freelists (MAX_ORDER).
On both x86 and ARM, with a standard page size of 4 Kb and MAX_ORDER of 11, the kmalloc upper limit is 4 MB!
The vmalloc upper limit is, in theory, the amount of physical RAM on the system.
In practice, the kernel allocates an architecture (cpu) specific “range” of virtual memory for the purpose of vmalloc: from VMALLOC_START to VMALLOC_END.
In practice, it’s usually a lot less. A useful comment by ugoren points out that:
” in 32bit systems, vmalloc is severely limited by its virtual memory area. For a 32bit x86 machine, with 1GB RAM or more, vmalloc is limited to 128MB (for all allocations together, not just for one).
The kernel module (can download the source code, see the link at the end of this article), also serves as a decent example of writing pure kernel code.
I kmalloc Limit Tests
First, lets check out the limits for kmalloc :
Continue reading kmalloc and vmalloc : Linux kernel memory allocation API Limits