As seen in the previous chapter, a
kernel function gets dynamic memory in a fairly straightforward
manner by invoking one of a variety of functions:
_ _get_free_pages( ) or
alloc_pages( ) to
get pages from the buddy system algorithm,
kmem_cache_alloc( ) or
kmalloc( ) to use the slab
allocator for specialized or general-purpose objects, and
vmalloc( ) to get a noncontiguous memory area. If
the request can be satisfied, each of these functions returns a page
descriptor address or a linear address identifying the beginning of
the allocated dynamic memory area.
These simple approaches work for two reasons:
The kernel is the highest-priority component of the operating system. If a kernel function makes a request for dynamic memory, it must have a valid reason to issue that request, and there is no point in trying to defer it.
The kernel trusts itself. All kernel functions are assumed to be error-free, so the kernel does not need to insert any protection against programming errors.
When allocating memory to User Mode processes, the situation is entirely different:
Process requests for dynamic memory
are considered nonurgent. When a process’s
executable file is loaded, for instance, it is unlikely that the
process will address all the pages of code in the near future.
Similarly, when a process invokes
malloc( ) to get additional dynamic memory, it doesn’t mean the process will soon access all the additional memory obtained. Thus, as a general rule, the ...