Linux: to swap or not to swap? - Page 1
Forum section: electronics / general

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 12, 2023, 07:25:31 pm
content: Probably a very common question, that has been answered numerous times. But one more time doesn't hurt, with possibly answers related to *recent* versions of Linux and various points of view.So the question is, is a swap partition necessary for a desktop/workstation use, 64GB+ RAM and a Linux 6.x kernel?What is the benefit in this particular case, and what would be any issue with not having any swap?

author: RoGeorge
author_rank: Super Contributor
timestamp: April 12, 2023, 07:42:04 pm
content: I don't know the theoretical answer, but I never use hibernate, to not wear out the SSD (it saves the RAM to disk, which would be a huge write). For a lesser wear out of the SSD, I used to take the effort and disable swap, and didn't had any problems running without swap. At some point I've forgot to disable it, and now I've just checked and I have a 2GB swap partition (with zero usage of course - on a machine with 32GB RAM).I always use suspend to RAM as standby.Swap can be a liability, too, there are some attacks to make the OS dump important info to swap, then try to read that after a reboot. Don't know the details.

author: DiTBho
author_rank: Super Contributor
timestamp: April 12, 2023, 07:53:20 pm
content: Quote from: SiliconWizard on April 12, 2023, 07:25:31 pmit depends on how much ram you can consume in the worst case.in my case, compiling cmake with 64Mb of ram (qemu/mips) requires 700Mb of ram in the worst case, so I need to add a swap file because I don t want to allocate more ram to the VM.Quote from: SiliconWizard on April 12, 2023, 07:25:31 pmbenefit = not (issue = process killed because out of ram)

author: shapirus
author_rank: Super Contributor
timestamp: April 12, 2023, 08:07:53 pm
content: Quote from: SiliconWizard on April 12, 2023, 07:25:31 pmIt is not neccessary until it is necessary.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 12, 2023, 08:14:32 pm
content: Should have mentioned that the main drives would be SSD - although it's pretty common these days - so yes, one concern is excessive wear for maybe a not so good reason.In theory, if you have a lot of RAM that you don't exhaust, swap use should be minimal, but not zero. Pages that are infrequently accessed will still be swaped out, even if there's ample RAM left. So in some use cases (in particular if you run your workstation for a long time without rebooting), the swap partition will still end up with significant stuff in it. I know this can be configured though to some extent.I have no intention to use hibernate. But I do use standby quite often.I have some experience with a no-swap install, as this is what I had done on my laptop (which has 16GB of RAM.) Never had any issue related to this, but I do not make a very intensive use the laptop, so there may be problems I've not run into.Yes I know the main issue would be processes getting killed automatically, without any prior warning. Which admittedly could be annoying.

author: shapirus
author_rank: Super Contributor
timestamp: April 12, 2023, 08:22:52 pm
content: Quote from: SiliconWizard on April 12, 2023, 08:14:32 pmIf you end up needing to use swap, the following will lower the chances of it being used until it's really necessary:1. vm.swappiness=0 in /etc/sysctl.conf (or rather /etc/sysctl.d/something.conf)2. usezswap.p.s. Arch Linux wiki is awesome.

author: ve7xen
author_rank: Super Contributor
timestamp: April 12, 2023, 08:50:51 pm
content: If I can, I always run desktops without swap. It hasn't been a real issue in years, I'd say since I was running 16GiB RAM.I find that if my machine wants to hit swap, something is going very wrong and it's probably unresponsive and pissing me off already, and I'd really appreciate the OOMK stepping in and saving things.

author: RoGeorge
author_rank: Super Contributor
timestamp: April 12, 2023, 09:09:37 pm
content: Quote from: SiliconWizard on April 12, 2023, 08:14:32 pmThis what I've read in wiki and all kind of online searches. However, in practice I've just looked and my desktop says 22.7GiB Used physical memory (32 GB RAM) and 0.0B Used swap memory.Using it as a daily desktop, electronics EDA, browsing (right now 411tabs in 29 windows in firefox and a few other browsers with only a handful of tabs), rare small programming/compiles, all opened since a week or so, with standby a few times a day, multimedia, youtube, etc. the home lab's computer, and ZFS (which is famous as memory hungry - in my usage it never made me left without RAM), and with all these, 0.0 Bytes swap.If you are concerned about SSD wear out, the main writers for me are the Firefox browser - google how to move its caches to RAM. Browsers are a pest, they have their own cache plus making use of temporary OS folders.The second consumer of SSD writes for me is the systemd logging, which might write a lot if some applications are buggy or misconfigured (they always are a few that fill MB of logs daily). Not systemd's fault, butit's impossible to disable systemdlogging. My understanding so far is systemd won't boot if you mask logging, and will respawn the logging services if you kill or stop them. At best redirect the logs to /dev/null. Did that once when an application was so buggy that it filled the entire disk in one day.

author: Karel
author_rank: Super Contributor
timestamp: April 12, 2023, 09:13:45 pm
content: Quote from: shapirus on April 12, 2023, 08:22:52 pmCode:$ cat /proc/sys/vm/swappiness60$ sudo sysctl vm.swappiness=30vm.swappiness = 30$ cat /proc/sys/vm/swappiness30Occasionally, a system uses a high percentage of swap memory even when there is RAM available for use.The culprit here is the 'swappiness' of the system. Yep, you read that right...swappiness. So now thatyou know the lingo, you're ready to explore what it means. Swappiness refers to the kernel parameterresponsible for how much and how often that the system moves data from RAM to swap memory.The default value for swappiness is 60; however, you can manually set it anywhere between 0-100.Small values cause little swapping to occur, whereas high values can cause very aggressive swapping.A value of zero causes no swapping at all to occur, so if you want to minimize swapping to its lowestpossible value without turning it off, you should set it to at least one.https://www.redhat.com/sysadmin/clear-swap-linux

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 12, 2023, 09:30:35 pm
content: I'll probably set up a swap partition and adjust the swappiness parameter. zswap is default on recent kernels as far as I've read.If wear is a concern, one could always dedicate a small (and thus cheap) SSD to the swap partition. If it ever wears off, no harm done, just change it.One can find decent 240GB SATA SSDs for as low as $20-$25. May not even be anything to fret about.I could set up two partitions on it, one for the swap and one for any frequently accessed cache such as browser caches. Non-critical data, no wear for the main SSD(s).

author: magic
author_rank: Super Contributor
timestamp: April 12, 2023, 09:34:35 pm
content: Is it useful, though?There are two advantages I can think of.1. Needing more memory allocated by processes than physical RAM. With 64GB, maybe this doesn't affect you.2. Swapping out rarely used data to keep more files in page cache. Is it really much difference with fast SSDs?I have a desktop machine with 32GB RAM and no swap. It works OK.Quote from: SiliconWizard on April 12, 2023, 08:14:32 pmThe really annoying thing is the system being almost out of RAM, with about zero memory left for page cache, constantly re-fetching executable code from disk just to keep the processes running. 100% disk utilization, slow as molasses, but nothing gets killed yet. Particularly dreadful with spinning rust.Quote from: ve7xen on April 12, 2023, 08:50:51 pmThis is generally true, particularly if it hits swap for reason #1.Although I find that long-running web browsers, particularly with loads of open tabs, particularly with loads of ads, are able to eat up pretty much any amount of memory. But the solution here is to deal with the root cause, I guess.editNote that if you ever feel like having (more) swap, you can always create and enable a temporary swap file. You won't be able to hibernate/resume from it (easily), but what the heck. This is how Windows avoids having swap partitions.

