Is it possible reduce swap memory size?

16,283

Solution 1

Yes. You can change the size of the swap partition, by using GParted. You can install it from the Ubuntu Software Center.

Remember that gparted won't work on a mounted partition. When you are working on the swap partition, you have to unmount it first with swapoff. When you are done, to active the new swap space you do it with swapon.

NOTE: You might want to consider doing this from a live/bootable CD or USB, to be safe. Also keep in mind that anytime you deal with partitions, there is risk involved in doing so.

NOTE: When dealing with partitions, always make sure that a backup is available in case something goes wrong. You may consider Clonezilla

Solution 2

I think that your best option is to lower the "swappiness" value, dealing with the partition table of your HDD can be tricky and dangerous.

run this command

gksudo gedit /etc/sysctl.conf

add this line

vm.swappiness=0

restart the computer, the kernel will not use the swap, the swap will be mounted but unused.

you can set this between 0 and 100, the meaning of this option is about the percentage of use of the swap space, 0 = never use the swap.

Share:
16,283

Related videos on Youtube

Pablo
Author by

Pablo

Hi everybody. My name is Pablo Cattaneo I live in Argentina and work at https://Lumile.com.ar as a front end developer. I really love working with JavaSript, Vue, Node and building PWA. I like music (Sting, Mile Davis, The Beatles) and I love swimming.

Updated on September 18, 2022

Comments

  • Pablo
    Pablo almost 2 years

    The matter is that my computer has 3Gb of memory ram. Therefore i think that i don't need too much swap memory size, and i really need free space in the hard disk. sorry by my English

  • Eliah Kagan
    Eliah Kagan almost 12 years
    It's inadvisable to change the partition table on the system drive from which the OS is running. When the size of a partition changes, that is done by editing the partition table. There are many good applications of GParted on installed Ubuntu systems, but this mistake is why it's not installed by default. To resize partitions, you should boot from an OS not installed on the physical drive where you're doing it. (So you can use an Ubuntu live CD/DVD/USB for this.) I'd recommend editing your answer to account for this. (If you prefer, though, I could post a separate answer.)
  • Eliah Kagan
    Eliah Kagan almost 10 years
    This doesn't "free space in the hard disk" (which the question asks for). To do that the swap partition must be shrunk, removed, or reformatted with its own filesystem where data may be stored. Shrinking it is probably the best of those three options.