SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have 16GB of ram, Intel i7-9700K (8) @ 4.900GHz, Asrock z390-itx mainboard, 1TB NVME, and 4TB backup SATA. I have Slackware64-current. I presently have a 8GB swap partition. I do some video rendering and some DNA sequence alignments which are the most computation and memory intense things that I do. I do monitor the memory use and I dont see the RAM use getting above 10 to 12 GB at any time even on a big video rendering project using all 8 threads intensively for about an hour of rendering time. The swap partition never seems to get used. Some years back I had 4GB memory and the swap partition would be employed on some DNA alignment tasks. I dont ever see it used any more.
So, do I still need a Swap partition? Old thinking would be that I would have a 32GB swap out there but I only have 8 GB now. I see that some asked this question ten years ago but 16 GB of RAM was less common back then. Of course I could disable the swap and experiment but I am interested in the experience and opinion of others.
I always keep a swap partition, although I do not follow the old rule-of-thumb about the size. I monitor the system load and every now and then I see some of it used.
I think it does not hurt to have, because disk storage has been always much bigger than RAM size.
So you have 16GB of RAM, it feels like a lot, it never gets full. Fine, what if your workflow changes tomorrow? Like you'll need to fire up a couple of RAM hungry virtual machines? The swap partition never gets in my way, so I keep making it. I don't use hibernation either, I think I don't fully understand the concept of it.
I run with a 2GB swap regardless of memory, even on a laptop that I use hibernate on. Laptop has 4GB of memory and never had an issue with hibernation. This desktop has 8GB of memory, I have occasionally seen the swap used but not very often.
Short answer: You don't need a swap partition, but always have some swap space to be able to detect a situation in which the OOM (Out Of Memory) killer could start and act accordingly.
That could be setting up a swap space using zram (I'd make it half your RAM size to begin with) ...
... and a swap file instead of a swap partition, with a lower priority than the swap in zram, with size at least the RAM size if you want to hibernate. If you don't hibernate 1G or so will be most often enough.
PS If you build very big software the linker can be really memory hungry. Before starting such a job I'd make a really big swap file. You have plenty of space, 32 G could be safe, but check with "free" periodically.
PPS You could as well use zram to mount /tmp instead of using a tmpfs, cf. this Gentoo document. And specifically for a SSD read also this one.
PPPS I just came across a project that can help avoid wearing out SD cards or USB sticks: log2ram.
Last edited by Didier Spaier; 07-16-2020 at 03:00 PM.
@Didier - thanks for the links especially about zram and the practical one although in French was not too French too read. Good tip about big software. I think I will scale my swap partition back to 1 to 2 GB and see how it goes.
RedHat's table on swap space is handy. For 16GB their recommended minimum is 4GB (no hibernation).
I also saw thrown around somewhere the square root of your RAM rounded up to the nearest power of 2 (giving 4GB again for 16GB RAM). Seems decent.
Also, might be worth quoting from RedHat:
Quote:
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory. Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files. Note that Btrfs does not support swap space.
In years past, the recommended amount of swap space increased linearly with the amount of RAM in the system. However, modern systems often include hundreds of gigabytes of RAM. As a consequence, recommended swap space is considered a function of system memory workload, not system memory.
I've NEVER subscribed to that stupid size formula even as far back as Win 3.0. It is completely ignorant in my view to increase swap size in direct proportion to RAM. The relationship is NOT Direct but Inverse - the more RAM one has, the less Swap one requires. The only caveat to that is for Hibernation which I've never done. Once we broke through the 512MB RAM "barrier" (not really an actual barrier, just common allotment) and then with the massive change with either actually usable PPA or real 64bit systems, the need for Swap became extremely limited and often entirely optional.
That said IMHO it isn't a bad idea to have some small amount of drive space setup as emergency Swap just in case. These days of disks measured in Terabytes even 1GB of drive space set aside for Swap is just no big deal and is at least a safety measure that costs next to nothing.
I haven't used swap in years, but in my defense I have never run a modern Linux box with less than 32Gb ram, lol. I think the last time I had 8GB was in 2005 or 2006. I always go overboard on hardwire though. No other hobbies so why not...
On a different note, this MacBook Pro has 8GB and is swapping with 2 apps open, but MacOS has always been fat. It has 2GB of swap and is using 600MB of swap. I hardly notice and swap hasn't gotten too much higher than that. All of this is running on an nvme drive so is lightening fast, which is probably why I never notice.
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,646
Rep:
Quote:
Originally Posted by Richard Cranium
If you want to hibernate your machine, you'll need swap at least equal to your memory size.
AFAIR that's not true anymore because the memory will get saved compressed in the swap partition. I've found no perfect rule of thumb though how much it in average can be compressed and what percentage (compared to your RAM) you need to be on the safe side. Obviously highly dependent on the data your computer is calculating at that very moment of hibernating.
If you want to hibernate your machine, you'll need swap at least equal to your memory size.
AFAIR that's not true anymore because the memory will get saved compressed in the swap partition.
But if zram is used the compression can be done with a 2:1 ratio, so if the same ratio is valid in a swap partition or file (which I don't know), that could stay true...
Remember the good ol days? When you installed windows 95 on a machine that had 8 or 16 MB of RAM? So it had to have a swap file. Every now and then the hard drive would start thrashing and the machine would almost lockup. To keep from getting mad you walked away from it for 5 min and let it sort it out.
Quote:
So, do I still need a Swap partition?
Only if you need it. If the machine won't run without it.
Quote:
I have never run a modern Linux box with less than 32Gb ram
Do you ever fill that up? With that much RAM you could make a RAM drive and install the OS in it. That would be fast. The gamers did that years ago. You just can't turn the machine off.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.