3

I have 24GB of available RAM in my machine, but I usually use far less than 8GB of it. However, sometimes I'm involved with large data files and I suddenly need 40GB, and on infrequent occasions, I'd like to be able to access even more (up to 60GB). This is mainly using numpy and Apache Arrow.

Right now I have a 20GB ssd swap file, and that works fine, but is obviously slow. I'd like to replace it with zRAM, and assuming say I get double compression on 16GB, that's 32GB, plus the leftover 8GB = 40GB total in "ram". Ideally though, I'd like to go even bigger than 40GB on occasion, and wonder if it's possible for the stuff that doesn't fit into zRAM to spillover further into a "traditional" SSD swap file or partition.

Is this doable? Obviously I'd want the zRAM to be prioritised over the disk swapfile.

3
  • What version of Ubuntu are you using?
    – David
    Mar 28, 2022 at 11:28
  • Looks like this answer might be helpful. unix.stackexchange.com/questions/613265/…
    – PonJar
    Mar 28, 2022 at 11:38
  • another tool is the package swapspace, which grows and shrinks the size of the swap file on demand. I use zswap and swapspace combined. A growing and shrinking swapfile is not the silver bullet it may seem since you need to have the free disk when required, but it is a final line of defence if you face a massive surge in demand for memory. Feb 13, 2023 at 5:19

2 Answers 2

7

zram

zram essentially is storage of compressed swap data in memory rather than on a disk. It acts as a regular and separate swap device. It thus can be used as additional swap space, besides swap partitions or swap files, and be given a certain priority.

Priorities for swap can be set with the swapon tool, and can be defined in /etc/fstab with the pri=value option. See man swapon.

Consider also zswap

Instead of using zram, you may consider another technology, zswap. Here, also memory is used to store swapped data. However, with this mechanism, your memory acts as a compressed memory cache for swap. Data that needs to be cached is first stored in zswap, and only committed to disk if needed, speeding up swapping and reducing disk I/O.

3
  • aha! So if I understand correctly, zswap combines both of the steps in one? Mar 28, 2022 at 13:55
  • 2
    Not sure which steps you refer to. zswap is something different: it is a memory cache for regular swap, so with limited swapping needs, swapped data never makes it to disk, in case of higher needs, the oldest data makes it to disk. So yes, it automatically is used first, if that is what you mean with second step.
    – vanadium
    Mar 28, 2022 at 14:42
  • yeah @vanadium I thought it might be a replacement for a swapfile but instead one uses the regular swap file and zswap simply ensures that (compressed) RAM is used first. It's exactly what I need. I found this broadly to be pretty good: wiki.archlinux.org/title/zswap Mar 28, 2022 at 17:34
1

Or not using swap on disk any more: https://docs.kernel.org/admin-guide/blockdev/zram.html#writeback

With CONFIG_ZRAM_WRITEBACK, zram can write idle/incompressible page to backing storage rather than keeping it in memory. To use the feature, admin should set up backing device via:

echo /dev/sda5 > /sys/block/zramX/backing_dev

before disksize setting. It supports only partitions at this moment.

It will take whole partition as a fallback storage of zram like swap partition.

Or even on file: https://unix.stackexchange.com/questions/581243/using-loopdev-for-zram-writeback-feature

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .