为什么ubuntu在有足够的空闲内存时使用swap?

Ksh*_*rma 9 swap

在运行 Virtual Box 时,我的系统经常访问硬盘驱动器并且运行缓慢。

当我使用 System Monitor 检查系统资源时,它显示处理器使用率为 15%,RAM 使用率为 65%,Swap 使用率约为 50%。

我的问题是为什么 ubuntu 在有足够的主内存可用时需要使用 Swap?

编辑 -

free命令的输出-

             total       used       free     shared    buffers     cached
Mem:       4075908    3056931    1018977          0       1944     308408
-/+ buffers/cache:    2746579    1329329
Swap:      4139004    1862551    2276453
Run Code Online (Sandbox Code Playgroud)

注意 - 在我升级12.04 Precise12.10 Quantal. 现在它太慢了,几乎没用。

小智 12

swappiness 参数控制内核将进程从物理内存移到交换磁盘上的趋势。由于磁盘比 RAM 慢得多,如果进程过于频繁地移出内存,这可能会导致系统和应用程序的响应时间变慢。

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 
Run Code Online (Sandbox Code Playgroud)

Ubuntu 中的默认设置是 swappiness=60。减少 swappiness 的默认值可能会提高典型 Ubuntu 桌面安装的整体性能。

资料来源:SwapFaq - Ubuntu Wiki

在启动 virtualbox 之前打开终端并粘贴它:

    sudo sysctl vm.swappiness=10
Run Code Online (Sandbox Code Playgroud)

启动可视化并检查交换使用率是否减少,如果是这种情况,则在终端中执行以下命令:

    gksu gedit /etc/sysctl.conf
Run Code Online (Sandbox Code Playgroud)

它会询问您的密码,输入密码,然后屏幕上会出现一个文本编辑器,一直向下滚动并在最后一行之后添加:

    vm.swappiness=10
Run Code Online (Sandbox Code Playgroud)

保存文件并重新启动计算机。

这应该够了吧!