5.5.3.6Memory area management

Memory areas are sequences of memory cells having contiguous physical addresses with an arbitrary length. The SLES kernel uses the buddy algorithm for dealing with relatively large memory requests, but in order to satisfy kernel needs of small memory areas, a different scheme, called slab allocator, is used. The slab allocator views memory areas as objects with data and methods. Most of the kernel functions tend to repeatedly request objects of the same type, such as process descriptors, file descriptors, and so on. Hence, the slab allocator does not discard objects, but caches them so that they can be reused.

The slab allocator interfaces with the page frame allocator algorithm, Buddy System, to obtain free contiguous memory. The slab allocator calls the kmem_getpages() function with a flag parameter that indicates how the page frame is requested. This flag diverts the call to get_zeroed_page() if the memory area is to be used for a user mode process. As noted before, get_zeroed_page() initializes the newly allocated memory area with zero, thus satisfying the object reuse requirement.

5.5.3.7Noncontiguous memory area management

In order to satisfy infrequent memory requests, SLES kernel uses noncontiguous memory area allocation methods which will reduce external fragmentation. The SLES kernel provides a mechanism via the vmalloc() function where non-contiguous physically memory can be used that is contiguous in virtual memory.

To allocate memory for kernel use, vmalloc() calls __vmalloc() with a gfp_mask flag that is always set to GFP_KERNEL __GFP_HIGHMEM. __vmalloc() in turn calls vmalloc_area_pages(), which will allocate the PTEs for the page requested.

5.5.4Process address space

The address space of a process consists of all logical addresses that the process is allowed to use. Each process has its own address space, unless it is shared. The kernel allocates logical addresses to a process in intervals called memory regions. Memory regions have an initial logical address, a length, and some access rights.

This section highlights how the SLES kernel enforces separation of address spaces belonging to different processes using memory regions. It also highlights how the kernel prevents unauthorized disclosure of information by handling object reuse for newly allocated memory regions.

Some of the typical situations in which a process gets new memory regions are:

creating a new process (fork())

loading an entirely new program (execve())

memory mapping a file (mmap())

creating shared memory (shmat())

expanding its heap (malloc()) and for growing its stack

All information related to the process address space is included in the memory descriptor (mm_struct) referenced by the mm field of the process descriptor. Memory descriptors are allocated from the slab allocator cache using mm_alloc(). Each memory region, represented by the vm_area_struct structure, identifies a linear address interval. Memory regions owned by a process never overlap.

To grow or shrink a process’s address space, the kernel uses the do_mmap() and do_unmap() functions. The do_mmap() function calls arch_get_unmapped_area() to find an available linear address interval. Because linear address intervals in memory regions do not overlap, it is not possible for the linear

128

Page 140
Image 140
IBM 10 SP1 EAL4 manual Process address space, Memory area management, Noncontiguous memory area management