You are not logged in.

#1 2020-05-10 21:15:52

jokerttt
Member
Registered: 2020-03-29
Posts: 11

SWAP in Arch Linux

Cheers!

Using Arch Linux for a while and never see my SWAP location being used.
The system has 32GB of RAM and 4GB SWAP.
Do I really need a SWAP?

Offline

#2 2020-05-10 21:30:07

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

Re: SWAP in Arch Linux

Apparently not.


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

Offline

#3 2020-05-11 08:45:54

ElisardoNieves
Member
From: Galicia, España
Registered: 2020-02-19
Posts: 22

Re: SWAP in Arch Linux

Yes and no, it depends. If it is a desktop computer where you do not want to hibernate, you do not need swap. But, if it is a laptop you need swap, since hibernating is a useful function in laptops.

If you want to hibernate I recommend a 36GB swap to avoid problems.

Offline

#4 2020-05-11 11:48:52

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,407

Re: SWAP in Arch Linux

https://wiki.archlinux.org/index.php/Swap wrote:

If it is beneficial to enable swap depends on the amount of installed physical memory, and the amount of memory required to run all the desired programs. If the amount of physical memory is less than the required amount, then it is beneficial to enable swap. This avoids out of memory conditions, where the Linux kernel OOM killer mechanism will automatically attempt to free up memory by killing processes.

Try compiling something like full llvm/clang suite or firefox on your machine and you'll find that having swap helps to keep your system responsive.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#5 2020-05-11 12:27:30

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

Re: SWAP in Arch Linux

ElisardoNieves wrote:

But, if it is a laptop you need swap

False.  I've only ran arch on laptops (well, a couple servers too), and I've never had a swap partition, and only briefly had a swap file on one of them.

From the context of this statement I can infer a valid meaning, but to assume other people's needs and desires must necessarily be equivalent to yours is not productive.  Suggesting that swap is important for hibernating is valid, but saying laptops need swap is not.

Whenever I did tinker with hibernation, I found resuming from hibernation to be no faster than a cold boot.  This will certainly depend on configurations and use-cases, and I have no doubt that hibernation is extremely valuable for many users.  But this is still far different from saying it is mandatory on all laptops.

Last edited by Trilby (2020-05-11 12:29:49)


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

Offline

#6 2020-05-11 15:27:09

jokerttt
Member
Registered: 2020-03-29
Posts: 11

Re: SWAP in Arch Linux

Lone_Wolf wrote:
https://wiki.archlinux.org/index.php/Swap wrote:

If it is beneficial to enable swap depends on the amount of installed physical memory, and the amount of memory required to run all the desired programs. If the amount of physical memory is less than the required amount, then it is beneficial to enable swap. This avoids out of memory conditions, where the Linux kernel OOM killer mechanism will automatically attempt to free up memory by killing processes.

Try compiling something like full llvm/clang suite or firefox on your machine and you'll find that having swap helps to keep your system responsive.


So nowadays, SWAP is useful only for compiling operations as extra RAM space, right?

Offline

#7 2020-05-11 17:20:54

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,703
Website

Re: SWAP in Arch Linux

Not necessarily. With the 16 GB RAM of my laptop, I can compile an entire linux kernel in RAM.
I'd argue that SWAP nowadays is only necessary for hibernation, as mentioned by @ElisardoNieves (although also @Trilby's critique appllies).
Compensating a lack of RAM with SWAP for running applications is a bad idea, since it's awfully slow. If lack of RAM for running applications is your problem, get more RAM.

Last edited by schard (2020-05-11 17:22:09)


Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#8 2020-05-11 20:16:30

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,821

Re: SWAP in Arch Linux

Build chromium in 16GB RAM…

@jokerttt you need swap space if you need it. With the swap size that you need.
This is highly subjective and depends on your usecases - which might even alter over time.
However you don't need a swap partition but can swap into a file, esp. if you just want to use it for hibernation (where you're also not going to need the entire RAM size if your RAM is always underused anyway)

If you don't have swap and run OOM, the kernel will kill processes to free RAM. With swap it will first use the (awefully slow) swap space.
There's almost no drawback from having some swap(file) - it's taking some disk space but otherwise just hang around until you actually need it.
However,

schard mostly wrote:

If a constant, systematic lack of RAM for running applications is your problem, get more RAM.

