{"id":81,"date":"2016-09-29T13:06:03","date_gmt":"2016-09-29T13:06:03","guid":{"rendered":"http:\/\/www.luo666.com\/?p=81"},"modified":"2019-01-19T04:45:20","modified_gmt":"2019-01-19T04:45:20","slug":"linux-%e5%86%85%e5%ad%98%e5%9b%9e%e6%94%b6%e6%9c%ba%e5%88%b6","status":"publish","type":"post","link":"http:\/\/www.luo666.com\/?p=81","title":{"rendered":"Linux \u5185\u5b58\u56de\u6536\u673a\u5236"},"content":{"rendered":"<div><\/div>\n<div>\u3010\u57fa\u672c\u7ed3\u6784\u3011<\/div>\n<div>5\u6761lru\u94fe\u8868\uff1a<\/div>\n<div>anonymous active<\/div>\n<div>anonymous inactive<\/div>\n<div>file active<\/div>\n<div>file inactive<\/div>\n<div>unevictable<\/div>\n<div><\/div>\n<div>\u6839\u636epage\u7684\u5c5e\u6027\uff08\u662f\u5426mlock\uff09\u5224\u65ad\u662f\u5426\u653e\u5230unevictable list\uff0c\u6839\u636epg_active\u548cpg_active\u6807\u5fd7\u5728active\u548cinactive\u4e4b\u95f4\u6d41\u52a8\u3002<\/div>\n<div>\n<hr \/>\n<p>\u3010\u5728active\u548cinactive\u4e4b\u95f4\u6d41\u52a8\u7684\u6838\u5fc3\u4e3a\uff1a\u3011<\/p><\/div>\n<div>&#8211; \u5982\u679c\u9875\u9762\u88ab\u8ba4\u4e3a\u662f\u6d3b\u8dc3\u7684\uff0c\u5219\u5c06\u8be5\u9875\u7684 PG_active \u7f6e\u4f4d\uff1b\u5426\u5219\uff0c\u4e0d\u7f6e\u4f4d\u3002<\/div>\n<div>&#8211; \u5f53\u9875\u9762\u88ab\u8bbf\u95ee\u65f6\uff0c\u68c0\u67e5\u8be5\u9875\u7684 PG_referenced \u4f4d\uff0c\u82e5\u672a\u88ab\u7f6e\u4f4d\uff0c\u5219\u7f6e\u4f4d\u4e4b\uff1b\u82e5\u53d1\u73b0\u8be5\u9875\u7684 PG_referenced \u5df2\u7ecf\u88ab\u7f6e\u4f4d\u4e86\uff0c\u5219\u610f\u5473\u7740\u8be5\u9875\u7ecf\u5e38\u88ab\u8bbf\u95ee\uff0c\u8fd9\u65f6\uff0c\u82e5\u8be5\u9875\u5728 inactive \u94fe\u8868\u4e0a\uff0c\u5219\u7f6e\u4f4d\u5176 PG_active \u4f4d\uff0c\u5c06\u5176\u79fb\u52a8\u5230 active \u94fe\u8868\u4e0a\u53bb\uff0c\u5e76\u6e05\u9664\u5176 PG_referenced \u4f4d\u7684\u8bbe\u7f6e\uff1b\u5982\u679c\u9875\u9762\u7684 PG_referenced \u4f4d\u88ab\u7f6e\u4f4d\u4e86\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u8be5\u9875\u9762\u6ca1\u6709\u88ab\u518d\u6b21\u8bbf\u95ee\uff0c\u90a3\u4e48 Linux \u64cd\u4f5c\u7cfb\u7edf\u4f1a\u6e05\u9664\u8be5\u9875\u9762\u7684 PG_referenced \u4f4d\uff0c\u56e0\u4e3a\u8fd9\u610f\u5473\u7740\u8fd9\u4e2a\u9875\u9762\u6700\u8fd1\u8fd9\u6bb5\u65f6\u95f4\u90fd\u6ca1\u6709\u88ab\u8bbf\u95ee\u3002<\/div>\n<div>&#8211; PG_referenced \u4f4d\u540c\u6837\u4e5f\u53ef\u4ee5\u7528\u4e8e\u9875\u9762\u4ece active \u94fe\u8868\u79fb\u52a8\u5230 inactive \u94fe\u8868\u3002\u5bf9\u4e8e\u67d0\u4e2a\u5728 active \u94fe\u8868\u4e0a\u7684\u9875\u9762\u6765\u8bf4\uff0c\u5176 PG_active \u4f4d\u88ab\u7f6e\u4f4d\uff0c\u5982\u679c PG_referenced \u4f4d\u672a\u88ab\u7f6e\u4f4d\uff0c\u7ed9\u5b9a\u4e00\u6bb5\u65f6\u95f4\u4e4b\u540e\uff0c\u8be5\u9875\u9762\u5982\u679c\u8fd8\u662f\u6ca1\u6709\u88ab\u8bbf\u95ee\uff0c\u90a3\u4e48\u8be5\u9875\u9762\u4f1a\u88ab\u6e05\u9664\u5176 PG_active \u4f4d\uff0c\u632a\u5230 inactive \u94fe\u8868\u4e0a\u53bb\u3002<\/div>\n<div>\n<hr \/>\n<p>\u3010\u601d\u8003\u3011<\/p><\/div>\n<div>\u4e2a\u4eba\u89c9\u5f97\uff0csecond chance\u56de\u6536\u7b97\u6cd5\u5728\u67d0\u79cd\u610f\u4e49\u4e0a\u4e5f\u53ef\u4ee5\u5b8c\u6210\u4e0a\u9762\u7684\u610f\u56fe\uff0c\u5373\u53d1\u73b0\u67d0\u4e2apage\u88abpg_referenced\u7f6e\u4f4d\u4e86\uff0c\u90a3\u4e48\u628a\u4ed6\u79fb\u5230\u94fe\u8868\u7684\u5c3e\u90e8\uff08\u6700\u65b0\u88ab\u8bbf\u95ee\uff09\uff0c\u8fd9\u6837\u5c31\u4e0d\u9700\u8981\u591a\u4e2alist\u4e86\u3002\u4f46\u662f\u8fd9\u6837\u5c31\u4e0d\u80fd\u7edf\u8ba1nr_active\u548cnr_inactive\u4e86\uff0c\u800cLinux\u7684\u56de\u6536\u7b97\u6cd5\u8fd8\u4f1a\u628a\u8fd9\u4e24\u4e2a\u94fe\u8868\u7684\u957f\u5ea6\u8003\u8651\u8fdb\u53bb\uff0c\u505a\u5230\u4e00\u5b9a\u7a0b\u5ea6\u7684\u5e73\u8861\uff0c\u6216\u8005\u8bf4\u4e3b\u52a8\u7684\u8fdb\u884c\u53cc\u5411\u7684\u6d41\u52a8\uff0c\u800c\u4e0a\u9762\u8bf4\u7684second chance\u4e00\u6761\u94fe\u7684\u7b97\u6cd5\u505a\u4e0d\u5230\u4e3b\u52a8\u53bb\u5e73\u8861\u3002\u6709\u4e86\u4e3b\u52a8\u5e73\u8861\uff0c\u5728\u56de\u6536\u7684\u65f6\u5019\u53ef\u4ee5\u53ea\u904d\u5386inactive\u94fe\u8868\uff0c\u51cf\u5c11\u4e86\u4e00\u6b21\u6027\u626b\u63cf\u592a\u591apage\u7684\u53ef\u80fd\u6027\uff0c\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u53ef\u4ee5\u7f13\u89e3\u7cfb\u7edf\u6027\u80fd\u6296\u52a8\u3002<\/div>\n<div><\/div>\n<div>\u5206\u4e86anonymous\u548cfile\u4e24\u79cd\u94fe\u7684\u76ee\u7684\uff0c\u6211\u76ee\u524d\u53ea\u8003\u8651\u5230\u53ef\u4ee5\u5728\u56de\u5199\u65f6\u533a\u522b\u8c03\u7528\u4e0d\u540c\u7684\u51fd\u6570\uff0c\u4e00\u4e2a\u5199\u5230swap\uff0c\u4e00\u4e2a\u8c03\u7528\u76f8\u5e94\u6587\u4ef6\u7cfb\u7edf\u7684\u56de\u5199\u51fd\u6570<\/div>\n<div><\/div>\n<div>freelist\u4fdd\u5b58\u4e86free\u7684\u7269\u7406\u9875\uff0ckswapd\u548calloc_slowpath\u4f1a\u7ed9\u4ed6\u6dfb\u7816\u52a0\u74e6\uff0c\u800c\u7a0b\u5e8f\u7684\u91ca\u653e\u7b49\u662f\u5176\u6536\u5165\u7684\u4e3b\u8981\u6765\u6e90\u3002kswapd\u5468\u671f\u6027\u7684\u5524\u9192\u6216\u8005\u88aballoc_slowpath\u5524\u9192\uff08\u5982\u679c\u5206\u914d\u5185\u5b58\u7684\u51fd\u6570\u6ca1\u80fd\u4ecefreelist\u4e0a\u627e\u5230\u6240\u9700\u7684order\u7684\u5185\u5b58\uff0c\u90a3\u4e48\u5c31\u8981\u60b2\u5267\u7684\u8fdb\u5165slowpath\u4e86\uff0c\u73b0\u8c61\u5c31\u662f\u7a0b\u5e8f\u5361\u987f\u4e86\uff0cqps\u4e0b\u964d\u4e86\u3002\u3002\u3002\uff09\uff0c\u5224\u65ad\u5f53\u524d\u5185\u5b58\uff08\u67d0\u4e2azone\uff0c\u5982\u679c\u6709numa\uff09\u662f\u5426balance\uff0c\u8fd9\u91cc\u7684balance\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u4e3a\uff082.6.32\u5185\u6838\uff09\u662f\u5426\u4f4e\u4e8elow water mark\uff08\u901a\u8fc7vm.min_free_kbytes\u7684\u8bbe\u5b9a\u503c\u8ba1\u7b97\u51fa\u6765\u7684\u4e00\u4e2a\u4e0b\u9650\u6c34\u4f4d\u503c\uff09\uff0c\u5982\u679c\u4f4e\u4e8e\u8fd9\u4e2a\u503c\uff0c\u90a3\u4e48kswapd\u4f1ashrink\u4e0a\u9762\u90a3\u4e9blist\uff0c\u7136\u540e\u91ca\u653e\u51fa\u6765\u7684page\uff0c\u6302\u5230freelist\u91cc\u9762\uff0c\u76f4\u5230\u5185\u5b58\u8fbe\u5230high water mark<\/div>\n<div>\n<hr \/>\n<p>\u3010shrink list\u7684\u987a\u5e8f\uff1f\u3011<\/p><\/div>\n<div>enum lru_list {<\/div>\n<div>\u00a0 \u00a0 LRU_INACTIVE_ANON = LRU_BASE,<\/div>\n<div>\u00a0 \u00a0 LRU_ACTIVE_ANON = LRU_BASE + LRU_ACTIVE,<\/div>\n<div>\u00a0 \u00a0 LRU_INACTIVE_FILE = LRU_BASE + LRU_FILE,<\/div>\n<div>\u00a0 \u00a0 LRU_ACTIVE_FILE = LRU_BASE + LRU_FILE + LRU_ACTIVE,<\/div>\n<div>\u00a0 \u00a0 LRU_UNEVICTABLE,<\/div>\n<div>\u00a0 \u00a0 NR_LRU_LISTS<\/div>\n<div>};<\/div>\n<div><\/div>\n<div>#define for_each_lru(lru) for (lru = 0; lru &lt; NR_LRU_LISTS; lru++)<\/div>\n<div><\/div>\n<div>#define for_each_evictable_lru(lru) for (lru = 0; lru &lt;= LRU_ACTIVE_FILE; lru++)<\/div>\n<div><\/div>\n<div>\u4f46\u662f\u771f\u6b63\u56de\u6536\u7684\u65f6\u5019\uff0c\u8fd8\u662f\u8981\u7ed9active\u51e0\u5206\u9762\u5b50\u7684\uff1a<\/div>\n<div>static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan,<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0struct lruvec *lruvec, struct scan_control *sc)<\/div>\n<div>{<\/div>\n<div>\u00a0 \u00a0 if (is_active_lru(lru)) {<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 if (inactive_list_is_low(lruvec, lru))<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 shrink_active_list(nr_to_scan, lruvec, sc, lru);<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 return 0;<\/div>\n<div>\u00a0 \u00a0 }<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 return shrink_inactive_list(nr_to_scan, lruvec, sc, lru);<\/div>\n<div>}<\/div>\n<div>\n<hr \/>\n<p>\u3010\u4ec0\u4e48\u6837\u7684page\u53ef\u4ee5\u88ab\u56de\u6536 \u3011<\/p><\/div>\n<div>\u8981\u770b\u5177\u4f53\u7684\u914d\u7f6e\uff0c\u5177\u4f53\u5e72\u6d3b\u7684\u51fd\u6570\u5728\u8fd9\u91cc\uff1a__isolate_lru_page<\/div>\n<div>\u57fa\u672c\u4e0a\u90fd\u53ef\u4ee5\u9664\u4e86unevictable\u4e0d\u53ef\u4ee5<\/div>\n<div>\u5982\u679c\u662f\u810f\u9875\uff1a<\/div>\n<div>Only pages without mappings or that have a<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0* -&gt;migratepage callback are possible to migrate<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0* without blocking<\/div>\n<div>migratepage\u662f\u4ec0\u4e48\u9b3c\uff1a\u5728move_to_new_page\u51fd\u6570\u4e2d\u627e\u5230\u4e0b\u9762\u4e00\u6bb5\u6ce8\u91ca<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \/*<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* Most pages have a mapping and most filesystems provide a<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* migratepage callback. Anonymous pages are part of swap<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* space which also has its own migratepage callback. This<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0* is the most common path for page migration.<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0*\/<\/div>\n<div>\n<hr \/>\n<p>\u3010\u53c2\u8003\u6587\u732e\u3011<\/p><\/div>\n<div><a href=\"http:\/\/blog.csdn.net\/wh8_2011\/article\/details\/52275231\">http:\/\/blog.csdn.net\/wh8_2011\/article\/details\/52275231<\/a><\/div>\n<div><a href=\"http:\/\/blog.tek-life.com\/%E8%AE%A4%E8%AF%86linux%E7%89%A9%E7%90%86%E5%86%85%E5%AD%98%E5%9B%9E%E6%94%B6%E6%9C%BA%E5%88%B6\/\">http:\/\/blog.tek-life.com\/%E8%AE%A4%E8%AF%86linux%E7%89%A9%E7%90%86%E5%86%85%E5%AD%98%E5%9B%9E%E6%94%B6%E6%9C%BA%E5%88%B6\/<\/a><\/div>\n<div><a href=\"http:\/\/www.ibm.com\/developerworks\/cn\/linux\/l-cn-pagerecycle\/\">http:\/\/www.ibm.com\/developerworks\/cn\/linux\/l-cn-pagerecycle\/<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u3010\u57fa\u672c\u7ed3\u6784\u3011 5\u6761lru\u94fe\u8868\uff1a anonymous active anonymous inactive file active file inactive unevictable \u6839\u636epage\u7684\u5c5e\u6027\uff08\u662f\u5426mlock\uff09\u5224\u65ad\u662f\u5426\u653e\u5230unevictable list\uff0c\u6839\u636epg_active\u548cpg_active\u6807\u5fd7\u5728active\u548cinactive\u4e4b\u95f4\u6d41\u52a8\u3002 \u3010\u5728active\u548cinactive\u4e4b\u95f4\u6d41\u52a8\u7684\u6838\u5fc3\u4e3a\uff1a\u3011 &#8211; \u5982\u679c\u9875\u9762\u88ab\u8ba4\u4e3a\u662f\u6d3b\u8dc3\u7684\uff0c\u5219\u5c06\u8be5\u9875\u7684 PG_active \u7f6e\u4f4d\uff1b\u5426\u5219\uff0c\u4e0d\u7f6e\u4f4d\u3002 &#8211; \u5f53\u9875\u9762\u88ab\u8bbf\u95ee\u65f6\uff0c\u68c0\u67e5\u8be5\u9875\u7684 PG_referenced \u4f4d\uff0c\u82e5\u672a\u88ab\u7f6e\u4f4d\uff0c\u5219\u7f6e\u4f4d\u4e4b\uff1b\u82e5\u53d1\u73b0\u8be5\u9875\u7684 PG_referenced \u5df2\u7ecf\u88ab\u7f6e\u4f4d\u4e86\uff0c\u5219\u610f\u5473\u7740\u8be5\u9875\u7ecf\u5e38\u88ab\u8bbf\u95ee\uff0c\u8fd9\u65f6\uff0c\u82e5\u8be5\u9875\u5728 inactive \u94fe\u8868\u4e0a\uff0c\u5219\u7f6e\u4f4d\u5176 PG_active \u4f4d\uff0c\u5c06\u5176\u79fb\u52a8\u5230 active \u94fe\u8868\u4e0a\u53bb\uff0c\u5e76\u6e05\u9664\u5176 PG_referenced \u4f4d\u7684\u8bbe\u7f6e\uff1b\u5982\u679c\u9875\u9762\u7684 PG_referenced \u4f4d\u88ab\u7f6e\u4f4d\u4e86\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u8be5\u9875\u9762\u6ca1\u6709\u88ab\u518d\u6b21\u8bbf\u95ee\uff0c\u90a3\u4e48 Linux \u64cd\u4f5c\u7cfb\u7edf\u4f1a\u6e05\u9664\u8be5\u9875\u9762\u7684 PG_referenced \u4f4d\uff0c\u56e0\u4e3a\u8fd9\u610f\u5473\u7740\u8fd9\u4e2a\u9875\u9762\u6700\u8fd1\u8fd9\u6bb5\u65f6\u95f4\u90fd\u6ca1\u6709\u88ab\u8bbf\u95ee\u3002 &#8211; PG_referenced \u4f4d\u540c\u6837\u4e5f\u53ef\u4ee5\u7528\u4e8e\u9875\u9762\u4ece active \u94fe\u8868\u79fb\u52a8\u5230 inactive \u94fe\u8868\u3002\u5bf9\u4e8e\u67d0\u4e2a\u5728 active \u94fe\u8868\u4e0a\u7684\u9875\u9762\u6765\u8bf4\uff0c\u5176 PG_active \u4f4d\u88ab\u7f6e\u4f4d\uff0c\u5982\u679c PG_referenced \u4f4d\u672a\u88ab\u7f6e\u4f4d\uff0c\u7ed9\u5b9a\u4e00\u6bb5\u65f6\u95f4\u4e4b\u540e\uff0c\u8be5\u9875\u9762\u5982\u679c\u8fd8\u662f\u6ca1\u6709\u88ab\u8bbf\u95ee\uff0c\u90a3\u4e48\u8be5\u9875\u9762\u4f1a\u88ab\u6e05\u9664\u5176 PG_active \u4f4d\uff0c\u632a\u5230 inactive \u94fe\u8868\u4e0a\u53bb\u3002 &hellip; <a href=\"http:\/\/www.luo666.com\/?p=81\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Linux \u5185\u5b58\u56de\u6536\u673a\u5236&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false,"jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[3],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7Dhki-1j","jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.luo666.com\/index.php?rest_route=\/wp\/v2\/posts\/81"}],"collection":[{"href":"http:\/\/www.luo666.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.luo666.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.luo666.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.luo666.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":4,"href":"http:\/\/www.luo666.com\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":85,"href":"http:\/\/www.luo666.com\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions\/85"}],"wp:attachment":[{"href":"http:\/\/www.luo666.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.luo666.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.luo666.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}