You are not logged in.

#1 2024-05-06 17:28:07

whittlers
Member
Registered: 2024-02-19
Posts: 58

[SOLVED] how to disable swap?

i installed arch with archinstall, and left 'enable swap' ticked on. i now regret this because i absolutely lack any needs for it (for now)

there is no entry of swap in /etc/fstab, so i checked archinstall code

	def setup_swap(self, kind: str = 'zram'):
		if kind == 'zram':
			info(f"Setting up swap on zram")
			self.pacman.strap('zram-generator')

			# We could use the default example below, but maybe not the best idea: https://github.com/archlinux/archinstall/pull/678#issuecomment-962124813
			# zram_example_location = '/usr/share/doc/zram-generator/zram-generator.conf.example'
			# shutil.copy2(f"{self.target}{zram_example_location}", f"{self.target}/usr/lib/systemd/zram-generator.conf")
			with open(f"{self.target}/etc/systemd/zram-generator.conf", "w") as zram_conf:
				zram_conf.write("[zram0]\n")

			self.enable_service('systemd-zram-setup@zram0.service')

i don't know if this is all it does, but i tried disabling this service with systemd, but i get this message (which i guess it means failure (?)):

The unit files have no installation config (WantedBy=, RequiredBy=, UpheldBy=,
Also=, or Alias= settings in the [Install] section, and DefaultInstance= for
template units). This means they are not meant to be enabled or disabled using systemctl.

Possible reasons for having these kinds of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/, .requires/, or .upholds/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.

i managed to disable it with

sudo systemctl mask --now swap.target

with guidance of ChatGPT, but there's still

zram0                 253:0    0     0B  0 disk

listed in listblock

Last edited by whittlers (2024-05-06 20:10:55)


sorry for bad english

Offline

#2 2024-05-06 18:13:28

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,999
Website

Re: [SOLVED] how to disable swap?

whittlers wrote:

i installed arch with archinstall, and left 'enable swap' ticked on. i now regret this because i absolutely lack any needs for it

Linux needs swap for efficient memory management: https://chrisdown.name/2018/01/02/in-de … -swap.html


Jin, Jîyan, Azadî

Offline

#3 2024-05-06 20:10:34

whittlers
Member
Registered: 2024-02-19
Posts: 58

Re: [SOLVED] how to disable swap?

i will activate swap once i learn how to encrypt it at boot

i was able to disable it removing the contents of /etc/systemd/zram-generator.conf

https://wiki.archlinux.org/title/Zram#U … -generator


sorry for bad english

Offline

#4 2024-05-06 20:30:50

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,999
Website

Re: [SOLVED] how to disable swap?

Why not just disable systemd-zram-setup@zram0.service? Or uninstall the zram-generator package.


Jin, Jîyan, Azadî

Offline

#5 2024-05-06 22:51:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] how to disable swap?

Head_on_a_Stick wrote:

Linux needs swap for efficient memory management

NEEDS?  No.  You could argue there are benefits - but claiming it is needed is plainly false.  I have not had swap on any linux machine in at least a decade.

My use-case is certainly not typical, and perhaps the average / typical user should use swap.  But a universal statement of it's necessity is hardly worth countering: it is plainly nonsense.

Last edited by Trilby (2024-05-06 22:51:14)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2024-05-07 05:46:05

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,999
Website

Re: [SOLVED] how to disable swap?

My apologies Trilby, obviously Linux can run without any swap (I did so myself for many years) but memory management will be more efficient and effective with swap and this remains true no matter how much RAM is installed. I would encourage you to read the linked article, it is very interesting and caused me to change my behaviour in respect of swap & Linux.


Jin, Jîyan, Azadî

Offline

#7 2024-05-07 13:44:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] how to disable swap?

I've read it several times.  If I cared, I'd publish a rebuttal that dissects and shows how nonsensical some of the points are.  But I really don't care to debunk every random blog post out there.

