ValdikSS10th July 2021 at 8:33pm

Русская версия заметки / This article in Russian

This article describes the installation and configuration process of a modern Linux-based operating system for a weak computer from 2007, which allows you to moderately comfortably use the Internet and do home and office work with all the common software of the latest versions.

If your computer of the same generation works very slowly with new versions of Windows, or if you still forced to use Windows XP with old software, but are not afraid to experiment - this note is for you.

If you have tried Linux before and it slowed down a lot - do not worry, the described configuration method significantly speeds up the operation of this OS with a small amount of RAM and with a regular disk (no SSD) installed.

First of all, let's define the concept of moderately comfortable work. In my understanding, this means the ability to interact with modern (bloated) websites without feeling constrained, and without being annoyed every minute by the freezes or lags.
For this, the minimum requirements are:

  • 64-bit processor - weaker 32-bit ones are not suitable for current websites, not because of their architecture, but because of performance. 64-bit processors appeared en masse in 2006-2007.
  • 1 GB RAM is the absolute minimum for the patient and calm users. 2 GB or more will greatly expand your multitasking capabilities and improve overall performance, so it's highly recommended.

If your computer is older than mine (for example, it has a 32-bit processor), this article will not work for you I'm afraid. For such machines, a special approach is required for both OS and software choice, which is beyond the scope of this note. However, the described configuration and hardware upgrades could be applied to it as well.

ValdikSS10th July 2021 at 9:01pm

I have a typical office computer of the time:

  • Motherboard: Gigabyte GA-945GCM-S2L (early LGA775 socket, GMA950 integrated graphics, September 2007)
  • 2 core 64 bit CPU: Intel® Core™2 Duo E4600 (2 cores, 2.4 GHz, late 2007)
  • 2 GB of RAM (DDR2 667 MHz, single module)
  • 160 GB Hard Disk: Samsung HD161HJ (SATA II, June 2007):
  • No discrete graphics card

The result of the test computer after the configuration

Running simultaneously:

  • Firefox with 37 active tabs (all data in RAM, no tab unloading, everything is fair)
  • Discord
  • Skype
  • LibreOffice with the document opened
  • Two PDF files (14 and 47 megabytes in size)
... all with 2GB of RAM. Looks impressive?

Switching between browser tabs and programs is moderately comfortable: the system slowed down at times, but kept being always responsive and did not freeze.

ValdikSS14th July 2021 at 11:15pm

If you are not interested in the technical details, but want to try it yourself and check the performance, use the LiveCD with pre-configured Linux Mint 20.2 "Uma" Xfce 64-bit distribution:

linuxmint-20.2-xfce-oldpc-le9-14.07.2021-64bit.iso (🧲 BitTorrent Magnet)

Download, create a bootable USB flash drive with any burning software (I recommend Rosa ImageWriter), boot into the OS.

Issue with 08.08.2021 ISO

ISO image from 08.08.2021 had a non-critical issue with systemd service with lead to systemd-sysctl.service startup error.

If you already installed the operating system using this ISO, the issue could be fixed by executing the following command

sudo sed -i '2aDefaultDependencies=no' /etc/systemd/system/le9-lowram-setup.service

ISO from 14.08.2021 has a fix for this issue (and this is the only change in this version).

On some older motherboards of the time the initial stages of USB booting are slow (USB 1.1 speed). Be patient.
To reduce memory consumption in Firefox set the Content process limit = 2 option in the browser performance settings.

This remastered ISO is not testing/experimental and is suitable for daily use. It differs from regular Linux Mint in only three ways:

  1. XanMod kernel is installed, with le9 patch integrated. It dramatically increases performance on low memory systems.
  2. Aggressive memory compression is configured with zram, which in used instead of physical swap ("page file" in Windows terms). If there is insufficient memory, data is compressed rather than swapped out onto the (slow) HDD. Allows you to use up to 150% more RAM than is physically available: 2 GB of RAM feels like 5 GB.
  3. Spectre and Meltdown CPU-level vulnerabilities mitigations are disabled: increases execution speed at the expense of reducing the security of hard-to-exploit vulnerabilities.

ValdikSS10th July 2021 at 8:06pm

Older computers share a set of common flaws: slow memory, a small amount of it, slow processor, slow integrated graphics (if discrete card is not installed).

