Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
Hardware Linux

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

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.

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

  • by rossdee ( 243626 )

    Why do we need virtual memory these days?

    • Re: (Score:3, Informative)

      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 w
      • If your memory is so tight that you need all this shuffling, maybe you should invest another $25 for more RAM!

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

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

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

    • 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

You've been Berkeley'ed!

Working...