个人工具

“UbuntuHelp:SwapFaq”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第2行: 第2行:
 
{{Languages|UbuntuHelp:SwapFaq}}
 
{{Languages|UbuntuHelp:SwapFaq}}
 
#title Swap Partition FAQ
 
#title Swap Partition FAQ
 
 
=== Introduction ===
 
=== Introduction ===
 
+
* '''This FAQ is aimed at Linux novices.'''
**** '''This FAQ is aimed at Linux novices.'''
+
* People always wonder how much swap they should put on install, or after installing without a clue think "oh my god", have I put enough swap? Maybe I should just reinstall with more swap?
 
+
* This FAQ will tell you how much swap you need and how to add more swap after installation.
**** People always wonder how much swap they should put on install, or after installing without a clue think "oh my god", have I put enough swap? Maybe I should just reinstall with more swap?
+
* You will be given very simple answers (so that you do not have to lose too much time reading this FAQ) and some explanations that may help you make your own opinion.
 
+
**** This FAQ will tell you how much swap you need and how to add more swap after installation.
+
 
+
**** You will be given very simple answers (so that you do not have to lose too much time reading this FAQ) and some explanations that may help you make your own opinion.
+
 
+
 
+
 
=== How much swap do I need? ===
 
=== How much swap do I need? ===
 
+
* If you have n Mb of ram, you need between n and 2*n Mb of swap.
**** If you have n Mb of ram, you need between n and 2*n Mb of swap.
+
* If you have a disk big enough, just put 2*n Mb swap.
 
+
**** If you have a disk big enough, just put 2*n Mb swap.
+
 
+
 
=== What is swap for? ===
 
=== What is swap for? ===
 
+
* As we'll see, there are basically four different purposes for swap :
**** As we'll see, there are basically four different purposes for swap :
+
** Some programs really are memory-consuming.
 
+
** Extra memory might come in handy.
* Some programs really are memory-consuming.
+
** Optimizing memory usage.
 
+
** Hibernation (suspend-to-disk)
* Extra memory might come in handy.
+
* To begin with, let's say that computers have changed a lot since swap was first used :
 
+
** At first, swap was needed to extend real memory capacity. You would use swap so that the available memory would be the addition of the ram space and the swap space.
* Optimizing memory usage.
+
** Nowadays, ram are often big enough so that we could use the computer without any swap at all.
 
+
* <u>Some programs really are memory-consuming :</u>
* Hibernation (suspend-to-disk)
+
** Sometimes, something big (like OpenOffice, Neverwinter Nights or some video editor) make the entire system need extra memory.
 
+
** In these cases, swap will be used to make the system able to handle the extra load.
**** To begin with, let's say that computers have changed a lot since swap was first used :
+
* <u>Extra memory might come in handy :</u>
 
+
** Unforeseeable events, might and will happen (a program going crazy, some action needing much more space than you thought, or any other unbelievable combination of events).
* At first, swap was needed to extend real memory capacity. You would use swap so that the available memory would be the addition of the ram space and the swap space.
+
** In these cases, swap will give you an extra delay to figure out what happens or to finish something.
 
