linux存储管理是什么,LINUX 存储管理

LINUX

address spaceMMUmemory management unitMMUCPUCPUMMUMMU

LINUX4GB03GB3GB4GB3GB4GBLINUX3GB3GB+4M76804M3GB3GB+4M04M04M

PGD PMD PTE Page Frame PFN(page frame number)

Translation Lookaside BuffersTLBs)RAMCPUMMUtranslation lookaside buffersTLBs

(VMA)VMA:vitual memory areavmalockedprotectedvmavmavm_nextVMAsVMAVMA struct mm_structstruct vm_area_struct * mmap vma

(VMA) avl_min_map_countVMAAVLVMAsAVLVMA

AVL

vm_area_struct

(1000,2000)

vm_avl_left

(2500,3000)

vm_avl_right

(500,670)

vm_avl_left

vm_avl_left

vm_avl_right

vm_avl_right

(350,450)

(800,900)

vm_avl_left

vm_avl_left

vm_avl_right

vm_avl_right

PCB Task structmm_struct_vm_area_struct vm_mm pgd mm vm_operations_struct vm_next mmap vm_ops pgd vm_area_struct pte pte page page frame framevm_next *open

(include/linux/fs.h,struct page) (page frame)INTEL CPU4K LINUXmem_map(mm/memory.c) mem_mapfree_area_init()(mm/page_alloc.c) struct page mem_map_t (linux/mm.h)mem_map_t

mem_map

struct page134 typedef struct page {135 struct list_head list;136 struct address_space *mapping; 137 unsigned long index; /* indexinode */ 138 struct page *next_hash;139 atomic_t count; /* count==0 */140 unsigned long flags; /* atomic flags, some possibly updated asynchronously */141 struct list_head lru;142 unsigned long age; /* */ 143 wait_queue_head_t wait;144 struct page **pprev_hash;145 struct buffer_head * buffers; /* */ 146 void *virtual; /* non-NULL if kmapped */147 struct zone_struct *zone;148 } mem_map_t;

bitmap mem_mapbitmap mem_mapbitmapfree_area_init()(mm/page_alloc.c) bitmapNR_MEM_LISTS(6)

bitmap 0(end_mem-start_mem) / PAGE_SIZE/20+3,20 1 (end_mem-start_mem) / PAGE_SIZE/21+3 2112 i (end_mem-start_mem) / PAGE_SIZE / 2i+3 2i1 5bit321320

free_area LINUXfree_areafree_areaNR_MEM_LISTSfree_area_struct struct free_area_struct { struct page *next; /* next,prevstruct page */ struct page *prev; unsigned int * map; /* bitmap */ }; static struct free_area_struct free_area[NR_MEM_LISTS]; free_area02 ifree_areai

__get_free_pages()__get_free_page()

free_pages()

LINUXbuddy2i (0

change_bit()bitmap bitmapfree_area free_area

LINUXMAX_SWAPFILESMAX_SWAPFILES8

4096 SWAP_SPACEbit4096 4096-10* 8 1 = 32687

int sys_swapon(const char * swapfile, int swapflags);

swapfileswapflagsSWAP_FLAG_PREFER0X8000SWAP_FLAG_PRIO_MASK(0X7FFF)swaponswapon

swap_infoswap_info_struct 25 struct swap_info_struct swap_info[MAX_SWAPFILES]; 49 struct swap_info_struct { 50 unsigned int flags; /* SWP_USEDSWP_WRITEOK */ 51 kdev_t swap_device; /* swap_device */ 52 spinlock_t sdev_lock; /* */ 53 struct dentry * swap_file; /* swap_fileinode */ 54 struct vfsmount *swap_vfsmnt; 55 unsigned short * swap_map;/* */ 56 unsigned int lowest_bit; /*swap_map */ 57 unsigned int highest_bit; /* */ 58 unsigned int cluster_next; /*clusterswap_map */ 59 unsigned int cluster_nr; /* cluster */ 60 int prio; /* */ 61 int pages; /* */ 62 unsigned long max; 63 int next; /* */ 64 };153 struct swap_list_t {154 int head; /* head of priority-ordered swapfile list */155 int next; /* swapfile to be used next */156 };23 struct swap_list_t swap_list = {-1, -1};

int sys_swapoff(const char * swapfile);

kswapdtry_to_swap_out() get_swap_pageswap_list.nextentryrw_swap_page(),entry CR2Present020

kswapdkswapdkswapdkernel threadkernel threadbdflushinitkswapd

L i n u x

P0CR2LINUX

do_page_fault()set_trap_gate(14, &page_fault); /* arch/i386/kernel/trap.c */ENTRY(page_fault) /* arch/i386/kernel/entry.S */ pushl $SYMBOL_NAME(do_page_fault) jmp error_code /* */

CR2vm_area_structvm_area_structLINUXSIGSEGVLinuxLinuxLinux

LRU(

dirty page

TLB):

L i n u xpage_hash_tablepage_hash_table mem_map_tmem_map_tL i n u x

512 fs/buffer.c

你可能感兴趣的:(linux存储管理是什么)