Fedora 35 using all my RAM as cache

About 10 days ago my notebook started to slow down, I started to check the resource utilization and there was no reason for the slowness, the CPU usage did not exceed 50% and the memory usage was at 5GB of the 8GB I have available.

Today I finally figured out why, despite only using 5GB of RAM, my Fedora has been using 2-4GB of RAM as cache. This has simply drained my RAM, slowing my notebook down.

As an example I leave two images:

In the first one I didn’t have any programs open or running in the background, I just turned on my notebook and left it idle for 5 minutes. The RAM usage was at 2GB while the cache was at 2.7GB.

In the second image I just opened a Chrome tab with the Ask Fedora home here, the RAM usage went to 3.4GB and the cache to 3.5GB.

Has anyone had this problem? Does anyone know how to solve?

That’s normal, and likely not the reason you’re experiencing slowdown.

Any otherwise free memory, on Linux, will typically be dedicated for cache and buffer space by the kernel, until it’s otherwise needed.
This is normal operation for the Linux kernel.

For example: I have 32GB of RAM, 13GB of which, is currently being used for cache.
If I were to preform a lot of disk I/O, that number would likely jump up even higher.

The 723MB of swapped pages is mildly concerning to me, but can also occur during normal operation.

What does your drive I/O usage look like?
You may want to consider adjusting your systems “swappiness”.

3 Likes

After researching I saw that using as much RAM as possible as a cache is really the Linux default. But I still think there’s something weird going on, it shouldn’t be using swape with so much RAM available yet.

What I think might be happening is the Kernel is not flushing this cache as I need RAM, so it starts using swape and the system slows down. See this new image, I have a few tabs in Chrome open and vscode, is using 3.8GB of RAM and 4.35GB of cache, resulting in 124MB of free RAM space.

I’ve tested a solution that seems to be working, I’ve added a routine in crontab to clear all cache every 10 minutes with the command:

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

That way I have free RAM and my Fedora doesn’t need to swap.

Does that make sense to you?

Caching is normal behavior of Linux systems, and actually is a feature to increase performance. Since RAM is faster than SDD/HDD, putting data that is often accessed in RAM cache is faster to read than going to the SDD/HDD every time. It also treats cache memory as available memory, so if an application actually needs RAM to do its work, it will remove data from cache and use that instead.

I believe you that you are experiencing a slow down in your notebook. But I don’t think you’ve proven a cause/effect relationship between that slowdown and cached memory.

It seems that your swap is only 4.25MiB, which means that the system is correctly operating by flushing cache to use as application memory when needed. If that swap usage goes up/down drastically then that would indicate that you may have a memory-related issue.

1 Like

It also looks like a lot of cpu usage for an idle system.I would check it after a reboot and if it’s still that high try looking at whats running.As far as memory as has been said it’s not unusual to have a fair amount of ram used along with cache.

In most cases chrome makes better performance at a cost of higher resources it always takes more ram and cpu. In my own testing.

In linux it is a feature cache in ram so it can access faster.

In this last image he was using little swape because I had already added crontab to clear the cache.

The caching isn’t the problem.
You could even turn it off but that would be a terrible idea, as your I/O performance would tank.
In many cases, the cache can essentially be treated as free memory, so long as it’s already been written back to the backing disks, which happens silently over time.

You mentioned that when the issue began, your system was using 5GB of RAM. 5GB out of 8GB, is a lot of RAM for that system, and it may have peaked higher before you caught it.
My guess is that your system reached a point where it had rather high memory pressure, and Linux began, preemptively, swapping pages to disk (slow). That would explain the high swap usage. This likely caused the slowdown you experienced, and it likely continued as your system had to, over time, swap the data back into memory (also slow).

If you adjust the swappiness, you can tune how soon the system begins to swap to disk, and only see that drop in performance when you reach very high memory usage.

