Skip to main content

How to Limit Firefox/Google Chrome CPU and RAM

Google Chrome and Firefox web browsers make extensive use of Memory and CPU utilization when multiple tabs are opened. We can limit the CPU and RAM for those browser, or other application by using systemd.

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.
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.systemd1.manage-units" &&
        subject.user == "test") {
            return polkit.Result.YES;
    }
});
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.
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.systemd1.manage-units" &&
        subject.isInGroup("admin")) {
            return polkit.Result.YES;
    }
});
Now login to the test user account and validate if the user can start and stop systemd services.
$ systemctl restart sshd
  [test@localhost ~]$ systemd-run --scope sleep 30
    Running scope as unit run-2845.scope.
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.

Firefox: /usr/share/applications/firefox.desktop
From:
Exec=/home/test/firefox/firefox %u

To:
Exec=systemd-run --scope -p CPUShares=200 -p MemoryLimit=5G /home/test/firefox/firefox %u
Chrome: /usr/share/applications/google-chrome.desktop From:
#Exec=/usr/bin/google-chrome-stable %U
To:
Exec=systemd-run --scope -p CPUShares=200 -p MemoryLimit=5G /usr/bin/google-chrome-stable %U
Exec=systemd-run --scope -p CPUShares=200 -p MemoryLimit=5G /usr/bin/google-chrome-stable
Exec=systemd-run --scope -p CPUShares=200 -p MemoryLimit=5G /usr/bin/google-chrome-stable --incognito
Now logout from the desktop session and then re-login to validate the feature.

Comments

Popular posts from this blog

Cara Disable Antimalware Service Executable di Windows 10

Disadari atau tidak, Windows 10 (dan juga windows-windows lainnya) hadir dengan banyak sekali aplikasi bloatware (aplikasi yang tidak perlu-perlu amat dimiliki oleh end user). Contohnya, adalah aplikasi yang seharusnya sudah tergantikan fungsinya oleh antivirus, seperti Antimalware Service Executable . Aplikasi ini dicurigai membuat Windows 10 mengalami inefisiensi memori/RAM, memakan resource yang tinggi, dengan Load yang tinggi (tanpa limit terkadang). Nah, berikut adalah cara men-disable nya: Tekan tombol Windows + I untuk membuka apliaksi Windows Setting. Pilih icon menu Update and Security Pilih lagi menu disamping kiri Windows Security Pada jendela baru yang muncul, ada pilihan Virus & Threat protection Klik ini Lalu matikan proses Real-time protection tersebut. Dengan Regedit. Buka dialog regedit, Windows + R dan ketik ‘regedit’ Cari Folder regedit ini HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender Buat sebuah DWORD baru dengan klik kanan

Setup Debian 11 Official Repository In sources.list (/etc/apt/sources.list)

When you install Debian 11 using a DVD, the OS installer sets the DVD as the source for getting packages for your system if you didn't choose to scan for network mirrors. Due to this reason, the system would ask you to insert a DVD if the disc is not present in the DVD drive when you try to install any software.  Also, the packages on DVD may not be the latest release.  So, we need to get the packages from the Internet. Media change: please insert the disc labeled 'Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04' in the drive '/media/cdrom/' and press [Enter] The /etc/apt/sources.list file with DVD as a source would look something like below. # deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb http://security.debian.org/debian-security bullseye-security

Cara Membuat Live USB VMWare ESXi 6.7 di Linux (Debian/CentOS)

VMWare ESXi 6.7 menyediakan satu installer dalam format CDROM ISO. Dalam tutorial kali ini kita akan membuat sebuah live USB dengan menggunakan sistem Linux, misalnya Debian dan CentOS. Untuk keperluan tutorial kali ini silakan pastikan sudah ada download installer ISO ESXi 6.7 dari https://my.vmware.com Siapkan satu USB Flashdisk dengan kapasitas lebih dari 1GB. Format dalam satu partisi dengan tool yang biasa dipakai dalam format partisi FAT32. Misal dengan FDISK: [sourcecode] fdisk /dev/sdX [/sourcecode] format ke FAT32: [sourcecode]mkfs.fvat -F 32 -n USB /dev/sdX1[/sourcecode] selanjutnya, kita buat USB tersebut bootable dengan syslinux. Bagi linuxnya belum ada syslinux, silakan install dulu (apt-get install syslinux atau yum install syslinux).