Swap memory is being used for no reason

The system freezes
CPU usage : 3% - 10%
Ram usage : 1.3 gb out of 7.7 gb
Swap usage : 0.8% out of 2 gb

I think the swap is the reason for frequent freezes
If, any thing else is the reason please tell me

Thanks in advance

Your swap is being used so as to free up more RAM for other things.

The 1.3 GiB of RAM usage you report is only data and code. Most of the RAM will actually be used for caching, but this does not reflect in the usage you are seeing.

Also note that what users often report as “freezing” is actually only a temporary effect on the user interface while the system is conducting some high-priority task, such as I/O (which includes swapping).

1 Like

How can know the real usage then??

In a terminal, type the following command… :arrow_down:

free
1 Like
               total        used        free      shared  buff/cache   available
Mem:            7860        2277        2077         579        3505        4702
Swap:           2047          15        2032

Okay or swap can be fixed

So, that tells you that approximately 2.0 GiB is used by applications and data, plus another ~3.4 GiB worth of buffers and cache and just over 0.5 GiB worth of shared memory — e.g. files on a tmpfs.

In other words, about 6 GiB of your RAM is effectively in use.

Then two gb is free(nearly)

Why swap working then ??

Because those 2 GiB free may be needed at any time, and it’s easier to move things to swap before that need arises than to only page it out in the last moment.

Thanks for information
So can I solve this by reducing ram usage of the system ?? If, yes tell me how.

Or upgrade the ram ???

That would be the better solution, yes.

1 Like

Thank you
How much then ???

Well, technically 8 GiB is enough — we’ve got people here at the forum with quite a bit less than that — but then the system will still be swapping, depending on what you’re running. Browsers for instance are very memory-hungry.

I would say that upgrading to 12 GiB will already be plenty, but depending on the cost of the memory modules, you might be better off upgrading to 16 GiB.

I am running my system here in 16 GiB, without swap, and I haven’t run into any problems yet.

[nx-74205:/dev/pts/3][/home/aragorn]
[aragorn] >  free -m
               total        used        free      shared  buff/cache   available
Mem:           15881        3232        6172        1715        6475       10600
Swap:              0           0           0
3 Likes

Thank you so much for information.

You allocated no swap??

1 Like

Hi,

if the “system freezes” really come from swapping, then you could tell the system to swap less.

If you run the command

sysctl --values vm.swappiness

you’ll probably see a value about 60.

If you want your system to swap lesser, then you could set the swappiness to a lower value by creating a config-file into your sysctl.d folder. Just type:

sudo touch /etc/sysctl.d/99-sysctl.conf

The “99” will ensure that this file will overwrite previous set values in sysctl.d, for example in 60-sysctl.conf, if such would exist.
Then add the following line to the new file:

vm.swappiness=20

If you are on KDE (or using kate as your text-editor), you can do it by simply open the file, add the above line and save (you will be asked for root-password). Or you just use nano from the terminal with root permission.

sudo nano /etc/sysctl.d/99-sysctl.conf

After you added the line and saved it to the file you can either reboot or run the command:

sudo sysctl --system

When you now run the first command again

sysctl --values vm.swappiness

the value should be 20, or the value you have set.

I have 16 GB RAM and run with a swappiness of 10. But I ran my system with 8GB of RAM and a swappiness of 60 for years, and to be honest, I had no freezes because of swapping. I’m on a i5-6600 CPU.

So I don’t know if your freezes come from swapping. If so, the above could help. And whether you need more RAM or not, as mentioned by Aragorn, depends on what you want to do with your computer. I am running audio production applications, that are needing much RAM. If you are just browsing and watching streams and video, 8GB should be enough.

As also stated above, many users in these days, don’t even use any swap.

1 Like

Sorry for the belated reply.

Yes, I did allocate a swap partition when I installed Majaro in 2019 — as the matter of fact, two of them, even, on different drives — but at that point, my machine had 8 GiB of RAM. After about six months, I decided to upgrade to 16 GiB RAM, and considering that this left me with a lot of headroom, I then disabled the swap partitions.

So I do have them, but I’m not using them. :slight_smile:

Before you splurge on more memory, you could (reversibly) try putting swap in memory, since you apparently have plenty free. I do this on a Manjaro install on an 8GB machine. Check this article:

Hope this helps,

R

I checked and I am surprised to see I have 10 swappiness.

Can I just disable the swap not remove the allocated space? Just to check

Which manjaro edition were you using in 2019??

I was and am still using the Plasma edition, on the Stable branch. It was called Manjaro 18.0.4 Illyria at the time, and I’ve seamlessly kept it updated ever since. The only changes to my hardware in all that time were…

  • the upgrade from 8 GiB to 16 GiB;
  • replacing a broken monitor by another one of the same dimensions and resolution; and
  • replacing a broken PS/2 keyboard by a USB keyboard.

I am currently still running the 5.4 LTS kernel, though, but that kernel wasn’t even out yet when I installed Manjaro. So I had been using 4.18 (I think), 5.1, 5.2 and 5.3 before that.

Okay, Thanks

Which kernal is better lts or rt(real-time)