Memory management - malloc & free (mm_kernel.c)

General features

Malloc and free functions operate on 4MB frames of memory. If malloc does not have enough memory, physical memory manager's function pmm_allocate_kernel_frames_unsafe is called to receive more frames.

Each received frame has this structure:



In the figure above H is 16B long free block with is_first flag set to 1 indicating that this free block cannot be assigned as full block (flags are described later). This is here to prevent disintegration and make 4MB frames connections easier. "data" means free and full blocks allocated by user. Finally, F is at least 16B long free block which is here to make 4MB frames connections easier.

However, contiguous 4MB frames of memory are merged as below (i is some natural number).



Free block structure

Free block has 16B long header that has the following structure:

Full block structure

Full block has 8B long header consisting of these items: