void *vmalloc(unsigned long size);
Just one parameter is required to specify the size of the required memory area — in contrast to the functions discussed earlier, the size unit is not pages but bytes, as is common in userspace programming.
The best-known example of vmalloc use is in the module implementation of the kernel. Because modules can be loaded at any time, there is no guarantee — particularly if the system has been up and running for a long time — that sufficient contiguous memory will be available for the sometimes voluminous module data. This problem can be circumvented by using vmalloc if sufficient memory can be pieced together from smaller chunks.
vmalloc is also invoked at about 400 other places in the kernel, particularly in device and sound drivers.
Because the memory pages used for vmalloc must in any case be actively mapped in kernel address space, it is obviously preferable to use pages from ZONE_HIGHMEM for this purpose. This allows the kernel to conserve the more valuable lower zones without incurring any added disadvantages. For this reason, vmalloc (along with the mapping functions discussed in Section 3.5.8) is one of the few occasions when the kernel is able to use highmem pages for its own purposes (and not for userspace applications).
Continue reading here: Reserving Memory with vmalloc
Was this article helpful?