Request for guide/tips/suggestiong for reducing ram usage

Due to some unforseen hardware issues, I am running with a restricted set of RAM, i.e. 8GB. I am running KDE plasma 6. I need some guides or hints or suggestions on how to reduced my RAM consumption so that disk based swap does not get used, i.e. disk trashing is avoided.

Can you please provide me with some options that can be used? Some tips or configurations that I can use? For example can I reduce the size of /run mount point to say something like 10% of actual physical RAM? Any suggestion would be welcome.

Currently when the system boots up, it takes up about 20% of the existing Physical RAM.
On using Firefox, KDevelop and ZIM the RAM consumption shoots up in excess of 75%. I am trying to keep the number of tabs to a bare minimum, but it still does not help. With only Firefox, ZIM and a terminal open the RAM consumption goes in excess of 45%.

That wouldn’t be an issue for modern SSDs.

You could use Zram (refer to ArchWiki for howto) for smoother memory and swap management.

My suggestin would be Zram plus a swapfile a few GB in size for when there is a need for some pages to be pushed out of the memory. And let Linux kernel handle things.

I wouldn’t mess around with reducing the size of /run as you may run into other issues for it not having enough space. You can check the amount of its actual RAM consumption:

df -h /run

You will see that /run does consume some RAM. It is for storing runtime data, but it is typically small and dynamically managed by the kernel.

This it the output of df -h /run that i ran. As you can see it mapped to 1.6GB.

$ df -h /run
Filesystem     Type   Size  Used Avail Use% Mounted on
tmpfs          tmpfs  1.6G  1.8M  1.6G   1%  /run

Thanks for suggesting Zram. Is this the link that I should be looking at? Or something else?

Dont know if this helps, this is the output of the free command

$free -mh
               total        used        free      shared  buff/cache   available
Mem:           7.5Gi       3.4Gi       2.3Gi       1.1Gi       2.8Gi       4.1Gi
Swap:           16Gi          0B        16Gi

I would follow this one, it’s explicitly for eos.

It’s nothing in there explicitly or specifically for EOS except the title.

It is basically copy-paste from ArchWiki.

And some specific user’s preferences, like:

zram-size=ram
compression-algorithm=zstd
swap-priority=60

There is a zram and there is a zswap? What is the difference between them?

If I recall on Windozs there used to be a feature called as ReadyBoost. Is something similar possible on Linux? My Laptop has a microsd card free, which I typically do not use. So if I were to get say 64GB microsd card, can I use it for swap, say 32 GB and RAM, say 16GB? If yes how can that be achieved?

From ArchWiki:

The difference compared to zram is that zswap works in conjunction with a swap device while zram with swap created on top of it is a swap device in RAM that does not require a backing swap device.

zwap as it is mentioned is already enabled in the kernel. It provides a compressed cache for swap pages in RAM.

zram on the other hand is a kernel module you will be installing yourself. It will create a compressed block device “mounted” in RAM for harboring swap pages. That is why it shows up as a partition if you look at:

sudo swapon -s
        
Filename				Type		Size		Used		Priority
/dev/zram0                              partition	4194300		512		100
/swap/swapfile                          file		8388604		0		-2

If you will be using zram, you would need to disable zswap in the kernel.

Honestly, from an end user’s point of view, in practice, I am not sure it makes much of a difference which one you use. Except zswap works in conjunction with a swapfile or swap partition. zram doesn’t need that.

If the disk tear and wear is your concern, modern sdds use wear leveling algorithms which aim to prolong the lifespan of the drive by preventing any single cell from being overused

Possible? Yes.
would be slower than your internal disk.
Lower lifespan, I would suppose, than your internal disk.
Personally, I wouldn’t choose this option as I see no gain in performance or avoiding disk tear.

1 Like

zram create a ramdisk which can be used for swap or other purpose, zswap is specific for swap.

It’s pretty slow for swap use, I guess you will have better performance with a good USB stick.

So no micro sd card.
ZRAM and ZSWAP are only used when SWAP comes into the picture. Currently i have 8 GB of RAM and a separate SWAP partition. Till now SWAP is not being used.

How do I reduce the RAM consumption by KDE? Currently at boot-up KDE consumes about 1.7 GB of RAM. Any settings that I can change to bring it down to say 1 GB or say below 1 GB?

