0
Linux matrix 5.15.2-xanmod1-1 #1 SMP Wed, 17 Nov 2021 02:36:25 +0000 x86_64 GNU/Linux 
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS sda ├─sda1 btrfs swap 477dd81e-6a88-4987-b830-47bea1ec1f5d 0 87% /swap └─sda2 btrfs root 2067df62-8ff6-4b52-9814-e4d5d8cf1577 55.3G 48% / zram0 [SWAP] 
 total used free shared buff/cache available Mem: 1.8Gi 1.2Gi 111Mi 56Mi 557Mi 446Mi Swap: 5.5Gi 1.6Gi 3.9Gi 

vm.swappiness = 10

So my issue is that when ever my system is under load, ie if I have too many tabs open in firefox, or running vscode and firefox at the same time, my system gets really laggy.

However, when I check the RAM usage its stuck at 75% and never goes over that. So there is 25% of unused RAM.

How do I get it to use more ram before swapping.

0

1 Answer 1

2

First of all, you're assuming the slowness is due to the full RAM, which is not necessarily the root cause. Theoretically there should be other reasons and bottlenecks that would lead to slowness occurrences, such as extensive I/O, too many processes expecting CPU etc, and you should first rule out other reasons before you decide the culprit is the memory. You could use vmstat command, for instance:

$ vmstat -w 1 procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu-------- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 120951240 9412 8313416 0 0 0 2 0 0 0 0 100 0 0 0 0 0 120951248 9412 8313416 0 0 0 0 143 210 0 0 100 0 0 0 0 0 120950980 9412 8313416 0 0 0 20 116 238 0 0 100 0 0 0 0 0 120950980 9412 8313416 0 0 0 0 180 315 0 0 100 0 0 0 0 0 120951232 9412 8313416 0 0 0 0 145 285 0 0 100 0 0 

If you see relatively high numbers under the swap section - si (swap in) or so (swap out) - that could indicate that the system is working out on swapping memory pages in and out the RAM to or from the swap. If the values there are low, there's probably another reason for the slowness (which you could probably see under procs, io or cpu).

Assuming you do see high swap in/out values in vmstat, that indicates that the bottleneck is indeed the RAM getting filled up.

Here's the description of swappiness from the Linux kernel documentation:

swappiness

This control is used to define how aggressive the kernel will swap memory pages. Higher values will increase aggressiveness, lower values decrease the amount of swap. A value of 0 instructs the kernel not to initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone.

The default value is 60.

First, notice that your swappiness value (10) is significantly lower than the default (60).

Let's say your firefox has a lot of tabs; Most of them are idle and aren't used much. If the swappiness is low, the machine will try to keep their data in RAM as much as possible and to avoid swapping out until it really has to free some memory for new pages; This means that the machine will start swapping only in times of need, and then it might be a bit too late, and at that moment you'll see some lagging waiting for the old memory pages to get swap out.

If the swappiness is higher, the system will page out old and idle memory pages more frequently and ahead of time, leaving more of your memory free for new pages. When you access those tabs again it will page in their memory from disk to RAM so it might be slower, but since you don't use those tabs very frequently it's better to keep them in swap and keep more free memory pages available for new processes.

I would suggest to increase your swappiness, so old and unused memory pages are swapped out more frequently and not only when the memory reaches its limit.

1
  • 1
    Your advice helped me figure out the source of the problem. Increasing the swappiness did make it less laggy, but the real issue was with zram. It had a lower swap priority than the slower disk partition, but I guess it was still preallocating the ram space. /dev/zram0 wasn't getting used at all. So I increased the priority with ``` swapon --priority 100 /dev/zram0 --fixpgsz && swapon --priority 90 /swap/swapfile --fixpgsz ``` So now all my ram is being used. Much Thx Commented Nov 21, 2021 at 21:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.