author: ve7xen
author_rank: Super Contributor
timestamp: April 12, 2023, 09:59:33 pm
content: Quote from: RoGeorge on April 12, 2023, 09:09:37 pmYou can configure journald not to write to disk at all, and keep logs in RAM only with storage=volatile in journald.conf.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 12, 2023, 10:18:16 pm
content: Quote from: ve7xen on April 12, 2023, 09:59:33 pmYeah, of course that kind of defeats the purpose of journaling to a large extent, but certainly a solution if you want to avoid wear from logging.Can systemd log to a specific dedicated mount point?If so, one could do as I suggested for the swap and cache files, use a dedicated drive for this. Considering this is frequently accessed, but not critical data, and that would leave your other storage alone.

author: julian1
author_rank: Frequent Contributor
timestamp: April 12, 2023, 11:08:48 pm
content: Some reasons to avoid dedicated swap partitions are - extra install complexity, security if not encrypted, possible issues around wear-leveling with ssd, never desirable for a public server where any paging affects response time.I found swap files are a pretty flexible alternative, and quick to setup up for occasional temporary need,(from old notes),Code:dd if=/dev/zero of=/mnt/4000Mb.swap bs=1024 count=4000000chmod 600 /mnt/4000Mb.swapmkswap /mnt/4000Mb.swapswapon /mnt/4000Mb.swapcat /proc/swaps

author: golden_labels
author_rank: Super Contributor
timestamp: April 13, 2023, 01:00:57 am
content: Toto, we are not in 1990s anymore! Swap is not “spare, slower RAM” and almost never(1)should be used like this. If nowadays one asks about swap in the context of running out of memory, one isdoing something wrong™.Let’s put aside the obvious hibernation case. On a running system, swap is a mechanism ofincreasingsystem performance. Swap acts as a backing storage for anonymous pages. It gives the kernel some air to breathe. Instead of having unneeded anonymous pages wasting precious RAM space, the kernel may use that space for storing actually useful data.The right picture to see is not: there is RAM for data and, if there is not enough of it, swap is used. While a bit imprecise, the much accurate picture is: everything is always stored on disk and RAM acts as a cache. Putting it in a bit different terms: you are always using a kind of “swap” (you have no choice) — you can at most decide, how much you dedicate to anonymous pages. This picture also answers the supposed “swap increases latency”, “swap destroys your SSD” and similar claims. If you see excessive swap-related I/O decreasing throughput, it is also not caused by the use of swap. It is because you have not enough RAM for the given job. Trying to hide the problem by 1990s-style use of swap will not help.Whether you choose a swap on a persistent storage medium or zram, depends entirely on your particular scenario. There is no one-fits-all answer, because the two primary factors — memory demand and swap bandwidth — differ greatly between systems. Test, choose whichever fits you better.(1)The rare exceptions are specific workloads which either are designed to work with swap or swap is coincidently not getting in their way.

author: ve7xen
author_rank: Super Contributor
timestamp: April 13, 2023, 02:16:45 am
content: Quote from: golden_labels on April 13, 2023, 01:00:57 amIf pages are not needed, they will be reclaimed and used by the kernel to do whatever it wants, whether or not they are backed by swap. Anonymous pages that have been written to and need to be kept alive are eligible to be swapped, but the kernel can't predict their future, and if they are swapped out, latency on the next access will go through the roof. So in general, the kernel avoids doing this unless it is in memory pressure. Presumably the application allocated that memory anonymously for a reason, instead of mmaping a file.QuoteThis islesscorrect than the naive idea you are trying to refute, which is overly simplistic but basically correct. You even mentioned anonymous pages yourself. Backed pages are an important use of RAM for code and file I/O, but the vast majority of memory utilization on most systems is not file-backed, it's just whatever working memory your browser and whatnot needs, which will never be written to disk (unless it gets swapped there). So one of RAM's roles is to act as a buffer & cache between the OS and non-volatile storage, but that is not itsonlyrole by any stretch.For example on the machine I am typing this right now, there is more than 3x anonymous memory active than file-backed memory:Code:Active(anon): 7137752 kBInactive(anon): 28468 kBActive(file): 2246060 kBInactive(file): 40464 kBQuoteThis is more or less true, as it was in the 1990s as well, and sometimes it is the only solution - but on the kind of machines we're talking about, desktop workloads with 32-64GiB of RAM, it's rarely needed. But whether or not you need the swap, the kernelwillopportunistically use it to prepare pages to be evicted quickly. Having it enabled will definitely increase writes to your storage, whether the kernel ever actually commits pages there or not.Is it possible that performance can be improved by swapping out very infrequently used anonymous pages in favour of more file cache or holding on to mmaped files longer in memory or some other opportunistic use? Sure, it sounds plausible, but as long as the kernel is choosing to leave gigabytes of memory completely free and unused (which is normal on my machines), including for 'free and zero-cost to evict' things like file cache, at least with the current virtual memory implementation it doesn't seem likely to me that you'd actually see any benefit outside of tuning some specific pathological workload that otherwise performs poorly. Especially as non-volatile storage performance has become an order of magnitude better with NVMe, which reduces the relative benefit of file cache too, meaning the kernel should be even less likely to want to use memory this way.

author: golden_labels
author_rank: Super Contributor
timestamp: April 13, 2023, 04:09:42 am
content: Quote from: ve7xen on April 13, 2023, 02:16:45 amKernel is now deleting data randomly? A new thing to me!No, they will not be reclaimed. Anonymous pages continue to exist until all processes release them. Kernel can do nothing about this.Quote from: ve7xen on April 13, 2023, 02:16:45 amYes, kernel does not evict pages from RAM unless it needs RAM. Any pages, not only anonymous. This is obvious, almost a tautology. What was the goal of mentioning this?Quote from: ve7xen on April 13, 2023, 02:16:45 amWhatever you think of the picture I presented, the refuted idea is not “naïve” or “simplistic”. It is outdated and incorrect in terms of how memory management works today and for what kind of operation it is being optimized.Quote from: ve7xen on April 13, 2023, 02:16:45 amOne can’t make an argument against a statement by negating the statement and using that negation as the argument. And this is what you did here, I believe. “Your picture is wrong, because: let’s assume the picture is wrong, therefore it is wrong”. Perhaps there is some miscommunication in either direction?Quote from: ve7xen on April 13, 2023, 02:16:45 amThen in my opinion your system is having not enough RAM.(1)If we are in the “for example” territory: on my machines:Code:Active(anon): 1122960 kBInactive(anon): 536088 kBActive(file): 3026396 kBInactive(file): 412788 kBCode:Active(anon): 20384 kBInactive(anon): 2604 kBActive(file): 89520 kBInactive(file): 431008 kBQuote from: ve7xen on April 13, 2023, 02:16:45 amBut in 1990s it was both the accepted remedy to use swap and the goal of having swap in the first place. Nowadays it is neither the solution, nor a goal of having swap. The general movement recently is to even abandon swap altogether as inherently harmful. With a countermovement of people subscribing to theview explained by Chris Down, to which I myself belong.Quote from: ve7xen on April 13, 2023, 02:16:45 amThe same hypothetical argument can be made in the opposite direction: that the kernel may in some circumstances force dirty file-backed pages earlier than needed, increasing writes.In both casesfor a 64GiB systems I do not see this being a significant issue.(1)With an exception of a particular situation, when one works mostly with webapps. Which by their very nature are ephemeral and must be stored in anonymous pages.

