{"id":3763,"date":"2012-03-06T20:11:40","date_gmt":"2012-03-06T12:11:40","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=3763"},"modified":"2012-03-06T20:45:52","modified_gmt":"2012-03-06T12:45:52","slug":"%e4%bc%99%e4%bc%b4%e7%ae%97%e6%b3%95%e7%9a%84%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/3763","title":{"rendered":"\u4f19\u4f34\u7b97\u6cd5\u7684\u6570\u636e\u7ed3\u6784"},"content":{"rendered":"<p>\u4f19\u4f34\u7b97\u6cd5\uff08buddy system\uff09\u5728\u7269\u7406\u5185\u5b58\u7ba1\u7406\u4e2d\u5360\u636e\u5341\u5206\u91cd\u8981\u7684\u4f4d\u7f6e\uff0c\u8fd9\u79cd\u7b97\u6cd5\u53ef\u4ee5\u6709\u6548\u7684\u907f\u514d\u5185\u5b58\u4e2d\u7684\u5916\u90e8\u788e\u7247\u3002\u6240\u8c13\u5916\u90e8\u788e\u7247\uff08external fragmentation\uff09\uff0c\u5c31\u662f\u6307\u5185\u5b58\u9891\u7e41\u8bf7\u6c42\u548c\u91ca\u653e\u5927\u5c0f\u4e0d\u540c\u7684\u8fde\u7eed\u9875\u6846\u540e\uff0c\u5bfc\u81f4\u5728\u5df2\u5206\u914d\u9875\u6846\u5757\u5468\u56f4\u5206\u6563\u4e86\u8bb8\u591a\u5c0f\u5757\u7a7a\u95f2\u7684\u9875\u6846\uff0c\u5c3d\u7ba1\u8fd9\u4e9b\u7a7a\u95f2\u9875\u6846\u7684\u603b\u6570\u53ef\u4ee5\u6ee1\u8db3\u63a5\u4e0b\u6765\u7684\u8bf7\u6c42\uff0c\u4f46\u5374\u65e0\u6cd5\u6ee1\u8db3\u4e00\u4e2a\u5927\u5757\u7684\u8fde\u7eed\u9875\u6846\u3002\u672c\u6587\u63a5\u4e0b\u6765\u8be6\u7ec6\u8bf4\u660e\u4f19\u4f34\u7b97\u6cd5\u5728\u5185\u6838\u4e2d\u7684\u7ed3\u6784\u63cf\u8ff0\uff0c\u5176\u57fa\u672c\u539f\u7406\u672c\u6587\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<p>\u5728\u6bcf\u4e2a\u5185\u5b58\u7ba1\u7406\u533a\u4e2d\u90fd\u6709\u4e00\u4e2afree_area\u6570\u7ec4\uff0c\u8be5\u6570\u7ec4\u7684\u957f\u5ea6\u4e3aMAX_ORDER\uff0c\u9ed8\u8ba4\u503c\u4e3a11\u3002free_area\u6570\u7ec4\u63cf\u8ff0\u7684\u5c31\u662f\u4f19\u4f34\u7b97\u6cd5\u4e2d\u6bcf\u4e2a\u5206\u914d\u9636\uff08\u4ece0\u523011\uff09\u6240\u5bf9\u5e94\u7684\u9875\u6846\u5757\u94fe\u8868\u3002\u6bd4\u5982free_area[2]\u6240\u5bf9\u5e94\u7684\u9875\u6846\u5757\u94fe\u8868\u4e2d\uff0c\u6bcf\u4e2a\u8282\u70b9\u5bf9\u5e944\u4e2a\u8fde\u7eed\u7684\u9875\u6846\uff082\u76842\u6b21\u65b9\uff09\u3002<\/p>\n<pre class=\"brush:c\">struct zone {\r\n\u2026\u2026\r\nstruct free_area        free_area[MAX_ORDER];\r\n\u2026\u2026\r\n}\r\n\r\n#ifndef CONFIG_FORCE_MAX_ZONEORDER\r\n#define MAX_ORDER 11\r\n#else\r\n#define MAX_ORDER CONFIG_FORCE_MAX_ZONEORDER\r\n#endif<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0cfree_area\u6570\u7ec4\u7684\u5143\u7d20\u7c7b\u578b\u662fstruct free_area\uff0c\u8be5\u7ed3\u6784\u7684\u63cf\u8ff0\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:c\">struct free_area {\r\n        struct list_head        free_list[MIGRATE_TYPES];\r\n        unsigned long           nr_free;\r\n};<\/pre>\n<p>\u5728\u8fd9\u4e2a\u7ed3\u6784\u4e2d\u7684\u786e\u6709\u4e00\u4e2a\u8868\u793a\u5f53\u524d\u5206\u914d\u9636\u6240\u5bf9\u5e94\u7684\u9875\u6846\u5757\u94fe\u8868free_list\uff0c\u4e0d\u8fc7\u8fd9\u91cc\u7a0d\u663e\u590d\u6742\u4e00\u4e0b\uff0c\u56e0free_list\u662f\u4e00\u4e2a\u94fe\u8868\u6570\u7ec4\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e5f\u79f0\u4e3a\u8fc1\u79fb\u6570\u7ec4\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e2a\u6570\u7ec4\u770b\u4f5c\u662f\u5bf9\u9875\u6846\u5757\u94fe\u8868\u7684\u8fdb\u4e00\u6b65\u7ec6\u5206\uff0c\u6bcf\u4e2a\u6570\u7ec4\u5143\u7d20\u5bf9\u5e94\u4e00\u79cd\u8fc1\u79fb\u7c7b\u578b\u7684\u9875\u6846\u5757\u94fe\u8868\u3002\u8fc1\u79fb\u5217\u8868\u662f\u5728\u5185\u68382.6.24\u4e2d\u5f15\u5165\u7684\uff0c\u5b83\u66f4\u52a0\u7684\u907f\u514d\u4e86\u7531\u4e8e\u7cfb\u7edf\u957f\u671f\u8fd0\u884c\u800c\u4ea7\u751f\u7684\u5916\u90e8\u788e\u7247\u3002\u9664\u4e86\u94fe\u8868\u7ed3\u6784\u4ee5\u5916\uff0c\u8be5\u7ed3\u6784\u4f7f\u7528nr_free\u8868\u793a\u5f53\u524d\u94fe\u8868\u4e2d\u7a7a\u95f2\u9875\u6846\u5757\u7684\u6570\u76ee\uff0c\u6bd4\u5982free_area[2]\u4e2dnr_free\u7684\u503c\u4e3a5\uff0c\u8868\u793a\u67095\u4e2a\u5927\u5c0f\u4e3a4\u7684\u9875\u6846\u5757\uff0c\u90a3\u4e48\u603b\u7684\u9875\u6846\u6570\u76ee\u4e3a20\u3002<\/p>\n<p>\u6839\u636e\u4e0a\u9762\u5bf9\u4f19\u4f34\u7b97\u6cd5\u6570\u636e\u7ed3\u6784\u7684\u63cf\u8ff0\uff0c\u53ef\u4ee5\u5f97\u5230\u4e0b\u9762\u7684\u5173\u7cfb\u56fe\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/edsionte.com\/techblog\/archives\/3763\/buddy\" rel=\"attachment wp-att-3768\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-3768\" title=\"buddy\" src=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2012\/03\/buddy.jpeg\" alt=\"\" width=\"344\" height=\"169\" srcset=\"http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2012\/03\/buddy.jpeg 614w, http:\/\/edsionte.com\/techblog\/wordpress\/wp-content\/uploads\/2012\/03\/buddy-300x148.jpg 300w\" sizes=\"auto, (max-width: 344px) 100vw, 344px\" \/><\/a><\/p>\n<p>\u4e0a\u56fe\u8868\u793a\u7684\u662f\u67d0\u4e2a\u5185\u5b58\u8282\u70b9\u4e2d\u7684\u67d0\u4e2a\u5185\u5b58\u7ba1\u7406\u533a\u4e2d\u7684\u4f19\u4f34\u7b97\u6cd5\u793a\u610f\u56fe\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u9875\u6846\u63cf\u8ff0\u7b26page\u4e2d\u6709\u4e00\u4e2alru\u5b57\u6bb5\uff0c\u8be5\u5b57\u6bb5\u5373\u4e3a\u94fe\u63a5\u6bcf\u4e2a\u9875\u6846\u5757\u7684\u94fe\u8868\u8282\u70b9\u3002<\/p>\n<pre class=\"brush:c\">struct page {\r\n\u2026\u2026\r\n        struct list_head lru;\r\n\u2026\u2026\r\n};<\/pre>\n<p>\u4ece\u56fe\u4e2d\u4e5f\u53ef\u4ee5\u770b\u51fa\uff0c\u94fe\u8868\u4e2d\u8d1f\u8d23\u8fde\u63a5\u524d\u540e\u9875\u6846\u5757\u7684\u662f\u8be5\u9875\u6846\u5757\u9996\u9875\u6846\u4e2d\u7684\u94fe\u8868\u8282\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f19\u4f34\u7b97\u6cd5\uff08buddy system\uff09\u5728\u7269\u7406\u5185\u5b58\u7ba1\u7406\u4e2d\u5360\u636e\u5341\u5206\u91cd\u8981\u7684\u4f4d\u7f6e\uff0c\u8fd9\u79cd\u7b97\u6cd5\u53ef\u4ee5\u6709\u6548\u7684\u907f\u514d\u5185\u5b58\u4e2d\u7684\u5916\u90e8\u788e\u7247 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[266],"tags":[314,407,304,302],"class_list":["post-3763","post","type-post","status-publish","format-standard","hentry","category-266","tag-314","tag-407","tag-304","tag-302"],"views":11019,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=3763"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3763\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=3763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=3763"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=3763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}