|
|
Log in / Subscribe / Register

Does it actually work?

Does it actually work?

Posted Apr 11, 2025 10:16 UTC (Fri) by Wol (subscriber, #4433)
In reply to: Does it actually work? by intelfx
Parent article: Three ways to rework the swap subsystem

> > But why? What makes that impossible precisely and exactly on Linux while perfectly possible on other OSes?

> Because you are (either accidentally or deliberately) conflating swap performance and memory management strategy.

And I may well be out of date, but people seem to be conflating swapping and paging. Am I right, in that a *swap* system *swaps processes* in and out of memory. While a *paging* system *swaps pages* in and out of memory. Which is why systems that page don't become as slow as systems that swap.

So a swapping system, faced with a large executable, will pull in the entire executable in order to run it. While a paging system will map the executable, pull in the first page to execute it, and only fault in further pages as required.

Same with working memory - a paging system will file-back the memory, and presumably flush dirty pages, and flag hot pages. While a swapping system will dump the entire memory, and read it all back, as required.

So a swapping system will be (relatively) slow because it's forever flushing and retrieving entire processes. A paging system on the other hand, will be dropping clean cold pages if required, so any program that is actively running will normally keep its hot paths in RAM without being dropped.

Cheers,
Wol


to post comments

Does it actually work?

Posted Apr 11, 2025 11:48 UTC (Fri) by daroc (editor, #160859) [Link] (1 responses)

I'm not intimately familiar with Linux's swap system, but I think the distinction you're making is not one the swap system makes. On my laptop right now I have ~500MB in swap, which appears to be small sections of memory from a variety of different processes.

Does it actually work?

Posted Apr 11, 2025 12:51 UTC (Fri) by khim (subscriber, #9252) [Link]

If I remember correctly μClinux can use “a swapping system” (just like ancient Unix versions like Xenix 8086 had to do because they worked on a system without any MMU, even strange and primitive ones, like 80286).

Mainstream Linux never had support for “a swapping system”, because it was never supported any hardware where that even makes any sense.

MacOS (Classic) and Windows developed very elaborate and clever system with handles and movable pages and also never did that.

That's why that distinction that Wol talks about is more-or-less forgotten in a world of modern software.

Does it actually work?

Posted Apr 11, 2025 12:44 UTC (Fri) by khim (subscriber, #9252) [Link] (3 responses)

> And I may well be out of date, but people seem to be conflating swapping and paging.

Well… there's a reason for that. Indeed, you are a bit out of date. About 30-40 years our of date, give or take.

> Am I right, in that a *swap* system *swaps processes* in and out of memory. While a *paging* system *swaps pages* in and out of memory. Which is why systems that page don't become as slow as systems that swap.

That's true, but the problem here is that the last system that was swapping out processes that someone may have had a chance to use was probably a DOS Shell that was included in MS DOS 4 (that's year 1988), moved to supelement disk in MS DOS 6 (that's year 1993) and excluded from Windows 95 (and later version). DR-DOS also had similar thing (it was born out of Concurrent_CP/M-86 that was used swapping, after all), but I don't remember the dates.

Linux, Windows and macOS never used this strategy and thus it's very hard for anyone to even recall that ever existed.

> So a swapping system will be (relatively) slow because it's forever flushing and retrieving entire processes. A paging system on the other hand, will be dropping clean cold pages if required, so any program that is actively running will normally keep its hot paths in RAM without being dropped.

You are absolutely correct, but in a world where “a swapping system” is “something that briefly existed very long time ago and for a relatively short time”… most people wouldn't even understand what you are talking about when you would start discussing that difference. Paging needs support in hardware to be efficient, but after Intel made said support mandatory with introduction of 80386 in 1985 no one was even thinking about using “a swapping systems” for anything anywhere.

From what I understand swapping was popular before introduction of IBM/370 in 1970, but I don't know the history of computers well enough to say how exactly “a swapping systems” and “a paging system” competed 50 years ago. “A swapping systems” were already a stuff that you read in a history book and not use for work, when Linus started work on Linux, thus, of course, in the context of Linux they don't matter at all.

Does it actually work?

Posted Apr 11, 2025 14:51 UTC (Fri) by Wol (subscriber, #4433) [Link] (2 responses)

> From what I understand swapping was popular before introduction of IBM/370 in 1970, but I don't know the history of computers well enough to say how exactly “a swapping systems” and “a paging system” competed 50 years ago. “A swapping systems” were already a stuff that you read in a history book and not use for work, when Linus started work on Linux, thus, of course, in the context of Linux they don't matter at all.

I think you might be surprised then!

The original linux "swapping system" is pretty much an exact copy of the original Unix swapping system, which probably does date from your aforementioned 1970!

Do you remember back when Linus made a rather controversial change to linux swap, 2.4.10 or 2.6.10 I think - I remember it was roughly a 10 - that gave people running Vanilla Linux a massive shock? Do you remember the old saw that "swap must be at least twice ram" which most people - even back then - thought was an old wive's tale?

Because Linus ripped out all the optimisation code, and that requirement came back! If you had a swap file, and the system tried to touch just ONE BYTE of swap, if it didn't have at least twice ram available, it locked up. HARD. (Most people didn't notice, because the distros put the code back ...)

But that was sparked by Andrea Arcangeli and ?Rick van Riel? squabbling over a new approach to memory management. I don't know the end of that story, other than the "swap system" was replaced with something much better and I don't know what the new system does.

I thought all this was documented by LWN, and I've tried to find it on several occasions without success. It could have been Zak's Kernel News, which was quite big back then ...

Cheers,
Wol

Does it actually work?

Posted Apr 11, 2025 15:27 UTC (Fri) by khim (subscriber, #9252) [Link] (1 responses)

> The original linux "swapping system" is pretty much an exact copy of the original Unix swapping system, which probably does date from your aforementioned 1970!

Maybe in some very early versions, I'm not familiar with what was there before Linux 1.2.something

> Do you remember back when Linus made a rather controversial change to linux swap, 2.4.10 or 2.6.10 I think - I remember it was roughly a 10 - that gave people running Vanilla Linux a massive shock?

Definitely not 2.4.10 and not 2.6.10. Maybe 1.1.10? Very unlikely even back then, actually.

I know that with Linux 2.2 it was already possible to build MySQL by adding temporary swap on my puny machine with 16MiB RAM. I.e. Linux behaved example like macOS behaves today and how tutorials sell “virtual memory” idea normally: if your system doesn't have enough RAM… just add more swap and get more virtual RAM!

That's fundamentally impossible with “a swapping system” approach: if you are swapping out the whole process and there are not enough RAM to even put a single copy in memory, then that's it, you couldn't continue…

I think what you remember is different quirk that early versions of Linux had: in early versions of Linux each page had a static place in swap (but could be loaded into memory in different places) and that meant that total amount of virtual memory was equal to the size of swap and not to the size of swap+RAM. That was somewhat irritating, sure, but I don't remember any version of Linux (except μClinux) that swaps out whole processes and not individual pages.

And yes, this is exactly what puzzles me, too: I know that it was possible to use Linux while using swap and a “poor man's RAM extension” quarter century ago. And it's essentially not possible to use it like that today. But what and when have changed? Was that change to Linux or to something in userspace? I actually suspect it's change to userspace: while old twm/fvwm/mwm setup designed to support dozen of hardware X terminals over slow network was very frugal in it's copying of data and thus worked even on Linux with pretty inefficient swap implementation “new way” with Compiz and its descendants now copies megabytes (or maybe gigabytes?) of data around every time it needs to redraw a single pixel… and without pile of hacks that macOS or Windows employ that means that use modern Linux UI without enough actual, real, physical RAM is, pretty much, impossible.

> I thought all this was documented by LWN, and I've tried to find it on several occasions without success. It could have been Zak's Kernel News, which was quite big back then ...

It would be great to find out. Because I don't remember of any version of Linux that had “a swapping system”, but I sure remember that time when Linux used swap inefficiently… yet it paging, just not a very efficient one… you were able to run app that needed more memory than system has physically available on all versions of Linux that I ever used.

Does it actually work?

Posted Apr 11, 2025 15:49 UTC (Fri) by corbet (editor, #1) [Link]

Wol is thinking about the big MM switch in 2.4.10 - see this page.

Linux has never had full-process swapping, though. What is called "swap" is paging for anonymous memory.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds