1

I can't clean SWAP memory. It cause that my Linux lag. I try clean but I got an output: you just be superuser.

I using jupyter notebook to learning convolution neural network. At the end of each epoch my SWAP is increasing.

6
  • 2
    Swap space is used for paging out memory that has been allocated by a program, but is not in current use. Swap is not slowing you down, but it looks like there's a memory leak in "learning convolution neural network".
    – waltinator
    Apr 16, 2019 at 22:18
  • What can I do? Switch off SWAP?
    – Badum
    Apr 16, 2019 at 22:36
  • Which version of Ubuntu are you using? How much RAM does your computer have?
    – user68186
    Apr 16, 2019 at 22:38
  • If swap is slowing your system down, it is because you are using more RAM than are available, Either reduce the usage or buy more memory.
    – Soren A
    Apr 17, 2019 at 6:00
  • 2
    Does this answer your question? How to empty swap if there is free RAM? Sep 23, 2022 at 15:28

4 Answers 4

4

Have you tried turning it off and on again?

As funny as it may seem. You can forcefully clear your swap by turning swap off and on again:

sudo swapoff -a
sudo swapon -a

This will mark all swap partitions as unused by swap (then re-marking them used). Note that this will force all swap memory into physical memory - meaning some bad things might happen if you don't have enough physical memory.

If you're using swap up, you might have a memory leak as someone else has suggested.

2
  • YES. I tried it but I can't do this, because I have full memory and I can't use cammand swapoff.
    – Badum
    Apr 17, 2019 at 8:56
  • 3
    @Badum then you are clearly lagging because your applications are using up too much memory. I'd ask another question about your memory usage problems (as opposed to unable to clear swap) and post some details about your system, how much ram you have, and what programs you are running. Apr 18, 2019 at 3:19
1

First you need to understand how swap works - when programs demand more memory than is physically available, kernel will move memory occupied by idle programs to swap to clear up memory for currently active program.

Hard to tell without more details, but it can be perfectly ok that your program needs more memory at the end of each epoch (whatever that means) and that forces kernel to use swap.

Don't bother cleaning swap. It shows swap in use even after it was used and it is not slowing down anything at that time. And when it is used, cleaning up makes no sense.

You have two options - close other programs which you don't use or install more physical memory. That will avoid using swap.

2
  • I closed all programs and I think I have a lot of physical memory. 16GB.
    – Badum
    Apr 17, 2019 at 8:58
  • We really cannot tell you more without more details, it may be perfectly ok what is happening in your system and also there may be a problem. Check the memory status before you start with free program, then do the same during the run, then during the peak and then after it finishes peak. Post it here and maybe we can find what is going on
    – marosg
    Apr 17, 2019 at 11:08
0

Badum, have you tried doing this?

  1. sync; echo 1 > /proc/sys/vm/drop_caches

  2. sync; echo 2 > /proc/sys/vm/drop_caches

  3. sync; echo 3 > /proc/sys/vm/drop_caches

    You can find the explanation here. Also, I got the commands from the same website.

1
  • 4
    You should explain the commands in your answer (incase the link dies). Apr 17, 2019 at 5:28
0

drop_caches is usually only useful when doing benchmarks and timing tests of file systems and block devices, or network attached storage or file systems. You shouldn’t use any drop_cache in the first place in any real production system. It is only for testing and debugging.

P.S. It did not let me comment so I wrote it here

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .