How can I clear my SWAP?
9,359
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.
Related videos on Youtube
Author by
Badum
Updated on September 18, 2022Comments
-
Badum over 1 year
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.
-
goo about 5 yearsSwap 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".
-
Badum about 5 yearsWhat can I do? Switch off SWAP?
-
user68186 about 5 yearsWhich version of Ubuntu are you using? How much RAM does your computer have?
-
Soren A about 5 yearsIf 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.
-
Badum about 5 yearsUbuntu 18.04 16GB RAM
-
-
AlwaysTalkingAboutMyDog about 5 yearsYou should explain the commands in your answer (incase the link dies).
-
Badum about 5 yearsYES. I tried it but I can't do this, because I have full memory and I can't use cammand swapoff.
-
Badum about 5 yearsI closed all programs and I think I have a lot of physical memory. 16GB.
-
marosg about 5 yearsWe 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 -
AlwaysTalkingAboutMyDog about 5 years@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.