{"id":103,"date":"2016-11-10T16:40:46","date_gmt":"2016-11-10T08:40:46","guid":{"rendered":"http:\/\/himmel.tech\/wp\/?p=103"},"modified":"2017-02-25T16:42:44","modified_gmt":"2017-02-25T08:42:44","slug":"os%e7%ad%86%e8%a8%98%e7%ac%ac%e5%85%ab%e7%ab%a0%ef%bc%9a%e5%85%a7%e5%ad%98%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/himmel.tech\/wp\/?p=103","title":{"rendered":"[OS\u7b46\u8a18]\u7b2c\u516b\u7ae0\uff1a\u5167\u5b58\u7ba1\u7406"},"content":{"rendered":"<p>\u552f\u4e00\u7684\u4e00\u6bb5\u64cd\u4f5c\u7cfb\u7edf\u7684\u7b14\u8bb0\u2026\u2026<\/p>\n<p><!--more--><\/p>\n<h2>\u80cc\u666f<\/h2>\n<ul>\n<li>\u7a0b\u5f0f\u9700\u8981\u8f09\u5165\u5230\u5167\u5b58\uff0c\u624d\u80fd\u88ab\u904b\u884c\uff1b<\/li>\n<li>\u5e7e\u4e4e\u6240\u6709\u7684\u8a2d\u5099\u64cd\u4f5c\u90fd\u9700\u8981\u7d93\u904e\u5167\u5b58\uff1b<\/li>\n<li>CPU\u53ea\u80fd\u76f4\u63a5\u8a2a\u554f\u5bc4\u5b58\u5668\u548c\u5167\u5b58\uff1b<\/li>\n<\/ul>\n<h3>Base and Limit Register<\/h3>\n<p>\u7528\u65bc\u6a19\u8b58\u7a0b\u5f0f\u53ef\u4f7f\u7528\u7684\u5408\u6cd5\u4e3b\u5b58\u7a7a\u9593\u3002<br \/>\nFor example:<br \/>\nBase  = 304000<br \/>\nLimit = 002000<br \/>\n\u5247\u7a0b\u5f0f\u53ef\u4ee5\u4f7f\u7528304000\uff5e306000\u9019\u6bb5\u5730\u5740\u7a7a\u9593\u3002<br \/>\n\u5b9a\u7fa9\u4e86\u4e00\u6bb5\u908f\u8f2f\u5730\u5740\u7a7a\u9593\u3002<\/p>\n<h3>Address Binding<\/h3>\n<p>\u5373\u6620\u5c04\uff0c\u6709\u4e09\u7a2e\u6a5f\u5236\uff1a<br \/>\n&#8211; Compile Time \u7de8\u8b6f\u6642<br \/>\n&#8211; Load Time \u5373\u93c8\u63a5\u6642<br \/>\n&#8211; Execution Time \u57f7\u884c\u6642\uff0c\u9700\u8981CPU\u786c\u4ef6\u652f\u6301\u91cd\u6620\u5c04<\/p>\n<p>\u7de8\u8b6f\u751f\u6210\u7684.o\u6587\u4ef6\u4e2d\u4e0d\u5b58\u5728\u5730\u5740\uff0c\u53ea\u5b58\u5728\u7b26\u865f\u5730\u5740\u3002<br \/>\nLink\u4e4b\u5f8c\u7b26\u865f\u5730\u5740\u8f49\u63db\u7232\u4e86Absolute Address\u3002<br \/>\n\u4e0d\u904e\u6709\u6642\u5373\u4f7f\u6642\u93c8\u63a5\u6642\u4e5f\u627e\u4e0d\u5230\u5730\u5740\uff0c\u9019\u6642\u5c31\u9700\u8981\u57f7\u884c\u6642\u7d81\u5b9a\u3002<\/p>\n<h3>Logical vs. Physical Address Space<\/h3>\n<p>Logical Address CPU\u4f7f\u7528\u7684\u5730\u5740<br \/>\nPhysical Address \u5167\u5b58\u4f7f\u7528\u7684\u5730\u5740<br \/>\n\u4e2d\u9593\u8981\u7d93\u904eMMU\uff0cMemory-Management Unit\uff0c\u786c\u4ef6\u5be6\u73fe\u5169\u500b\u5730\u5740\u9593\u7684\u8f49\u63db\u3002<br \/>\n\u9019\u7a2e\u60c5\u6cc1\u53ea\u767c\u751f\u65bc\u904b\u884c\u6642\u7d81\u5b9a\uff0c\u7de8\u8b6f\u6642\u548c\u93c8\u63a5\u6642\u7d81\u5b9a\u7684\u908f\u8f2f\u548c\u7269\u7406\u5730\u5740\u662f\u76f8\u540c\u7684\u3002<\/p>\n<h3>Dynamic Loading<\/h3>\n<p>\u8001\u820a\u4f5c\u696d\u7cfb\u7d71\u7684\u8655\u7406\u65b9\u5f0f\uff0c\u5982Windows 3.1\u3002<br \/>\n\u4e00\u90e8\u5206\u4ee3\u78bc\u6c92\u6709\u88ab\u8f09\u5165\u5167\u5b58\uff0c\u800c\u662f\u8a2a\u554f\u6642\u624d\u88dd\u5165\u9032\u7a0b\u5167\u5b58\u7a7a\u9593\u3002<br \/>\n\u4e0d\u9700\u8981OS\u652f\u63f4\uff0c\u88dd\u5165\u5730\u5740\u662f\u9810\u5148\u6c7a\u5b9a\u597d\u7684\uff0c\u7531\u7a0b\u5e8f\u958b\u767c\u8005\u5be6\u73fe\u3002\u4fdd\u5b58\u908f\u8f2f\u5730\u5740\u3002<br \/>\n<em>Dynamic loading is a mechanism by which a computer program can, at run time, load a library (or other binary) into memory, retrieve the addresses of functions and variables contained in the library, execute those functions or access those variables, and unload the library from memory.<\/em><\/p>\n<h3>Dynamic Linking<\/h3>\n<p>\u73fe\u4ee3\u4f5c\u696d\u7cfb\u7d71\u7684\u8655\u7406\u65b9\u5f0f\u3002\u5982DLL\uff0c\u9700\u8981\u4f5c\u696d\u7cfb\u7d71\u7684\u5e6b\u52a9\u3002<br \/>\n\u5b58\u5132\u7684\u662f\u7b26\u865f\u5730\u5740\u3002<\/p>\n<h2>Swapping<\/h2>\n<p>\u4e2d\u671f\u8abf\u5ea6\u6a5f\u5236\u3002<\/p>\n<h2>Memory Allocation<\/h2>\n<h3>Contiguous Allocation\/\u7a7a\u9593\u9023\u7e8c\u5206\u914d<\/h3>\n<p><em>Contiguous\u5f37\u8abf\u6bd7\u9130\uff0cContinuous\u5f37\u8abf\u4e0d\u53ef\u6253\u65b7\u3002<\/em><br \/>\n\u4f7f\u7528Base\u548cLimit\u5169\u500b\u5bc4\u5b58\u5668\u3002CPU\u6aa2\u67e5\u5167\u5b58\u8a2a\u554f\u5730\u5740\uff0c\u5982\u679c\u8d85\u51fa\u7bc4\u570d\uff0c\u5247\u89f8\u767cTrap\u3002<br \/>\n\u7576\u4e00\u500b\u65b0\u7684\u9032\u7a0b\u9032\u5165\u6642\uff0c\u5b83\u6703\u88ab\u52a0\u8f09\u5230\u7b2c\u4e00\u500b\u8db3\u5920\u5927\u7684\u201c\u7a7a\u6d1e\u201d\u4e2d\u3002<br \/>\n\u64cd\u4f5c\u7cfb\u7d71\u9700\u8981\u8a18\u9304\uff1a \u5206\u914d\u904e\u7684\u5167\u5b58\uff0c\u7a7a\u9592\u5167\u5b58\uff08\u7a7a\u6d1e\uff09\u3002<\/p>\n<ul>\n<li>First-fit: \u627e\u7b2c\u4e00\u500b\u80fd\u4e1f\u9032\u53bb\u7684<\/li>\n<li>Best-fit: \u627e\u4e00\u500b\u5927\u5c0f\u6700\u5408\u9069\u7684<\/li>\n<li>Worst-fit: \u627e\u6700\u5927\u7684\u7a7a\u6d1e<\/li>\n<\/ul>\n<p><em>Memory Utilization &lt;===> Memory Consumption<br \/>\n\u6307\u5167\u5b58\u6d88\u8017\u91cf\uff0c\u986f\u7136\u8d8a\u5c0f\u8d8a\u597d\u3002<br \/>\nMemory footprint \u8d8a\u5c0f\u8d8a\u597d<\/em><\/p>\n<p>\u6703\u7522\u751f\u5f88\u591a\u788e\u7247\u3002<br \/>\n&#8211; \u5167\u90e8\u788e\u7247\uff1a\u9032\u7a0b\u7533\u8acb\u4e86888K\uff0c\u4f46\u7cfb\u7d71\u7d66\u4e861M\u3002<br \/>\n&#8211; \u5916\u90e8\u788e\u7247\uff1a\u9032\u7a0b\u548c\u9032\u7a0b\u4e4b\u9593\u7684\u788e\u7247\u3002<\/p>\n<h3>\u9801\u5f0f\u5206\u914d<\/h3>\n<p>\u5c07\u5167\u5b58\u5283\u5206\u7232\u5e40(Frames)\uff0c512Byte~8192Byte\u4e4b\u9593\u3002<br \/>\n\u908f\u8f2f\u5730\u5740\u5283\u5206\u7232\u5169\u90e8\u5206\uff1a Page Number + Page Offset\uff0c\u8b93Page\u8207Frame\u6709\u76f8\u540c\u7684\u5927\u5c0f\u3002<br \/>\n\u64cd\u4f5c\u7cfb\u7d71\u7dad\u8b77\u4e00\u5f35\u8868\uff0c\u8a18\u9304\u9801\u548c\u5e40\u7684\u6620\u5c04\u95dc\u4fc2\u3002\u53e6\u5916\uff0c\u7cfb\u7d71\u9084\u9700\u8981\u7dad\u8b77\u4e00\u5f35Free Frame Table\u3002<\/p>\n<p><strong>\u512a\u9ede\uff1a<\/strong> \u5fb9\u5e95\u6d88\u9664\u4e86External Fragment\u3002<br \/>\n<strong>\u7f3a\u9ede\uff1a<\/strong> \u9084\u662f\u7121\u6cd5\u6d88\u9664Internal Fragment\u3002\u6bd4\u5982\u8a2d\u7f6eFrame\u72322M\uff0c\u4f46\u67d0\u500b\u9032\u7a0b\u53ea\u9700\u89811.5M\u3002<br \/>\n\u786c\u4ef6\u8981\u6c42\uff1a<br \/>\nPage table \u5132\u5b58\u8207\u4e3b\u5b58\u4e2d<br \/>\nPTBR &#8211; Page-table base Register<br \/>\nPTLR &#8211; Page-table length Register<br \/>\n\u4f46\u9019\u6a23\u4e00\u4f86\u6bcf\u6b21\u8a2a\u554f\u5167\u5b58\u6703\u9020\u6210\u5169\u6b21\u5be6\u969b\u7684\u5167\u5b58\u8a2a\u554f\uff0c\u56e0\u6b64\u8981\u628aPage table\u90e8\u5206\u4e1f\u5728TLB(Translation Lookaside Buffer)\u88cf\u9762\uff0c\u9019\u6a23\u53ea\u6703\u5728TLB Miss\u7684\u6642\u5019\u7522\u751f\u5169\u6b21\u5167\u5b58\u8a2a\u554f\u3002<br \/>\n\u6bcf\u500b\u9032\u7a0b\u90fd\u6709\u81ea\u5df1\u7684Page Table\uff0c\u4e26\u7528valid-invalid bit\u4f86\u6a19\u8a8c\u3002\u53ef\u4ee5\u5171\u4eab\u9801\u9762\u4f86\u5171\u4eab\u4ee3\u78bc\u3002<\/p>\n<h4>\u9ad8\u7d1a\u5f62\u614b<\/h4>\n<ul>\n<li>Hierarchical Paging &#8211; 2-level Page-table, Page-table\u592a\u5927<\/li>\n<li>Hashing Paging<\/li>\n<li>Inverted Page Table<br \/>\nTable[i]\u5b58\u5132PID, Page Number\uff0c\u6bcf\u6b21\u8a2a\u554f\u5f9e\u524d\u5f80\u5f8c\u6383\u8868\uff0c\u7b2c\u4e00\u500b\u5339\u914d\u4e0a\u7684i\u5c31\u662fFrame Number\u3002  <\/li>\n<\/ul>\n<h3>Segmentation \u6bb5\u5f0f\u5206\u914d<\/h3>\n<p>\u4e00\u500b\u7a0b\u5e8f\u7531\u8a31\u591a\u6bb5\u7d44\u6210\uff0c\u6bcf\u500b\u6bb5\u662f\u4e00\u500b\u908f\u8f2f\u55ae\u5143\u3002<br \/>\n\u6bcf\u500b\u6bb5\u64c1\u6709\u4e00\u6bb5\u5167\u5b58\u7a7a\u9593\u3002<br \/>\n\u908f\u8f2f\u5730\u5740\u5206\u7232\u5169\u90e8\u5206&lt;\u6bb5\u865f\uff0c\u504f\u79fb\u91cf><br \/>\n\u6bb5\u8868\uff1a\u6bb5\u865f &#8212;> [Base, Limit]<br \/>\n\u4fdd\u8b77\u4f4d<\/p>\n<p>\u5be6\u969b\u4e0a\uff0c\u6bb5\u5f0f\u5206\u914d\u65bc\u9801\u5f0f\u5206\u914d\u7d93\u5e38\u4e00\u8d77\u4f7f\u7528\uff0c\u6bd4\u5982\u5954\u9a30\uff0c\u5148\u5c07\u5167\u5b58\u5206\u9801\uff0c\u7136\u5f8c\u5c07\u9801\u5206\u6bb5\u3002<br \/>\nCPU\u767c\u51fa\u7684\u908f\u8f2f\u5730\u5740\u5206\u5169\u6bb5\uff0cSelector + Address<br \/>\n\u6bd4\u5982Intel Pentium:<br \/>\nLogical Address -> Linear Address -> Pyhsical Address<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u552f\u4e00\u7684\u4e00\u6bb5\u64cd\u4f5c\u7cfb\u7edf\u7684\u7b14\u8bb0\u2026\u2026<\/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":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p83CFH-1F","_links":{"self":[{"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=103"}],"version-history":[{"count":2,"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":105,"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=\/wp\/v2\/posts\/103\/revisions\/105"}],"wp:attachment":[{"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himmel.tech\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}