Live data from Hacker News

Modernizing Linux swapping: introducing the swap table

lwn.net

51–60 of 132 posts

Re: Modernizing Linux swapping: introducing the swap table

#51
post #34

Earlier quoted context omitted.

The pro-swap stance has never made sense to me because it feels like a logical loop. There’s a common rule of thumb that says you should have swap space equal to some multiple of your RAM. For instance, if I have 8 GB of RAM, people recommend adding 8 GB of swap. But since I like having plenty of memory, I install 16 GB of RAM instead—and yet, people still tell me to use swap. Why? At that point, I already have the s…

The reason you're supposed to have swap equal in size to your RAM is so that you can hibernate, not to make things faster. You can easily get away with far less than that because swap is rarely needed.

> so that you can hibernate

The “paging space needs to be X*RAM” and “paging space needs to be RAM+Y” predate hibernate being a common thing (even a thing at all), with hibernate being an extra use for that paging space not the reason it is there in the first place. Some OSs have hibernate space allocated separately from paging/swap space.

Re: Modernizing Linux swapping: introducing the swap table

#52

Earlier quoted context omitted.

zram has been "obsolete" for years, I don't know why people still reach for it. Linux supports proper memory compression in the form of zswap https://wiki.archlinux.org/title/Zswap

Because I'd rather compress ram when running low on memory rather than swapping to my disks. zram is also default on some distros (e.g. Fedora).

Did you read the link? Additional disk swap is optional, and if for some reason you would still like to have one, it's easy to disable writeback, using just the RAM.

And even if one enables zswap and configures nothing else, compressing RAM and only swapping out to disk under extreme pressure is still the default behavior.

Re: Modernizing Linux swapping: introducing the swap table

#53

Earlier quoted context omitted.

The pro-swap stance has never made sense to me because it feels like a logical loop. There’s a common rule of thumb that says you should have swap space equal to some multiple of your RAM. For instance, if I have 8 GB of RAM, people recommend adding 8 GB of swap. But since I like having plenty of memory, I install 16 GB of RAM instead—and yet, people still tell me to use swap. Why? At that point, I already have the s…

Another factor other commenters haven't mentioned, although the article does bring it up: you may disable swap and you will still get paging behavior regardless, because in a pinch the kernel will reclaim pages that are mmapped to files. Most typically binaries and librairies. Which means the process in question will incur a map page read next time it schedules. But of course you're out of memory, so the kernel will…

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.

Re: Modernizing Linux swapping: introducing the swap table

#54
post #23

Earlier quoted context omitted.

I've heard "square root of physical memory" as a heuristic, although in practice I use less than this with some of my larger systems.

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.

That's not so much a rule of thumb as an assessment you can only make after thorough experimentation or careful analysis.

Re: Modernizing Linux swapping: introducing the swap table

#55

Earlier quoted context omitted.

The pro-swap stance has never made sense to me because it feels like a logical loop. There’s a common rule of thumb that says you should have swap space equal to some multiple of your RAM. For instance, if I have 8 GB of RAM, people recommend adding 8 GB of swap. But since I like having plenty of memory, I install 16 GB of RAM instead—and yet, people still tell me to use swap. Why? At that point, I already have the s…

> There’s a common rule of thumb that says you should have swap space equal to some multiple of your RAM. That rule came about when RAM was measured in a couple of MB rather than GB, and hasn't made sense for a long time in most circumstances (if you are paging our a few GB of stuff on spinning drives your system is likely to be stalling so hard due to disk thrashing that you hit the power switch, and on SSDs you are…

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, it is going to become unresponsive very quickly - 0.1% memory excess causes a 2x degradation, 1% - 10x degradation, 10% - 100x degradation.

Re: Modernizing Linux swapping: introducing the swap table

#56

Earlier quoted context omitted.

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.

That's not so much a rule of thumb as an assessment you can only make after thorough experimentation or careful analysis.

You don't need "horough experimentation or careful analysis". Just keep free swap space below few hundred megabytes but above zero.

Re: Modernizing Linux swapping: introducing the swap table

#58

Earlier quoted context omitted.

That's not so much a rule of thumb as an assessment you can only make after thorough experimentation or careful analysis.

You don't need "horough experimentation or careful analysis". Just keep free swap space below few hundred megabytes but above zero.

"Keep swap space below few hundred megabytes but above zero" is a good example of a rule of thumb.

"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" is not.

Re: Modernizing Linux swapping: introducing the swap table

#59

I'd like to see Linux gain support for actual memory compression, without the need to go through zram, similar to macOS/Windows.

zram has been "obsolete" for years, I don't know why people still reach for it. Linux supports proper memory compression in the form of zswap https://wiki.archlinux.org/title/Zswap

I didn't realize zswap also uses in-memory compression. It might be a combination of poor naming and zram being continuously popular.

Re: Modernizing Linux swapping: introducing the swap table

#60
post #29

Earlier quoted context omitted.

That's not useful as a rule of thumb, since you can't know the size of "all inactive anonymous pages" without doing extensive runtime analysis of the system under consideration. That's pretty much the opposite of what a rule of thumb is for.

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 GBs of RAM). Check its utilization periodically. If it is full, add a few hundred megabytes more. That's all.

It's not like it's easy to shuffle partitions around. Swap files are a pain, so you need to reserve space at the end of the table. By the time you need to increase swap the previous partition is going to be full.

Better overcommit right away and live with the feeling you're wasting space.

Post reply on HN