- 0
- 0
- 约1.86千字
- 约 8页
- 2026-03-12 发布于北京
- 举报
Linux内核?
第十讲Linux内存子系统数据结构主讲人:赵亚华章培训网、[]华章培训网
数据结构第2页一、数据结构 1、mm_struct structmm_struct{ structvm_area_struct*mmap; structrb_rootmm_rb; structvm_area_struct*mmap_cache; … pgd_t*pgd; … unsignedlongstart_code,end_code,start_data,end_data; unsignedlongstart_brk,brk,start_stack; unsignedlongarg_start,arg_end,env_start,env_end; … mm_context_tcontext; … };
数据结构第3页 2、vm_area_struct structvm_area_struct{ structmm_struct*vm_mm; unsignedlongvm_start; unsignedlongvm_end; structvm_area_struct*vm_next; //typedefstruct{unsignedlonglongpgprot;}pgprot_t; pgprot_tvm_page_prot; unsignedlongvm_flags; /*Flags,listedbelow.*/ structrb_nodevm_rb; union{ struct{ structlist_headlist; void*parent; structvm_area_struct*head; }vm_set; structprio_tree_nodeprio_tree_node; }shared;
数据结构第4页 structlist_headanon_vma_node; structanon_vma*anon_vma; structvm_operations_struct*vm_ops; unsignedlongvm_pgoff; structfile*vm_file; };
代码第5页二、代码 1、初始化 在copy_process中初始化页表: copy_mm- mm=allocate_mm(); memcpy(mm,oldmm,sizeof(*mm)); mm_init(mm);-mm_alloc_pgd(mm);//赋值pdg字段 dup_mmap; tsk-mm=mm; 2、动态分配内存 do_mmap2(addr,len,prot,flags,fd,pgoff); addr=get_unmapped_area(file,addr,len, pgoff,flags);
代码第6页 vma=kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL); vma-vm_mm=mm; vma-vm_start=addr; vma-vm_end=addr+len; vma-vm_flags=vm_flags;
代码第7页 3、缺页中断 do_page_fault- vma=find_vma(mm,address); handle_mm_fault(mm,vma,address,write)- …//寻找页表项位置 handle_pte_fault 4、回收 如果是page回收则只回收分配的page,如果是虚拟 地址回收则还需要解除vm_area_struct的映射并且 收回vm_area_struct本身。
感谢您对华章培训网的支持!.
原创力文档

文档评论(0)