KernelNewbies:

Most of the kernel's program code (text) is used via large pages (2M and 1G on x86). This makes each TLB entry that the kernel uses cover more space which means the CPU spends less time walking the page tables and more time doing other work.

However, the kernel module code is placed in small pages. Historically, large amounts of contiguous memory are difficult to allocate in the kernel. For instance, if a 500KB module came along, and we tried to allocate memory for it using kmalloc() (which uses large pages mostly), it would be relatively likely to fail, and we would not be able to load the module. vmalloc() gets around this problem by allocating a bunch of small pages and then stitching them all back together.

Your goal here is to find all of the cases of vmalloc() and vfree in kernel/module.c. Convert them to try to call alloc_pages_exact() instead of vmalloc(). If alloc_pages_exact() fails, then fall back to vmalloc(). kmalloc_section_memmap() is an example of similar code.

Then, find all the instances of vfree() in kernel/module.c If the address is a vmalloc address, then call vfree(), otherwise call free_pages_exact(). kfree_section_memmap() does something similar, although with free_pages() instead of free_pages_exact().

If normal kernel memory obtained from alloc_pages_exact() isn't executable, there will be some extra steps to obtain executable memory.

KernelNewbies: KernelProjects/NoMoreModuleVmalloc (last edited 2014-05-12 21:04:53 by DaveHansen)