{"id":109,"date":"2025-10-13T10:50:09","date_gmt":"2025-10-13T02:50:09","guid":{"rendered":"https:\/\/blog.furry.pub\/?p=109"},"modified":"2025-10-13T10:50:09","modified_gmt":"2025-10-13T02:50:09","slug":"debian-%e7%b3%bb%e7%bb%9f%e8%ae%be%e7%bd%ae%e8%99%9a%e6%8b%9f%e5%86%85%e5%ad%98%ef%bc%88swap%ef%bc%89%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/blog.furry.pub\/?p=109","title":{"rendered":"Debian \u7cfb\u7edf\u8bbe\u7f6e\u865a\u62df\u5185\u5b58\uff08Swap\uff09\u5b8c\u5168\u6307\u5357"},"content":{"rendered":"\n<p>Re:<a href=\"https:\/\/blog.sijia.fun\/index.php\/archives\/120\/\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/blog.sijia.fun\/index.php\/archives\/120\/<\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-0\">Debian \u7cfb\u7edf\u8bbe\u7f6e\u865a\u62df\u5185\u5b58\uff08Swap\uff09\u5b8c\u5168\u6307\u5357<\/h1>\n\n\n\n<p>\u5728\u8d44\u6e90\u6709\u9650\u7684 Debian \u670d\u52a1\u5668\u4e0a\uff0c\u5408\u7406\u914d\u7f6e\u865a\u62df\u5185\u5b58\uff08Swap\uff09\u53ef\u663e\u8457\u63d0\u5347\u7cfb\u7edf\u7a33\u5b9a\u6027\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u8bbe\u7f6e\u548c\u4f18\u5316\u865a\u62df\u5185\u5b58\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-1\">\u4ec0\u4e48\u662f\u865a\u62df\u5185\u5b58\uff08Swap\uff09\uff1f<\/h2>\n\n\n\n<p>\u865a\u62df\u5185\u5b58\u662f\u64cd\u4f5c\u7cfb\u7edf\u4f7f\u7528\u786c\u76d8\u7a7a\u95f4\u6269\u5c55\u7269\u7406\u5185\u5b58\u7684\u673a\u5236\u3002\u5f53\u7269\u7406\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u7cfb\u7edf\u5c06\u4e0d\u5e38\u7528\u7684\u5185\u5b58\u9875\u9762\u4e34\u65f6\u5b58\u50a8\u5230\u865a\u62df\u5185\u5b58\u4e2d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-2\">\u521b\u5efa\u4ea4\u6362\u6587\u4ef6\uff08\u63a8\u8350\u65b9\u6cd5\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \u521b\u5efa\u4e00\u4e2a\u4ea4\u6362\u6587\u4ef6\uff081GB\u5927\u5c0f\uff09\n<code>sudo fallocate -l 1G \/swapfile<\/code>\n# \u5982\u679c fallocate \u547d\u4ee4\u4e0d\u53ef\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528 dd \u547d\u4ee4\uff1a\n# sudo dd if=\/dev\/zero of=\/swapfile bs=1024 count=1048576\n\n# 2. \u8bbe\u7f6e\u5b89\u5168\u6743\u9650\n<code>sudo chmod 600 \/swapfile<\/code>\n\n# 3. \u5c06\u6587\u4ef6\u683c\u5f0f\u5316\u4e3a\u4ea4\u6362\u7a7a\u95f4\n<code>sudo mkswap \/swapfile<\/code>\n\n# 4. \u542f\u7528\u4ea4\u6362\u6587\u4ef6\n<code>sudo swapon \/swapfile<\/code>\n\n# 5. \u9a8c\u8bc1\u4ea4\u6362\u7a7a\u95f4\u662f\u5426\u5df2\u542f\u7528\n<code>sudo swapon --show\nfree -h<\/code>\n\n# 6. \u8bbe\u7f6e\u5f00\u673a\u81ea\u52a8\u542f\u7528\uff08\u7f16\u8f91 \/etc\/fstab \u6587\u4ef6\uff09\n<code>echo '\/swapfile swap swap defaults 0 0' | sudo tee -a \/etc\/fstab<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-3\">\u4f18\u5316\u4ea4\u6362\u7a7a\u95f4\u4f7f\u7528<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-4\">\u8c03\u6574 Swappiness \u53c2\u6570<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u67e5\u770b\u5f53\u524d\u8bbe\u7f6e\n<code>cat \/proc\/sys\/vm\/swappiness<\/code>\n\n# \u4e34\u65f6\u4fee\u6539\uff08\u503c\u8d8a\u4f4e\u8d8a\u4e0d\u503e\u5411\u4f7f\u7528\u4ea4\u6362\u7a7a\u95f4\uff09\n<code>sudo sysctl vm.swappiness=10<\/code>\n\n# \u6c38\u4e45\u4fee\u6539\n<code>echo 'vm.swappiness=10' | sudo tee -a \/etc\/sysctl.conf<\/code><\/code><\/pre>\n\n\n\n<p>Bash<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-5\">\u63a8\u8350\u7684 Swappiness \u503c<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u670d\u52a1\u5668\u73af\u5883\uff1a10-20<\/li>\n\n\n\n<li>\u684c\u9762\u73af\u5883\uff1a30-60<\/li>\n\n\n\n<li>\u5185\u5b58\u6781\u5c0f\u7684\u7cfb\u7edf\uff1a60-100<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-6\">\u4ea4\u6362\u7a7a\u95f4\u5927\u5c0f\u5efa\u8bae<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7cfb\u7edf\u5185\u5b58<\/th><th>\u63a8\u8350\u4ea4\u6362\u7a7a\u95f4\u5927\u5c0f<\/th><\/tr><\/thead><tbody><tr><td>&lt; 1GB<\/td><td>\u5185\u5b58\u7684 2 \u500d<\/td><\/tr><tr><td>1-2GB<\/td><td>\u7b49\u540c\u4e8e\u5185\u5b58\u5927\u5c0f<\/td><\/tr><tr><td>2-8GB<\/td><td>\u5185\u5b58\u7684\u4e00\u534a\u5230\u7b49\u540c\u5927\u5c0f<\/td><\/tr><tr><td>&gt; 8GB<\/td><td>\u81f3\u5c11 4GB<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5bf9\u4e8e 557MB \u5185\u5b58\u670d\u52a1\u5668\uff0c\u5efa\u8bae\u8bbe\u7f6e 1GB \u5230 1.5GB \u7684\u4ea4\u6362\u7a7a\u95f4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-7\">\u76d1\u63a7\u4ea4\u6362\u7a7a\u95f4\u4f7f\u7528\u60c5\u51b5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u67e5\u770b\u4ea4\u6362\u7a7a\u95f4\u4f7f\u7528\u60c5\u51b5\n<code>free -h<\/code>\n\n# \u8be6\u7ec6\u67e5\u770b\u4ea4\u6362\u7edf\u8ba1\u4fe1\u606f\n<code>vmstat 1 5<\/code>\n\n# \u67e5\u770b\u54ea\u4e9b\u8fdb\u7a0b\u5728\u4f7f\u7528\u4ea4\u6362\u7a7a\u95f4\n<code>for file in \/proc\/*\/status ; do awk '\/VmSwap|Name\/{printf $2 \" \" $3}END{ print \"\"}' $file; done | sort -k 2 -n -r | head -10<\/code><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Re:https:\/\/blog.sijia.fun\/index.php\/archives\/120\/ Debian \u7cfb\u7edf\u8bbe\u7f6e\u865a\u62df\u5185\u5b58 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[3],"tags":[4,6,5],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-3","tag-linux","tag-swap","tag-5"],"_links":{"self":[{"href":"https:\/\/blog.furry.pub\/index.php?rest_route=\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.furry.pub\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.furry.pub\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.furry.pub\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.furry.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=109"}],"version-history":[{"count":1,"href":"https:\/\/blog.furry.pub\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/blog.furry.pub\/index.php?rest_route=\/wp\/v2\/posts\/109\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/blog.furry.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.furry.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.furry.pub\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}