Edit 1: The freezing just happened and I was able recover from it. Log(syslog) from the freezing until 'now': https://ufile.io/ivred

Edit 2: It seems a bug/problem with GDM3. I'll try Xubuntu.

Edit 3: Now I'm using Xubuntu. The problem still happens, but a lot less often. So.. it is indeed a memory issue.

I'm currently using Ubuntu 18.10 Live CD since my HD died. I did some customizations to my LiveCD mainly towards memory consumption, because I have only 4GB of RAM.

When my free memory goes below 100MB, my pendrive LED starts to blink like crazy and the system freezes letting me time to just get out of GUI interface (Ctrl+Alt+f1...f12) and reboot(Ctrl+Alt+Del) or, sometimes to close Google Chrome with sudo killall chrome.

So I created a very simple script to clean the system cache and close Google Chrome. Closing Chrome out of the blue like that is fine, since it asks you to recover the tabs when it wasn't closed properly.

The question: It works like a charm 95% of the time. I don't know if my script is too simple or there is another reason for this intermittent freezing since I can't check the log, because of the need of reboot. Is there a more efficient way to do that? Am I doing it wrong?

Obs.: I have another script to clean the cache that runs every 15 minutes. Since I created those scripts I am able to use my LiveCD every day with almost no freezing. Maybe 1 per day.. Before that I had to reboot every 30-40min, because I use the Chrome with several tabs.

My script:


while true ; do 
free=`free -m | grep Mem | awk '{print $4}'`
if [ "$free" -gt 0 ]
    if [ $free -le 120 ]; #When my memory consuptiom goes below 120MB do the commands below. 

if pgrep -x "chrome" > /dev/null
        sudo killall -9 chrome
        sudo su xubuntu
        /usr/bin/google-chrome-stable --password-store=basic --aggressive-cache-discard --aggressive-tab-discard
    echo "Stopped"

    sudo sysctl -w vm.drop_caches=3
        sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches 

fi & sleep 1; done
  • 1
    Do you have swap partition on pendrive? Then disable it. swapoff -a. – Ipor Sircer Nov 24 '18 at 17:21
  • No swap partition on my pendrive. – Lucas Rizzini Nov 24 '18 at 17:39
  • 3
    Then teach chrome to use less ram. Look at parameters, for example: --mem-pressure-system-reserved-kb=XXX, --aggressive-cache-discard, --aggressive-tab-discard, etc... 4gb is fairly enough to run chrom[e|ium] nowadays. My chromium nevers eats more than 2.6gb in any conditions (even with 50+ opened tabs). – Ipor Sircer Nov 24 '18 at 18:23
  • use an real open source less RAM extensive browser, or maybe try to not open too much tab – Kiwy Nov 28 '18 at 10:44
  • I need to use Google Chrome and a lot of tabs. Otherwise, I would have already changed my browser. – Lucas Rizzini Nov 28 '18 at 12:29

The solution that "fra-san" gave at the comments here fitted perfectly. Using "cgroup-tools" package I was able to limit Chrome memory usage successfully. I tested it opening dozens of tabs at the same time and I could see the memory limit in action. However, I had to leave my script running, since, as much as I mostly use Chrome, system cache consumes a lot of RAM too.

My steps:

1- Used this script from: Limit memory usage for a single Linux process


# This script uses commands from the cgroup-tools package. The cgroup-tools commands access the cgroup filesystem directly which is against the (new-ish) kernel's requirement that cgroups are managed by a single entity (which usually will be systemd). Additionally there is a v2 cgroup api in development which will probably replace the existing api at some point. So expect this script to break in the future. The correct way forward would be to use systemd's apis to create the cgroups, but afaik systemd currently (feb 2018) only exposes dbus apis for which there are no command line tools yet, and I didn't feel like writing those.

# strict mode: error if commands fail or if unset variables are used
set -eu

if [ "$#" -lt 2 ]
    echo Usage: `basename $0` "<limit> <command>..."
    echo or: `basename $0` "<memlimit> -s <swaplimit> <command>..."
    exit 1


# parse command line args and find limits


if [ "$1" = "-s" ]

if [ "$1" = -- ]

if [ "$limit" = "$swaplimit" ]
    echo "limiting memory to $limit (cgroup $cgname) for command $@" >&2
    echo "limiting memory to $limit and total virtual memory to $swaplimit (cgroup $cgname) for command $@" >&2

# create cgroup
sudo cgcreate -g "memory:$cgname"
sudo cgset -r memory.limit_in_bytes="$limit" "$cgname"
bytes_limit=`cgget -g "memory:$cgname" | grep memory.limit_in_bytes | cut -d\  -f2`

# try also limiting swap usage, but this fails if the system has no swap
if sudo cgset -r memory.memsw.limit_in_bytes="$swaplimit" "$cgname"
    bytes_swap_limit=`cgget -g "memory:$cgname" | grep memory.memsw.limit_in_bytes | cut -d\  -f2`
    echo "failed to limit swap"

2- Named it as "limitmem" and copied to /usr/bin/ so I could call it from terminal just with limitmem. Now I can open a process limiting the memory usage to, for example, 800MB using this syntax:limitmem 800M command

In my case: limitmem 1000M google-chrome --password-store=basic --aggressive-cache-discard --aggressive-tab-discard

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.