My swapdisk can write 100 MB/s. When the system swaps out it only writes 8-20 MB/s.

iostat says the device is 100% active, so I have the feeling that Linux is seeking on the drive or swapping out small chunks.

I could explain this if there were swap-ins at the same time, but there are no swap-ins and no other disk I/O.

Is it possible for me to tell Linux to swap out in bigger contiguous chunks, say, determining the oldest 10 MB pages and swap them out in one chunk?

A bit like saying the page frame size of swap is not 4K but 10M.

For my system I think an algorithm along the lines of this would be ideal:

dirty_pct = dirty pages / all RAM
if dirty_pct > 50%:
   # Half of memory is dirty, slowly start swapping out
   if busy_time(swapdevice) < dirty_pct:
       # if RAM is 60% dirty, start swapping if disk is less than 60% busy
       # if RAM is 90% dirty, start swapping if disk is less than 90% busy
       identify the next 10 MB that would be swapped if dirty_pct had been 100%
       save the 10 MB to swap as a single chunk
       mark the pages as clean

This way my system would start swapping out at 50% dirty and it would not affect performance, because it would do so on a drive that was sitting idle anyway. Maybe the swapped data will never be used, and then we wasted some IO that was sitting idle anyway.

$ uname -a
Linux r815 4.15.0-99-generic #100-Ubuntu SMP Wed Apr 22 20:32:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • 1
    Use zram instead it'll be much easier to achieve hundreds of MBs or even GB/s – phuclv May 9 '20 at 5:49
  • @phuclv How? I am seriously asking because I am already using zswap and that does nothing for swapping faster to disk. It compresses to RAM, but when it runs out of RAM it starts swapping to disk, too. And that is the situation I am in. – Ole Tange May 9 '20 at 7:48
  • well if you really lack that much memory then I think it'll be better to buy more memory or at least use an SSD which has much higher IOPS and lower access time. If you use an HDD then random read/write will be terrible. I've never used zswap so I'm not sure whether it's better or worse than zram. You can try switching to zram for sometime to see – phuclv May 9 '20 at 8:19
  • @phuclv That might be a workaround. It still does not explain why my current drive is only writing 8-20 MB/s when it could be writing 100 MB/s. – Ole Tange May 9 '20 at 8:22
  • it's already there iostat says the device is 100% active, so I have the feeling that Linux is seeking on the drive or swapping out small chunks HDDs can only serve about 80-150 IOPS so if the request queue is already full the performance will be capped at that point. If each request only reads a tiny amount of blocks then you won't be able to achieve the maximum speed. SSD can achieve 150000-500000 IOPS so it'll be better. Without SSD on Windows there's ReadyBoost which utilizes the low access time of USB flash drives or SD cards but there's nothing like that on Linux – phuclv May 9 '20 at 8:29

Not. It isn't possible.

Linux Kernel decide through different algorithms about RAM, Swap Spaces, Last Swap Location Used, Disk Cache Responsive, Swapiness and so other things when and how to use Swap memory allocation.

The system can't just wait to have "10MB> page collection" because memory managing is on-demand to avoid system freezes and process killing.

However, some bugs related to RAM and Swapping management have been reported during the years due to really bad performance when the system starts to swap.

I can say you that Disk Usage is improvable using zswap, because the biggest problem here is the exponential multiplication of pages when arriving swap (that's because memory pages linking).

zswap compress that multiplication, making less disk reads/writes and can have a prominent impact on your CPU usage.

zswap is kernel-managed and you have a lot of useful low-level configurations to adapt it to your system needs.


  • I am already using zswap and while it helps a little, it also hits the disk eventually. Can you elaborate why the system cannot immediately identify the next 10 MB that would be swapped and why my algorithm above is impossible to implement? – Ole Tange May 9 '20 at 8:17

nice question. it depends on the type of filesystem you mount. I think it something related to the kernel space, but googling on it I found that on xfs filesystem you can debug it at userspace level :


  • 1
    You link is about Extent swap is a low level mechanism exported by XFS to facilitate filesystem defragmentation. That does not seem to be relevant to memory swapping. – Ole Tange May 8 '20 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.