Offline

#9 2020-05-12 11:06:02

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,407

Re: SWAP in Arch Linux

(awefully slow) swap space

Having swap on your fastest drive (my swapfile is on a nvme2 drive connected through PCIe v3 ) helps with that.

Besides compiling large projects (the kernel does not qualify as a large project wrt time / memory needed during compilation) there are other things that require lots of memory .
Try editing 4k (or even 8k) video .

Many people will never do such things and they may not need swapspace .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#10 2020-05-12 12:40:26

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

Re: SWAP in Arch Linux

Lone_Wolf wrote:

Try editing 4k (or even 8k) video

Define "editing".  It's trivial to do cutting, croping, pasting, and even some compositing of high quality videos with ffmpeg on a core2 duo with 4 GB ram and no swap.  But if you want to use a beast like Kdenlive ... well, yes, you may need swap just to open the program.


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

Offline

#11 2020-05-12 13:08:00

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,599

Re: SWAP in Arch Linux

4G swap is actually quite small if FI you start building ISO's.
If you do and start building big ones better use 32G swap, yes that's right 32G!!
Your squasfs can reach 50G's++ and so you 32G + 4G =36G wouldn't be enough, just saying....
So just to be prepared for the future create a big swap;)

Offline

#12 2020-05-12 13:28:41

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

Re: SWAP in Arch Linux

By that logic, your squashfs could reach multiple TB.  Do you have that much swap?  Have you actually had a squashfs reach 50G?  The root partition of my installed system only uses 5G - while I know I'm fairly minimal, I doubt an arch iso could ever reach 50GB given that installing all but the top 1% largest packages in the repos would amount to 69GB of installed size ... and many of these packages would conflict and couldn't actually be installed together.

And what are you doing with these 50GB isos?

Last edited by Trilby (2020-05-12 13:29:35)


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

Offline

#13 2020-05-12 13:41:55

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,599

Re: SWAP in Arch Linux

@Trilby, yes I have squashfs that reach that size... I know it's kinda big but create your own BlackArch based on archiso. You'll find out squashfs will be able to grow even bigger than 50G.
So yes for these purposes I personally like to have a big swap.

What I do with these ISO's?, well you can fill in the purposes I think;)

Offline

#14 2020-05-12 16:50:00

sabroad
Member
Registered: 2015-05-24
Posts: 242

Re: SWAP in Arch Linux

seth wrote:

If you don't have swap and run OOM, the kernel will kill processes to free RAM.

It's worse than that: without swap, before invoking OOM killer, the kernel is forced to evict only clean pages, so that code can't execute without hard-fault paging in/out.
https://unix.stackexchange.com/a/24646


--
saint_abroad

Offline

#15 2020-05-12 17:20:34

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

Re: SWAP in Arch Linux

Also see the very first comment on that answer as to why that's not nearly as compelling of an argument as it superficially sounds.

In the end, there is no one-size-fits-all policy of what will be best or most efficient when memory is running out.  The fact is, running out of memory is a failure condition that one should spend more effort to avoid rather than trying to estimate which attempt at minimally destructive coping will be "best" when avoiding it fails.

If you must fail, fail gracefully.  But that should not be plan A.

Last edited by Trilby (2020-05-12 17:21:24)


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

Offline

#16 2020-05-13 00:38:25

sabroad
Member
Registered: 2015-05-24
Posts: 242

Re: SWAP in Arch Linux

Trilby wrote:

The fact is, running out of memory is a failure condition that one should spend more effort to avoid rather than trying to estimate which attempt at minimally destructive coping will be "best" when avoiding it fails.

If that were true then kernel would never vm.overcommit_memory .

Trilby wrote:

If you must fail, fail gracefully.  But that should not be plan A.

Failing gracefully (with swap) is plan A, because the alternative is to not try.

I'd rather the kernel let me open 16 Chrome tabs (at 2GB VSZ and 200MB RSS each), than to never overcommit and deny the VSZ malloc even though there's plenty of unused RSS memory.

Last edited by sabroad (2020-05-13 00:49:02)


--
saint_abroad

Offline

#17 2020-05-13 01:37:43

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

Re: SWAP in Arch Linux

Yes, one should not try to use up all available memory.  Unless of course one is a gnome developer.


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

Offline

Board footer

Powered by FluxBB