Allocation of Discontiguous Pages in the Kernel

Physically contiguous mappings are best for the kernel for the reasons given above, but they cannot always be used successfully. When a larger chunk of memory is allocated, it may be that it is not available in a contiguous block despite all efforts made to avoid this situation. This is not a problem in userspace because normal processes are designed to use the paging mechanism of the processor even though this is costly in terms of speed and TLBs.

The same technique can also be applied in the kernel. As discussed in Section 3.4.2, the kernel reserves a chunk of its virtual address space so that it can set up contiguous mappings in them.

As Figure 3-37 shows, a memory zone for the management of discontiguous memory on IA-32 follows the direct mapping of the first 892 MiB of RAM after an intervening safety gap of 8 MiB. This segment has all the properties of a linear address space; the pages assigned to it can be located anywhere in RAM memory. This is achieved by modifying the kernel page tables responsible for this area.

Protection gap

Protection gap

Figure 3-37: vmalloc area in the kernel's virtual address space on IA-32 systems.

A self-contained area separated from the other areas by a memory page is assigned to each vmalloc allocation. Like the boundary between direct mappings and the vmalloc area, the purpose of this is to safeguard against incorrect memory access operations; these occur only as a result of kernel faults and should be reported by a system error message rather than allowing the data of other kernel parts to be overwritten unnoticed. Because this separation is made in virtual address space, no valuable real memory pages are wasted.

vmalloc is the interface function used by the kernel code to request memory that is not necessarily contiguous in physical memory but is always linear in virtual memory.

Continue reading here: Info

Was this article helpful?

0 0