As for what caused the high memory usage. Web browsers are notorious memory hogs, so I’d likely blame chrome. Maybe you have some extra tabs open, or a tab that was using excessive memory, or maybe it just needed to run a GC cycle, and maybe you only caught it afterwards.

It may also be, that your swappiness is set to begin swapping when your system exceeded around 5GB of usage. I’ve seen it set as low as 50% by default.
I highly suggest you try tuning your swap settings, as, right now, they are your most likely culprit.

1 Like

You could also check with system monitor processes on column “Disk read” and “Disk write” if there any current heavy activities on reads and writes to you disk drive. I have this experiences with heavy activities on reads and writes that causing the system to slowdown but on different OS.

Let me quickly clarify a key detail of exactly what those numbers mean, and how cache actually relates to them.

The “Cache” value you’re seeing is a part of free memory. That is, it’s how much of your free memory the kernel is using as I/O cache. This memory is still considered (from the position of userland applications) to be free memory, as the kernel will give it up as soon as it’s needed. It only serves to allow the kernel to better utilize the systems available resources, while improving performance. Without it, disk accesses would be drastically slower, and the overhead for doing things this way is minimal.

It is not counted under what you’re seeing as “Allocated” memory. Allocated memory refers resident and shared memory in use by applications, libraries, and specific kernel allocations (things like kthreads, modules, and SLAB/SLUB allocations).

2 Likes

Thanks a lot for the explanations, so actually my problem could be a bad swape configuration or a lot of disk operations load. I’m going to turn off my task of clearing the cache in crontable and I’m going to check these two possibilities.

@cptgraywolf do you have any configuration suggestions for my swape?

If your ram is less than 8gb
Swap=<ram
If more then 16gb of ram you have it is not worth it to have a swap but you can create one similar to 8gb

Swap may very well be contributing to the disk I/O bottleneck. If there, indeed, is one.
After all, swap, when using a swap-to-disk configuration, as is common, and as you have configured, is a disk I/O operation.

The biggest value you’ll want to adjust is, as I’ve alluded to, called vm.swappiness.
You can check it’s current value using ‘sysctl vm.swappiness’. The value is essentially the percentage of free RAM the system wants to have remaining before the kernel will begin to swap preemptively (This is a drastic oversimplification, but it works for this case. There are other values involved in this calculation as well.). As RAM usage increases into the the range defined by vm.swappiness, the system will put more and more pressure on swapping pages out disk.

The value you use for vm.swappiness depends on the system, and what you’re doing.
If you’re seeing a lot of higher memory usage, a higher swappiness could cause the system to become I/O bottlenecked early on, causing what’s knows as “thrashing”. The disk becomes overwhelmed by requests to read/write many non-contiguous regions, as the system continuously preforms many page swaps (something already inherently slow), while also still trying to handle normal filesystem accesses.
On the other hand, setting the value too high can result in a massive spike in I/O as the system panics to try and swap out unneeded pages when the memory usage suddenly gets too high. This doesn’t normally happen on systems with much more RAM (I have mine set as low as 5), but for a system like yours, it may be a bad idea to set it too low.

You’ll probably want to play with the value a bit, to see what works best.
You can set it temporarily using ‘sudo sysctl vm.swappiness=<new-value>’. I’d start somewhere between 20-40. probably try not to go below 10-15.
To make the setting permanent, you’ll want to crate a config under /etc/sysctl.d. I have mine under a config for a number of different virtual memory setting, in a file called “/etc/sysctl.d/99-vm.conf”, but the exact name doesn’t matter too much. Just follow the “<00-99>-<name>.conf” naming convention (eg. 55-swappiness.conf), and add the line “vm.swappiness=<your-value>” to the file.

Play with the value as needed, and don’t be afraid to ask questions if something is behaving oddly.

There may also be other settings you can adjust. I don’t use Chrome, but there may be tunables somewhere that control its GC cycle, or other such settings, that may help salivate high memory usage.

1 Like

I have 8GB of RAM, my swape are set in 7.66GB. So, I belive the size of swape it’s OK.