author: shapirus
author_rank: Super Contributor
timestamp: April 13, 2023, 07:24:43 am
content: Quote from: Karel on April 12, 2023, 09:13:45 pmThis statement is false.

author: magic
author_rank: Super Contributor
timestamp: April 13, 2023, 07:33:06 am
content: Quote from: ve7xen on April 13, 2023, 02:16:45 amHe obviously meant "unneeded" as "not needed right now".Linux does swap out rarely accessed anonymous pages to make room for page cache growth. The balance between swapping out anonymous pages or evicting page cache slots is controlled by vm.swappiness and it applies when memory is needed for any purpose, including cache.The same concern about latency of swapped out anonymous pages also applies to evicted file backed pages. You can't universally win by arbitrarily prioritizing one over the other.Quote from: ve7xen on April 13, 2023, 02:16:45 amIt is more correct for reasons given above. The former behavior only occurs with vm.swappiness=0.In other wordsQuote from: ve7xen on April 13, 2023, 02:16:45 amquite often, yesQuote from: ve7xen on April 13, 2023, 02:16:45 amnoQuote from: ve7xen on April 13, 2023, 02:16:45 amthis is a tautologyQuote from: ve7xen on April 13, 2023, 02:16:45 amExactly.Quote from: ve7xen on April 13, 2023, 02:16:45 amNot sure what you mean by that. And page cache is "zero cost" to evict only if you don't need the same file later.Quote from: ve7xen on April 13, 2023, 02:16:45 amSuch pathological workload has already been mentioned. A web browser with 100 tabs, each downloading infinite number of ads in the background and keeping them referenced somewhere so they aren't garbage collected by the browser. The stale junk is (hopefully) not accessed, so it can drift to swap and leave RAM free for more useful things.Quote from: ve7xen on April 13, 2023, 02:16:45 amThe same NVMe makes it a nonissue to swap in an anonymous page, meaning the kernel should be even less likely to want to use memory for anonymous pages.And this is the reason why having or not having swap is no longer making that much perceptible performance difference, and the less difference it makes the harder it is to tell whether it's better or not, and more stupid arguments will be had about it

author: RoGeorge
author_rank: Super Contributor
timestamp: April 13, 2023, 10:43:25 am
content: I do not understand the following:- the desktop has 32GB of RAM- the install wizard created a 2GB swap partition (seems negligible small when compared with the amount of RAM)If I compare that 32+2 GB install, with another machine that has 34GB RAM (not 32) and NO swap, which one will run faster? The 32GB RAM machine, or the 34GB RAM machine? Same OS, same load.

author: DiTBho
author_rank: Super Contributor
timestamp: April 13, 2023, 02:36:57 pm
content: Just thinking, you can buy a small HDD and use it only as swap device and temp files.Partition1 swapPartition2 tempIt will make long life and prosper for your SSD.

author: magic
author_rank: Super Contributor
timestamp: April 13, 2023, 03:22:19 pm
content: Quote from: RoGeorge on April 13, 2023, 10:43:25 amI doubt you will find a scenario where 32GB + 2GB swap is better than 34GB.The best you can do with swap is dump the lest important 2GB of "anonymous" allocations there.The 34GB machine will simply keep these data in RAM (no other choice) and have the same amount left for other stuff.One potential exception is if you have some "clever" applications which knows how much RAM you have and sizes its memory use to fill it all.But then it's debatable if it's still "same load" on both machines.And of course the only right answer is to expand from 34GB to 48GB or 64GB, as possible

author: RoGeorge
author_rank: Super Contributor
timestamp: April 13, 2023, 04:32:02 pm
content: OK, thank you. To rephrase the question, if I have no swap, my 32GB RAM desktop goes belly up if somehow it runs out of RAM, right? Same will do if I have only 30 GB RAM + 2GB swap, right? For my desktop usage 30 or 32 GB is the same, never run out of RAM so far.It was never clear to me: Are there any hidden advantages, or maybe hidden needs for the OS, to keep a swap as long as I only use half of RAM? Do I have to have a swap if the physical RAM is plenty?Is the swap needed because it extends the amount of RAM, or is it also needed because it will help the OS fail graciously (vs an allegedly sudden fail when the OS only has RAM)?

author: ve7xen
author_rank: Super Contributor
timestamp: April 13, 2023, 04:41:30 pm
content: Quote from: golden_labels on April 13, 2023, 04:09:42 amWhat was meant by 'not needed' if not 'released'? If they are not released, they are needed.QuoteMemory is not necessarily backed by disk unless that is what the application asks for, and if that'snotwhat the application asked for, it wanted working RAM, not disk. This should also be obvious.QuoteNo, memory is not disk cache primarily. It is volatile working storage, and not generally connected to disk at all, and to suggest so is absurd. This should be self-evident by the fact that a system can operate just fine without swap, or without enough swap to cover all anonymous allocations, in which case the RAM fundamentally cannot be simply 'disk cache'. It can't even be viewed logically as such, there simply is no expectation of disk backing for anonymous memory. Even if swap is present, a page can nominally exist only in RAM or only on disk, or on both; this not the behaviour of a cache.Quote from: ve7xen on April 13, 2023, 02:16:45 amI assume that must be the case. I demonstrated why your picture is wrong - the existence of anonymous memory, which is not, by default, backed by disk. Ergo, memory is not disk cache.QuoteOn this I mostly agree. From a technical point of view, swap should not be actively harmful, but I also don't view it as particularly necessary. If you have enough RAM, you shouldn't be worried about file cache being insufficient either, and with fast SSDs it is less of an issue. It's the same as ever - if performance isn't good enough, just buy more hardware! In my experience though, thrashing under memory pressure (with desktop workload) remains a major problem, and is made significantly worse by prolonging activation of the OOM killer, which is in effect what swap does. So for usability's sake I generally just disable it. Maybe it can be tuned to behave better under those pathological conditions, but it doesn't seem worth the effort.Data on write load with and without swap would be interesting to see, but I agree it's practically irrelevant.

