Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


CPU 0 CPU 1 CPU n

FIX_KMAP_BEGIN FIX_KMAP_END

1 = KM_BOUNCE_READ
2 = KM_SKB_SUNRPC_DATA,...

01234567 01234567n n 01234567 n

Figure 3-42: Mapping high-memory pages by means of fixed mappings.

Once the appropriate index has been calculated using the formula specified above and the associated
fixmap address has been found, all the kernel need do is modify the page tables accordingly and flush
the TLBs to put the changes into effect.

Thekunmap_atomicfunction unmaps an existing atomic mapping from virtual memory by reference to
its type and virtual address simply by deleting the corresponding entry in the page tables.

MappingFunctionson MachineswithoutHighmem


Many architectures do not support high memory because they don’t need it — 64-bit architectures head
this list. However, to permit use of the above functions without having to constantly distinguish between
highmem and non-highmem architectures, the kerneldefines several macros that implement compatible
functions in normal memory (these are also used when highmem support is disabled on highmem-
capable machines).

<highmem.h>
#ifdef CONFIG_HIGHMEM
...
#else
static inline void *kmap(struct page *page)
{
might_sleep();
return page_address(page);
}

#define kunmap(page) do { (void) (page); } while (0)
#define kmap_atomic(page, idx) page_address(page)
#define kunmap_atomic(addr, idx) do { } while (0)
#endif

3.6 The Slab Allocator


Every C programmer is familiar withmallocand all its related functions in the standard library; they are
frequently invoked by most programs to reserve a few bytes of memory.

The kernel must also frequently allocate memory but cannot resort to the standard library functions.
The buddy system resources described above support the allocation of memory in pages, but this unit is
much too big. If space is needed for a string with 10 characters, reserving a full page with 4 KiB or more
is not only wasteful but absolutely unacceptable. The obvious solution is to split the memory in a page
into smaller units that can then hold large numbers of small objects.
Free download pdf