Yes it is okey and having more swap is not good as swap is far far slower thn the actual ram of your system. Swap is just something that provide your system a crashless stable system. And hang free and swap is just a buffer for your ram.

@cptgraywolf Once again, thank you very much for the explanations. The result of the command sysctl vm.swappiness was 60. I’m going to do daily tests here with the values 20, 25, 30, 35 and 40 before setting a final value.

Regarding Chrome, do you suggest any other more efficient browser?

Chrome is not a good browser it don’t have fingerprint protection, tracking protection and ads block plus it collects everything you type everything you search even in incognito mode so it really not recommended. But if you don’t care your security and privacy chrome is good.
Now my recommendation is use firefox, librewolf, tor, chromium, ungoogled chromium, brave, vivaldi(ui is not open source).
Note Chrome is base on chromium but it adds stuff to make it a bad browser.and when you want a browser for any os any device try opensource one.

Unfortunately, as of today, there are really only two core browsers left which support the modern web.

Your choices are either Chromium (the upstream for Google Chrome), and one of it’s dozens of derivatives, or Mozilla Firefox, and one of it’s, entirely forgettable, and likely, even more buggy, offshoots.

The browser industry is currently caught in a death spiral of such rapid competition, and fast-paced development, in an attempt to keep up with the quickly evolving standards of the web, that neither gets the needed time to properly optimize in the way they should. While there have been strides in browser efficiency, such things often take a back seat, in the face of ensuring that they support the latest protocols, standards, and security. The result being that, every year, both browsers become a little slower, harder to maintain, and much harder to compete with, as, taking the time to properly optimize every feature, would take weeks of development time that nether team can afford in such a fast-paced landscape, and anyone trying to start from scratch has miles to run to play catch-up with the two biggest competitors.

On top of this, modern sites often abuse the features of current browsers, in a brutal attempt to “stay up-to-date”. The result are sites that are bloated with over complicated JavaScript, dynamic content, ads, and tracking cookies and software, resulting in a terrible, bloated mess (See Lunduke’s parable of the dynamically loaded refrigerator). A site that should be primarily static content, take up a few kilobytes to a few megabytes, and take a second, or less, to load, will often be weighed down with several megabytes of JavaScript alone, take several seconds to load in content from every possible source on the internet (while simultaneously violating your privacy), and end up consuming hundreds of megabytes of RAM, or more.

To say that the current state of the web is, “bleak”, would be, entirely justified, and, an understatement.

While there are projects attempting to build browsers that are more efficient, most lack the funding, the development force, and the support needed to keep up with the modern web. Many are left in a state of poor maintenance, where, while looking something up on Google may be perfectly fine, some sites may fail, or flat out refuse to load, with some causing outright crashes.

Essentially, in the end, until we get a new, real competitor in the browser space, there really aren’t any meaningful choices. They’re all the same internal engines, running the same, unfortunate, bloated, code. Neither side is winning this fight, and we all get to pay for it in system resources.

Apologies for the rant there, but this is a rather frustrating subject.
I’d love to say that I use Firefox because it’s objectively better, but the truth is, I’ve only stuck with it because everything else is, pretty much, equally as bad.

You’re right @cptgraywolf , unfortunately there’s not much we can do. I ended up choosing to test Brave, I liked the privacy ideals it defends, even though I know that deep down it’s just a Chrome that doesn’t send my data to Google.

I will follow my tests to solve the performance problem. @cptgraywolf and @frankjunior , thank you very much for all your attention.

One other thing to note.

If you don’t restart your system between tests, and there is preexisting data in swap, it may interfere with your results.

You can simply disable and re-enable the swap to force it to clear by running ‘sudo bash -c ‘swapoff -a && swapon -a’’. This may take a while, as any data in the swap will be read, and either moved back into memory, or discarded, but it will leave you with a clean swap.

This can also be useful to test if reading data back from swap is causing a slowdown.