Linux Paging


### four-level paging for future hardware which has many three level to mapping to hardware

each process has its own Page Global Directory and its own set of page (upper, middle, null)tables
![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F81e93678-3bfb-4c92-ad67-8febcbb65be7%2Ftemp.jpg?table=block&id=0c97af39-ebe2-4696-b377-c3c931e8f15f&cache=v2)
![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F0d77a5e8-bea8-4ece-82bd-39352f2d73e0%2Ftemp.jpg?table=block&id=fad97902-3c20-4c54-a857-31c1235cc219&cache=v2)
task struct data sturucture has mm pointer, mm is pointer which has image mm_struct data sturcture. that has mmap pointer. process's meta data sturcture vm araa struct
pgd is page first table base address directory


1. read then page fault (segmentation fault) start end area
2. write code is fault so OS read commision
3. also fault because because r/w no physical in frame then replacement
> ![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fe3a42f71-e4d2-4057-97b8-80ace7bef2d1%2FUntitled.png?table=block&id=4dd69d90-4471-4c46-be35-7f144ff711d8&cache=v2)

![](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F56c9d36a-87cf-4f5b-b9ad-cbde6a4d621d%2Ftemp.jpg?table=block&id=67c9f0be-bd02-44ac-8eeb-48005baed1a4&cache=v2)
**KMA: **dynamic memory allocation in head (3gb) by malloc. in kernel (1gb) memory allocationbecause kernel cannot use malloc
- contiguous page frame allocator : alooc_pages()
- noncontiguous page fram allocator : vmalloc()
- memory object allocators : the slab alloctor- kmem_cache_alloc : congifuous allocation of kernel objects- kmalloc() : contiguous allocation of arbitrary length up to 128kb

## Page replacemnet in linux
- **two LRU listsinactive_list - pages not known to be importantactive_list - pages known to be referenced frequently**
- kernel swap daemon (a kernel thread)
- more on page replacemnet mechanism
> 64bit usually use 3 level paging

