4

I'm using Linux on my Steam Deck (SteamOS/Arch Linux).

Is there a method to set a hard cap/limit on the maximum total RAM Chrome can use with command line arguments? (to 8 GB out of the device's max 16 GB)

Chrome works just fine with tons of tabs open on my Windows laptop with 8 GB of RAM, and I can always kill individual processes with Chrome's built-in task manager.

But on the Steam Deck's Arch Linux, if I forget to use Chrome's built-in task manager to kill tabs/processes, having too many tabs of certain poorly optimized websites can cause the entire machine to hang. Then I have no choice but to hard reset by holding the power button.

I already use uBlock Origin to clean up websites, but that doesn't seem to be enough.

--TL;DR--

I want to use command-line arguments to set a hard cap on the maximum total RAM that Chrome can use to 8 GB out of the device's 16 GB of RAM.

If I use the KDE Menu Editor, I can directly add command-line arguments to Chrome.

The command-line to execute is:

run --branch=stable --arch=x86_64 --command=/app/bin/chrome --file-forwarding com.google.Chrome @@u %U @@

Is there an argument I can add to do this? Looking for something like: "--max_ram_usage 8192MB"

Z0OM
  • 3,149
JLHack7
  • 41

1 Answers1

3

You can use ulimit to set the soft and hard limits for the maximum virtual memory size.

ulimit -Sv 8192000; ulimit -Hv 8192000; google-chrome

With an output:

ulimit -Sv 8192000; ulimit -Hv 8192000; google-chrome &
sleep 2
PID=$(pgrep google-chrome)
ps -o pid,rss,vsz -p $PID

Running this modified command, you should see the PID, RSS, and VSZ values for the Chrome process. the RSS value represents the actualy memory usage, the VSZ value represents the total virtual memory size allocated by the process. sleep 2 ensures that there is a pause to allow Chrome to start and allocate memory.

Set the Virtual memory with output:

ulimit -v 8192000 && google-chrome &
sleep 1
PID=$(pgrep google-chrome)
ulimit -aH | grep "virtual memory"
ulimit -aS | grep "virtual memory"
cat /proc/$PID/limits | grep "Max address space"

Linux bash inline command to execute a program and limit the resource

Bash ulimit builtin command

Linux Ulimit Command

HOWTO: Use ulimit command to set soft limits

User limits - limit the use of system-wide resources.

ulimit - Modify shell resource limits.

Z0OM
  • 3,149
  • The problem with this approach is that, as you said, it limits the virtual memory which is not the same as the real user memory. Many applications allocate a large amount of virtual address space right at the beginning but the RSS is small and gradually growing. For instance, it might allocate more then 8G but use only 1G, which is not a problem, but your approach will not allow this and the application would fail. – aviro Jun 27 '23 at 10:57