HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
hakavlad
le9-patch
Systems & Infrastructure2021–2022
hakavlad / le9-patch

le9-patch

[PATCH] mm: Protect the working set under memory pressure to prevent thrashing, avoid high latency and prevent livelock in near-OOM conditions

8Distinct people
11Mentions
0Explicit recommenders
228GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

[PATCH] mm: Protect the working set under memory pressure to prevent thrashing, avoid high latency and prevent livelock in near-OOM conditions

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 1:49:46 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by month11 dated mentions

Observed mentions: 2021-03-14 15:39:20 UTC to 2022-02-04 20:38:44 UTC.

01232021-03-01 00:00:00 UTC to 2021-04-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 commentsMar 20212021-04-01 00:00:00 UTC to 2021-05-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2021-05-01 00:00:00 UTC to 2021-06-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2021-06-01 00:00:00 UTC to 2021-07-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2021-07-01 00:00:00 UTC to 2021-08-01 00:00:00 UTC (exclusive): 3 mentions; 1 submissions, 2 comments2021-08-01 00:00:00 UTC to 2021-09-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 commentsAug 20212021-09-01 00:00:00 UTC to 2021-10-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2021-10-01 00:00:00 UTC to 2021-11-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2021-11-01 00:00:00 UTC to 2021-12-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2021-12-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2022-01-01 00:00:00 UTC to 2022-02-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2022-02-01 00:00:00 UTC to 2022-03-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 commentsFeb 2022

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
Mar 20212021-03-01 00:00:00 UTC2021-04-01 00:00:00 UTC202
Apr 20212021-04-01 00:00:00 UTC2021-05-01 00:00:00 UTC000
May 20212021-05-01 00:00:00 UTC2021-06-01 00:00:00 UTC000
Jun 20212021-06-01 00:00:00 UTC2021-07-01 00:00:00 UTC101
Jul 20212021-07-01 00:00:00 UTC2021-08-01 00:00:00 UTC312
Aug 20212021-08-01 00:00:00 UTC2021-09-01 00:00:00 UTC000
Sep 20212021-09-01 00:00:00 UTC2021-10-01 00:00:00 UTC101
Oct 20212021-10-01 00:00:00 UTC2021-11-01 00:00:00 UTC101
Nov 20212021-11-01 00:00:00 UTC2021-12-01 00:00:00 UTC101
Dec 20212021-12-01 00:00:00 UTC2022-01-01 00:00:00 UTC000
Jan 20222022-01-01 00:00:00 UTC2022-02-01 00:00:00 UTC101
Feb 20222022-02-01 00:00:00 UTC2022-03-01 00:00:00 UTC101

What Hacker News says

