Score:2

memory empty but swap full?

cn flag

I'm on Ubuntu mate 21.04 with swappiness set to default 60. Why is the system predominantly using the swap if there is ~55 GB of empty memory? The swap file is on nvme drive but memory is still faster so why with the default swappiness it is not being used more?

enter image description here

muru avatar
us flag
It just means that whatever process whose memory was pushed into swap is just not active for it to be pulled back into RAM. If it were, it would be.
us flag
With so much memory, you really don't need swap. Disable swap and use zram instead.
heynnema avatar
ru flag
@ArchismanPanigrahi My personal opinion is that **every** machine needs swap, no matter how much RAM. I recommend increasing the /swapfile from 2G to 4G, and setting vm.swappiness=10.
heynnema avatar
ru flag
Status please...
heynnema avatar
ru flag
Status please...
Score:4
cn flag

Indeed, a lot of swap is used despite low memory use and plenty of free memory. The current status depends on the history of use, though. If earlier in the session, memory was heavily used, unused pages would be swapped to disk. These pages will not be removed from swap, unless they are needed again. If not needed, they just will remain in swap even if a lot of free memory has become available again.

ThomasHunter avatar
cn flag
It is the other way around. That's why I'm asking because it is surprising to me. There is 7.1 GiB used and 55.5 GiB free. Yet instead of utilizing more of the memory the system is filling up the swap.
vanadium avatar
cn flag
Right, I see. Thank you for correcting. That could be a result of use "history": swapped memory will not be released even if memory is being freed by other processes. To have the whole picture, you should actually follow how memory use and swap use evolve as you do particular things on the computer - I changed the answer.
Score:2
ru flag

Historically, a 2G /swapfile has never been enough.

Let's increase your /swapfile from 2G to 4G, and change your vm.swappiness value...

/swapfile

Note: Incorrect use of the rm and dd commands can cause data loss. Suggest copy/paste.

In the terminal...

sudo swapoff -a           # turn off swap
sudo rm -i /swapfile      # remove old /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile  # set proper file protections
sudo mkswap /swapfile     # init /swapfile
sudo swapon /swapfile     # turn on swap
free -h                   # confirm 64G RAM and 4G swap

Edit /etc/fstab, using sudo -H gedit /etc/fstab or sudo pico /etc/fstab.

Confirm this /swapfile line in /etc/fstab... and confirm no other “swap” lines... use SPACES in this line... confirm NO TABS...

/swapfile  none  swap  sw  0  0

reboot                    # reboot and verify operation

vm.swappiness

Because you have so much RAM, set your vm.swappiness=10. This will reduce swapping on your configuration. It sounds like you know how to do this (edit /etc/sysctl.conf), but if not, please ask for further instructions.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.