+
* <u>Swap can optimize memory usage :</u>
* Nowadays, ram are often big enough so that we could use the computer without any swap at all.
+
** Hard drives are considerably slower than RAM. So when you need a file (be it a data file, like this video you're watching again and again, executables, like Firefox, or libraries), Linux reads the file into RAM and keeps it there so than the next time you need it again, it's already in RAM and data access is much faster (thousands of times faster). We call these portions of RAM that accelerate disk read "cached memory." They make a <u>huge</u> difference in terms of responsiveness.
 
+
** Linux automagically moves RAM reserved by programs but not really used in swap so that this ram can serve the better purpose of having more cached memory.
**** <u>Some programs really are memory-consuming :</u>
+
* <u>Hibernation needs swap</u>
 
+
** The hibernation feature (suspend-to-disk) writes out the contents of the memory to the swap partition before turning off the machine. Therefore, your swap partition should be at least as big as your RAM size. The hibernation implementation currently used in Ubuntu, ''swsusp'', needs a swap or suspend partition, and can not use a swap file on an active file system.
* Sometimes, something big (like OpenOffice, Neverwinter Nights or some video editor) make the entire system need extra memory.
+
 
+
* In these cases, swap will be used to make the system able to handle the extra load.
+
 
+
**** <u>Extra memory might come in handy :</u>
+
 
+
* Unforeseeable events, might and will happen (a program going crazy, some action needing much more space than you thought, or any other unbelievable combination of events).
+
 
+
* In these cases, swap will give you an extra delay to figure out what happens or to finish something.
+
 
+
**** <u>Swap can optimize memory usage :</u>
+
 
+
* Hard drives are considerably slower than RAM. So when you need a file (be it a data file, like this video you're watching again and again, executables, like Firefox, or libraries), Linux reads the file into RAM and keeps it there so than the next time you need it again, it's already in RAM and data access is much faster (thousands of times faster). We call these portions of RAM that accelerate disk read "cached memory." They make a <u>huge</u> difference in terms of responsiveness.
+
 
+
* Linux automagically moves RAM reserved by programs but not really used in swap so that this ram can serve the better purpose of having more cached memory.
+
 
+
**** <u>Hibernation needs swap</u>
+
 
+
* The hibernation feature (suspend-to-disk) writes out the contents of the memory to the swap partition before turning off the machine. Therefore, your swap partition should be at least as big as your RAM size. The hibernation implementation currently used in Ubuntu, ''swsusp'', needs a swap or suspend partition, and can not use a swap file on an active file system.
+
 
+
 
=== Should I reinstall with more swap? ===
 
=== Should I reinstall with more swap? ===
 
+
* '''<u>Definitely no</u>'''.
**** '''<u>Definitely no</u>'''.
+
* If you need more swap, just read the answer to "How do I add more swap ?".
 
+
**** If you need more swap, just read the answer to "How do I add more swap ?".
+
 
+
 
=== How do I add more swap? ===
 
=== How do I add more swap? ===
 
+
* Usually, people associate swap with a swap partition, maybe because they've been proposed to create a swap partition on install. In fact any file can be used as a swapping device, be it a partition or a conventional file.
**** Usually, people associate swap with a swap partition, maybe because they've been proposed to create a swap partition on install. In fact any file can be used as a swapping device, be it a partition or a conventional file.
+
* With the 2.6 kernel, "a swap file is just as fast as a swap partition."([http://en.wikipedia.org/wiki/Paging#Swapping_in_Linux Wikipedia:Paging], [http://lkml.org/lkml/2006/5/29/3 LKML]). If you're considering responsiveness, my advice: add more RAM. Swapping to a partition or a file won't change anything.
 
+
* We will add more swap by adding a swap file.
**** With the 2.6 kernel, "a swap file is just as fast as a swap partition."([http://en.wikipedia.org/wiki/Paging#Swapping_in_Linux Wikipedia:Paging], [http://lkml.org/lkml/2006/5/29/3 LKML]). If you're considering responsiveness, my advice: add more RAM. Swapping to a partition or a file won't change anything.
+
* <u>Adding more swap is a four-step process :</u>
 
+
** a- Creating a file the size you want.
**** We will add more swap by adding a swap file.
+
** b- Formatting that file to create a swapping device.
 
+
** c- Adding the swap to the running system.
**** <u>Adding more swap is a four-step process :</u>
+
** d- Making the change permanent.
 
+
* <u>We will consider (as an example) a 512 Mb swap need.</u>
* a- Creating a file the size you want.
+
* <u>a- Creating a file the size you want :</u>
 
+
** We will create a /mnt/512Mb.swap swap file.
* b- Formatting that file to create a swapping device.
+
 
+
* c- Adding the swap to the running system.
+
 
+
* d- Making the change permanent.
+
 
+
**** <u>We will consider (as an example) a 512 Mb swap need.</u>
+
 
+
**** <u>a- Creating a file the size you want :</u>
+
 
+
* We will create a /mnt/512Mb.swap swap file.
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512
 
sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* What is important here is '''count=512''', which means we want our file to contain 512 blocks of '''bs=1M''', which means block size = 1 MegaBytes.
 
* What is important here is '''count=512''', which means we want our file to contain 512 blocks of '''bs=1M''', which means block size = 1 MegaBytes.
 
+
** <u>b- Formatting that file to create a swapping device :</u>
**** <u>b- Formatting that file to create a swapping device :</u>
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo mkswap /mnt/512Mb.swap
 
sudo mkswap /mnt/512Mb.swap
 
</nowiki></pre>
 
</nowiki></pre>
 
+
* <u>c- Adding the swap to the running system :</u>
**** <u>c- Adding the swap to the running system :</u>
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo swapon /mnt/512Mb.swap
 
sudo swapon /mnt/512Mb.swap
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* You can see with "'''cat /proc/meminfo'''" that your additionnal swap is now available.
 
* You can see with "'''cat /proc/meminfo'''" that your additionnal swap is now available.
 
+
** <u>d- Making the change permanent :</u>
**** <u>d- Making the change permanent :</u>
+
 
+
 
* edit your /etc/fstab:  
 
* edit your /etc/fstab:  
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo gedit /etc/fstab
 
sudo gedit /etc/fstab
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* and add this line at the end of the file:  
 
* and add this line at the end of the file:  
 
<pre><nowiki>
 
<pre><nowiki>
 
/mnt/512Mb.swap  none  swap  sw  0 0
 
/mnt/512Mb.swap  none  swap  sw  0 0
 
</nowiki></pre>
 
</nowiki></pre>
 
 
* save and reboot
 
* save and reboot
 
=== Troubleshooting ===
 
=== Troubleshooting ===
 
'''Note:'''this regards mainly swap on hard disk partitions, but it could help you anyway. Also replace /dev/hda8 with your configuration.
 
'''Note:'''this regards mainly swap on hard disk partitions, but it could help you anyway. Also replace /dev/hda8 with your configuration.
 
 
<u>'''Help!'''</u> The swap is not being used! When I issue the free command, it shows something like this:
 
<u>'''Help!'''</u> The swap is not being used! When I issue the free command, it shows something like this:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
tom@tom:~$ free
 
tom@tom:~$ free
第132行: 第78行:
 
Swap:      674688          0    674688
 
Swap:      674688          0    674688
 
</nowiki></pre>
 
</nowiki></pre>
 
+
* 1- First try, if it is because the system cannot use swap or because it just does not need it. Start many memory consuming applications (e.g. Gimp, web browsers, OpenOffice etc) and then issue the free command again. Is swap being used now?
**** 1- First try, if it is because the system cannot use swap or because it just does not need it. Start many memory consuming applications (e.g. Gimp, web browsers, OpenOffice etc) and then issue the free command again. Is swap being used now?
+
* 2- See if there is a swap partition at all:  
 
+
**** 2- See if there is a swap partition at all:  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo fdisk -l
 
sudo fdisk -l
 
</nowiki></pre>
 
</nowiki></pre>
 
 
you should be able to see something like this in the output  
 
you should be able to see something like this in the output  
 
<pre><nowiki>
 
<pre><nowiki>
 
/dev/hda8            4787        4870      674698+  82  Linux swap / Solaris
 
/dev/hda8            4787        4870      674698+  82  Linux swap / Solaris
 
</nowiki></pre>
 
</nowiki></pre>
 
 
If not, you either need to create a swapfile (see above as to how to do it) or create a swap partition. In order to do that, you can for example
 
If not, you either need to create a swapfile (see above as to how to do it) or create a swap partition. In order to do that, you can for example
 
+
* boot from your Ubuntu install CD (rather usin the expert bot option), create a swap partiton out of the free space on your hardddisk and then interrupt your installation
**** boot from your Ubuntu install CD (rather usin the expert bot option), create a swap partiton out of the free space on your hardddisk and then interrupt your installation
+
* or just use cfdisk (lookup its man page for more info).
 
+
**** or just use cfdisk (lookup its man page for more info).
+
 
+
 
However, let us just suppose you have a swap partition.
 
However, let us just suppose you have a swap partition.
 
There are several ways of enabling it.
 
There are several ways of enabling it.
 
+
* 2.1- First make sure you have something like this  
**** 2.1- First make sure you have something like this  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
/dev/hda8      none            swap    sw              0      0
 
/dev/hda8      none            swap    sw              0      0
 
</nowiki></pre>
 
</nowiki></pre>
 
 
in /etc/fstab. It enables swap on boot.
 
in /etc/fstab. It enables swap on boot.
 
+
* 2.2- Then try to disable all swap, recreate it and then enable it again  
**** 2.2- Then try to disable all swap, recreate it and then enable it again  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
swapoff -a
 
swapoff -a
第167行: 第103行:
 
swapon -a
 
swapon -a
 
</nowiki></pre>
 
</nowiki></pre>
 
+
* 2.3 Some people also reported this to help:
*** 2.3 Some people also reported this to help:
+
** 1) cfdisk : erase the old Swap partition and recreate a new one
****** 1) cfdisk : erase the old Swap partition and recreate a new one
+
** 2) reboot (mandatory)
****** 2) reboot (mandatory)
+
** 3) mkswap /dev/hda8
****** 3) mkswap /dev/hda8
+
** 4) swapon -a
****** 4) swapon -a
+
 
