Memory management (operating systems)
Logic gates: SRAM, DRAM
What is data/contrl/addr bus?
What problems we will meet in memory management?
Memory allocation and release. Bootmem and Buddy system is pretty good. Can we eliminate Bootmem?
How to distribute these memory to processes? Virtual memory.
How to translate linear address to physical address? Page table.
Exchange data between primary memory and second memory. Paging.
What are the pitfall of manuplate directly physcial memory
__GFP_IO: allow disk IO
__GFP_FS: allow fs operations, depend on io.
more details in lwn, lkd
mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
__pte(((phys_addr_t)page_nr << PAGE_SHIFT) | massage_pgprot(pgprot));
For vmalloc(), chechk here vmap_page_range_noflush()
For kmap(), check kmap_init()
How to emulate the process of translate va to pa?
not in kernel?
flush tlb after page table modification.
Direct mapping area
high_memory (-128UL << 20)
Hwo Vmalloc works?
Work in HIGHMEM and NORMALMEM
The skeleton is rbtree, root is global variable vmap_area_root.rb_node.
struct vm_struct likes struct address_space, functionlly;
struct vmap_area likes struct vm_area_struct.
the page in ZONE_NORMAL will not use directly mapping pfn address! It use VMALLOC address!
Vmalloc coherence with vfree() after vmalloc_sync_one
deatils in vmalloc_sync_one() and vunmap_pte_range()
Persistent Kernel Mappings
kmap(struct page *)
How kmap works?
Check kmap_init(), later!
##Process virtual memory
* struct vm_area_struct: The intervals of legal address are called memory areas is permitted to access.
* struct address_space: To establish an association between the regions of the vm and the places where the related data are located.
i_mmap: how many processes opened this file.
* sturct mm_struct: how many files(vm_area_struct) does this process opened.
syscall remap_file_pages Nolinear mappings is deprecated, since Linux 3.16
a virtual address and physical address. –page tale
a memory region of a process and its virtual page addresses. –vm_area_struct
a region of file(one physical) and all virtual address spaces(many virtual) into which the region is mapped. address_space->i_mmap.
a physical page and the processes that share the page(used in swap case)
Page fault: If a process accesses a part of virtual address space not yet associated with a page in memory
Segment fault: address is not in VMA, namely invalid address! Check bad_area() in x86.
Null pointer: probably, mostly catched in below 0x08048000.
* NUMA/UMA pg_data_t: My PC is UMA, numatop, numastat, numactl
* ZONE(DMA/NORMAL/HIGHMEM) struct zone:
* struct page is the basic unit of kernel mm knowns as page frame.
The goal of strcut page is to describe physical memory, not the data contained therein.
* The buddy system is per-zone struct free_area
* Physical address is connected to Virtual address by pfn = page - mem_map;
data synchronization, the flush threads, pdflush
The available RAM memory in a computer is never enough to meet user needs or to always satisfy memory-intensive applications.
* Where is Per-CPU variable?
static Per-CPU in .data(?) below high_memory!
runtime Per-CPU, it’s GFP_KERNEL in pcpu_create_chunk()
flat mem -> uma
discontig -> NUMA
sparse -> Hotplug + NUMA
When does kernel alloc these struct pages in x86_64?
vmemmap silimar to memmap
When kmap_atomic() BUG_ON effect?
How cpu resolve address below high_memory?
x86 used page table to all address!
Mips cpu can be aware of this address!
How to deal with useless page? : > /home/firo/bigdata
*pfmemalloc – skb 表示申请了紧急内存!
- compound pages