These flaws must be taken into account when choosing an OS: the graphical interface must be lightweight, compositing must be lightweight and compatible with old video cards by technologies (GMA 500 graphics on machine under test machine only supports OpenGL 1.4).
The general concept of the distro is also important: the abundant use of the alternative way of installing applications in Ubuntu (Snap) leads to duplicated libraries and increased memory consumption both by the programs themselves (due to several sets of libraries in RAM) and by the daemons for serving them.
The last important factor is a toolkit, which is used to make a desktop environment. Running a GTK3 browser in a GTK3 environment will require less RAM than in a GTK2 or Qt environment due to the same libraries usage for both the environment and the software. With a small amount of memory, this plays a role.

My choice fell on "XFCE" and "LXDE" lightweight desktop environments.

The first one provides an environment and a set of programs familiar to any computer user, has a vast number of configuration settings for the system and computer components.
The second is less customizable, has more meager options for configuring peripherals, but also consumes less RAM: ≈300 MB XFCE (Mint 20.2) versus ≈180 MB for LXDE (Lubuntu 18.04).

Recommended distributions

Since we will be using a computer to surf the modern Internet, we need an up-to-date operating system that receives software and security updates. There are countless specialized distributions "for outdated hardware", but they are either built on a non-standard package base and are not updated by the authors in a timely manner (if at all), or they rely on the lightest set of programs, in particular, alternative browsers that are not able to fully work with complex and constantly changing sites.
Therefore, our choice is a full-fledged "regular" Linux distribution.

For computers with 2 GB or more RAM I believe that Linux Mint 20.2 "Uma" - Xfce (64-bit) is the best choice: nice and sleek interface, excellent built-in system management software, a good set of default software, high-quality translation to non-English languages and a comprehensive welcome screen are ideal for non-Linux users. This is the distribution offered in a customized form above.

For computers with 1-1.5 GB of memory, Lubuntu 18.04 is recommended: it consumes less memory at the cost of less visual appeal, poor system settings and a simplified set of software (but the browser is still the latest Firefox here). There is a 32-bit version for very old processors, but this version will not allow you to install programs that are present only in 64-bit form, such as Skype or Discord.
It's a good non-extreme option for weak computers from "full-fledged" distributions.

The distro is needed to be configured for weak PCs: at least setup and enable zram memory compression and improve work under low memory conditions.

If you were previously interested in running Linux on an old computer, you may have come across specialized operating systems such as Puppy Linux, Tiny Core, Slax, and others. These distributions are not very suitable for everyday casual usage for a person who is not familiar with Linux: quite frequently it have issues with peripheral configuration such as printers and inability to install proprietary programs (Skype, Zoom) easily.

It is reasonable to use such distributions if the computer is no longer suitable for running common operating systems, but it's not worth getting it as your first choice.

ValdikSS10th July 2021 at 8:16pm

The Linux kernel does not perform well under RAM shortage conditions on desktop computers.
When running programs use RAM almost to its max, it is not uncommon for system to fall under thrashing:

In computer science, thrashing occurs when a computer's virtual memory resources are overused, leading to a constant state of paging and page faults, inhibiting most application-level processing. This causes the performance of the computer to degrade or collapse. The situation can continue indefinitely until either the user closes some running applications or the active processes free up additional virtual memory resources.

Under regular conditions, any operating system uses RAM to the maximum, filling the "free" regions with the cache of files, programs and libraries. As soon as a running program needs memory, the operating system throws away the least requested piece of cache and gives it to the program that requested the memory allocation.

When the memory is almost completely filled with real data (not cache), the operating system has to decide: how much of cache to throw out, how much and what data to send to the swap, and how intensively to perform these operations.
The Linux kernel with standard configuration considers the cache to be the least overall demanded type of data in RAM, discarding it too aggressively for the sake of real data, swapping out real data in small batches. Because of this, an avalanche effect arises, when the entire computer works only to transfer program executables, libraries and swap back and forth from and to HDD, leaving almost no time for the execution of programs.

Continuous reading of system libraries and programs, especially from a slow HDD, leads to a performance drop by orders of magnitude. The system may lose responsiveness for minutes, which is especially true for older computers.

