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.

Badum
  • 19

4 Answers4

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.

AlwaysTalkingAboutMyDog
  • 3,783
  • 2
  • 25
  • 38
  • 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 '19 at 08: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. – AlwaysTalkingAboutMyDog Apr 18 '19 at 03: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.

marosg
  • 1,303
  • I closed all programs and I think I have a lot of physical memory. 16GB. – Badum Apr 17 '19 at 08: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 '19 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.

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

Dennis
  • 21