+
 
+
 
=== Example of making a swap file ===
 
=== Example of making a swap file ===
 
This is an example of making and using a swap file on a computer with no swap partition.
 
This is an example of making and using a swap file on a computer with no swap partition.
第222行: 第155行:
 
-/+ buffers/cache:    349192    150304
 
-/+ buffers/cache:    349192    150304
 
Swap:      524280      53384    470896
 
Swap:      524280      53384    470896
 
 
user@computer:~$ free
 
user@computer:~$ free
 
total      used      free    shared    buffers    cached
 
total      used      free    shared    buffers    cached
第230行: 第162行:
 
</nowiki></pre>
 
</nowiki></pre>
 
=== Performance (advanced) ===
 
=== Performance (advanced) ===
 
 
There is a parameter which defines the attitude of kernel to swap.
 
There is a parameter which defines the attitude of kernel to swap.
 
This parameter is controlling how soon the kernel begin to fill the swap.
 
This parameter is controlling how soon the kernel begin to fill the swap.
 
 
This parameter is called "swappiness" and has a value in the 0-100 range.
 
This parameter is called "swappiness" and has a value in the 0-100 range.
 
swappiness=0 means it will use swap as last as possible.
 
swappiness=0 means it will use swap as last as possible.
 
swappiness=100 means it will begin to swap very early.
 
