LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-16-2020, 12:56 AM   #1
Regnad Kcin
Member
 
Registered: Jan 2014
Location: Beijing
Distribution: Slackware 64 -current .
Posts: 663

Rep: Reputation: 460Reputation: 460Reputation: 460Reputation: 460Reputation: 460
Is a swap partition still necessary?


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.
 
Old 07-16-2020, 01:25 AM   #2
solarfields
Senior Member
 
Registered: Feb 2006
Location: slackalaxy.com
Distribution: Slackware, CRUX
Posts: 1,449

Rep: Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997Reputation: 997
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.
 
3 members found this post helpful.
Old 07-16-2020, 01:55 AM   #3
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
If you want to hibernate your machine, you'll need swap at least equal to your memory size.
 
5 members found this post helpful.
Old 07-16-2020, 01:59 AM   #4
Regnad Kcin
Member
 
Registered: Jan 2014
Location: Beijing
Distribution: Slackware 64 -current .
Posts: 663

Original Poster
Rep: Reputation: 460Reputation: 460Reputation: 460Reputation: 460Reputation: 460
I don't ever hibernate my machine.
 
1 members found this post helpful.
Old 07-16-2020, 02:10 AM   #5
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 07-16-2020, 02:13 AM   #6
chrisretusn
Senior Member
 
Registered: Dec 2005
Location: Philippines
Distribution: Slackware64-current
Posts: 2,978

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
Depends on what you do I guess.

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.
 
1 members found this post helpful.
Old 07-16-2020, 02:13 AM   #7
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,063

Rep: Reputation: Disabled
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.
Long answer: read In defence of swap: common misconceptions, in the kernel documentation zram.txt, to learn about page faults this article, for an example of practical zram usage this one (in French). For setting a swap file instead of a swap partition, there is plenty of information on line.

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.
 
15 members found this post helpful.
Old 07-16-2020, 02:43 AM   #8
Regnad Kcin
Member
 
Registered: Jan 2014
Location: Beijing
Distribution: Slackware 64 -current .
Posts: 663

Original Poster
Rep: Reputation: 460Reputation: 460Reputation: 460Reputation: 460Reputation: 460
@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.
 
Old 07-16-2020, 11:36 AM   #9
drgibbon
Senior Member
 
Registered: Nov 2014
Distribution: Slackware64 15.0
Posts: 1,221

Rep: Reputation: 943Reputation: 943Reputation: 943Reputation: 943Reputation: 943Reputation: 943Reputation: 943Reputation: 943
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.

Last edited by drgibbon; 07-16-2020 at 11:50 AM.
 
Old 07-16-2020, 11:48 AM   #10
enorbet
Senior Member
 
Registered: Jun 2003
Location: Virginia
Distribution: Slackware = Main OpSys
Posts: 4,787

Rep: Reputation: 4435Reputation: 4435Reputation: 4435Reputation: 4435Reputation: 4435Reputation: 4435Reputation: 4435Reputation: 4435Reputation: 4435Reputation: 4435Reputation: 4435
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.
 
Old 07-16-2020, 12:25 PM   #11
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,504

Rep: Reputation: Disabled
Gave up worrying about swap when I got 4GB ram.....

(Seldom bothered when I only had 2GB.)

Laptops that hibernate, & heavy usage of processing are the main users for swap these days; but that's not my way of usage.
 
Old 07-16-2020, 02:01 PM   #12
sevendogsbsd
Senior Member
 
Registered: Sep 2017
Distribution: FreeBSD
Posts: 2,252

Rep: Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011Reputation: 1011
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.
 
Old 07-16-2020, 03:25 PM   #13
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,646

Rep: Reputation: 147Reputation: 147
Quote:
Originally Posted by Richard Cranium View Post
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.
 
Old 07-16-2020, 04:35 PM   #14
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,063

Rep: Reputation: Disabled
Quote:
Originally Posted by titopoquito View Post
Quote:
Originally Posted by Richard Cranium View Post
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...
 
Old 07-16-2020, 05:04 PM   #15
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,145
Blog Entries: 6

Rep: Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832Reputation: 1832
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.
 
  


Reply

Tags
swap



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is a linux-swap partition necessary in Puppy 4.1.2? gray53 Linux - Newbie 2 09-14-2009 06:41 PM
SWAP partition, is it necessary???? webquinty Linux - Kernel 7 05-22-2009 08:10 PM
swap partition necessary? vonbiber Slackware 9 05-10-2009 12:55 PM
Is swap partition necessary? samstar Linux - General 26 06-02-2007 10:35 PM
Is a swap partition really necessary? YodaCows Linux - Newbie 21 04-05-2006 12:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration