Linux Memory Management

Linux supports virtual memory with the help of the three-level page table structure. These are:

  • Page Directory
  • Page Middle Directory
  • Page Table

1. Page Directory: Each process maintains a page directory, each page in the process having an entry in the page directory. Each entry in the page directory has a pointer, which points to one entry of the page middle directory.

2. Page Middle Directory: Each entry in the page middle directory, points to a page table.

3. Page Table: The virtual address space of LINUX contains 4 fields:
Linux Memory Management

Page Allocation: The kernel maintains a list of continuous page frames groups of fixed size. A group may consist of 1, 2, 4, 8, 16, 32-page frames. Pages are allocated and dislocated in memory using the buddy algorithm.

Page Replacement Algorithm: In the primary clock page replacement algorithm, we use a single bit that is called use-bit based on the use-bit, the algorithm replaces the page. But LINUX follows another type of replacement policy. In which each page maintains an 8-bit count variable. It is incremented automatically when the page is referenced (accessed).

Kernel Memory Allocation: In the Lazy buddy algorithm, each block is fixed with the size of a page.

Example: The kernel needs 33 kb, each block size is 32 kb, then it requires 2 blocks, remaining 31 kb memory will be wasted, overcome this problem LINUX processed another method. So, it is called ‘ Stub Allocation’. In the Stub Allocation method, it maintains all sizes of blocks based on the need it allocates the blocks.