Why MGLRU is so special? First, we need to know that there is an algorithm for managing the page cache in the Linux kernel. It works by keeping track of which pages have been used most recently and which ones have not. When the system needs to free up memory, it selects the page that has been used the least recently and swaps it out to disk. This is called LRU algorithm, which stands for Least Recently Used algorithm, used in the memory management system.
However, as we know it, the traditional active/inactive LRU algorithm used in Linux kernel is not doing a very good job. The common issue is high CPU usage in OOM situations. Therefore, we need a better LRU algorithm, MGLRU? According to Google, tested on tens of millions of ChromeOS users and about a million Android users, MGLRU shows an overall 40% decrease in kswapd CPU usage, in addition to improvements in other UX metrics, e.g., an 85% decrease in the number of low-memory kills and an 18% decrease in rendering latency.
To put it simply, just by enabling the magical MGLRU, you can save yourself to some extent from the OOM kills today!
Note, you need to use Linux kernel 6.1 or above to enable this feature. As of this writing, openSUSE Tumbleweed runs on Linux kernel 6.2.8. It's an advantage of running on a rolling release, you don't have to wait for months or even years for some major improvements.
Linux kernel 6.3 will bring further improvements to MGLRU also. See the news on Phoronix.
Check whether your kernel enable
CONFIG_LRU_GEN. You'll need to know your current kernel name in GNOME about page in your system settings. Or run
uname -rin the terminal. Then, go to
/bootand copy your kernel config's file name. For example,
config-6.2.8-1-defaultwhich is my current kernel config file. Open the terminal and type:
cat /boot/config-6.2.8-1-default | grep CONFIG_LRU_GEN
If this returns
y, your kernel supports
MGLRU, you can proceed to the next step.
Open plain text editor, entering this service file code and save it as
[Unit] Description=Multi-Gen LRU Enabler Service ConditionPathExists=/sys/kernel/mm/lru_gen/enabled [Service] Type=oneshot # Turn on MGLRU, valid values: [0; 7] and [yYnN] ExecStart=/bin/bash -c "/bin/echo y > /sys/kernel/mm/lru_gen/enabled" # Set the thrashing prevention vaule in milliseconds, valid values: >= 0 ExecStartPost=/bin/bash -c "/bin/echo 1000 > /sys/kernel/mm/lru_gen/min_ttl_ms" [Install] WantedBy=default.target
/etc/systemd/systemusing GNOME Files in admin mode by using
Open YaST Services Manager and enable the service to run on boot.
Reboot the system.
Check whether MGLRU is enabled on your system by:
This should return
0x0007. If it returns
0x0000, this means it's not enabled yet.
This should return
1000for the optimal thrashing prevention.
There's an open issue to enable MGLRU by default on openSUSE. If you're interesting, you can participate by submitting your test results. See comment #10 in the issue thread for more details.
Cover Photo by Resource Database on Unsplash
Abstract Photo by Resource Database on Unsplash
Top comments (0)