You can allocate virtual memory (in kernel space of course) from the kernel's vmalloc region using the vmalloc() API:
#include <linux/vmalloc.h>
void *vmalloc(unsigned long size);
Some key points to note on the vmalloc:
- The vmalloc() API allocates contiguous virtual memory to the caller. There is no guarantee that the allocated region will be physically contiguous; it may or may not be (in fact, the larger the allocation, the less the chance that it's physically contiguous).
- The content of the virtual pages allocated is, in theory, random; in practice, it appears to be arch-dependent (the x86_64, at least, seems to zero out the memory region); of course, (at the risk of a slight performance hit) you're recommended to ensure memory zeroing out by employing the vzalloc() wrapper API
- The vmalloc() (and friends) APIs must only ever be invoked from a process context (as it might...