For the longest time I was torn over making Linux default on my main computer. I have a Dell Inspiron 3670 with a 7th Generation Intel Core i5-8400 CPU @ 2.80GHz × 6 and 12gb of RAM. It also has Intel Optane memory. I can’t remember how much it was. Anyways, I loaded Linux Mint 20 to it and was using it without any problems. I replaced the 1 gb hard drive with a 500 gb SSD. I was reviewing system resources with Htop one day when running a virtual machine and noticed about 20 mb of swap being used. This was odd to me because out of 11.5 gb of memory I was using around 6 gb. I understand somewhat the purpose of swap, but being at 50% capacity and using swap was odd to me because I had an old dell that ran on 8 gb of RAM and I had never noticed the swap being used. I tried clearing the swap time and time again but it would start using it every time. Sometimes while at normal idle with no extra programs running. I did not want this to affect my SSD so I reloaded my system and put the home folder and swap file on the 1 gb hard drive and loaded the system to the SSD. Alas, it was doing it again. I was okay with this because the swap was on my HD and not the SSD. That was until I was running two virtual machines in virtualbox and they were extremely slow and it seemed to affect my host system. I wiped virtualbox and installed Gnome boxes, but my question is this: Does this have something to do with the Intel Optane Memory within CPU or bios, or is it something else? Thank you in advance for your answers to this problem. If any more information is needed, just let me know.
Forgot to mention that it keeps increasing at times to 50 mb of swap use. I tested the theory of swap use on an old laptop with 4 gb of memory. I got to about 75% of RAM usage before swap was being used. This is why I am puzzled about a 12 gb of memory at 50% use was using swap.
Swap file or swap partition?
I’m assuming file. I’m a noob and trying to learn these things. Heck it may be a partition for all I know. Sorry. I’m trying to google to find out how to find out.
/dev/sdc1 partition 3998716 0 -2
swapon -s and it will tell you the type. Linux Mint uses a swapfile by default. This might be worth posting on the Linux Mint forum. What about this, how much RAM is allocated to the VM?
@GUI_Linux_Guy Can you check the swappiness by using the terminal output “cat /proc/sys/vm/swappiness” ? This number is the setting that will set up how sensitive the system will go into swap . Usually it should be 60 in the default, but if you prefer to use swap only when the system memory is close to be full, then you might change it into 5 - 10 range.
It is a 4 gb partition. When I had mint installed before it was a swap file. It happened on both.
The swappiness is set to 60. On the last set up on LM 20 I had it set to 10 and it still did it. What I really need to see is how and why the swap is used. It doesn’t make sense at 50% that swap should be used. At least from what I’ve heard in the past about swap.
After doing a little work in virtual machines and writing an ISO to a USB, I checked my system monitor and this was happening (this was after setting the swappiness to 10):
I learned something new about swap and it reminded me about this thread.
Swap is going to act preemptively, and move stuff into swap before it is necessary. That is not to say that your machine is going to the disc for this information. It is really a backup in case the machine needs to allocate a bunch of memory to another task, or many tasks.
Instead of swapping out to the swap file/partition at the exact moment a bunch of new tasks fill up your RAM, which would cause a system slow down, the system can free up that memory immediately knowing there is a copy safely in swap.
@Ethanol, so swap is just storing the information? What I see as “swap in use” is not swap in use, but just how much storage is taken up on the swap partition or file, right? What I was afraid of was swap using this space kinda like writing XX mb from the time I seen it until I restarted my computer consistently. So swap is just storage that is stationary and just being stored to free up actual RAM, right? Thank you for that information and your answers to my questions if you please!
The way that swapping works is quite complicated. And my previous post is kind of a poor description.
swap is not for the overflow of your entire pool of RAM. Swap is for preemptively storing data from the many small chunks of memory your RAM is divided into, before those chunks get completely full.
Ultimately there will almost always be some swap in use. RAM is grouped into many little chunks. When one area reaches a threshold of “fullness” it will start writing to swap so it doesn’t run out of space in that chunk of RAM. Swappiness has no affect on when swapping occurs but instead changes what gets swapped.
For much more depth on the matter I found this source: https://www.howtogeek.com/449691/what-is-swapiness-on-linux-and-how-to-change-it/ which in turn sources the Linux Kernel source code.
A common mistake among new linux users, myself included for a very long time, is caring about swap. You need to have some swap for optimal performance, but unless you’re willing to delve deep into the what the kernel does with memory, the best idea is to just leave it alone.
Linux is a very complex and refined kernel (honestly it’s a piece of art), and there are all sorts of smart things going on to optimize the runtime of your system.
If you look closely at memory (RAM) usage you’ll also notice that it increases over time, and doesn’t get back to an empty state even if you close everything but your desktop environment. That’s by design and shouldn’t be of any concern to you.
With other operating systems (mostly windows) you typically care about this stuff because the kernel isn’t as advanced as Linux. But in Linux, you don’t have to worry about it.
Let your swap get used, and don’t mess with swappiness, that’s my advice.
Lay back and enjoy your system, do what matters to you and be happy! If you’re into OS development, you can indulge in studying the way the kernel manages memory, along with many other wonderful things like process and I/O scheduling.
@gabmus, thanks for that great information! It is much appreciated!