3

So I understand that swap mem is used when computer runs out of space on ram.

Once there is available space in the memory how can I move contents of swap to ram so taht it doesn't slow me down?

3 Answers 3

5

If you really have enough RAM to not need swap, then issue:

/sbin/swapoff -a

This will remove all swap from the system, move any useful data to RAM and then prevent the system from using it.

This, of course, comes with consequences but that will become evident if you don't have enough RAM.

2
  • "comes with consequences" What are the consequences? Computer totally freezes?
    – Spikatrix
    Sep 9, 2019 at 9:33
  • The process requesting RAM may be denied. Other processes may be killed by the kernel. There is a school of thought that says a Linux system should have some swap for efficient virtual memory management but I haven't investigated that.
    – kronenpj
    Sep 9, 2019 at 12:05
1

1. if you want to "make linux stop using swap" You can change the swapiness

sysctl vm.swappiness=0

There are some great explanations here: https://askubuntu.com/questions/103915/how-do-i-configure-swappiness

2.move contents of swap to ram

I think you can only remove everything from your swap to ram by turning the swap off and then on. https://serverfault.com/questions/110436/linux-how-to-explicitly-unswap-everything-possible

0

If you really want to stop using swap forever you will have to do 2 things:

  1. as root (or sudo) run the command swapoff -a
  2. Edit the /etc/fstab file and remove/comment out the line that mounts swap partition on boot.

Without a proper sized swap partition, you will loose the ability to hibernate your computer.

It is better to reduce the use of swap by lowering swappiness to 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.