Announcement

Collapse
No announcement yet.

Fedora 33 Looking To Use Swap On zRAM By Default With systemd's zram-generator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #21
    Originally posted by pal666 View Post
    i would rather swap to optane than waste memory on zram. and if you suffer from swapping, the most stupid thing you could do is reduce available ram
    Yet Android(Since 4.4) and ChromeOS (since 2013) have been making use of zram in RAM constrained devices. I used it myself on a 2GB RAM laptop with cheap 32GB USB stick and it was much better than swapping only to disk, the compression is quite useful. In what case would you benefit from swap on such slower storage over zram?

    I have in my notes someone doing a compilation test on a device where zram finishes the job in 47 minutes, but using swap on an HDD instead of zram took 9.5 hours, they cite it'd be much worse on slower storage media that has even worse random I/O than HDDs.


    Originally posted by tuxd3v View Post
    If Zram can use disk as swap storage, then its not Zram, but instead Zswap..
    No, it's literally in the zram kernel docs... see `CONFIG_ZRAM_WRITEBACK`

    ZRAM with backing storage will move only idle + uncompressible pages to the slower layer depending on config.

    The main difference afaik between ZRAM and ZSWAP, is that zram will create a compressed block device, which can be used for swap or other things, but it stores uncompressed data to a given limit, which is compressed at whatever ratio, the limit isn't for compressed size, so 3GB of ZRAM could be only using 1-2GB of your RAM, maybe even less depending on how well the data compresses. With zswap, it compresses the data then stores it and is only for swap.

    If you want to set a hard limit on how much RAM is used by ZRAM, you need to use `mem_limit` config(linking to the patch as the kernel docs for it are lacking). As it's a compressed block device, a uncompressed size needs to be set, it is also what the user will see as swap size like in the System Monitor utilities, although that'd probably seem a bit confusing I guess if the limit is reached but the reported swap space still has plenty of room. So if it's important for you to define a hard mem limit with less concern for the virtual block uncompressed size, then that option is there for you.

    You're only reducing memory with zram when it's actually got something allocated, you're not reserving a portion of RAM exclusively in advance. Similar to tmpfs for /tmp.

    ZSWAP is similar afaik but only for swap, keeping a cache in RAM with a max % of RAM to allow using for it, which I think is based on stored compressed size, with a backing storage swap device required instead of optional. zswap can also configure a threshold to avoid a thrashing condition between the cache in RAM and the backing storage swap device via `accept_threshold_percent`.

    ZRAM doesn't have to only be used for swap though, a phoronix user here has chimed in a few times with their knowledge on the subject and their own github projects such as zram-config.

    Comment


    • #22
      Originally posted by ssokolow View Post

      Aside from the compression, I was told that Linux's memory defragmentation requires that some swap exist to function properly and my experience has supported that.

      When I was running a pure RAM setup with 16GiB of RAM, it was as if I had a memory leak over the course of a month or two, which seemed to be spread more or less evenly across all my long-running applications. Enabling some zram-backed swap fixed the problem.
      Interesting. Does anyone else have a comment or experience with this? All the desktop computers I've owned for the past ten years have had 12 or more GB of RAM, so I haven't set up a swap partition in years. I guess I should set one up just in case.

      Comment


      • #23
        You'd probably get a little better overall performance if you enable swap.

        Comment


        • #24
          Originally posted by polarathene View Post
          No, it's literally in the zram kernel docs... see `CONFIG_ZRAM_WRITEBACK`

          ZRAM with backing storage will move only idle + uncompressible pages to the slower layer depending on config.
          Many thanks for your comment.
          you are talking about a baking device as if you were using a disk for swaping, but its for iddle/incompressible pages..
          Also its a optional feature, like you said..
          Code:
          * Optional Feature
          = writeback
          But my understanding about Zram is ok, I use it for quite some time, with lz4( lz4 is blazing fast even in arm devices.. ) algo( compression ratio ~3:1 aprox.. )

          Now my comment,
          Was about Zswap..
          I got the impression that it is compression to disk, or maybe that was the unique feature that I saw on it, last time I checked..
          But you and others are saying that its like zram,, I need to check

          Comment


          • #25
            Originally posted by Michael_S View Post
            Interesting. Does anyone else have a comment or experience with this? All the desktop computers I've owned for the past ten years have had 12 or more GB of RAM, so I haven't set up a swap partition in years. I guess I should set one up just in case.
            The concept is identical to a hard-drive..
            Imagine with the course of time, your computer memory starts to be fragmented, in the same way the hard drives do( its not the same.. memory is set in pages.. but also does the harddrives which is set in sectors.. )..
            Now just Imagine you need a lets say 5MB of contiguous space, but it happens that you don't have it..
            why?
            because you have plenty of *free memory*, but *its fragmented in small chunks(pages)*, so your last resource is to swap..
            But if you don't have swap, your memory management system will suffer a lot to find those 5MB( here 5MB is a example..), it could even lead to freeze in a severe situation..
            In the normal course of work of a computer, it allocates and deallocates zillions of times, differents amounts of memory( then leading to fragmentation.. )..if you have a swap partition those requests that cannot be full-filled, end there, leading to less fragmentation, and so on, less page faults and so on..faster..

            Comment


            • #26
              I don't see any benefit to this - as former swap on zram user. When swapping happened, computer was all the same not responsive, and not really later though I wasn't doing any rigorous comparisons, just my impression. If we are talking about defaults, I would rather put /tmp (and maybe also /var/tmp though it's more risky) on zram instead of tmpfs. This is where memory is actually wasted uncompressed.
              Last edited by reavertm; 07 June 2020, 11:54 AM.

              Comment


              • #27
                Originally posted by pal666 View Post
                i would rather swap to optane than waste memory on zram. and if you suffer from swapping, the most stupid thing you could do is reduce available ram
                ....if I had that as an option, sure

                Like I said though, I'm using it more as insurance in case I run some oddball program that actually expects a swap to exist than as a necessary for day to day use swap device. The way I look at it, if I'm suffering from swapping, some program went FUBAR or I'm running too much crap at once since I have a 48gb ram desktop.

                The only time I've actually used swap in the past few years is when Steam had that GPU acceleration memory leak bug when the new style was in beta. Does a memory leak even count as swap use? I suppose it's technically using swap, but still....

                Comment


                • #28
                  I'm pretty happy with this. I've been using zswap on my Fedora laptops for ages. I haven't tried zram. But it looks like a similar idea.

                  My laptop had 600 MiB in swap the other day, after running Android Studio and a 4 GB Windows virtual machine. The cool thing though was that none of that was on disk. It had something like a 3.3 compression ratio and less than 160 MB really stored.

                  Comment


                  • #29
                    This would be amazing! Does systemd already have a unit file that does this? I've played with zram a few times, but it's a bit of a faf and needs to be done each time the system boots, so having something that just does it automatically would save so much time

                    Comment


                    • #30
                      Thanks for the information!

                      Now, since zram is taking up RAM to do its thing, that also means your system needs to utilize the swap space more often, correct?

                      Comment

                      Working...
                      X