Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
Hardware Linux

Linux Swap Table Code Shows The Potential For Huge Performance Gains (phoronix.com) 50

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.

Linux Swap Table Code Shows The Potential For Huge Performance Gains

Comments Filter:
  • by yababom ( 6840236 ) on Friday May 16, 2025 @07:41PM (#65382141)

    For those unfortunate / foolish enough to be relying on swap...

    • by Sethra ( 55187 )

      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.

      • by dsgrntlxmply ( 610492 ) on Friday May 16, 2025 @08:13PM (#65382205)
        I have direct experience with this in consumer electronics. Working at minimum hardware cost alongside application flexibility and variation in externally supplied data, one can at times rapidly get into an acute memory shortage. A swap mechanism can give a few extra seconds to recognize the condition and to evict something to resolutely reclaim some space.
      • 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...

    • by gweihir ( 88907 )

      Yep, thought the same thing. Faking memory is not really for regular use ...

    • Well it saved me a few times when dealing with a memory-leak/run away process.
      Second one was my programming mistake.

      It got me some extra time to kill the process that was consuming all the memory.
  • by BrightCandle ( 636365 ) on Friday May 16, 2025 @08:02PM (#65382179)
    Linux uses swap even when RAM isn't full. VM_Swappiness means that it will push pages of programs memory use out if it thinks it can get more performance with the memory for file caching. More information on how this sort of works before this patch: https://www.howtogeek.com/4496... [howtogeek.com]
    • by Sethra ( 55187 ) on Friday May 16, 2025 @08:11PM (#65382199)

      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.

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

        • by erice ( 13380 )

          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.

          • I run gentoo and some compiles can be really big
          • My backup regime compresses using lrzip, which will use tons of memory. It is quite a bit more efficient than less memory hungry compressors.
        • This is insane. Without swap, a single process can bring down the entire system if not properly ulimited.

          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.
          • by gweihir ( 88907 )

            You have no clue what you are talking about. With swap, a single process can bring down the entire system if not ulimited properly as well. It just takes a bit longer and may put serious load on your disk (not good) before things grind to a halt. Seriously, stop claiming nonsense.

        • 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

        • 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

        • by gweihir ( 88907 )

          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.

      • 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

      • The fact that it is not set to zero should tell you something important.
    • by tlhIngan ( 30335 )

      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

  • by rossdee ( 243626 )

    Why do we need virtual memory these days?

    • Re:Why (Score:5, Informative)

      by BrightCandle ( 636365 ) on Friday May 16, 2025 @08:17PM (#65382219)
      Because it improves performance by saving drive reads and writes. For example we have a program in memory and its doing nothing sat idle consuming half of all our memory. But we are using another program which is reading lots of files in and writing out updates. The second program if given more RAM for caching the file contents its reading would run considerably faster, the NVMe SSD might read at a few 1GB/s but RAM is going to be 100x faster. If the OS pushes the unused programs memory out onto the swap we can that memory for file cache and get better performance for the current program doing work. We can also cache writes into files and only push completed large groups of blocks back to the drive allowing bigger sequential writes which results in less IO overhead and sequential access. If you have ever run CrystalDisk you will know is substantially faster to do this than apparently random writing or individual blocks of 4k.
      • If your memory is so tight that you need all this shuffling, maybe you should invest another $25 for more RAM!

        • 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

          • by gweihir ( 88907 )

            That is some advanced nonsense. Servers run just as well as desktops swapless. The only thing swap does on Linux is that running out of memory comes a bit later.

          • You're right about laptops. They are hard to upgrade, and this is a big problem for me as a developer.

    • by evanh ( 627108 )

      Virtual Memory does not require swapping ability to still be VM. Swapping is an optional add-on feature.

      • by evanh ( 627108 )

        BTW: Swap space is still a physical memory type, just like DRAM, but much slower access.

    • by darkain ( 749283 )

      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

      • We use the same words or phrases for different things. Sometimes this leads to confusion.

        • by evanh ( 627108 )

          This is not one of those cases. Virtual memory is not swap. Anyone that conflates the two has just got it wrong.

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

            • by evanh ( 627108 )

              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)

        by Tony Isaac ( 1301187 ) on Saturday May 17, 2025 @12:07AM (#65382555) Homepage

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

        • by evanh ( 627108 )

          The question asked "Why do we need virtual memory these days?" looks to be conflating VM with swap. Hence the attempts to clarify.

      • Not just userspace. Kernel doesn't operate on unmapped memory, either.
        Also, the translation happens on the CPU well before the memory controller (or even the root complex).
        • by cstacy ( 534252 )

          Not just userspace. Kernel doesn't operate on unmapped memory, either.

          Also, the translation happens on the CPU well before the memory controller (or even the root complex).

          You are correct in correcting someone there, but I'll just mention that originally, in the old days, CPUs did not have virtual memory and it was done by a separate memory controller circuit. They sometimes called it a Memory Management Unit (MMU). This was the case even with advanced microprocessor chips, not just the really ancient iron.

      • by cstacy ( 534252 )

        Mapping tricks notwithstanding, VM was more interesting in the old days when you had much more RAM than address space. (And we had demand paging / swapping, too. Just less likely to get there.)

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

      • That is a different use case where you wanna use KMS memory merging itâ(TM)s built into the kernel.

      • by cstacy ( 534252 )

        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.

        It's too bad the virtual machine instances can't share pure pages with each other.

    • I suspect, in part, the same reasons that we historically did. You are much less likely to be on a 32 bit system and it's a lot easier to afford a lot of RAM in absolute terms; but it remains pretty expensive to have more RAM than you'll ever need, mass storage remains considerably cheaper than RAM, and it's typically still preferable to have things slow down when you run out of RAM rather than having the OOM killer sweep through.

      There's also the sheer convenience(and potentially better outcomes, dependi
    • by gweihir ( 88907 )

      You do not. I have it turned off on most of my Linux boxes. But it can still have benefits.

      • That is a terrible idea, for performance and for stability.

        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.
        • by gweihir ( 88907 )

          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

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

        • by gweihir ( 88907 )

          Hibernation is a really bad idea, for a number or reasons. One is that it is hard to secure it.

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

      • by gweihir ( 88907 )

        Indeed. Virtual memory is not even required for swap or the other way round. It is just convenient to do both at teh same time as the needed hardware in the MMU has overlaps. But running swapless does in no way mean running without virtual memory.

"Mr. Spock succumbs to a powerful mating urge and nearly kills Captain Kirk." -- TV Guide, describing the Star Trek episode _Amok_Time_

Working...