Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
man8alexd
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
6 ms
·
61.
▲
by
man8alexd
8mo ago
All LRUs, file-backend and anonymous are handled by the same code. There are some conditionals here and there - executable pages are promoted to active LRU on the first access, locked pages (if I remember correctly) too, but all pages go th
62.
▲
by
man8alexd
8mo ago
Overcommit allows much better memory utilization. People disable overcommit all the time and get surprised when their programs start failing mallocs while there are still tons of discardable page cache in the system. https://unix
63.
▲
by
man8alexd
8mo ago
I'm the OP. I got myself into collecting falsehoods people believe about Linux swap and OOM[1]. There is an entry about this 2x rule in this collection, with my answer on how to select swap size. My question on Retrocomputing.StackExch
64.
▲
by
man8alexd
8mo ago
Anonymous memory and files have different access patterns. Files are frequently read sequentially and only once, so there is no need to keep them in memory. When files are read, cached memory pages are put into inactive file LRU first and p
65.
▲
by
man8alexd
8mo ago
> You seem to prefer it over slowing down. An unresponsive system is not a slowdown. You keep ignoring that. >> You assume that leaked memory is inactive and goes to swap. This is not true. > At best, you can say "it's
66.
▲
by
man8alexd
8mo ago
> You seem to be very certain about that inevitable memory leak. It is fashionable to disable swap nowadays because everyone has been bitten by a swap thrashing event. Read other comments. > A memory leak does not lead to thrashing. B
67.
▲
by
man8alexd
8mo ago
> Thrashing is the penality for using too much swap. I was saying there is no penality for having a lot of swap available, but unused. Unless you overprovision memory on a machine or have carefully set cgroup limits for all workloads, yo
68.
▲
by
man8alexd
8mo ago
I have updated my collection of falsehoods people believe about Linux swap and OOM https://alexeydemidov.com/2025/05/15/falsehoods-people-and-L...
69.
▲
by
man8alexd
8mo ago
> There is no penalty for giving a system too much swap (apart from disk space) There is a huge penalty for having too much swap - swap thrashing. When the active working set exceeds physical memory, performance degrades so much that the
70.
▲
by
man8alexd
8mo ago
Then see the link in my previous comment.
71.
▲
by
man8alexd
8mo ago
Unused or Inactive memory is memory that hasn't been accessed recently. The kernel maintains LRU (least recently used) lists for most of its memory pages. The kernel memory management works on the assumption that the least recently use
72.
▲
by
man8alexd
8mo ago
> So not being able to mark apps processes as kill me first and leave others like ssh bash up is a missing feature. systemd OOMScoreAdjust has existed for at least a decade. /proc/*/oom_adj since Linux kernel 2.6.11 - two
73.
▲
by
man8alexd
8mo ago
There is cgroup memory.min
74.
▲
by
man8alexd
8mo ago
There is no actual swapping in the modern kernels. Nowadays, it is paging, when the kernel pages out individual unused memory pages, not entire processes, so it keeps all non-blocked processes running, but only necessary memory pages in the
75.
▲
by
man8alexd
8mo ago
Your bash session is most likely still in memory but the system is spending 99.9% of time waiting for swap I/O, trying to free a few pages of memory. Swap random access latency is 10^3 slower than RAM.
76.
▲
by
man8alexd
8mo ago
> However in almost all normal cases, this grossly overestimates the required memory and thus leads to swapping when technically it is not needed. This is not true. Disabling overcommit doesn't change reclaim and swapping behaviour
77.
▲
by
man8alexd
8mo ago
When you set cgroup limits, you tell the kernel how to determine when a process is misbehaving and needs to be OOM-killed.
78.
▲
by
man8alexd
8mo ago
swap causes thrashing if you have too large swap and no cgroup limits.
79.
▲
by
man8alexd
8mo ago
It is possible to measure process memory utilitsation and set appropriate cgroup limits.
80.
▲
by
man8alexd
8mo ago
Exactly opposite. Don't use swap partitions, and use swap files, even multiple if necessary. Never allocate too much swap space. It is better to get OOM earlier then to wait for unresponsive system.
81.
▲
by
man8alexd
8mo ago
You don't need "horough experimentation or careful analysis". Just keep free swap space below few hundred megabytes but above zero.
82.
▲
by
man8alexd
8mo ago
Swap is not a replacement for RAM. It is not just slow. It is very-very-very slow. Even SSDs are 10^3 slower at random access with small 4K blocks. Swap is for allocated but unused memory. If the system tries to use swap as active memory, i
83.
▲
by
man8alexd
8mo ago
Binaries and libraries are not paged out. Being read-only, they are simply discarded from the memory. And I'll repeat, actively used executable pages are explicitly excluded from reclaim and never discarded.
84.
▲
by
man8alexd
8mo ago
There are different definitions of "just work".
85.
▲
by
man8alexd
8mo ago
You are right, it is not a rule of thumb, and you can't determine optimal swap size right away. But you don't need "extensive runtime analysis". Start with a small swap - a few hundred megabytes (assuming the system has
86.
▲
by
man8alexd
8mo ago
https://chrisdown.name/2018/01/02/in-defence-of-swap.html
87.
▲
by
man8alexd
8mo ago
The proper rule of thumb is to make the swap large enough to keep all inactive anonymous pages after the workload has stabilized, but not too large to cause swap thrashing and a delayed OOM kill if a fast memory leak happens.
88.
▲
by
man8alexd
8mo ago
This rule of thumb is outdated by two decades. The proper rule of thumb is to make the swap large enough to keep all inactive anonymous pages after the workload has stabilized, but not too large to cause swap thrashing and a delayed OOM kil
89.
▲
by
man8alexd
8mo ago
Look into /proc/<PID>/status and /proc/<PID>/smaps
90.
▲
by
man8alexd
8mo ago
It sucks without proper cgroup limits because swap makes OOM slower to trigger. Either set the cgroup limits or make the swap small.
More ›