资源描述:
《Linux内存管理》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、MemoryManagementinLinuxAnandSivasubramaniamTwoPartsArchitectureIndependentMemoryShouldbeflexibleandportableenoughacrossplatformsImplementationforaspecificarchitectureArchitectureIndependentMemoryModelProcessvirtualaddressspacedividedintopagesPagesizegiveninPAGE_SIZEmacroinasm/page.h(4Kforx86and8Kf
2、orAlpha)Thepagesaredividedbetween4segmentsUserCode,UserData,KernelCode,KernelDataInUsermode,accessonlyUserCodeandUserDataButinKernelmode,accessalsoneededforUserDataput_user(),get_user(),memcpy_tofs(),memcpy_fromfs()allowkerneltoaccessuserdata(definedinasm/segment.h)Registerscsanddspointtothecodean
3、ddatasegmentsofthecurrentmodefspointstothedatasegmentofthecallingprocessinkernelmode.Get_ds(),get_fs(),andset_fs()aredefinedinasm/segment.hSegment+Offset=4GBLinearaddress(32bits)Ofthis,userspace=3GB(definedbyTASK_SIZEmacro)andkernelspace=1GBLinearAddressconvertedtophysicaladdressusing3levelsIndexi
4、ntoPageDir.IndexintoPageMiddleDir.IndexintoPageTablePageOffsetPageDir.AndMiddleDir.AccessFunctions(inasm/page.handasm/pgtable.h)Structurespgd_tandpmd_tdefineanentryofthesetables.pgd_alloc_alloc()/pgd_free()toallocateandfreeapageforthepagedirectorypmd_alloc(),pmd_alloc_kernel()/pmd_free(),pmd_free
5、_kernel()allocateandfreeapagemiddledirectoryinuserandkernelsegments.pgd_set(),pgd_clear()/pmd_set(),pmd_clear()setandclearaentryoftheirtables.pgd_present()/pmd_present()checksforpresenceofwhattheentriesarepointingto.pgd_page()/pmd_page()returnsthebaseaddressofthepagetowhichtheentryispointing…..Pag
6、eTableEntry(pte_t)AttributesPresence(ispagepresentinVAS?)Read,WriteandExecuteAccessed?(age)DirtyMacrosofPgprot_typePAGE_NONE(invalid)PAGE_SHARED(read-write)PAGE_COPY/READ_ONLY(readonly,usedbycopy-on-write)PAGE_KERNEL(accessibeonlybykernel)PageTableFunctionsmk_pte(),Pte_clear(),set_pte()pte_mkclean
7、(),pte_mkdirty(),pt_mkread(),….pte_none()(checkwhetherentryisset)pte_page()(returnsaddressofpage)pte_dirty(),pte_present(),pte_young(),pte_read(),pte_write()ProcessAddressSpace(nottoscale!)Kernel0xC0000000Filenam