Don't get me wrong, it's pretty well-written overall.  The author makes their case laudably.  But that's what they're doing: making a case.  They have some valid points and do provide some support for the value of swap - but it is most definitely not the universally conclusive case you make it out to be.  It's one side of the story.  I'd actually encourage people considering the value of swap to to read that blog too.  But assuming that any single blog post is the full and complete story perfectly representing reality is - quite frankly - naive.

Last edited by Trilby (2024-05-07 15:03:35)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2024-05-07 14:59:19

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,307

Re: [SOLVED] how to disable swap?

Trilby wrote:

My use-case is certainly not typical, and perhaps the average / typical user should use swap.

Linux needs swap for toprovide efficient memory management for you

If you never get into the situation where over the lifetime of the boot file cache allocation + present anon pages exceed the available RAM, swap is a pointless.
It'll likely not even be used and just sits there.

If you read larger amounts of data from disk and do not bypass the cache or drop caches afterwards you'll eventually run out of free (not! available) RAM and at this point swap is a seriously good idea unless you know that the inactive pages are gonna have a younger age or more likely access than the old file backed pages.
One can actually deliberately "trick" the system w/ access patterns that will make the swap reliably do the wrong thing (instead of pinning memory you let it slide, open a lot of files and then, when the kernel just thought it would be a good idea to drop the inactive pages in favor of more file pages, ignore the files and access the inactive anon pages instead. <nelson>ha-haah</nelson>)

tl;dr - the human can outsmart the system in either direction through information advantages and, task-dependent, can provide superior memory management w/o any swap usage.
But Joe Shmoe DesktopUser wants to have some swap space, resp. all the reasons they usually present why they think swap is bad have a strong tendency to be completely wrong.

Offline

#9 2024-05-07 15:13:47

Wild Penguin
Member
Registered: 2015-03-19
Posts: 388

Re: [SOLVED] how to disable swap?

This is getting a bit OT... but personally, I do use swap. I could well probably go without, but here's why I believe it is useful in my use case:

- I often leave many programs open I don't use for a prolonged time (hours, sometimes days)
- Everything is bloated these days (as in: takes a lot of RAM, takes a lot of HDD space)
- I (also) use mechanical HDDs to store some of my programs (Games)

Sometimes the idle programs, which take up gigabytes of RAM go into swap. This means I have more RAM free for FS cache (the exact situation as in the blog post).

Bottom line: the usefulness of SWAP depends on your usage patterns and HW. Do you have mechanical HDDs, where you have data you access often? Do you use, say, >50% of your RAM (not counting cache)? Them SWAP might be useful. Monitor your RAM usage to find out.

SWAP is not useful in run-away (bugs, moemory-leak) situations, and might cause the system to become practically unusable, but in static "reserved but not used" high-RAM usage, it might be useful.

Do you hibernate to disk? Then it is almost a no-brainer to have a swap file/partition, as it can double for hibernation. Put it on an SSD.

Otherwise, no, it is not "needed". Honestly, I believe (for most uses, on a modern computer with most of it disk I/O coming from SSDs), the benefit is negligible. It should also be pointed out that that blog post is old, coming from 2018? It doesn't have a date (I can find) but I believe I've seen the same post linked to for at nearly a decade. Things might have changed a bit.

Offline

#10 2024-05-07 15:26:52

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,307

Re: [SOLVED] how to disable swap?

NAND is still magnitudes slower than DRAM - file caches will become semi*-pointless w/ NRAM - #whereismynram

*it's probably a good idea to cache opened files that get unlinked so they remain available regardless of the inodes.

Offline

#11 2024-05-08 14:14:32

tekstryder
Member
Registered: 2013-02-14
Posts: 508

Re: [SOLVED] how to disable swap?

Fun thread.. It's a swapless life for me wink

$ free -t
               total        used        free      shared  buff/cache   available
Mem:       131715876    30004552    41112192    18249368    80100488   101711324
Swap:              0           0           0
Total:     131715876    30004552    41112192

Offline

Board footer

Powered by FluxBB