Ask Your Question

How to force the system to donot use the swap memory in fedora 21?

asked 2015-04-16 15:49:17 -0600

ddkroyal001 gravatar image

How to force the system to do not use the swap memory in fedora 21? System become very slow when its uses the swap memory of hdd and even ram is still 50% available in memory...

edit retag flag offensive close merge delete



How much RAM do you have?

On Linux machines with 8 GiB or more, you can often get away without having a swap file. Ultimately it will depend on how many memory intensive applications you have running concurrently.

I have a 16 GiB machine, which is often running an 8 GiB KVM instance, plus Firefox, Thunderbird, Nautilus, Libre Office, Totem, Clementine, Evince and numerous Gnome shell plugins (not to mention the plugins for the other apps). I rarely hit more than 80% usage and I don't have a swap file.

snowolfe gravatar imagesnowolfe ( 2015-04-16 22:27:29 -0600 )edit

One other thing to consider with the swap file is Hibernate. If you use hibernate to suspend your machine, then the swap file is used to offload the entire RAM to disk. Consequently you will need the swap file and it will need to be at least as big as the amount of RAM you have - I recommend more to allow for the possibility that the swap file is already in use.

snowolfe gravatar imagesnowolfe ( 2015-04-17 22:17:21 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2015-04-16 17:09:35 -0600

aeperezt gravatar image

updated 2015-04-16 20:04:12 -0600

You can turn swap off by issue as root or with sudo this command on the terminal

swapoff -a


sudo swapoff -a

edit flag offensive delete link more

answered 2015-04-17 11:09:09 -0600

masteroman gravatar image

If I recall correctly there is also a possibility to set vm.swappiness level via sysctl program

To check current value of this option you can use following command:

sysctl -a | grep vm.swappiness

And with this command:

sysctl -w vm.swappiness=0

you can turn it off completely (system will not swap anymore). Setting this option value to 1 will allow swapping to disk only if RAM is exausted. To permanently save that option accross reboots you can define it in file in /etc/sysctl.d/ directory (/etc/sysctl.d/99-sysctl.conf for example).

edit flag offensive delete link more



*note , turning of swap is generaly not recommended because if you run out of free RAM your OS might crash.

masteroman gravatar imagemasteroman ( 2015-04-17 11:17:09 -0600 )edit

If you must keep a swap file due to limited RAM, or heavy utilization, then a low vm.swappiness value (1 to 10) is definitely the way to go.

snowolfe gravatar imagesnowolfe ( 2015-04-17 22:12:18 -0600 )edit

Nice wish I could upvote twice.

somethingSomething gravatar imagesomethingSomething ( 2015-04-19 10:25:24 -0600 )edit

answered 2015-04-16 23:24:09 -0600

snowolfe gravatar image

As noted in the answer from @aeperezt, you can use swapoff -a to disable swap and swapon -a to enable it again - use swapon -s to see a summary of swap file usage and priority etc.

If you want to permanently remove swap space from your system:

  1. Switch to root using:
    sudo -i
    Use your password.
  2. Disable swap:
    swapoff -a
  3. Create a backup of the fstab file (we will edit it next):
    cp /etc/fstab{,.orig}
  4. Edit the /etc/fstab file to remove the swap file entry (use an editor you are comfortable with, for example vi or nano). It will look something like:
    /dev/mapper/HOST-swap   swap   swap   defaults  0 0
    The first entry on the line may point to a device file (/dev/VALUE) or possibly a UUID=some-random-long-string -- just look for the swap entries and delete the entire line.
  5. IMPORTANT: To avoid running into issues when you next reboot, check that the /etc/fstab file is valid by issuing:
    mount -a
    swapon -s   # to verify swap is not active
    If it reports a problem, then fix the problem in the fstab file before continuing (remember you have your backup from step 3).
  6. Ideally you would reclaim the disk space by using tools like lvm or btrfs and/or fdisk/gdisk, but the steps needed are very much dependent on whether you are using lvm or btrfs or raw partitions. Too many combinations to list here.
edit flag offensive delete link more


Is it safe to use the 'swapoff -a' when system is still using swap memory ?

ddkroyal001 gravatar imageddkroyal001 ( 2015-04-17 11:15:49 -0600 )edit

@ddkroyal001 To be honest, I am not 100% sure. My understanding is, as long as you have enough free RAM to accommodate the current swap usage, then using swapoff -a will transfer the contents of the swap space back into RAM as part of disabling the swap.

snowolfe gravatar imagesnowolfe ( 2015-04-17 17:54:06 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2015-04-16 15:49:17 -0600

Seen: 8,374 times

Last updated: Apr 17 '15