<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar/8638045102788407707?origin\x3dhttp://micro1o.blogspot.com', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

(转贴)Ubuntu下优化交换分区

转贴自 OwnLinux.cn

[感谢 3k背景辐射 撰文]写在前面的话:我最近把我只有512M的老爷机加了一跟512M的的内存。但是我发现,当机器运行一段时间后越来越慢,一看系统监视器发现swap 里面居然驻留了200M的数据,我想:好你个乌斑兔儿,居然好好的物理内存你不吃,来吃swap!所以,自己就准备对它进行点点“教育”。

在ubuntu里面,swappiness的值的大小对如何使用swap分区是有着很大的联系的。swappiness=0的时候表示最大限度使用物理内存,然后才是swap空间,swappiness=100的时候表示积极的使用swap分区,并且把内存上的数据及时的搬运到swap空间里面。两个极端,对于ubuntu的默认设置,这个值等于60,建议修改为10。具体这样做:
1.查看你的系统里面的swappiness
$ cat /proc/sys/vm/swappiness

不出意外的话,你应该看到是 60
2.修改swappiness值为10
$ sudo sysctl vm.swappiness=10

但是这只是临时性的修改,在你重启系统后会恢复默认的60,所以,还要做一步:
$ gksudo gedit /etc/sysctl.conf

在这个文档的最后加上这样一行:
vm.swappiness=10

然后保存,重启。ok,你的设置就生效了。你会发现,现在乌斑兔儿跑得更快了!
当然,你可以用其他编辑器进行修改,如kate,vi,vim,nano……只需要把gedit替换成它们就ok了!因为考虑到大多数人都用的gnome桌面,就写的gedit。

ps:我找这个问题花了很多时间,在中国的网页上基本没发现答案,最后在help.ubuntu.com上终于发现了它,因此把它简要的翻译出来,供大家参考参考…
原文地址 https://help.ubuntu.com/community/SwapFaq

Performance tuning with ''swappiness''

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and on to the swap disk. As disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.
  • swappiness can have a value of between 0 and 100
  • swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
  • swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache
  • Ubuntu uses a default setting of swappiness=60

Reducing the default value of swappiness will probably improve overall performance for a typical Ubuntu desktop installation. A value of swappiness=10 is recommended, but feel free to experiment. Note: Ubuntu server installations have different performance requirements to desktop systems, and the default value of 60 is likely more suitable.

How to check the swappiness value
cat /proc/sys/vm/swappiness


How to change the swappiness value

A temporary change (lost on reboot) with a swappiness value of 10 can be made with:
sudo sysctl vm.swappiness=10

To make a change permanent, edit the configuration file with your favorite editor:
gksudo gedit /etc/sysctl.conf

Search for vm.swappiness and change its value as desired. If vm.swappiness does not exist, add it to the end of the file like so:
vm.swappiness=10

Save the file and reboot.

标签: ,

You can leave your response or bookmark this post to del.icio.us by using the links below.
Comment | Bookmark | Go to end