swappiness=100 means it will begin to swap very early.
 
 
Currently the default value is 60, but lowering to 10 or 5 would cause
 
Currently the default value is 60, but lowering to 10 or 5 would cause
 
the machine to be better responsive.
 
the machine to be better responsive.
 
 
==== How to check the swappiness value ====
 
==== How to check the swappiness value ====
 
<pre><nowiki>
 
<pre><nowiki>
 
$ cat /proc/sys/vm/swappiness
 
$ cat /proc/sys/vm/swappiness
 
</nowiki></pre>
 
</nowiki></pre>
 
 
==== How to change the swappiness value ====
 
==== How to change the swappiness value ====
 
+
* edit the /etc/sysctl.conf:
**** edit the /etc/sysctl.conf:
+
 
<pre><nowiki>
 
<pre><nowiki>
 
$ sudo gedit /etc/sysctl.conf
 
$ sudo gedit /etc/sysctl.conf
 
</nowiki></pre>
 
</nowiki></pre>
 
+
* and add this line in the end of the file (change 10 to the value you want):
**** and add this line in the end of the file (change 10 to the value you want):
+
 
<pre><nowiki>
 
<pre><nowiki>
 
vm.swappiness=10
 
vm.swappiness=10
 
</nowiki></pre>
 
</nowiki></pre>
 
+
* save and reboot
**** save and reboot
+
=== Advanced Topics ===
 
+
SwapSpace
 
=== Author ===
 
=== Author ===
 
+
* Yannick Le Saint (kyncani) <[email protected]>
**** Yannick Le Saint (kyncani) <[email protected]>
+
* Tomas Hnyk <[email protected]> - troubleshooting section
**** Tomas Hnyk <[email protected]> - troubleshooting section
+
* Max Randor <max (DOT) randor <at>googlemail.com>
**** Max Randor <max (DOT) randor <at>googlemail.com>
+
 
+
 
=== About the document ===
 
=== About the document ===
 
+
* '''<u>TODO :</u>'''
**** '''<u>TODO :</u>'''
+
** Determine the more standard emplacement for swap files (FHS).
 
+
** Add power suspend considerations.
* Determine the more standard emplacement for swap files (FHS).
+
* 15/05/2005, 01:42
 
+
** First version.
* Add power suspend considerations.
+
 
+
**** 15/05/2005, 01:42
+
 
+
* First version.
+
 
+
 
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
 
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 21:37的版本

  1. title Swap Partition FAQ

Introduction

  • This FAQ is aimed at Linux novices.
  • People always wonder how much swap they should put on install, or after installing without a clue think "oh my god", have I put enough swap? Maybe I should just reinstall with more swap?
  • This FAQ will tell you how much swap you need and how to add more swap after installation.
  • You will be given very simple answers (so that you do not have to lose too much time reading this FAQ) and some explanations that may help you make your own opinion.

How much swap do I need?

  • If you have n Mb of ram, you need between n and 2*n Mb of swap.
  • If you have a disk big enough, just put 2*n Mb swap.

What is swap for?

  • As we'll see, there are basically four different purposes for swap :
    • Some programs really are memory-consuming.
    • Extra memory might come in handy.
    • Optimizing memory usage.
    • Hibernation (suspend-to-disk)
  • To begin with, let's say that computers have changed a lot since swap was first used :
    • At first, swap was needed to extend real memory capacity. You would use swap so that the available memory would be the addition of the ram space and the swap space.
    • Nowadays, ram are often big enough so that we could use the computer without any swap at all.
  • Some programs really are memory-consuming :
    • Sometimes, something big (like OpenOffice, Neverwinter Nights or some video editor) make the entire system need extra memory.
    • In these cases, swap will be used to make the system able to handle the extra load.
  • Extra memory might come in handy :
    • Unforeseeable events, might and will happen (a program going crazy, some action needing much more space than you thought, or any other unbelievable combination of events).
    • In these cases, swap will give you an extra delay to figure out what happens or to finish something.
  • Swap can optimize memory usage :
    • Hard drives are considerably slower than RAM. So when you need a file (be it a data file, like this video you're watching again and again, executables, like Firefox, or libraries), Linux reads the file into RAM and keeps it there so than the next time you need it again, it's already in RAM and data access is much faster (thousands of times faster). We call these portions of RAM that accelerate disk read "cached memory." They make a huge difference in terms of responsiveness.
    • Linux automagically moves RAM reserved by programs but not really used in swap so that this ram can serve the better purpose of having more cached memory.
  • Hibernation needs swap
    • The hibernation feature (suspend-to-disk) writes out the contents of the memory to the swap partition before turning off the machine. Therefore, your swap partition should be at least as big as your RAM size. The hibernation implementation currently used in Ubuntu, swsusp, needs a swap or suspend partition, and can not use a swap file on an active file system.

Should I reinstall with more swap?

  • Definitely no.
  • If you need more swap, just read the answer to "How do I add more swap ?".

How do I add more swap?

  • Usually, people associate swap with a swap partition, maybe because they've been proposed to create a swap partition on install. In fact any file can be used as a swapping device, be it a partition or a conventional file.
  • With the 2.6 kernel, "a swap file is just as fast as a swap partition."(Wikipedia:Paging, LKML). If you're considering responsiveness, my advice: add more RAM. Swapping to a partition or a file won't change anything.
  • We will add more swap by adding a swap file.
  • Adding more swap is a four-step process :
    • a- Creating a file the size you want.
    • b- Formatting that file to create a swapping device.
    • c- Adding the swap to the running system.
    • d- Making the change permanent.
  • We will consider (as an example) a 512 Mb swap need.
  • a- Creating a file the size you want :
    • We will create a /mnt/512Mb.swap swap file.
sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512
  • What is important here is count=512, which means we want our file to contain 512 blocks of bs=1M, which means block size = 1 MegaBytes.
    • b- Formatting that file to create a swapping device :
sudo mkswap /mnt/512Mb.swap
  • c- Adding the swap to the running system :
sudo swapon /mnt/512Mb.swap
  • You can see with "cat /proc/meminfo" that your additionnal swap is now available.
    • d- Making the change permanent :
  • edit your /etc/fstab:
sudo gedit /etc/fstab
  • and add this line at the end of the file:
/mnt/512Mb.swap  none  swap  sw  0 0
  • save and reboot

Troubleshooting

Note:this regards mainly swap on hard disk partitions, but it could help you anyway. Also replace /dev/hda8 with your configuration. Help! The swap is not being used! When I issue the free command, it shows something like this:

tom@tom:~$ free
total       used       free     shared    buffers     cached
Mem:        515980     448664      67316          0      17872     246348
-/+ buffers/cache:     184444     331536
Swap:       674688          0     674688
  • 1- First try, if it is because the system cannot use swap or because it just does not need it. Start many memory consuming applications (e.g. Gimp, web browsers, OpenOffice etc) and then issue the free command again. Is swap being used now?
  • 2- See if there is a swap partition at all:
sudo fdisk -l

you should be able to see something like this in the output

/dev/hda8            4787        4870      674698+  82  Linux swap / Solaris

If not, you either need to create a swapfile (see above as to how to do it) or create a swap partition. In order to do that, you can for example

  • boot from your Ubuntu install CD (rather usin the expert bot option), create a swap partiton out of the free space on your hardddisk and then interrupt your installation
  • or just use cfdisk (lookup its man page for more info).

However, let us just suppose you have a swap partition. There are several ways of enabling it.

  • 2.1- First make sure you have something like this
/dev/hda8       none            swap    sw              0       0

in /etc/fstab. It enables swap on boot.

  • 2.2- Then try to disable all swap, recreate it and then enable it again
swapoff -a
/sbin/mkswap /dev/hda8
swapon -a
  • 2.3 Some people also reported this to help:
    • 1) cfdisk : erase the old Swap partition and recreate a new one
    • 2) reboot (mandatory)
    • 3) mkswap /dev/hda8
    • 4) swapon -a

