My laptop runnning 20.04 has only 8GB of RAM but 32GB of swap on NVMe disk.

When RAM usage reaches ~90%, the "Web Content" processes of Firefox 79.0 (only those which are greedy in RAM such as social networks) start to juggle with memory pretty fast, even if the guilty tabs are inactive, and even if I finally free huge quantity of RAM to reach a reasonable percentage of usage as shown in the screenshot below.

Firefox juggles with chunks of RAM

My issue with this behaviour is that it slows down the whole system on the long term. THe only workaround I found is to open many apps to force swapping, and then close them so that RAM is freed but swap rate remains high.

I have 2 wishes:

  • How can I tell the kernel to swap earlier? At least Firefox wouldn't have to deal with a few % of free memory. For instance just like the Windows pagefile strategy which seems to swap pages way before the Linux kernel does. My swapiness is currently 1, which looks the less terrible, I tried high values such as 60, 90, 100: it does not swap earlier but it's definitely slower.
  • How can I prevent "Firefox Web Content" from juggling with RAM chunks for no reason? Not only it uses 100% of 1 CPU a few seconds for each change, but also the full system becomes slow a few seconds, that's really nasty. Note: I am not wishing it could use less RAM, first because all browsers are RAM-greedy and second because I have 32GB of swap which can surely host pages from tabs I don't use so much. So I just want it to stop freeing memory that it will request again 10 seconds later.
  • This is a Firefox memory management issue not a Linux one. As I'm not 100% sure how to achieve the results you're aiming for, I have found some possible resources. You can modify per process swappiness by setting up cgroups: Cgroups Memory You could also consider establishing a memory limit for Firefox to make it swap earlier. I would just find a Firefox add-on to hibernate tabs though. – Kaleb Burklow Aug 4 '20 at 16:28
  • Yes, I sort of intended to circumvent that firefox issue by telling the kernel to swap. I'm currently starting firefox with systemd-run --scope -p MemoryLimit=3G firefox and it seems to work, let's see if it's OK on the long term. – myoan Aug 4 '20 at 21:36
  • UPDATE: After 1 day of test less RAM is used but the bouncing continues with memory. – myoan Aug 5 '20 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.