Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


The heap is a contiguous memory area that grows from bottom to top when expanded. Themm_struct
structure already mentioned includes the start and the current end address (start_brkandbrk)ofthe
heap in virtual address space.

<mm_types.h>
struct mm_struct {
...
unsigned long start_brk, brk, start_stack;
...
};

Thebrksystem call expects just a single parameter to specify the new end address of the heap in virtual
address space (it can, of course, be smaller than the previous value if the heap is to be shrunk).

As usual, the entry point for the implementation of thebrksystem call is thesys_brkfunction, whose
code flow diagram is shown in Figure 4-16.

Check resource limits

sys_brk

find_vma_intersection

do_brk

do_munmap

Align brk value per page

Increase of brk value?

Return new brk value

Return new brk value

No

Yes

Figure 4-16: Code flow diagram forsys_brk.

Thebrkmechanism is not another independent kernel concept but is implemented on the basis of anony-
mous mappings to reduce internal overhead. Many of the functions to manage memory mappings
discussed in the preceding sections can therefore be reused to implementsys_brk.

After it has been checked that the new desired address forbrkis actually within the heap limits, the first
important action ofsys_brkis to align the request to page size.

mm/mmap.c
asmlinkage unsigned long sys_brk(unsigned long brk)
{
unsigned long rlim, retval;
unsigned long newbrk, oldbrk;
struct mm_struct *mm = current->mm;
Free download pdf