I already added a swapfile with this https://wiki.archlinux.org/title/Swap#Swap_file_creation method. Can i add a second swapfile because my first one is not enough? Is it possible have two swap files?? Can i use same method (here https://wiki.archlinux.org/title/Swap#Swap_file_creation) and use say label it “swapfile2” or do I have to delete the original swap file and then remake a new one?
You can add a second one but unless you are going to put it one different device, it would make more sense to just enlarge the first file.
You could also have a look at zram instead of using swap space or a swap file, saves you space that you can use for storage instead.
Is there a way to enlarge the original swap file or must delete it and create a new one?
I will check it out thanks…can this be used in addition to my swapfile or must one or the other?
I haven’t tried using both, but seeming zram is also seen as swap I would think that if you use a swap file and zram that the two will just be added together to get the total swap size available for your system.
Yes, you can use them both.
$ sudo swapon -s Filename Type Size Used Priority /dev/zram0 partition 4194300 1253072 100 /swap/swapfile file 8388604 0 -2
The higher priority assigned to zram makes sure that it will be used before the other swap device.
You can read about it here: https://wiki.archlinux.org/title/Swap#Priority
You could enlarge it but the commands would basically be the same as creating a new one so I would just delete it and create another. You should disable it first with
I prefer zswap myself. IIRC pages in zram are at a dead end, while pages in zswap can often get 3-1 compression with z3fold and can also get pushed out onto the pagefile/swapfile under memory pressure.
I’ve been using this for a while to setup a systemd service to manage it all.
looks like it might be integrated already in arch:
I had never heard of zswap before. Looking at it seems like zswap is part of the kernel because it is built in en zram is a kernel module. Both seem to support compression, so what would be the advantage of using zswap over zram other than that zswap is builtin in the kernel and zram is a kernel module?
As far as I know, both are modules, but looking more closely, I can’t see a zswap module. I can see a z3fold module. Maybe things have changed since I last looked at it a couple of years ago.
Advantage I see is if you get page into zram, then the only things it can do is sit there, consuming zram memory, or be ejected back into general memory for use. You can never get those pages pushed into a general page/swap file, so you have a fixed limitation of main memory which includes compressed zram.
For zswap, if the page gets too old, or there is other memory pressure, pages can be pushed out of zswap memory onto a page file, freeing a zswap page, and z3fold means often get 2-3 normal pages compressed into 1 zswap page. A kind of tiered storage for memory pages.
I just expanded my desktop to a Lenovo M720Q, still old, but cheaper than new, with RAM to 64GB, so I don’t expect to need much zswap or zram any more, but when I was running 8GB, with zswap, and also ZFS root with compressed ZFS ARC, there was a lot of compressed memory happening, and the old 12 year old laptop was suffering, it was a continual battle I think between firefox and the memory system, and the page file was getting some work. If I was using zram I think it would have been a problem because the page file was unused.
zram could have gotten better over the years, so things could have changed, but zswap builtin seems promising for zswap usage.
My current system also has that much memory so it probably won’t matter much whether I use zram or zswap. I’ll try to setup it when I have time to see the difference, but in short it looks like zswap makes better use of your ram than zram.
Lots of opinions, not a lot of hard data. And there may be cases of each depending on the situation, so that doesn’t make a choice easy either. I was happy enough with zswap, do don’t see a need to change.
Zram has also an optional writeback feature:
Configuration from my currently running kernel (6.4.3)
CONFIG_ZRAM=m # CONFIG_ZRAM_DEF_COMP_LZORLE is not set CONFIG_ZRAM_DEF_COMP_ZSTD=y # CONFIG_ZRAM_DEF_COMP_LZ4 is not set # CONFIG_ZRAM_DEF_COMP_LZO is not set # CONFIG_ZRAM_DEF_COMP_LZ4HC is not set # CONFIG_ZRAM_DEF_COMP_842 is not set CONFIG_ZRAM_DEF_COMP="zstd" CONFIG_ZRAM_WRITEBACK=y # CONFIG_ZRAM_MEMORY_TRACKING is not set CONFIG_ZRAM_MULTI_COMP=y
Yes, saw that in the reddit article, seems to have happened after I last looked at it, or is better documented now.
The following article has a good comparison overview.
Interesting. Linux 5.9 vintage, so a few years ago? Didn’t see a date on the article. Seems to be somewhat load dependent as to the winner, and unless I had very specific constraints I don’t think it it worth chasing down more than deciding to enable one or the other, and I already have zswap setup in some places. Both my desktop and laptop are not memory constrained at the moment, so I’ll either leave it alone, or use the default, or my ansible setup scripts will do something along those lines eventually, work in progress.
I didn’t see but it must be a few years back since “Fedora 33+” is also mentioned, but it was more about being able to get an idea of them in a comparison.