author: ve7xen
author_rank: Super Contributor
timestamp: April 13, 2023, 05:06:19 pm
content: Quote from: RoGeorge on April 13, 2023, 04:32:02 pmYes, if it actuallyruns out, which means all file cache has been evicted and there's nothing left for the kernel to reclaim. Then it will invoke the OOM killer, which will choose a process to kill, in order to make more memory available. If swap is available, then the same situation will lead to thrashing as active pages are swapped on and off disk as they are needed, which can make the system barely usable. Personally I prefer the killer on a desktop.QuoteSwap is not needed at all, as long as you have enough memory and don't care about hibernate. The argument here is that it gives the kernel a place to stash memory pages that it doesn't think are likely to be used any time soon ('hidden browser tabs with ads' as given by example). If that happens, it frees that memory for opportunistic usage, such as file cache, which can improve the performance of disk I/O, which is often very relevant for interactive performance. Whether that really makes a noticeable difference on your system is going to depend on your workload and actual memory utilization, as well as how much memory the kernel is able to page out this way, and how badly it kills performance when it has to bring it back. I'm of the opinion that opportunities to do this effectively are rare, and the benefit of an extra GB or two of file cache when you already have 20GB of it is minimal. The cost of doing so incorrectly (e.g. going back to one of those tabs and having to bring a ton of pages back) is pretty high by contrast, so I don't think it's worth it in practice. If you're on the edge though and have barely any file cache, the benefit might be worth it. If you do want to have swap on a system with plenty of RAM, I would recommend reducing vm.swappiness.

author: shapirus
author_rank: Super Contributor
timestamp: April 13, 2023, 05:11:37 pm
content: Quote from: RoGeorge on April 13, 2023, 04:32:02 pmThe OOM killer will kick in and kill the process which it considers the trouble maker.Quote from: RoGeorge on April 13, 2023, 04:32:02 pmYes, except that the OOM killer will kick in a little bit later, because it will take slightly longer to run out of memory, because disk-backed swap is slower than RAM.Quote from: RoGeorge on April 13, 2023, 04:32:02 pmNo.Quote from: RoGeorge on April 13, 2023, 04:32:02 pmNo.In addition, there's a curious fact that some software even refuse to run if swap is enabled on the system (e.g., kubernetes).Quote from: RoGeorge on April 13, 2023, 04:32:02 pmYes. Historically it was invented to allow the processes to allocate and use more memory than the amount of physical RAM without spending crazy money on additional memory modules at the expense of performance (disk-based swap is much slower).I can imagine a use case, probably not too realistic, where having swap would be beneficial, in which two conditions are true:- there is a process (or multiple processes) which need to use a lot of memory, but the data in that memory is accessed very infrequently;- there is very intensive disk read access taking place, especially when the disk is slow.In this case, it may be desirable to enable swap to allow the kernel to move rarely accessed memory pages into swap to free up as much RAM as possible for buffers/cache.Quote from: RoGeorge on April 13, 2023, 04:32:02 pmThere is (usually) no OS failure in the OOM situation. The OOM killer gets rid of the processes that it considers to be resource abusers and whatever is left continues normal operation. It's the total amount of memory that counts, not the type of it, save for the disk vs RAM speed that I mentioned above.

author: RoGeorge
author_rank: Super Contributor
timestamp: April 13, 2023, 05:51:59 pm
content: Quote from: ve7xen on April 13, 2023, 05:06:19 pmThat's the bird eye view I was looking for. Thank you. Since I was asking for a home desktop, I'll prefer a sudden fail rather than disk trashing, especially trashing with a silent SSD.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 13, 2023, 07:42:02 pm
content: Quote from: DiTBho on April 13, 2023, 02:36:57 pmWhat did I say just above?I was mentioning a "small" SSD instead though, as they have become quite cheap, will still provide much better performance when accessed, and if it wears out, it's absolutely no big deal.

author: DiTBho
author_rank: Super Contributor
timestamp: April 14, 2023, 12:23:37 pm
content: Quote from: SiliconWizard on April 13, 2023, 07:42:02 pmYou said, since it's cheap so if it wears out, it's absolutely no big deal, I say ... ummmMy opinion, but "small" SSDs can be as cheap as you like and still will die if used for continuous I/O, while HDDs are also getting cheap and work better for that purpose.Inferior performance? Yes SSDs are faster, and HDDs are fast enough, then, it depends on your purpose, for me, the best I can do ishybrid storageSSD -> RO, to load programs libraries, making it writable only on specific occasions (e.g. system update)HDD -> RW, to process stuff that need temporary storage + swap partitionOr, at least have the foresight to use two SSDs: one for the operating system, one for temporary filesSSD#0 -> RO, to load programs libraries, making it writable only on specific occasions (e.g. system update)SSD#1 -> RW, to process stuff that need temporary storage + swap partition (cheap and easy replaceable)so when SSD#1 dies ... only the latter dies and you don't have to rush to restore the system.What I meant

author: rdl
author_rank: Super Contributor
timestamp: April 14, 2023, 05:16:27 pm
content: Just like flash drives, memory cards, etc., there's a manufacturing cost overhead that can't be avoided, so the smallest and cheapest you can buy constantly increases in capacity. And there is little savings in going small.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 14, 2023, 07:18:33 pm
content: @DiTBho: I get it, this is just debatable. If you want a super long-term operating of your system without any hardware change, I agree. The HDD will (usually) win. My point here was that, for this use case where performance may still matter, but the data itself is temporary and non-critical, using a cheap SSD and having to change it every couple years looks like a pretty workable solution while not sacrificing anything.But obviously it's 100% up to each individual situation.

author: golden_labels
author_rank: Super Contributor
timestamp: April 15, 2023, 01:47:26 am
content: Quote from: RoGeorge on April 13, 2023, 04:32:02 pmOthers have already responded to the question directly, but let me make an important note here. Do not be focused too much on swap being 2 GB. If you used some wizard, don’t seek any deeper logic behind the choice of 2 GB. Doubtful there is any: there isn’t many choices. An arbitrary value, a result of some ancient or unfounded trade lore, or — though I admit I personally never heard about anything doing this(1)— an outcome of a statistical research (“fits most users”). The problem, which a wizard can’t overcome, is is that the amount of swap needed is tightly bound to your particular workload and whether you use hibernation.In the distant past there were two “common knowledge” approaches. One was “as much as RAM”, the other “2× RAM size”. One comes from Microsoft Windows; the source of the other is more obscure, but appears to be somewhat related to enterprise usage of Linux. Both are ancient, devised when 4GiB RAM was nerds’ wet dream, and the Windows one is specifically bound to “swap is an emergency RAM” approach.In myopinionthe sanest approaches are:A blind one:(2)just set swap to “a few gigs”. That may be not suitable for hibernation, if you have 32 GiB RAM. But otherwise: basically “just works”, doesn’t waste too much disk space in case you were wrong, in case of a catastrophic memory leak this size is bearable.If not using hibernation: the typical value you get from “Used” column infree -h. The reasoning behind is, that it gives the system an opportunity to push everything out of RAM. Which should (and will) never happen, but this is a ballpark estimate.If using hibernation: choose the percentage of cases in which hibernation should not fail and set swap to the corresponding percentile of memory used (as above, fromfree -h). The reasoning behind this is: it will provide enough space for hibernation to work. There are a few more factors to consider, than memory used, but typically they are countered by data being compressed for hibernation.The latter two options should not be taken with religious rigour. I see them more as bringing focus to the most important factors than being a direct advice.But I truly believe that, with systems offering that much RAM, we are at the time in which even above suggestions are becoming obsolete. And we need time to develop new ones.Quote from: RoGeorge on April 13, 2023, 04:32:02 pmNeither. For the first part see my post above. For the second: if an OOM condition occurs due to a runaway memory leak, this is a catastrophe one way or the other. The presence of swap doesn’t make it graceful. Quite opposite: the system gets blocked completely for a long time. This can be addressed with suitable cgroup settings for services and/or daemons likeearlyoomorsystemd-oomd. But with these in use the entire question becomes moot.(1)I suspect I came across a few choices/guides, where this was the case, but this is merely my suspicion. No evidence. So I assume I never met with that.(2)I know, that in the tech crowd there is a strong tendency to make decisions, which at least give a feeling of being taken thoughtfully. But that has its drawbacks too: internal bikesheding and magical thinking. Sometimes it’s better to not have any technical reason, than being trapped into wasting time on following advice which only pretends to offer solid logic.

author: DiTBho
author_rank: Super Contributor
timestamp: April 15, 2023, 09:00:42 am
content: Quote from: golden_labels on April 15, 2023, 01:47:26 amthat rulewith k = { 0.0, 0.1, 0.2, ... 1.0, 1.1, 1.2, ... 2.0, 2.1, .... n }swap.size = k x ram.sizewas/is anempiric approachbased onstatistical analysis.my PPC-7550 cannot address more than 2GB of ram, the kernel is 32bit and cannot allocate more than 512Mbyte of stack per process.At the moment the PSU is dead and i'm still trying to figure out how to fix it, during its golden ages it usually spent its time at compiling stuff, from the development of custom programs, to compiling "stage{1,2,3,4}" for Catalyst, so { cpp, cc1, ld, make, perl, python, lua, ... } have always beenthe most used processes, and rarelya single process in that list needs more than200Mbyteof ram, as well as rarely I run more than two big Catalyst-processes in parallel, as well as rarely I need to compile C++ stuff.Mozilla and Netscape were nice to be built in the early 2000s, once configured, and gcc from v2.96 to 4.1.2 have always been kind in terms of the required ram.However, when years ago Firefox was written entirely in C++ (now it's an hybrid mess, impossible to be cross-compiled) , I remember there was very high swap pressure with more than 800 Mbytes consumed by gcc.4.5, that means 2.8Gbyte requires on a machine that physically address 2GB.I remember a couple of "out of ram" crashes because I hadn't allocated any swap, thinking that 2GByte of ram was enough for everything, even because in 2005, 2Gbyte was a rarity to have on a computer since very expensive.RAM: 2GBSwap: 0 <------------ k= 0.0, you assume the ram is already enoughSo then my choice was 2GB of disk space instead of 1GB for the swap, as"coverage" safe(k = 1.0), just in case.RAM: 2GBSwap: 2GB <------------ k= 1.0Probably k = 2.0 had/has a similar "coverage" choice behind its shoulders

author: DiTBho
author_rank: Super Contributor
timestamp: April 15, 2023, 09:10:18 am
content: p.s.moving from gcc v8.5 to v12 reveals that the new compilers consume 2x times the RAM, and if you don't have enough, that's where if you opted for higher k coverage for your swap.size you made a wise choice.

author: Karel
author_rank: Super Contributor
timestamp: April 15, 2023, 09:27:06 am
content: For me, the reason to add a relatively small swap partition, is just to "get notified by slowlyness" whenthe system is about to run out of memory.I'm thinking about to write myself a little desktop widget that notifies me when used ram reachesa threshold. In that case I will not use a swap partition anymore.

author: DiTBho
author_rank: Super Contributor
timestamp: April 15, 2023, 09:40:40 am
content: Quote from: Karel on April 15, 2023, 09:27:06 amlove this idea, just ...if I implemented that monitor on my router, I am afraid it would light up and blink more than a Christmas tree

author: golden_labels
author_rank: Super Contributor
timestamp: April 17, 2023, 02:38:59 am
content: Quote from: Karel on April 15, 2023, 09:27:06 amIn most workloads you will receive that “notification” without swap too. Processes will wait for file-backed pages.For a more civilized approach seePressure Stall Informationindicators. The feature is relatively fresh, so also often left unnoticed.

author: rdl
author_rank: Super Contributor
timestamp: April 17, 2023, 05:10:46 am
content: I just installed MX on a new-to-me old computer. I don't think it created a swap partition. All I remember doing was adjusting a slider to choose how to allocate the space between system and home. I'm pretty sure it was using the entire drive. My other Debian 10 computer has a swap partition bigger than the amount of RAM. I don't remember who's idea that was.

author: BradC
author_rank: Super Contributor
timestamp: April 17, 2023, 05:20:18 am
content: I've been using SSDs in my laptops since 2005, servers since 2010 and desktops since 2011. I always make the swap partition at least the size of RAM, and in some cases twice the size (xfs_repair can use a *lot* of RAM) and log/cache everything to disk.In all cases, on all machines under all circumstances the wear on the SSD is such that the machine itself will be long dead before it exceeds the endurance of the flash. I've never seen it be close to an issue. I have seen plenty of people implement pathological workarounds to a purported issue though.

author: magic
author_rank: Super Contributor
timestamp: April 17, 2023, 07:55:02 am
content: Quote from: BradC on April 17, 2023, 05:20:18 amActually, I have done swap on SSD once upon a time and there were indeed no serious problems with it.Large SSDs have high write endurance, mine still shows "medium wearout indicator" at 100/100.The machine had 16GB RAM and swap was lightly used. I kept swap mostly for hibernation.

author: DiTBho
author_rank: Super Contributor
timestamp: April 17, 2023, 10:24:50 am
content: Code:____________________________| || reverse initiator || | brdige| HBA iSCSI FC-optic ---------- FC-optic <========> SAS|__ ____________|| || || || PCI64 |___|___________|____________| |DMA || ___|_______ || | | allocated || | 31GB ram | to iSCSI || |__________| || uart| SBC PA8900 || 1GB ram eth0 ------ ssh| ramrootfs || GNU/Linux || reverse initiator ||___________________________|This is what I use for my-cross-compiling CatalystIt's an hacked a computer HBA installed into a mobo with 32GB of ram.It's how to turn a "server" into a "SAS device", so a remote host can see it as "storage device" for temporary storage, which is 90% of what a tool-chain does./dev/sda <------ SDD, ReadOnly, kernel and rootfs ( { /var, /tmp, /build /user } are not mounted here)/dev/sdb <------ HDD, ReadWrite, { /var, /user } are mounted here/dev/sdc <------ rSAS, ReadWrite, { /tmp, /build } are mounted hereThe host believes /dev/sdc is an iSCSI device, whereas at the end of the cable there is a computer which lends its "ram-disk" pretending to be a true block-device.advantages:1) it faster than an HDD (200Mbyte/sec read/write, limited by .. well .. the PA PCIX)2) doesn't use any flash3) provides more IOPdisadvantages1) consumes more electricity than an SSD (250Watt)2) it's volatile3) it's *very* expensive if you have to buy parts, I got mine for 200 UKP (as-is, damaged), and I was lucky

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 17, 2023, 07:40:08 pm
content: I don't really see a benefit compared to using a "cheap" dedicated SSD even if it doesn't have infinite lifetime (as I suggested), given the cost and power draw, but to each their own!

author: nctnico
author_rank: Super Contributor
timestamp: April 17, 2023, 08:38:16 pm
content: For deskop systems I disable swap. There is no use for it with tens of GB of memory. Even a super fast SSD will be considerably slower. On embedded targets with a smaller memory, I setup a swap to prevent the OOM killer to kick in when an application reserves a lot of memory. In most cases the memory isn't even used. Ofcourse swappiness is set to 0