Example of making a swap file

This is an example of making and using a swap file on a computer with no swap partition.

user@computer:~$ sudo dd if=/dev/zero of=/mnt/512Mb.swap bs=1M count=512
Password:
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 35.3802 seconds, 15.2 MB/s
user@computer:~$ sudo mkswap /mnt/512Mb.swap
Setting up swapspace version 1, size = 536866 kB
no label, UUID=dd6a01c8-93f0-41e0-9b7a-306956d8821b
user@computer:~$ sudo swapon /mnt/512Mb.swap
user@computer:~$ cat /proc/meminfo
MemTotal:       499496 kB
MemFree:          9156 kB
Buffers:          4748 kB
Cached:         233140 kB
SwapCached:        724 kB
Active:         254432 kB
Inactive:       157920 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:       499496 kB
LowFree:          9156 kB
SwapTotal:      524280 kB
SwapFree:       523556 kB
Dirty:             128 kB
Writeback:           0 kB
Mapped:         243420 kB
Slab:            20672 kB
CommitLimit:    774028 kB
Committed_AS:   648680 kB
PageTables:       2224 kB
VmallocTotal:   524280 kB
VmallocUsed:      5708 kB
VmallocChunk:   518176 kB
user@computer:~$ gksudo gedit /etc/fstab
user@computer:~$ free
total       used       free     shared    buffers     cached
Mem:        499496     479488      20008          0       8256     215892
-/+ buffers/cache:     255340     244156
Swap:       524280       3856     520424
user@computer:~$ free
total       used       free     shared    buffers     cached
Mem:        499496     492768       6728          0       1240     142336
-/+ buffers/cache:     349192     150304
Swap:       524280      53384     470896
user@computer:~$ free
total       used       free     shared    buffers     cached
Mem:        499496     493136       6360          0       7528     174700
-/+ buffers/cache:     310908     188588
Swap:       524280      17148     507132

Performance (advanced)

There is a parameter which defines the attitude of kernel to swap. This parameter is controlling how soon the kernel begin to fill the swap. This parameter is called "swappiness" and has a value in the 0-100 range. swappiness=0 means it will use swap as last as possible. swappiness=100 means it will begin to swap very early. Currently the default value is 60, but lowering to 10 or 5 would cause the machine to be better responsive.

How to check the swappiness value

$ cat /proc/sys/vm/swappiness

How to change the swappiness value

  • edit the /etc/sysctl.conf:
$ sudo gedit /etc/sysctl.conf
  • and add this line in the end of the file (change 10 to the value you want):
vm.swappiness=10
  • save and reboot

Advanced Topics

SwapSpace

Author

About the document

  • TODO :
    • Determine the more standard emplacement for swap files (FHS).
    • Add power suspend considerations.
  • 15/05/2005, 01:42
    • First version.