You are not logged in.
Pages: 1
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
Apparently not.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
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
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
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
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
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
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,
If a constant, systematic lack of RAM for running applications is your problem, get more RAM.
Offline
(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
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
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
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
@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
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
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
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 .
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
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
Pages: 1