

Linux Swap Table Code Shows The Potential For Huge Performance Gains (phoronix.com) 42
A new set of 27 Linux kernel patches introduces a "Swap Tables" mechanism aimed at enhancing virtual memory management. As Phoronix's Michael Larabel reports, "the hope is for lower memory use, higher performance, dynamic swap allocation and growth, greater extensibility, and other improvements over the existing swap code within the Linux kernel." From the report: Engineer Kairui Song with Tencent posted the Swap Table patch series today for implementing the design ideas discussed in recent months by kernel developers. The results are very exciting so let's get straight to it: "With this series, swap subsystem will have a ~20-30% performance gain from basic sequential swap to heavy workloads, for both 4K and mTHP folios. The idle memory usage is already much lower, the average memory consumption is still the same or will also be even lower (with further works). And this enables many more future optimizations, with better defined swap operations." "The patches also clean-up and address various historical issues with the SWAP subsystem," notes Larabel.
Context: In Linux, swap space acts as an overflow for RAM, storing inactive memory pages on disk to free up RAM for active processes. Traditional swap mechanisms are limited in flexibility and performance. The proposed "Swap Tables" aim to address these issues by allowing more efficient and dynamic management of swap space, potentially leading to better system responsiveness and resource utilization.
Context: In Linux, swap space acts as an overflow for RAM, storing inactive memory pages on disk to free up RAM for active processes. Traditional swap mechanisms are limited in flexibility and performance. The proposed "Swap Tables" aim to address these issues by allowing more efficient and dynamic management of swap space, potentially leading to better system responsiveness and resource utilization.
Huge Performance Gains... (Score:3)
For those unfortunate / foolish enough to be relying on swap...
Re: (Score:2)
This was going to be my response as well. I can't remember the last time I ran a linux instance with insufficient memory. But I can see use cases on SOC or IoT devices.
Re:Huge Performance Gains... (Score:5, Informative)
Re: (Score:2)
I've seen this on the fine print with the marketing of low-end Android tablets on Amazon and ebay.
6GB of RAM - i.e. 4+2. but does anyone really want the wear and tear of writing to storage on media that is soldered in? Admittedly this is throwaway hardware that will end up in landfill/recycling within 4 years but still...
Re: (Score:2)
Yep, thought the same thing. Faking memory is not really for regular use ...
Re: (Score:2)
Re: (Score:2)
The problem is on your side. Because that is not what I wrote. Some clue required...
Re: (Score:2)
Second one was my programming mistake.
It got me some extra time to kill the process that was consuming all the memory.
Linux uses Swap even when memory isn't full (Score:5, Informative)
Re:Linux uses Swap even when memory isn't full (Score:4, Informative)
It's almost never a good idea to leave this value at it's default. For example - the "tuned" profile "throughput-performance" will set this down to 5.
Re: (Score:3)
I always disable swap, unless I am on some pathetically limited hardware. I have 64GB RAM in my desktop and 8GB in my laptop, and no need for any swap on either. Swap just means the system thrashes more before the OOM killer kicks in, plus I don't need a bunch of extra writes on my SSDs.
Re: (Score:2)
I always disable swap, unless I am on some pathetically limited hardware. I have 64GB RAM in my desktop and 8GB in my laptop, and no need for any swap on either. Swap just means the system thrashes more before the OOM killer kicks in, plus I don't need a bunch of extra writes on my SSDs.
My desktop also has 64GB of RAM but it does swap occasionally.
Re: (Score:2)
If I use up all of the RAM on the system, it's not necessarily me that dies from an sbrk() failure before the OOM killer kicks in.
There's a reason machines have swap by default- it's because those that design them are smarter than you are.
Re: (Score:2)
I used a 4GB 2008 laptop until half a year ago when hardware issues forced me to replace it (this one a 2020 Dell with an upgrade to 32GB for the heck of it).
Swap was essential for daily use because the browser already used up loads of RAM (not even using Firefox or Chromium) and I activated zswap some years ago eventually when I read about it.
It did the trick of improving overall peformance and seemed to save on disk read and writes as well from observation, and I still have zswap enabled on this laptop ju
Re: (Score:2)
I always disable swap, unless I am on some pathetically limited hardware. I have 64GB RAM in my desktop and 8GB in my laptop, and no need for any swap on either. Swap just means the system thrashes more before the OOM killer kicks in, plus I don't need a bunch of extra writes on my SSDs.
I always have craploads of swap precisely because it makes thrashing much much less worse when I do exceed the RAM. I do have enough RAM, but I sometimes screw up. If you're dealing with multi-10 GB datasets it doesn't take
Re: (Score:2)
Same here. Linux is, unlike traditional UNIX, designed to run be this way as well. This becomes important in diskless setups (small embedded uses, for example) and convenient in desktop or server use with plenty of memory. As a bonus, you do not have to worry about secrets ending up in swap if you run swapless and things become a bit simpler, which is always a plus.
Re: Linux uses Swap even when memory isn't full (Score:3)
It's almost never a good idea to leave this value at it's default. For example - the "tuned" profile "throughput-performance" will set this down to 5.
Yah that still swaps. Linux will fill all physical memory with filesystem cache first. Then does one of two things for each cache miss. At a swappiness of 5, for every 100 pages read, 97 pages of old FS cache will be replaced and 3 of some process's idle memory will get swapped out. All you're doing is slowing it down, and over time you'll always have a bunch of process memory swapped out. The actual rate it happens at depends on your workload, how many cache misses you get over time. A daily filesystem bac
Re: (Score:2)
Re: (Score:2)
Yes, this can increase performance. Basically if the system is idle enough, Linux can write changed pages to disk ahead of time so if it needs to swap out the pages, they've already been committed to disk and can immediately be reallocated on demand.
Basically instead of writing data to disk when you need to, you write it ahead of time so if it's needed, it's already done. It requires a balance - you don't want to be too aggressive and writing data constantly to disk because you can use up valuable disk I/O
Why (Score:2)
Why do we need virtual memory these days?
Re:Why (Score:4, Informative)
Re: (Score:2)
If your memory is so tight that you need all this shuffling, maybe you should invest another $25 for more RAM!
Re: (Score:2)
Your statement isn't wrong, but only really valid for desktops. Sure, top-class laptops have replaceable RAM, but even on mid-class laptops RAM is being soldered and can't be upgraded anymore. Soldered RAM is pretty much the only option you'll get in low-class laptops. Margins have been very thin for quite a while now in "laptop land". And soldered RAM is cheaper than installing connectors to have upgradeable RAM. As a manufacturer, that choice is easily made.
Pop!_OS 20.04 ran marvelously well in my Lenovo
Re: (Score:2)
Virtual Memory does not require swapping ability to still be VM. Swapping is an optional add-on feature.
Re: (Score:2)
BTW: Swap space is still a physical memory type, just like DRAM, but much slower access.
Re: (Score:3)
I understand the usage of the term "virtual memory" here, as its been incorrectly correlated to swapping memory to disk since its inception really... but i do hope at some point the realization in the broader community that "virtual memory" literally means all memory on a modern operating system's user space. this is how we can get multiple instances of the same application running at once, as they're using the same virtual memory addresses that are then translated over to physical addresses by the memory c
English is an overloaded language Re:Why (Score:1)
We use the same words or phrases for different things. Sometimes this leads to confusion.
Re: (Score:2)
This is not one of those cases. Virtual memory is not swap. Anyone that conflates the two has just got it wrong.
Re: (Score:2)
You might find it helpful to read the summary.
Context: In Linux, swap space acts as an overflow for RAM, storing inactive memory pages on disk to free up RAM for active processes
This is indeed talking about swapping memory pages to disk.
Re: (Score:2)
Yes, the question asked "Why do we need virtual memory these days?" looks to be conflating VM with swap. Hence the attempts to clarify.
Re:Why (Score:4, Informative)
According to the summary:
Context: In Linux, swap space acts as an overflow for RAM, storing inactive memory pages on disk to free up RAM for active processes
This is clearly referring to swapping memory to disk, not your proposed concept of "all memory on a modern OS user space."
Re: (Score:2)
The question asked "Why do we need virtual memory these days?" looks to be conflating VM with swap. Hence the attempts to clarify.
Re: (Score:2)
Also, the translation happens on the CPU well before the memory controller (or even the root complex).
Re: (Score:2)
Well, for one specific case; I needed to start up four VMs in my home lab for a test where each one needed 16GB of RAM, my system had 64GB total, and I didn't feel like going and buying several hundred dollars of RAM, throwing away the 64GB I have already in order to do it.
Re: Why (Score:2)
That is a different use case where you wanna use KMS memory merging itâ(TM)s built into the kernel.
Re: (Score:2)
There's also the sheer convenience(and potentially better outcomes, dependi
Re: (Score:2)
You do not. I have it turned off on most of my Linux boxes. But it can still have benefits.
Re: (Score:2)
It's alright as long as you never have any kind of memory pressure, but then that just means you're really wasting a good portion of your RAM.
Re: (Score:2)
Nope. That is actually an expected use-case today. For a _classical_ UNIX it would be a bad idea, but Linux is more advanced. For example, systems like Solaris may even kernel-panic without swap. Linux does not. Also, in the classical situation, not having enough memory was normal. The modern situation is that memory is plenty and the amount you save is rather small in comparison. Of course, the used kernel must have been designed with swapless operation in mind. Linux is and you seem to be stuck a bit in t
Re: (Score:2)
I still have swap enabled on my current 32GB laptop even thought it's not used after an uptime of a month at the moment.
Zswap on top of that enables more (efficient) buffer space as it compresses old pages eligible for swap.
Then there's also the need for swap to enable hibernation to disk.
Re: (Score:2)
Hibernation is a really bad idea, for a number or reasons. One is that it is hard to secure it.
Re: (Score:2)
For address-space isolation. Swap is just a way of overloading RAM, but virtual memory has other benefits, especially the ability to run programs in entirely separate address spaces. It provides a useful mechanism for hibernation, as well. A sexier aspect is building an address space with shared read-only components and read-write areas for your applications - I'm not sure if Linux can do this, but IBM's VM operating system did this back in the 1980s.