author: alm
author_rank: Super Contributor
timestamp: April 17, 2023, 11:26:01 pm
content: Quote from: nctnico on April 17, 2023, 08:38:16 pmYou might want to (re)read thearticle by Chris Downreferenced by golden_label earlier in the thread, because you are falling into the traps like thinking setting swappiness=0 on a solid state system is a good idea, or that adding swap to a system with a lot of memory would somehow harm performance because the SSD is slower than your memory.

author: BradC
author_rank: Super Contributor
timestamp: April 17, 2023, 11:29:03 pm
content: Quote from: nctnico on April 17, 2023, 08:38:16 pmThere's always use for swap. Infrequently (or not at all) parts of applications will get pushed out to swap in order to free up more memory for buffers & cache. My desktop has 64G of ram and still has nearly a gig pushed out to swap at the moment.You often don't *need* swap, although even with 64G xfs_repair will OOM on a 4TB filesystem I have here. I need to provision another 128G of swap to get that to completion.

author: shapirus
author_rank: Super Contributor
timestamp: April 18, 2023, 08:54:07 am
content: Quote from: BradC on April 17, 2023, 11:29:03 pmNo, except for rare scenarios with heavy disk i/o and processes with big unused/rarely used chunks of data in memory. And not until Used+Buf/cache >= Total.Here's my desktop where having swap wouldn't improve anything and could make the system less responsive if the kernel decided to move something to swap:Code:$ uptime11:47:31 up 32 days, 20:21, 30 users, load average: 0.79, 1.01, 0.99$ free -htotal used free shared buff/cache availableMem: 62Gi 27Gi 3.5Gi 395Mi 32Gi 34GiNow, the point in the article referenced earlier,Quoteis only valid for the "dirty pages", aka data in the buffers that has yet to be flushed to the underlying storage device and that will be forced to flush if the pages need to be reclaimed. If it's for the read cache, then the cost of reclaiming those pages is nowhere near the swap operations, which is typical for a desktop system where the disk workload is mostly read-only.

author: alm
author_rank: Super Contributor
timestamp: April 18, 2023, 11:45:16 am
content: Quote from: shapirus on April 18, 2023, 08:54:07 amHere you assume that the anonymous pages and read cache are equally likely to be needed; but if the kernel decided to swap out the anonymous page, its algorithm predicted that the read cache page is more likely to be needed. Why would you want to take away this choice from the kernel by preventing it from swapping out anonymous pages to save a tiny amount of SSD storage? My desktop has been doing some heavy I/O over night and is still doing it, and with 32 GB RAM is currently sitting with 490 MiB free, 5.6 GB used, 26GB buffer/cache and 2.6 GiB out 8GiB swap usage for a number of hours. Clearly it hasn't needed those 2.6 GiB all morning. So the result without swap would have been 2.6 GiB less buffers / cache for the gain of a few GB SSD storage. Would the 2.6 GiB less buffers have negatively performance? I can't tell, but I'm certainly not missing the 8 GiB of SSD storage.

author: shapirus
author_rank: Super Contributor
timestamp: April 18, 2023, 01:01:07 pm
content: Quote from: alm on April 18, 2023, 11:45:16 amCorrect. It depends on the use case actually.Quote from: alm on April 18, 2023, 11:45:16 amYes. This in turn means that the usefulness of swap depends on how accurate the kernel prediction algorithm is for a given use case. In my practice I rarely (if at all) used swap as anything but "emergency memory", but yes, sometimes it can be useful. Heavy disk I/O is a good hint that enabling swap should be considered.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 18, 2023, 08:54:34 pm
content: So, for typical desktop use (not talking about server use), assuming you're actually not running out of memory, whether this actually gets your better performance on average in any given, real-life situation (as is often claimed here and there) is almost undecidable. You can only cherry pick very specific situations for which it actually would, and then claim that whoever disables swap is an idiot.So you end up choosing enabling/configuring or disabling swap altogether based on a non-entirely rational decision, and some in this thread have evoked that it was even almost a political fight on some level.

author: alm
author_rank: Super Contributor
timestamp: April 18, 2023, 10:32:35 pm
content: Quote from: SiliconWizard on April 18, 2023, 08:54:34 pmOn average it will either improve performance by giving the kernel more options in how to most efficiently manage memory or just not make a difference. Only if you cherry pick very specific situations where the kernel gets it wrong might it negatively affect performance. Whether that's enough to warrant the effort and SSD storage to set up swap is up to the individual.Quote from: SiliconWizard on April 18, 2023, 08:54:34 pmThere's a difference between saying "you're wrong for disabling swap" and "you're wrong for disabling swap with the goal of improving performance".

author: nctnico
author_rank: Super Contributor
timestamp: April 19, 2023, 08:21:50 am
content: The problem I have with swap is that I have applications open for several days before using them. With swap enabled, it takes time to activate those applications. There is more than enough memory in my system to work with so swap simply isn't necessary.

author: DiTBho
author_rank: Super Contributor
timestamp: April 19, 2023, 08:28:53 am
content: Quote from: alm on April 18, 2023, 10:32:35 pmin both points you have well summed up my views about that

author: shapirus
author_rank: Super Contributor
timestamp: April 19, 2023, 08:59:27 am
content: Quote from: nctnico on April 19, 2023, 08:21:50 amThis is exactly what happens. Linux will happily swap out a web browser or other memory-hungry applications which are always running, but can stay idle for prolonged periods of time (e.g., nights). And then, once the user tries to use them, the system needs to load the pages from swap, which has a negative impact on the UI responsiveness.

author: alm
author_rank: Super Contributor
timestamp: April 19, 2023, 09:16:11 am
content: And what do you think would happen under the same memory pressure without swap?

author: shapirus
author_rank: Super Contributor
timestamp: April 19, 2023, 09:20:25 am
content: Quote from: alm on April 19, 2023, 09:16:11 amNothing. The pages would be readily available in RAM.

author: alm
author_rank: Super Contributor
timestamp: April 19, 2023, 11:57:26 am
content: Quote from: shapirus on April 19, 2023, 09:20:25 amYou seem to think that without swap the kernel won't get rid of data in memory. It will, just only some types of data (file backed pages). Which it will also have to reload whenever the application becomes active again. Data that you're more likely to need than the data the kernel would have swapped out if it had swap.I remember twenty years ago when computers had maybe 64MB of memory that programs you hadn't used for a while had to be reloaded from hard drive, which took forever. This was not specific to swap, however, and a sign of low memory and slow storage. Now both of these have improved, I don't see this problem anymore with swap enabled.

author: Ed.Kloonk
author_rank: Super Contributor
timestamp: April 19, 2023, 12:06:24 pm
content: In a previous decade on a lousy 32-bit netbook, I recall (after checking free memory >= used swap memory), I used a script to periodically turn off and back on the swap to force the system purge the swap file to recover system snappiness without the need to reboot. Unlike other OS's.Can you even still do this now? (I'm in the swap minimal or even no swap camp)

