2
votes

I am working on developing a block driver in linux. The requirement is to allocate a huge chunk of memory(example more than 128KB, 2MB or 8MB or so...), divide the memory into small chunk and sent it through scatter-gather list. The scatter gather entries will be controlled by the user application.

I know there is a strict limitation of memory available in kernel. How can I achieve this at the kernel. Any help is highly appreciated.

1
"chunk" not "junk", hahaha. Chunk means "piece", junk means "trash". - Shahbaz

1 Answers

3
votes

You can use vmalloc to allocate from virtual memory. This way, you can have all the memory you want (capped by the amount of memory there is).

From mm/vmalloc.c:

/**
* vmalloc - allocate virtually contiguous memory
* @size: allocation size
* Allocate enough pages to cover @size from the page level
* allocator and map them into contiguous kernel virtual space.
*
* For tight control over page level allocator and protection flags
* use __vmalloc() instead.
*/

vmalloced memory can be freed with, you guessed it, vfree.