Gitpod Cloud IDE: 30% off for first 3 months. CODE: KEVINHQ. Click here

How to prevent a frozen desktop on Linux

Background story

I migrated my old laptop Dell Inspiron 3421 to Debian 10 some days ago. I’ll share the details on another post.

This Debian 10 runs with gnome-core, so it’s using the Gnome desktop environment. At first, everything seems running smoothly.

I open a few Reddit tabs on its default browser, Firefox ESR. Nothing sluggish on this laptop with 2GB RAM. At this point, I don’t install any packages other than those:

  • Upwork tracking app
  • htop. It is for monitoring the CPU and RAM usage.
  • Vim editor

Other packages were from the default packages from gnome-core: Calculator, Calendar, etc. I can’t remove them without removing gnome-core and losing the desktop environment.

Why not using LXDE or another lighter DE?

I migrate from Lubuntu with LXDE to Debian. The main reason is there are several problems with that desktop environment. Yes, it’s very light. However, it doesn’t work well with my use cases.

Problem

The problem begins when I try to work with Google Sheet webpage. The laptop suddenly freezes.

I try to switch to the terminal and kill the process but no success. The desktop is frozen. Then, I leave it for around half-hour. Nothing changes.

In the end, I have no choice but to press the power button for some seconds. Yes, I need to force it to shut down.

Solution

After thinking for a while, I remember, one of my friends talking about the OOM mechanism. OOM is an abbreviation for Out-Of-Memory.

It’s a mechanism of operating system to kill the process that eats up too much memory on the machine.

Then, I start to wonder why this Debian OOM mechanism doesn’t kill the process and prevent the system from freezing. Perhaps, I need to explore more on this part in the future.

As for the solution to my current problem, I come up with these:

  • I disable the swap permanently. It is my personal preference. I hate to see my machine gets slow because it’s starting to swap the data on RAM to disk.
  • Then, I install the earlyoom package: sudo apt install earlyoom

After that, I configure it by

  • opening the /etc/default/earlyoom
  • updating the EARLYOOM_ARGS with -r 30 -m 1
  • At last, I restart the earlyoom process.

You can read about the earlyoom configuration on their Github page.

Result

I verify the result by opening the same tab with Google Sheet on Firefox ESR. I set up the same situation that triggers the frozen system earlier.

Here’s what I observe so far:

  1. No more frozen desktop.
  2. When out-of-memory is happening (well, the laptop only has 2GB of RAM), it kills the Firefox tab gracefully.

Verdicts

We all know 2GB of RAM isn’t sufficient to run Debian with Gnome desktop smoothly. The documentation recommends 1GB to run Debian with a desktop. But, it mentions not to run with Gnome.

Yet, the steps I’ve done above are working well to deliver the result: no more frozen system without adding more RAM.

Still, I can’t deny the ideal solution for the problem is adding one more RAM module to the empty slot on this laptop.

One more: though I do all of them on Debian, I am sure it’s possible to use these solutions on another Linux distribution, as long as you can install the earlyoom package.

Veerotech Web Host: 50% off on first month with code: 1stmonth50. Plus free $10 credit. Click here