Live data from Hacker News

Modernizing Linux swapping: introducing the swap table

lwn.net

91–100 of 132 posts

Re: Modernizing Linux swapping: introducing the swap table

#91
post #84

Earlier quoted context omitted.

It's not possible for the kernel to predict the memory needs of a process unfortunately

But how about not scheduling swapped out processes if there currently is no free ram for their current RSS? of course kernel cannot know that a new process will balloon to eat all RAM, but once it has done so, is there a way to let it run to completion without being swapped out to "improve responsivity"?

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 memory.

Re: Modernizing Linux swapping: introducing the swap table

#92

Earlier quoted context omitted.

Indeed. I think what's really needed is some way to mark pages as "required for interactivity" so that nothing related to the user interface gets paged out, ever. That, I think, would go at least some way towards restoring the feeling of "having a computer's full attention" that we had thirty years ago.

There is, mlock() or mlockall(), but it requires developer support. I wish there is an administrator knob that allows me to mark whole processes without needing to modify them.

There is cgroup memory.min

Re: Modernizing Linux swapping: introducing the swap table

#93

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

It is not obsolete. It's also useful for other things.

Re: Modernizing Linux swapping: introducing the swap table

#94
post #34

Earlier quoted context omitted.

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.

I do wish there was a way to reserve swap spaces for hibernation that don't contribute to the virtual memory. Else by construction the hibernation space is not sufficient for the entire virtual memory space, and hibernation will fail when the virtual memory is getting full.

this. i don't even want swap for my apps. they allocate to much memory as it is. i'd rather they be killed when the memory runs out or simply be prevented from allocating memory that's not there. the kind of apps that can be safely swapped out are rarely using much memory anyways.

but i do want hibernate to work.

Re: Modernizing Linux swapping: introducing the swap table

#95

One pet peeve I have with virtual memory management on Linux is that, as memory usage approaches 100%, the kernel starts evicting executable pages because technically they're read-only and can be loaded from disk. Thus, the entire system grinds to a halt in a behavior that looks like swapping, because every program that wants to execute instructions has to load its instructions from disk again, only to have those ins…

Is it as bad with ssd?

Re: Modernizing Linux swapping: introducing the swap table

#96
post #87
post #44

Earlier quoted context omitted.

> RAM is for volatile data, disk is for data persistence. Genuinely curious where this idea has come from. Is it something being taught currently?

No, not currently -- since the start of computers. This is quite literally part of Computing 101; see https://web.stanford.edu/class/cs101/lecture02.html#/9 , slides 10-12. You can ask your favourite search engine or language fabricator about the differences between RAM and disk storage, they will all tell you the same thing. Frankly, it's kind of astonishing that this needs to be explained on a site like HN.

I have no idea where on those slides it says non-volatile storage should not be used for non-permanent, temporary data.

It does note main differences (speed, latency, permanence). How does that limit what data disk can be used for?

What would one use optane DIMMs for?

Also, if my program requires huge working set to process the data, why would I spend the effort and implement my own paging to templrary working files, instead of allocating ridiculous amount of memory and letting OS manage it for me? What is the benefit?

Re: Modernizing Linux swapping: introducing the swap table

#97
post #37
post #30

Earlier quoted context omitted.

I'm also in the GP's camp; RAM is for volatile data, disk is for data persistence. The first "why would you do that" that needs to be addressed is why volatile data should be written to disk. And "it's just a few % of your disk" is not a sufficient answer to that question.

Because of cost - particularly given the current state of the RAM market. In order to have so much memory that you never hit memory spikes, you will deliberately need to buy RAM to never be used. Note that simply buying more RAM than what you expect to use is not going to help. Going back to my post from earlier, I had a laptop with 8GB of RAM at a time where I would usually only need about 2-4GB of RAM for even rela…

how much swap do you have? i have 16GB now, and 16GB ram. i had a machine before with 48GB ram. obviously having more ram and no swap should perform better than the same amount of memory split into ram and swap.

Re: Modernizing Linux swapping: introducing the swap table

#98

Earlier quoted context omitted.

Actively used executable pages are explicitly excluded from reclaim. And if they are not used, why should they stay in memory when the memory is constrained? It is not the first time I have heard complaints about executable pages, but it seems to be some kind of common misunderstanding. https://news.ycombinator.com/item?id=45369516

What is "actively used"? The bash session that I was using 2 seconds before system grinded to a halt sure didn't count.

The set of possibly blocking operations for interactively using bash is big. Executable pages of the bash executable are far from the only thing that could be missing.

If the machine is swap trashing, all i/o goes to the same congested queue. .bash_history read or write access, memory allocation, stuff your terminal program does, stuff your wayland compositor or X11 stack does, bash accessing data in its memory that has been swapped out, etc etc. And each of those could be waiting for a while to issue their IO request since the IO system is flooded by swap IO.

There should be a tool that can show the interdependent graph of pending, blocking io operations.

Re: Modernizing Linux swapping: introducing the swap table

#99

Both Canonical and Microsoft recommend enabling swap file for Ubuntu cloud images, even if you allocate plenty of RAM to the VM. Any thoughts on that?

https://chrisdown.name/2018/01/02/in-defence-of-swap.html

I get we want a magical OS that reads minds and abstracts itself from users, but these days low mem situations are technical events for people trying to optimize resources use and balance uptime.

So not being able to mark apps processes as kill me first and leave others like ssh bash up is a missing feature.

Shouldn't the os have a bunch of auto hooks to invoke for machines under duress? Yes you might be able to do it in userspace but .. userspace will probably get unpredictability nuked in stress situations.

The WMs should have a "freeze all apps desktop except this one shell window" mode. Didn't NeXT have that?

Having some swap basically required has always seemed like a smell. A legacy from the 640k oops wasn't enough days. I can see emergency memory swap system as a feature, which it currently isn't...

Re: Modernizing Linux swapping: introducing the swap table

#100
post #7

Earlier quoted context omitted.

I ran Linux without swap for some years on a laptop with a large-for-the-time amount of RAM (about 8GB). It _mostly_ worked, but sudden spikes of memory usage would render the system unresponsive. Usually it would recover, but it in some cases it required a power cycle. Similarly, on a server where you might expect most of the physical memory to get used, it ends up being very important for stability. Think of VM or…

I dont get why anti-swap is so prevalent in Linux discussions. Like, what does it hurt to stick 8-16-32gb extra "oh fuck" space on your drive. Either you're going to never exhaust your system ram, so it doesn't matter, minimally exhaust it and swap in some peak load but at least nothing goes down, or exhaust it all and start having things get OOM'd which feels bad to me. Am I out of touch? Surely it's the children wh…

1) in the Microsoft days I would have a lot of available ram, bur windows still would aggressively swap, and I would get enraged when changing to an app that would have to swap in while I had 4gb of memory free

2) the os tried to be magical, but a swap thrash is still crap... I would much rather oom kill apps than swap thrash. For a desktop user: kill the fucking browser or electron apps, don't freeze the system/ui.

Post reply on HN