Users have been looking for a fix for freezes since at least 2008 (bug 12309). The issue is so widespread and obvious that it has its own article on Lurkmore (Russian Encyclopedia Dramatica), and its discussion appears from one year to another in professional community.
Developers are introducing various techniques in new versions of the kernel, aimed at eliminating one or another aspect of the issue, but for 2021 this bug is still not fixed completely.

le9 patch

Countless methods of dealing with thrashing have been proposed over the years. The patch called "le9" is another modification aimed at fixing the problem of running Linux when the RAM is almost full. It creates soft protection against program code and libraries eviction from RAM, which has a positive effect on the overall system performance.

le9 patch, by my subjective feelings, is the most effective measure. Unlike other methods and workarounds for the issue, it works not only under nearly-full memory conditions with a large amount of RAM on modern PCs, but also with a constant lack of it in old computers (1-2 GB).

Currently le9 is presented as a modification for the Linux source code and is not included in the standard kernel or in any distribution. To use it, you need to install a third-party kernel where this patch is applied. As of July 2021, there are two such kernels: XanMod and pf-kernel (with a bit customized le9 patch version).

In presented Mint build le9 cache is configured to reserve 25% of RAM for programs and libraries cache, but not more than 512 MiB.
Cache size could be modified by configuring sysctl vm.clean_low_kbytes value.

sudo sysctl vm.clean_low_kbytes=200000
sets cache size to 200 MB.

Other solutions to the problem

Various utilities to prevent a long or complete system hang presented on the nohang project page.
They are divided into two types:

  • Programs that aid early termination of processes that are actively consuming memory (OOM Killer). Not suitable for computers with 1-2 GB of RAM, in which memory, from the point of view of these programs, is never enough.
  • Programs that speed up the system under heavy swap usage. Some of them prevent code and program libraries from being unloaded from memory, some of them reduce the size of the RAM available to user programs, giving it to system processes.

Also on modern computers with a large amount of memory and SSD, it makes sense to increase the amount of data swapped out at a time:

vm.swappiness=100   ← do not consider unloading the file cache as a priority task

vm.watermark_scale_factor=200   ← increase the amount of swapped out data at a time

ValdikSS10th July 2021 at 8:21pm

Reading from the HDD and writing arbitrary data to it in a random (non-linear) way is a very slow operation, which is why the use of swap is associated with the system slowdowns for most users.

Compression of RAM, despite the additional CPU load, works at least two orders of magnitude faster than disk access, accelerating the system from the state of "barely tossing and turning" to "that's fine." RAM compression is also used in Windows 10 (to the limited extent, small amount of data is getting compressed).

For moderately comfortable work in conditions of a constant lack of memory and a slow hard disk, you will have to exclude the use of physical disk swap as much as possible and resort to an extreme setting: using 150% of RAM as compressed.
There is no contradiction here: the memory is getting compressed only upon swapping out, reaching 2.5-3 times the compression ratio.

On Debian, Ubuntu and related distributions, zram is configured with the zram-tools package, which can be tweaked in the /etc/default/zramswap file.

In the Mint build the updated version of the package from the Ubuntu 21.04 repositories is used.

The fastest compression algorithm lz4 is recommended.

ValdikSS10th July 2021 at 8:23pm

Software improvements are great, but the best way to speed up your computer is to improve your hardware.

The highest priority should be given to "installing more RAM". If you only have 1 GB, you should do it as soon as possible. A 2 GB DDR2 module costs $3.3-$6.7, and the difference in performance between 1 GB and 2 GB is heaven and earth. The vast majority of computers from 2007 can operate with 4 GB or 8 GB of memory (depending on the number of slots for RAM), which is necessary for optimal performance in demanding programs and serious multitasking.
Dual Channel Memory improves both memory bandwidth and integrated video performance when no discrete graphics card is installed. It is better to install two 2 GB memory modules than one 4 GB memory module.

Next by priority is the processor. Since we use memory compression, the faster the processor, the faster the system will run. A decent dual-core Intel E8500 will cost $4-$9.5 at the flea market (4 cores cannot be installed on the test machine motherboard).

The third is SSD. A fast disk will significantly speed up the first launch of programs and reduce switching time between them when memory is full, but it is not a necessary component with 4+ GB of RAM and proper OS setup.
The most expensive component to upgrade.

These are general guidelines for upgrading. Detailed information should be found on specialized forums on the Internet, in relation to your platform.