author: Karel
author_rank: Super Contributor
timestamp: April 19, 2023, 12:24:24 pm
content: Quote from: Ed.Kloonk on April 19, 2023, 12:06:24 pmYes:Code:sudo swapoff -a ; sudo swapon -a

author: shapirus
author_rank: Super Contributor
timestamp: April 19, 2023, 03:20:06 pm
content: Quote from: alm on April 19, 2023, 11:57:26 amCorrect, but only if there is not enough free memory for newly written malloc()'ed pages. It will then free up some buffer/cache pages.In this situation, however, it will not:Code:$ free -htotal used free shared buff/cache availableMem: 62Gi 20Gi 9.1Gi 369Mi 33Gi 42GiSwap: 0B 0B 0BThere's plenty of free memory for whatever use. And if something of the 33G of buffers/cache needs to be freed, it's not a big deal, because most of it, in my case, are "clean" pages, aka read file cache.Quote from: alm on April 19, 2023, 11:57:26 amNo. Why? The application data (code and whatever data structures it uses) is already in memory. If the app is terminated and restarted, then yes, it will need to read from disk, unless the respective files, which are typically very small binaries, are cached.Quote from: alm on April 19, 2023, 11:57:26 amI'm not sure what it means. Data have to be read from hard drive only when the app and/or its resources are not already in memory, be it data pages or file cache.

author: magic
author_rank: Super Contributor
timestamp: April 19, 2023, 04:32:24 pm
content: Quote from: shapirus on April 19, 2023, 03:20:06 pmCode and and read only data sections are memory mapped into the process and treated mostly* like all other file-backed data - subject to eviction under memory pressure and then faulted-in when the process attempts to resume execution.* one exception is that you can't modify an executable file which is being executed by a process

author: shapirus
author_rank: Super Contributor
timestamp: April 19, 2023, 04:44:40 pm
content: Quote from: magic on April 19, 2023, 04:32:24 pmI doubt that. But even if it is so, code is tiny. Most of the memory is taken by structures for which memory is allocated with malloc() and then written into. These cannot be evicted other than along with killing the process by the OOM killer.

author: alm
author_rank: Super Contributor
timestamp: April 19, 2023, 05:15:54 pm
content: Quote from: shapirus on April 19, 2023, 03:20:06 pmSo we're back to "if there's no memory pressure, the kernel is unlikely to evict pages, so it does not make much of a difference either way except possibly making available more memory for caching" as discussed on page 1.Quote from: shapirus on April 19, 2023, 03:20:06 pmIf the kernel feels memory pressure, it will try to evict pages. Without swap anonymous pages are not an option, so clean file-backed pages containing code or data the application needs are more likely to be evicted from memory and will need to be read back from disk when needed again. To the user this appears like swapping, but this behavior is actually more likely without any swap space available, since the kernel has fewer pages to choose from to evict.

author: shapirus
author_rank: Super Contributor
timestamp: April 19, 2023, 05:25:39 pm
content: ...which boils down to:- if you have enough memory for both apps and cache, you don't need swap;- if you don't have enough memory for them, add more memory; enable swap only if you can't afford more memory or all the slots are already used.

author: Norbert
author_rank: Newbie
timestamp: April 19, 2023, 05:27:36 pm
content: Quote from: nctnico on April 19, 2023, 08:21:50 amIf it is of any help, I have a 24GiB system running and have set vm.swappiness to 10 (in /etc/sysctrl.conf).The system starts swapping very, very late and only quite moderate.Swap is only used if some extreme build jobs run once a week. With little performance impact, swap is on a flash drive.

author: nctnico
author_rank: Super Contributor
timestamp: April 23, 2023, 03:50:17 pm
content: Quote from: shapirus on April 19, 2023, 04:44:40 pmIndeed. The kernel can not decide to discard data from memory at will because it doesn't know whether it is used or not. File backed pages is another word for disk caching. Disk caching can be useful at times but at some point it has diminishing returns. How large is the biggest file you work on? And how much memory would you need to keep that data in memory for 10 applications? A couple of hundred MB is likely more than enough. Many years ago I tested whether compiling buildroot (embedded Linux system consisting of kernel and all user space applications) would compile faster using a hard drive or SSD. It turned out it didn't make any difference (same PC with about 20GB of memory).

author: alm
author_rank: Super Contributor
timestamp: April 23, 2023, 06:20:14 pm
content: Quote from: nctnico on April 23, 2023, 03:50:17 pmThis is not what anyone is talking about when talking about evicting from memory. The way virtual memory works is that the kernel can decide where and how to store the data. Whenever the page is hit it will trigger the kernel to load the data if necessary. So for a read-only code page that exists on disk, it can decide to remove it from RAM and load it back from disk if necessary. Without swap, that will be one of the likely targets, together with discarding cache or writing out buffers (which is more expensive).Quote from: nctnico on April 23, 2023, 03:50:17 pmNo, it's a word for data that's mmap'ed from a file as opposed to be mapped with the MAP_ANONYMOUS flag. The latter are called anonymous pages.

author: nctnico
author_rank: Super Contributor
timestamp: April 23, 2023, 06:51:37 pm
content: Sorry, but an application will need to mmap a file onto memory specifically for your case to work. This unlikely for most applications. From what I've seen most applications will load a file into memory, break it into structures and write it back on disk when it is done. An exception may be databases but that is more appropriate for servers that run a narrow range of applications.For normal desktop use, having swap degrades GUI responsiveness when switching to a different application after a while. On Windows this is even worse; in some cases it takes several seconds for an application to pop-up with swap enabled. I have been around computers long enough to know where swap is usefull and where it is not. For a desktop computer swap is more likely to degrade performance than improve it. Memory is cheap nowadays. Without swap an application that needs more memory (including mapping a file) than is available will simply run out at which point it is time to add more memory or enable swap. But until then, having swap is more likely to degrade performance than improve it.If you read this article carefully enough, you'll see that avoiding swap (by having more than enough memory) is the best option by far for a desktop machine:https://lwn.net/Articles/690079/

author: golden_labels
author_rank: Super Contributor
timestamp: April 23, 2023, 07:39:10 pm
content: What the eye doesn’t see, the heart doesn’t grieve over.Swap is bad, because GUI gives visual feedback; the lack of swap is great, because non-GUI processes may at best blink I/O LED. /sIf swap affects GUI, maybe the system runs too many processes for its RAM (more likely) or it needs changing configuration (less likely) by limiting memory(1)with cgroups for offending services?(1)That limits the entire memory, including file cache.

