{"id":208518,"date":"2021-02-13T09:26:51","date_gmt":"2021-02-13T01:26:51","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=208518"},"modified":"2021-01-29T10:39:35","modified_gmt":"2021-01-29T02:39:35","slug":"arm64-linux-doc","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/arm64-linux-doc.html","title":{"rendered":"\u4e00\u6587\u770b\u660e\u767d ARM64 Linux \u5185\u6838\u9875\u8868\u7684\u5757\u6620\u5c04"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5185\u6838\u6587\u6863Documentation\/arm64\/memory.rst\u63cf\u8ff0\u4e86ARM64 Linux\u5185\u6838\u7a7a\u95f4\u7684\u5185\u5b58\u6620\u5c04\u60c5\u51b5\uff0c\u5e94\u8be5\u662f\u6b64\u65b9\u9762\u6700\u6743\u5a01\u6587\u6863\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5185\u6838\u6587\u6863Documentation\/arm64\/memory.rst\u63cf\u8ff0\u4e86ARM64 Linux\u5185\u6838\u7a7a\u95f4\u7684\u5185\u5b58\u6620\u5c04\u60c5\u51b5\uff0c\u5e94\u8be5\u662f\u6b64\u65b9\u9762\u6700\u6743\u5a01\u6587\u6863\u3002<\/p>\n

\u4ee5\u5178\u578b\u76844K\u9875\u548c48\u4f4d\u865a\u62df\u5730\u5740\u4e3a\u4f8b\uff0c\u6574\u4e2a\u5185\u6838\u7a7a\u95f4\u7684\u865a\u62df\u5730\u5740\u5206\u5e03\u5982\u4e0b\uff1a<\/p>\n

\"\"<\/p>\n

\u4eceffff000000000000\u5230ffff7fffffffffff\u662f\u4e00\u6bb5\u9488\u5bf9\u7269\u7406\u5730\u5740\u7684\u7ebf\u6027\u6620\u5c04\u533a\uff0c\u6700\u5927\u652f\u6301128TB\u7684\u7269\u7406\u5730\u5740\u7a7a\u95f4\uff0c\u8fd9\u4e00\u6bb5\u5730\u5740\u975e\u5e38\u7c7b\u4f3cARM32\u7684low memory\u6620\u5c04\u533a\u3002<\/p>\n

\u6211\u4eec\u770b\u770b\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7684\u9875\u8868\uff0c\u6211\u4eec\u65e2\u53ef\u4ee5\u7528\u6700\u7ec8\u7684\u301020:12\u3011\u5bf9\u5e94\u7684PTE\u6620\u5c04\u9879\uff0c\u4ee54K\u4e3a\u5355\u4f4d\uff0c\u8fdb\u884c\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u6620\u5c04;\u53c8\u53ef\u4ee5\u4ee5\u301029:21\u3011\u5bf9\u5e94\u7684PMD\u6620\u5c04\u9879\uff0c\u4ee52M\u4e3a\u5355\u4f4d\uff0c\u8fdb\u884c\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u6620\u5c04\u3002<\/p>\n

\"\"<\/p>\n

\u5bf9\u4e8e\u7528\u6237\u7a7a\u95f4\u7684\u865a\u62df\u5730\u5740\u800c\u8a00\uff0c\u5f53\u6211\u4eec\u8fdb\u884c\u7684\u662fPMD\u6620\u5c04\u7684\u65f6\u5019\uff0c\u6211\u4eec\u5f97\u5230\u7684\u662fHuge Page\uff0cARM64\u76842MB\u7684huge page\uff0c\u5728\u865a\u62df\u548c\u7269\u7406\u4e0a\u90fd\u8fde\u7eed\uff0c\u5b83\u5728\u5b9e\u8df5\u5de5\u7a0b\u4e2d\u7684\u597d\u5904\u662f\uff0c\u53ef\u4ee5\u51cf\u5c0fTLB miss\uff0c\u56e0\u4e3a\uff0c\u5982\u679c\u8fdb\u884c\u4e862MB\u7684\u6620\u5c04\uff0c\u6574\u4e2a2MB\u4e0d\u518d\u9700\u8981PTE\uff0c\u6620\u5c04\u5173\u7cfb\u5927\u4e3a\u51cf\u5c0f\u3002<\/p>\n

\"\"<\/p>\n

\u5bf9\u4e8e\u5185\u6838\u7a7a\u95f4\u800c\u8a00\uff0c\u4eceffff000000000000\u5230ffff7fffffffffff\u7684\u8fd9\u6bb5\u865a\u62df\u5730\u5740\uff0c\u5982\u679c\u4e0e\u7269\u7406\u5730\u5740\u8fdb\u884c\u7684\u662f\u4e00\u79cdPMD\u6620\u5c04\u7684\u8bdd\uff0c\u663e\u7136\u4e5f\u53ef\u4ee5\u8fbe\u5230\u540c\u6837\u7684\u6548\u679c\u3002\u4f46\u662f\uff0c\u8fd9\u4e0d\u610f\u5473\u7740\u5b83\u4eec\u5c31\u662fHuge Page\u3002\u4f17\u6240\u5468\u77e5\uff0c\u5185\u6838\u5f00\u673a\u628a\u7269\u7406\u5730\u5740\u5f80\u865a\u62df\u5730\u5740\u8fdb\u884c\u7ebf\u6027\u6620\u5c04\uff0c\u5e76\u4e0d\u610f\u5473\u7740\u8fd9\u7247\u5185\u5b58\u88ab\u5185\u6838\u62ff\u8d70\u4e86\uff0c\u5b83\u53ea\u662f\u8fdb\u884c\u4e86\u4e00\u79cd\u6620\u5c04\uff0c\u4ee5\u4fbf\u65e5\u540e\u8c03\u7528kmalloc()\uff0cget_free_pages()\u7b49API\u7533\u8bf7\u7684\u5185\u5b58\u662f\u76f4\u63a5\u5df2\u7ecf\u6709\u865a\u5b9e\u6620\u5c04\u7684\u3002\u6240\u4ee5\uff0c\u5373\u4fbf\u5185\u6838\u8fdb\u884c\u7684\u5c31\u662fPMD\u6620\u5c04\uff0c\u5728\u5185\u5b58\u7684\u5206\u5272\u4e0a\uff0c\u8fd8\u662f\u53ef\u4ee5\u4ee54K\u4e3a\u5355\u4f4d\u7684\uff1a<\/p>\n

\"\"<\/p>\n

\u6240\u4ee5\uff0c\u5373\u4fbf\u6211\u4eec\u5728\u5185\u6838\u7a7a\u95f4\u8fdb\u884cPMD\u6620\u5c04\uff0c\u91cc\u9762\u7684\u6bcf\u4e2a\u84dd\u8272\u5706\u5708(\u4e00\u4e2a4K\u9875)\uff0c\u8fd8\u662f\u53ef\u4ee5\u88ab\u5355\u72ec\u5206\u914d\u7684\uff0c\u8fd9\u79cd\u5206\u914d\u53ef\u4ee5\u662fkmalloc\u3001vmalloc\uff0c\u7528\u6237\u6001\u7684malloc\u7b49\u3002\u5185\u6838\u6001\u8fdb\u884c\u7684PMD\u6620\u5c04\uff0c\u4e0d\u610f\u5473\u7740\u76f8\u5173\u76842MB\u6210\u4e3a\u4e86huge page\uff0c\u5b83\u7eaf\u7cb9\u53ea\u662f\u4e3a\u4e86\u670d\u52a1\u4e8e\u5f53\u5185\u6838\u4ee5\u7ebf\u6027\u6620\u5c04\u7684\u865a\u62df\u5730\u5740\u8bbf\u95ee\u8be5\u7269\u7406\u5730\u5740\u7684\u65f6\u5019(\u6211\u4eec\u8ba4\u4e3a\u5185\u6838\u5927\u591a\u6570\u65f6\u5019\u662f\u7528\u8fd9\u4e2a\u7ebf\u6027\u6620\u5c04\u7684\u865a\u62df\u5730\u5740\u7684)\uff0c\u51cf\u5c0fTLB miss\u3002<\/p>\n

\u5f53\u7136\uff0c\u66f4\u725b\u903c\u7684\u60c5\u51b5\u4e0b\uff0c\u5185\u6838\u5e94\u8be5\u4e5f\u53ef\u4ee5\u76f4\u63a5\u7528\u301038:30\u3011\u4f4d\u7684PUD\u6765\u8fdb\u884c\u6620\u5c04\uff0c\u8fd9\u6837\u6620\u5c04\u5173\u7cfb\u662f1GB\u7684\uff0c\u5219\u6574\u4e2a1GB\u540e\u9762\u5360TLB\u7684\u65f6\u5019\uff0c\u53ea\u9700\u8981\u5360\u4e00\u4e2a\u5165\u53e3\u3002<\/p>\n

\"\"<\/p>\n

\u5f53\u7136\uff0c\u5982\u679c\u7528\u6237\u6001\u7684\u865a\u5b9e\u6620\u5c04\u662f\u8fd9\u6837\u7684\uff0c\u7528\u6237\u5b9e\u9645\u5f97\u5230\u4e86\u4e00\u4e2a1GB\u7684\u5de8\u9875\u3002\u4f46\u662f\u5bf9\u4e8e\u5185\u6838\u7684\u7ebf\u6027\u6620\u5c04\u533a\u57df\u800c\u8a00\uff0c\u5373\u4fbf\u6211\u4eec\u8fdb\u884c\u4e861GB\u7684PUD\u6620\u5c04\uff0c\u8fd91G\u5185\u90e8\u5c31\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5207\u5272\u4e3a4KB\u9875\u6216\u80052MB\u7684\u5de8\u9875\u3002\u8bb0\u4f4f\uff1a\u5185\u6838\u6001\u7684\u7ebf\u6027\u6620\u5c04\u533a\u7684\u6620\u5c04\u53ea\u662f\u4e2a\u6620\u5c04\u5173\u7cfb\uff0c\u4e0d\u662f\u4e2a\u5206\u914d\u5173\u7cfb\u3002\u6bd4\u5982\u4e0b\u9762\u76841GB\u7684\u5185\u6838\u7ebf\u6027\u6620\u5c04\u76841GB\u533a\u57df\uff0c\u4ecd\u7136\u53ef\u4ee5\u88ab4K\u5206\u914d\u8d70\uff0c\u6216\u8005\u88ab\u7528\u6237\u4ee5huge page\u4ee52MB\u4e3a\u5355\u4f4d\u5206\u914d\u8d70\uff1a<\/p>\n

\"\"<\/p>\n

\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u771f\u5b9e\u7684\u8c03\u8bd5\u624b\u6bb5\u6765\u9a8c\u8bc1\u6211\u4eec\u7684\u60f3\u6cd5\uff0c\u8fd9\u4e2a\u8c03\u8bd5\u624b\u6bb5\u5c31\u662fPTDUMP(Page Table Dump)\uff0c\u76f8\u5173\u7684\u4ee3\u7801\u5728ARM64\u5185\u6838\u7684\uff1a<\/p>\n

\r\narch\/arm64\/mm\/ptdump.c\u548cptdump_debugfs.c\r\n<\/pre>\n

\u6211\u4eec\u628a\u5b83\u4eec\u5168\u90e8\u9009\u4e2d\uff0c\u8fd9\u6837\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2adebugfs\u63a5\u53e3\uff1a<\/p>\n

\r\n\/sys\/kernel\/debug\/kernel_page_tables\r\n<\/pre>\n

\u6765\u83b7\u77e5\u5185\u6838\u6001\u9875\u8868\u7684\u60c5\u51b5\u3002<\/p>\n

\u6211\u7528qemu\u542f\u52a8\u4e86\u4e00\u4e2a4GB\u5185\u5b58\u7684ARM64\u865a\u62df\u673a\uff0c\u53ef\u4ee5\u770b\u5230\u524d1GB\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4\u5927\u591a\u6570\u662fPMD\u548cPTE\u6620\u5c04\uff0c\u540e\u9762\u76843GB\uff0c\u5168\u662fPUD\u6620\u5c04\uff1a<\/p>\n

\"\"<\/p>\n

\u6211\u7684\u5185\u6838\u542f\u52a8\u53c2\u6570\u52a0\u4e86rodata=0\uff1a<\/p>\n

\r\n$ cat \/proc\/cmdline root=\/dev\/vda2 rw console=ttyAMA0 ip=dhcp rodata=0\r\n<\/pre>\n

\u539f\u56e0\u662f\u5185\u6838\u5728\u51e0\u79cd\u60c5\u51b5\u4e0b\uff0c\u662f\u4e0d\u4f1a\u505a\u8fd9\u79cdPMD\u548cPUD\u6620\u5c04\u7684\uff0c\u76f8\u5173\u4ee3\u7801\u89c1\u4e8e\uff1a<\/p>\n

\"\"<\/p>\n

\"\"<\/p>\n

rodata_full\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u603b\u662f\u6210\u7acb\u7684\uff0c\u5b83\u5bf9\u5e94\u7740\u5185\u6838\u7684\u4e00\u4e2aConfig\u9009\u9879CONFIG_RODATA_FULL_DEFAULT_ENABLED\uff0c \"Apply r\/o permissions of VM areas also to their linear aliases\"\uff0c\u8fd9\u4e2a\u9009\u9879\u63d0\u9ad8\u4e86\u5185\u6838\u7684\u5b89\u5168\u6027\uff0c\u4f46\u662f\u51cf\u5c0f\u4e86\u5185\u6838\u7684\u6027\u80fd\u3002<\/p>\n

\"\"<\/p>\n

\u6211\u5728\u5185\u6838\u542f\u52a8\u53c2\u6570\u52a0\u7684rodata=0\u5b9e\u9645\u4e0a\u662f\u8ba9rodata_full\u4e3afalse\u3002\u5982\u679c\u6211\u628a\u8fd9\u4e2akernel\u542f\u52a8\u9009\u9879\u53bb\u6389\uff0c\u6211\u5f97\u5230\u7684\u5185\u6838\u9875\u8868\u662f\u5b8c\u5168\u4e0d\u4e00\u6837,\u7ebf\u6027\u6620\u5c04\u533a\u4e5f\u5168\u90e8\u662fPTE\u6620\u5c04\uff1a<\/p>\n

\"\"<\/p>\n

\u6700\u540e\uff0c\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u4e0d\u4ec5\u7ebf\u6027\u6620\u5c04\u533a\u53ef\u4ee5\u4f7f\u7528PMD\u6620\u5c04\uff0cvmemmap\u6620\u5c04\u533a\u4e5f\u662f\u57284K\u9875\u9762\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u7528PMD\u6620\u5c04\u7684\uff1a<\/p>\n

\"\"<\/p>\n

\u5b57\u8282\u8df3\u52a8\u7684\u5b8b\u7267\u6625\u7ae5\u978b\u53d1\u4e86\u4e00\u4e2apatchset\uff0c\u4f01\u56fe\u5728\u7528\u6237\u5206\u5f97\u5de8\u9875\u7684\u60c5\u51b5\u4e0b\uff0c\u5220\u9664\u5de8\u9875\u5185\u90e8\u76844KB\u7684\u5c0fpage\u5360\u7528\u7684page struct\u7684\u5185\u5b58\u6d88\u8017\uff0c\u8fd9\u4e2apatchset\u5728\u5723\u8bde\u8282\u524d\u76ee\u524d\u53d1\u5230\u4e86V11\uff1a<\/p>\n

https:\/\/lore.kernel.org\/linux-mm\/20201222142440.28930-1-songmuchun@bytedance.com\/<\/p>\n

\"\"<\/p>\n

\u5728\u8fd9\u4e2apatchset\u4e2d\uff0c\u5b83\u5c31\u9700\u8981\u62c6\u5206vmemmap\u7684PMD\u6620\u5c04\u4e3aPTE\u6620\u5c04:<\/p>\n

\"\"<\/p>\n

\u8fd9\u4e2apatchset\u7684\u539f\u7406\u5efa\u7acb\u5728\uff0c\u5f53\u5185\u6838\u4ee54KB\u5206\u9875\u7684\u65f6\u5019\uff0c\u6bcf\u4e2apage\u9700\u898164\u5b57\u8282\u7684page struct\u3002\u4f46\u662f\uff0c\u5f53\u7528\u6237\u628a\u5b83\u5206\u914d\u4e3a\u5de8\u9875\u7684\u65f6\u5019\uff0c\u65f6\u5019\uff0c\u6211\u4eec\u4e0d\u518d\u9700\u8981\u4e00\u4e2a\u4e2a4KB\u5355\u72ec\u7528page struct\u63cf\u8ff0\uff0c\u5bf9\u4e8e\u8fd9\u79cdcompound page\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u5e94\u8be5\u53ef\u4ee5\u628a\u540e\u9762\u7684page struct\u7684\u5185\u5b58\u76f4\u63a5\u91ca\u653e\u6389\uff0c\u56e0\u4e3a\u60c5\u51b5\u5b8c\u5168\u662f\u96f7\u540c\u7684\uff0c\u8fd9\u6837\u53ef\u4ee5\u5269\u4e0b\u4e0d\u5c11\u5185\u5b58\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5185\u6838\u6587\u6863Documentation\/arm64\/memory.rst\u63cf\u8ff0\u4e86ARM64 Linux\u5185\u6838\u7a7a\u95f4\u7684\u5185\u5b58 […]<\/p>\n","protected":false},"author":1898,"featured_media":208535,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[632],"class_list":["post-208518","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-arm64-linux"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/208518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=208518"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/208518\/revisions"}],"predecessor-version":[{"id":210740,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/208518\/revisions\/210740"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/208535"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=208518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=208518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=208518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}