It’s a lot, I don’t know KDE, there’s maybe a tool for checking memory consumption in detail.
You can also install a CLI tool like smem (in the AUR).

yay -S smem

then you can check what’s memory hungry :

sudo smem -tk

(sudo so that you can also check applications launched by root and not by the user only)

Perhaps try disabling things you’re not needing in Background Services (un-tick them on the left).

I’d suggest being a little cautious with this though. Be careful not to deactivate something that’s going to be integral.

Honestly, messing around with the services, how much would you think the OP could shave off the memory usage? A couple of hundreds of MB?

With 8GB RAM, one needs to adjust the expectations and usage to the limitations. I have a system with equal amount of RAM running Arch and GNOME. It runs fine for my use case which surely is different from the OP but yet the fact remains.

Adding zram + some GB of swapfile as has been suggested is a viable option plus adjusting your expectation and adapting your usage to the hardware limitations. There is no more to it as I see it.

Perhaps not even that much. It’s curious that you might find issue with considering it though. It’s by no means intended as an alternative to what you’ve already suggested. It doesn’t need to be, both can be done.

Disabling unnecessary services is a reasonable step. It’s something I’ve been doing on installs for years, in the past under Windows, and now under Linux.

  • I have manually specified my location for night light, I don’t need automatic location updates for it.
  • I don’t use any bluetooth devices, so the Bluetooth service is superfluous.
  • I can turn off the yearly donation request service :sweat_smile:
  • I don’t need my device LEDs to syncronise with Plasma’s accent colour.
  • I don’t use the Firefox Flatpak so I don’t need a service that provides support for it.
  • I don’t want Plasma browser integration, let alone a reminder.
  • I don’t use a proxy, so the verifier is unnecessary.
  • I prefer not to have removable devices auto-mounted.
  • My NAS uses SFTP, not SMB, so I can disable the SMB watcher.
  • My desktop has no touchpad, so I don’t need that.

That’s my use case, others may choose entirely different things.

It may not free up loads of RAM, but it very simply stops things from running and consuming resources that are entirely unnecessary.

1 Like

No I wasn’t disputing the disabling of services, per se, in order for them to stop consuming resources.

But, since the focus of OP is the RAM usage, as you yourself admit, disabling as many services as not rendering your DE useless, would only get you that far. In terms of RAM gain, the amount would be insignificant thus irrelevant for OPs wish to decrease the RAM usage.

If the focus is having less RAM being occupied by the DE itself for having it available for other usage, I see no other options than to opt for a more light weight DE or to take it one step further to use some WM.

I’ll leave that for @Archie1 to decide.

Yeah the same thought crossed my mind. But the brief was for reducing RAM consumption under Plasma, so figured lets exhaust that option first :sweat_smile:

Yes me too. But at end of the day @Archie1 would need to adjust their usage to the reality imposed by the limitations of the hardware. You cannot work around that.

You choose KDE, that’s perfectly fine, but then accept 1.7 GB (give or take) of RAM being already occupied at fresh boot. And then take it from there.

But this? Permit me to doubt.

At any rate, I guess, I have already paid my 2 cents here, so…

Have you thought of adding a window manager like i3 or openbox? They can be installed alongside with no issues. I have i3 installed as a just in case option.

Don’t really see you doing this, I think even LxQt and LMDE used around a gig. (Could be wrong just thinking of when I was setting up an old laptop with only 4gb).

Yeah, changing DE is probably the only way to go if you want lower ram usage, KDE is not known for being the lightest around (even if it’s not that much). Even by disabling services and such i don’t see it going much lower, the lower i got it was around 1.2~1.3Gb on a fresh install.

You can also try to use other, less memory hungry apps like a lighter browser, disabling useless extensions, unloading unused tabs, blocking useless scripts,images etc… to reduce firefox ram usage. (minimal improvement but everything is good to take)

If you are using Integrated graphics you could shave a little bit more memory by disabling certain visual effects and transparency/blur, but again, that would save only a couple of Mb and won’t really be noticeable.

At the end of the day, the real improvements will come at the cost of a quality of life reduction, it’s up to you to see if you are ready to make that sacrifice. If not, swap is probably the only way you can get more usable “ram”.

1 Like