author: nctnico
author_rank: Super Contributor
timestamp: April 23, 2023, 07:50:24 pm
content: Quote from: golden_labels on April 23, 2023, 07:39:10 pmThat is not the case. There is more than enough RAM but with the default settings, appearantly unused memory gets swapped onto disk without giving any performance benefit at all because there is no memory shortage to begin with. Ofcourse you can resort to setting swapiness to 0 but not configuring a swap space is simply less work. With enough memory having swap is like having a solution looking for a problem (which doesn't exist).

author: tatel
author_rank: Frequent Contributor
timestamp: April 23, 2023, 09:05:21 pm
content: Quote from: SiliconWizard on April 12, 2023, 07:25:31 pmI would say no, unless you expect to be short on ram. We do have some 50 TP-Link WR841-ish routers here. They are 8/32 devices. We build a customized image for them without swap support at all. Mainly because we needed the space on flash to have other things. These are as stripped-down systems as we could do.That was on 2014. So far not just one problem we could identify as coming from having no swap. IIRC they have like 8 MB free ram at start, maximum (there are like 4 years since they are maintained by my fellow tech-profane neighbors) Now we have to get new ones because we can't put any currently security supported OpenWRT on them anymore (since some years ago). BTW, we are not sure we could get any so-reliable devices so possibly we will update flash and ram chips instead. We do have uptimes in the several months range usually. It comes very handy since we are speaking of not-paid, not-for-profit work in this case. So we want to have almost zero maintenance.After that, I never, ever had any swap on any machine, unless I expect it to be short on ram for some reason like big builds, video edition, etc. I think is *way* better to have more ram if needed and at all possible.About SSD: You could mount /var and /tmp on a classic HD. Modern linuxes do a lot of short writings to disk and that goes to these partitions. My current machine (AMD Ryzen 7 3800X 8-Core, 32 GB RAM) amazed me the first time I booted it, because there were no start messages, just got directly into graphical login. After putting /var and /tmp on HD, boot time is about 3 seconds.Alternatively, you could use Devuan to get rid of systemd and hunt for rutinary writing to disks. I do that on machines destined to have linuxcnc. Like Athlon 64 dualcores with 2-4 GB RAMYMMV though, so take this with the customary grain of salt

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 23, 2023, 09:10:44 pm
content: Quote from: tatel on April 23, 2023, 09:05:21 pmWhether on a HDD or a separate SSD as I suggested (for performance, even if that means a slightly shorter lifetime of this one which would essentially contain just temporary data.)The problem with this approach is that the mount point may not be available when the system boots until pretty late in the boot process, so you'd miss logging from most of the boot.Do you have any tips to handle that? Would that entail making your own custom initramfs? (Which I'd rather not do, what a pain to deal with this at every kernel update.)

author: tatel
author_rank: Frequent Contributor
timestamp: April 23, 2023, 09:28:37 pm
content: My dmesg and /var/log/sylog don't show any symptoms. No need to modify one thing, I would say

author: alm
author_rank: Super Contributor
timestamp: April 23, 2023, 10:27:44 pm
content: Quote from: nctnico on April 23, 2023, 06:51:37 pmHave a look into /proc/*/maps. You'll see many processes mapping binaries, shared libraries, devices, data files like fonts or browser cache. Mmap is used all over the place in *nix applications because it allows the kernel to efficiently manage the memory. Currently on my desktop system running standard desktop stuff like browsers that has been on all day there are 122824 regions of file-backed maps, which does not correspond to 122824 files because many processes will mmap multiple regions of the same file. Still, it clearly shows that even on the average desktop file-backed memory mapping is ubiquitous.Quote from: nctnico on April 23, 2023, 07:50:24 pmWhat do you think setting swappiness does? It sets a balance between file-backed pages (see above) and anonymous pages (memory not backed by files of devices, for example memory allocated by malloc()). So if you set it to a low value, instead of writing anonymous pages to swap it will evict file-based pages that also need to be read back from disk when they are needed. Pages that are probably more likely to be needed than the pages it would have written to swap. The only thing it will save on is writes if you're very concerned about storage lifetime (say a flash memory device without wear leveling).Quote from: SiliconWizard on April 23, 2023, 09:10:44 pmIs this supposedly shorter lifetime based on fact or superstition? In my experience the economic lifetime of SSDs is far shorter than the technical lifespan. So a 60 GB SSD might be at the end of its life now? Who cares, I'll likely have replaced it by a higher capacity/performance model years ago.Quote from: tatel on April 23, 2023, 09:05:21 pmThis is a false dichotomy: more RAM is generally good, but using swap does not prevent you from installing more RAM. The cost of the storage space on modern SSDs is negligible. You still same to have the mistaken idea that swap is there as a buffer if you need more RAM, rather than to improve performance by evicting rarely used pages that otherwise could not be evicted.

author: nctnico
author_rank: Super Contributor
timestamp: April 23, 2023, 10:47:21 pm
content: There is no shortage, so why even evict rarely used (hint: there is no such thing as unused memory that is claimed/in use by an application) if it isn't necessary? Keep in mind that without swap, the kernel doesn't need to keep track of which pages are used regulary and which not. I completely fail to see where there is any performance gain from having swap in a system that has enough memory. It is more like the opposite because with more memory, the kernel needs to do more bookkeeping when swap is enabled.

author: alm
author_rank: Super Contributor
timestamp: April 23, 2023, 10:54:19 pm
content: Quote from: nctnico on April 23, 2023, 10:47:21 pmBecause for most workloads more cache is better. Some pages might only be necessary when you shut down your computer, or for remote access which you use once per month.Quote from: nctnico on April 23, 2023, 10:47:21 pmI feel like I'm repeating myself, but no this is not how it works. The kernel will still evict pages and need to keep track of which to evict, the eviction will just be limited to file backed pages. So instead of swapping out that anonymous memory allocated by a backup program that runs during the night, it might evict a font or shared library that you haven't used recently.

author: magic
author_rank: Super Contributor
timestamp: April 23, 2023, 11:07:57 pm
content: Quote from: nctnico on April 23, 2023, 10:47:21 pmIn a perfect worldQuote from: nctnico on April 23, 2023, 10:47:21 pmStill does. From a router with no swap support at all:Code:# cat /proc/meminfoMemTotal: 126324 kBMemFree: 96604 kBBuffers: 2172 kBCached: 8808 kBSwapCached: 0 kBActive: 9816 kBInactive: 4456 kBActive(anon): 4372 kBInactive(anon): 92 kBActive(file): 5444 kBInactive(file): 4364 kBblah blah

author: NiHaoMike
author_rank: Super Contributor
timestamp: April 25, 2023, 01:52:22 am
content: For well over 10 years, every PC I set up didn't have swap. Never had any problem with it.

author: olkipukki
author_rank: Frequent Contributor
timestamp: April 30, 2023, 09:40:47 pm
content: Quote from: SiliconWizard on April 12, 2023, 07:25:31 pmOn 64GB machine I keep a swap 'just in case' of 1/2 size of RAM.Usually, couple VMs runs at same time, although a swap used rarely.Quote from: SiliconWizard on April 12, 2023, 07:25:31 pmTrying to hibernate 256GB RAM Linux didn't end up well

author: SiliconWizard
author_rank: Super Contributor
timestamp: May 01, 2023, 02:34:14 am
content: Quote from: NiHaoMike on April 25, 2023, 01:52:22 amThat's also my experience, with the disclaimer - that I stated - that I haven't been running Linux for real, heavy workstation use, hence the question more aimed at this use case.My uses have mostly been on a laptop (which has 'light' use) and a headless box that I use for development purposes. In both cases, no swap, and never had any trouble with it.But this time, it would be for 'heavy' workstation use, and typically putting the machine in standby when not in use (no hibernation as I said), so potentially relatively long up times.My conclusion so far is what has been said a few posts ago - I'm going to activate a swap partition on a small dedicated SATA SSD, that will also be used for cache files and otherwise content that changes frequently, so that I limit the wear on the much more expensive, NVMe SSDs that I have.