11 sources
If the computer is slow enough under load, you can use wall clock to count many seconds it takes to start a program that needs to load many libs and data (LibreOffice, Firefox, Blender, GIMP). You can also watch FPS of supertuxkart when the system is under load: https://www.youtube.com/watch?v=c5bAOJkX_uc https://github.com/hakavlad/le9-patch But yes, we need a popular well behaved benchmark to measure desktop responsiveness.
In Ask HN: Is there any tool for benchmarking responsiveness for Linux?
Oh that’s a known problem. There are many kernel patches floating around that fix it by triggering the OOM killer when the system is thrashing. Here’s one based on ChromeOS’s solution: https://github.com/hakavlad/le9-patch I’ve never had this specific problem back when I was daily driving desktop Linux, but I did run into 1000 other ones that needed bandaid solutions just like this. It’s death of a thousand cuts: https://news.ycombinator.com/item?id=28490753 I see that nothing’s changed in the last couple of years.
In Programs that were launched with impossible command line options
As long as you have only spinning rust for swap I disable it. After reading that article some time ago I tried to add a little swap to my shared general purpose machines (running quite a mixed workload that sometimes tends to explode e.g. matrix synapse is famous for that) and the box still grinded into an unresponsive state even with just 4GB swap. Maybe I did something wrong - But I'd rather tolerate an OOM kill (mostly contained by cgroups/container/lxd) and a few seconds (or minutes) of unresponsiveness instead of a complete lockup that results in a hard reset. Not sure if it's better on SSD. I've enabled zswap for 1/8 of memory on the Desktop and this seems to improve things but as long as you have spinning rust or other slow storage my experience is that the machine will die a slow death as long as swap is active. There is some inte
Read the rest
resting stuff in newer kernels - like multigenerational mru [1] and that le9 patchset [2] Am I missing something? If you have full control over the memory usage this might be useful for the mentioned usecase but for a general purpose machine this doesn't work? 1: https://patchwork.kernel.org/project/linux-mm/cover/20210818... 2: https://github.com/hakavlad/le9-patch
In In defence of swap: common misconceptions (2018)
The reason the OOM killer never kicks in is because you actually never run into an OOM, or almost never. What usually happens is that in near-OOM conditions, the kernel starts reclaiming memory pages backed by file (sometimes called "trashing"). This operation manages to keep some extra memory available, but it makes the system almost unresponsive because it's constantly copying memory back and forth from the disk. It may take anywhere between minutes to hours before the system finally OOMs and the OOM killer is invoked. This problem has been there forever but has been made worse by the improved speeds of modern storage technologies: with slower disk I/O, the OOM condition was reached sooner. There are several solutions: - Buy more RAM: if your system routinely goes nearly OOM something is not right. - Add a (small) swap. It doesn't have
Read the rest
to be a partition: nowadays most filesystems support swap file. Just create an empty file and mark it as swap. - Limit the amount of thrashing or protect some pages from being reclaimed. This has been proposed by Google first and several other people since then, but AFAIK it has never been implemented in the mainline kernel. Regarding the latter solution, there is a patchset called le9-patch[1] that is included in some alternative Linux kernels and it should be relatively safe to use. [1]: https://github.com/hakavlad/le9-patch
In Moving Google toward the mainline
The amount of dirty pages the kernel keeps in RAM is configurable through sysctl. If the buffer is full any further write blocks the process. If you have less free RAM than the allowed dirty page buffer what you said is correct though. There is a new patch[1] that allows to set a soft and hard minimum of RAM reserved for clean pages. This fixes the problem almost completely even under the heaviest loads. cgroups like a silbling post mentioned can also help by setting soft limits for heavy background tasks like compile jobs. Setting a soft limit will give them as much RAM as is available, or swap them out completely when things are heavily contented, effectively pausing the processes. It requires some setting up though, so it's not a solution for all cases, but it can make sense even without the thrashing problem. [1]: https://github.com/h
Read the rest
In Hastening Linux process cleanup with process_mrelease
While that is true, you can invoke the OOM killer at any time you want by pressing Ctrl+Alt+Print("SysRq")+F(uck?). Given the letter they picked it seems like they're fully aware of the deficiency. As to why it was never really addressed, that's a good question. The recent le9[1] patch addresses the most annoying symptom of running out of memory by keeping some amount of RAM reserved for clean pages (like static program code) so that those won't get swapped in and out so much. That greatly improves responsiveness under low memory conditions. [1]: https://github.com/hakavlad/le9-patch
In Hastening Linux process cleanup with process_mrelease
How will systemd-oomd communicate to the user? I was using https://github.com/hakavlad/nohang And it sent notification signaling to save your work before the application X will be killed. (I always wanted a way to click somewhere on the notification to prevent nohand from killing it when unwanted) Also nohang use PSI data does oomd does it too? Finally the author of nohang is working on arguably superior solutions: https://github.com/hakavlad/prelockd https://github.com/hakavlad/memavaild https://github.com/hakavlad/le9-patch It's unfortunate that systemd has chosen to integrate an inferior solution
In Systemd 248 RC3: systemd-oomd is now considered fully supported

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.