Limit CPU and Memory to Firefox and chrome web-browser on a Linux desktop

Limit CPU and Memory to Firefox and chrome on a Linux desktop

Google Chrome and Firefox web browsers make extensive use of Memory and CPU utilization when multiple tabs are opened. It is not possible to limit ourselves to a certain number of tabs but we can limit the resource utilization for these browsers diligently and to make sure they don’t cross the assigned limit.

Using systemd’s transient scope units one can allocate a certain amount of memory and CPU shares to Firefox and chrome web-browser applications. systemd’s transient Units are only allowed for a super user(root) hence the need is to first allow the user or group that wants this feature.

Add the following polkit rule in /etc/polkit-1/rules.d/60-systemd-manage.rules file. The following rule makes sure that the user ‘test’ is allowed to start systdmd Units. Change the username of your choice.

Alternatively, a group of users can be granted the same privileges through the same rule with just a little modification. Make sure the user is part of the ‘admin’ group.

Now login to the test user account and validate if the user can start and stop systemd services.

Now modify the Gnome Launcher file of firefox or chrome from /usr/share/applications directory. Modify the Exec parameter as below to set 5G Memory limit and give 200 CPU cycles limit for to firefox and chrome. Generally 1024 CPU cycles is equivalent to 1 CPU. Giving 2048 CPU cycles would allow chrome and Firefox to use two CPUs if required.

Now logout from the gnome session and then re-login to validate the feature.

Test Result

Now execute the systemd-cgtop command to monitor the utilization of firefox and chrome browsers.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ramesh Sahoo

I describe myself as a troubleshooter, problem solver, techie, quick learner, and good mentor. I have 11+ years of IT industry experience in many MNCs.