[SOLVED] Easy and/or practical way to shrink swap partition?

...zramswap [AUR], then:

sudo systemctl enable zramswap.service
sudo systemctl start zramswap.service
sudo systemctl status zramswap.service 

...in my VMs & my real Manjaros.

Ie, no swap partitions for me anymore.

Very interesting!

On the AUR page (https://aur.archlinux.org/packages/zramswap/) somebody is pointing out that systemd-swap should be used instead (https://github.com/Nefelim4ag/systemd-swap)

Are you familair with that? Looks like it uses zram and zswap in the background.

1 Like

I've tried to make that one work before, once months ago [i failed], & again earlier today [i failed again]. Clearly i'm doing something wrong. Otoh, the AUR one is literally no more complex than installing it then running those three commands. For an idiot like me, the fact that i had no problem with zramswap meant it became my preference, despite coming from AUR.

systemd-swap defaults to only enabling zswap and using the current swap as-is. If there is no swap configured on the system already, I don't think it will do anything because the dynamic swap allocation (swapfc) is disabled in the settings.

If you only want to use it for zram:

sudo cp /etc/systemd/swap.conf /etc/systemd/swap.conf.d/99-swap.conf
sudo [vi/nano/editor of choice] /etc/systemd/swap.conf.d/99-swap.conf

Change defaults to:
zswap_enabled=0
zram_enabled=1

Then
sudo systemctl enable systemd-swap --now

I did not need to reboot (but I had no swap/zswap/zram configured before I tried).

6 Likes

Ta. Yeah. A few months(?) back we had another thread re this stuff, & if i recall correctly(?), & if i understand(?) your reply here correctly, another reason that i prefer zramswap over systemd-swap [when my focus is only on eliminating a swap partition altogether] is that the former exactly allows me to, y'know, eliminate a swap partition, whereas the latter necessitates me keeping a swap partition, ie, utterly antithetical to my objective.

systemd-swap only defaults to using zwap (which needs a swap file). But you can change the default to use zram which does not (cannot?) use a swap partition or file. I'm using zram right now with no swap partition configured with systemd-swap.

2 Likes

That is perfect! I have systemd-swap now up and running. Very easy. I created my own config turning off everything except for zram:

/etc/systemd/swap.conf.d/myswap.conf:

zswap_enabled=0
zram_enabled=1
swapfc_enabled=0
swapd_auto_swapon=0

zram_size=4G

swapd_auto_swapon is on by default. It finds all swap partitions and enables them automatically. I turned it off to be sure.

2 Likes

I use the "petsam.conf" :wink:

Maybe somebody is interested

2 Likes

+

Question for either/both of you [i'm trying now to convert myself from AUR `zramswap` to Community `systemd-swap` (for no other reason than preferring native repo over AUR where possible)] ... why did you do this? I'm conceptually struggling with this, given https://wiki.archlinux.org/index.php/Swap#systemd-swap says

Set swapfc_enabled=1 in the Swap File Chunked section of /etc/systemd/swap.conf.

...which rightly or wrongly i interpret by implication to mean that they're saying ONLY that is enabled, ie, zswap_enabled= & zram_enabled= both would be 0... ?

Further confusing me [seems to confirm your interpretation, & rebut my interpretation of the Arch Wiki] is...


Edit: On further examination of that Wiki, the text i quoted seems to fall under the subsection of Swap file, ergo is not applicable here. Oh hang it... i don't understand this stuff, but shall just go with the flow, ie, only enable zram. Sigh.

You answered your own questions. So I assume it went ok?

@spacecase doesn't seem to have much to say however. I wonder if we answered the original question?

1 Like

Yes thanks. Btw, i chose deliberately to edit my post with my "answer", rather than instead just delete the whole thing, so that future readers who might come along with similar confusion as me, might then be able to follow the reasoning & learn from my stumbles.

I think my question was answered. Basically it seems that I should just fire up a LiveCD, and gpart it.

However, the issue that I may or may not run into is that the partitions would need to be contiguous in order to grow the root into where swap was. That totally depends on my individual layout. It does look like the partitions are contiguous, so it seems very doable.

However, if I do this I lose the ability to hibernate. I can't say that I remember the last time I've ever hibernated this machine in the 3-ish years that I've owned it, but it is a nice thing to be able to do.

Anyway, I believe my question has been answered. Not sure if I'm actually going to do it or not though.

That being said, the discussion going on here has raised a new question...

What's the difference between this systemd swap thing and standard swap involving fstab and swapon?

Thanks for all the replies.

I would say none! It's just the way you configure it. Anyway, systemd does control everything, whether with fstab directions, or automatic, if you use systemd in kernel space (in mkinitcpio.conf) with no swap, tmp, or other partitions in fstab. (that's a short answer, I have to sleep.. :stuck_out_tongue_winking_eye:).

1 Like

I never used swap in the last 5 years or so because I never felt I had the need (16gb ram on desktop, 8gb on laptop) but this thread interests me (I guess it's a good excuse to fiddle with something new and get out of this boredom). Can I possibly benefit from systemd-swap eventhough I don't recall ever needing it even running multiple VMs?

1 Like

I have 32 GB & 8 GB RAM respectively in Tower & Laptop. When i first left windoze for Linux [Mint 16 KDE] in early 2014, i was sure that i wanted to hibernate, hence i [gasp] gave Tower 40 GB Swap partition [gasp again], & Lappy 8 GB [i think]. Soon after i decided [rightly or wrongly] that my SSDs would not love me back if i kept hibernating, so i stopped that & disabled hibernation. That left these ginormous wasteful essentially-redundant Swap partitions, which later [not immediately coz ... laziness] i shrank [gparted] to 4 GB & 2 GB respectively. More recently again, i decided that was still a stupid waste of space, as most of the time my machines never swap, & based on the few times they have, it was pragmatically little different to if the OS had permanently frozen, or rebooted, as i had to eventually logout anyway to recover performance... ie, having a Swap partition did not pragmatically help me. Later again i discovered zram [distro then was Maui], so used that & formally gparted my Swaps into oblivion. Once in Manjaro i used zramswap [coz i was too dim to understand how to use systemd-swap], til my very recent replacement of zramswap with systemd-swap after kindly Manjaroos helped me by typing slowly with short words. For me at least, my change from a formal Swap partition to zram to zramswap to systemd-swap was motivated by my experience-based belief that my boxes don't swap, but having the software-swap fallback option was prudent insurance against a putative future low memory incident. Anyway, what the hell, tis all good new learning for me.

1 Like

If you don't want to use zswap, swapfc, or zram, systemd-swap has no use at all. You can't use it to manage a traditional swap partition/file as far as I can tell.

But zswap (compressed swap pages in memory backed by physical swap) is probably better if you're going to use swap anyway. swapfc (dynamic swap) is better if you don't need hiberation. And zram may be beneficial if you don't want physical swap at all.

But on 16+ GB RAM systems, if there is a OOM condition, the user is probably doing things that require a lot more memory rather than a little more memory, so zswap or zram alone probably won't be all that beneficial. swapfc can be configured to adds hundreds of GB of swap on-the-fly however, assuming you have the disk space... and patience! :see_no_evil:

1 Like

By Archwiki (automatic swap file setup)

Automated

systemd-swap

Install the systemd-swap package. Set swapfc_enabled=1 in the Swap File Chunked section of /etc/systemd/swap.conf . Start/enable the systemd-swap service. Visit the authors GitHub page for more information and setting up the recommended configuration.

1 Like

swapfc is not the same as traditional swap. It is an alternative swap method, but not a true replacement. The system cannot hiberate using it.

From GitHub page

Q: Can we use this to enable hibernation?
A: Nope as hibernation wants a persistent fs blocks and wants access to swap data directly from disk, this will not work on: zram, swapfu, swapfc (without some magic of course).

2 Likes

I was referring to this

meaning it does the swap file, which of course cannot do hibernation. :wink:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by