To Swap or Not? Using Swap Space in Modern Computers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to the OTB Channel have you ever wondered in this modern age where computers have well potentially dozens of gigabytes of RAM why on earth you still need to allocate swap space let's discuss after the intro [Music] right welcome back and cheers nice cup of coffee here so let me start today's video by just apologizing this is only the second video this week real life has started to kick in as the lockdown comes to an end and I've just been short a time so that said let's talk about the subject of the video to swap or not using swap in modern computers I've chosen this subject because I've lost counts over the years of just how many times I've been asked by users I I've been supporting do I need to create a swap partition or a swap file and just exactly how much swap should I be creating and I'm not surprised that I keep out being asked those questions because often there isn't a clear answer opinions vary depending on where you look and it becomes even more complex now that we've got computers that are running 32 gig or more of RAM because they have loads of physical memory installed and the chances are all things being well their computers will never actually have to access the swap space well before we start let me tell you what I use irrespective of how much RAM I've got on my computer I've got 16 gig at the moment I use a swap file as opposed to a swap partition of 4 gig and I take steps to ensure that that is accessed as infrequently as possible why do I make the decision to set up that configuration well hopefully that will be clear as we go through this video so let's get started ok well before we start let me just get rid of a myth if you've got computer with 8 gigs of physical RAM installed and you also have an 8 gig swap partition or swap file that does not mean you have the equivalent of 16 gig of ram in terms of if you had 16 gigs of physical RAM installed on your computer swap space is much slower to use than physical Ram so if your computer is using swap all the time it's performance is likely to be quite poor as compared to if it was just using physical Ram and if you find yourself in a situation where swap is being used an awful lot there's a simple answer here you need more memory go out and buy some more RAM if that's at all possible so that said you might think that swap then needs to be or the use of swap needs to be avoided at all costs well yes and no you would prefer that your system always just uses physical memory but there are occasions when swap can be useful so looking at the first bullet point here you might be using a really memory intensive application for instance video editing software you saw my experience with kdenlive a few weeks ago when that situation happens and you have an application that is really RAM hungry swap can help because your system can swap out pages of memory to a swap file to free up more physical RAM for the system to deal with its immediate demands so if you suddenly find that your memories all being used up perhaps you've got a system with a not huge amount of memory swap can be quite useful on the occasions where you're using it to its its full capability it's also the case that many applications when they launch launch all sorts of processes that allocate themselves blocks of RAM but once you've started up the application they are essentially inactive but they are taking up portions of your RAM that cannot be used your system has the capability to swap them out to your swap partition or swap file and free up resources for dealing with active processes which makes sense the third reason why swap might be used is if you hibernate your system hibernation or otherwise known as suspend to disk requires that the system state in memory is swapped out to disk space be that a swap partition or a swap file so you use that as part of the suspend to disk process this is perhaps become less common with the onset of SSDs where we attempt to minimize the disk writes to SSDs at all times and on many Linux systems it isn't actually activated by default and you would have to take physical steps to get it working nevertheless hibernation is still one of the reasons my swap is used so just to summarize why would you use swap well your system has a small amount of RAM and you're tending to use it to its full capability you use Ram intensive programs you hibernate your system or worst case scenario you could also get an application that goes rogue and suddenly starts eating up all of your RAM and if you have a swap space where your RAM can swap out pages of memory too it gives you a little bit more time to try and salt it out before your system crashes so you might be saying after that well hold on Steve I've got 32 gig around in my system nothing I use ever gets anywhere close to using up my physical RAM even when I'm doing such things as video editing and if I don't need a swap space I would rather save that disk space for more important things than creating a swap partition or a swap file and that may be a viable answer the choice is completely yours there is always of course the odd chance that you could get a robot rogue application that starts eating up all of you memory but you take the chance you may decide however that you know overall it sounds like it's going to be safer to create some sort of swap space just in case the question you you're then going to be faced with is well how much do I need to create well this is where opinions vary wildly when I first started using Linux 16 years ago we were still using machines with 128 Meg 256 Meg of RAM at most and the advice then was you're swap space should be at least two times your physical ram but ideally two and a half times your physical RAM or even more and two and a half times was why I used to say most of the time that's come down a little bit here as RAM sizes have gone up and up and now we see well a range of different suggestions some webpages will suggest that you use swap space equal to twice your physical RAM others suggest that your swap space should be equal to your physical RAM so if you have eight Giga physical RAM installed you should have an eight gig swap space others say that actually even that rule is perhaps a little bit over the top if you have 16 gig of ram you should limit yourself to 8 gig as an absolute maximum as far as swap space is concerned because the chances are you're not gonna need more than that and then pick any other alternative in between because depending upon where you look the answer will probably be different so given the disagreements what are you going to choose because there is no definitive answer well I take the view that if you do hibernate your system that your swap space should be equivalent to the amount of physical RAM that you have installed so if you have 8 gig of ram create an 8 gig swap space if you hibernate if you don't hibernate well I would suggest that you don't need anywhere near that and 4 or 5 gigs will probably be sufficient on adjusting case basis which is the reason that I create a four gig partition because it's just there for just in case I don't hibernate my system so to me it's a little bit of extra safety do I need it no probably not I very rarely see my computer actually use swap space which is a good thing but nevertheless you have to make that decision now there are some resources out there that make some suggestions but it's importantly you just see these as suggestions one of them is the abun - well what was the wiki the abun - documents page and looking at what they say I'm just gonna move to the combined view now they have listed a range of different possible sizes based on one how much RAM you have installed to whether or not you use hibernation and we start at one gig and move all the way up to 64 gig and you can see they they start at one gig of ram which let's face it these days that's not many people and they say you should have a minimum of 512 Meg of swap if you don't hibernate and as you move up through the scale up to four gigs the saying you should have 50% of your physical RAM or swap space and then that starts to get less and less and less the more physical RAM you have installed so even if you have 64 gigs in use on your system they're saying an 8 gig swap space would be sufficient and if like me you have 16 gigs the same a 4 gig swap space will be sufficient I think that's quite sensible let's face it if you have 64 gig of ram and you follow the advice to create a swap partition of twice the size of your physical Ram do you really want to be wasting a hundred and twenty eight gigabytes of space on a rampart ition I certainly wouldn't especially if I'm using SSDs when we move over to the third column though they're not as conservative as I would be so for one and two gigs of ram the same will you swap should be equivalent to your RAM size but then they start to increase that from four gig onwards so the same if you've got four gig of ram and you hibernate you should use six or create a six gig swap space and it goes all the way up so that if you've got sixteen gig installed and you hibernate the same 20 gig of swap space and if you've got 64 gig installed the same you should use 72 gig of swap space I think you could probably come down to a swap space equivalent to your physical Ram if you hibernate but given the amount of space that you would be using if you hibernate your system the amount of wasted disk space in my opinion that results from high Bonet in your system would put me off hibernating anyway even if I did it which I don't so the big issue here is do you hibernate or do you not hibernate if you do hibernate you're gonna need to allocate a big chunk of your physical disk space to swap if you don't well it's up to you yes you could get away without it but as long as you have the available disk space a four or five six gig swap partition or swap file should be enough now that brings us to the issue of do you create a swap partition or do you create a swap file again opinions vary some distros don't even bother these days on the automatic installation to create a swap file they just automatically creates sorry to create a swap partition they just automatically create a swap file and in terms of performance there isn't a huge amount of difference you can see some people saying well as minor performance differences here and there but overall it doesn't really matter I suppose one of the considerations for me is if I'm multi booting three or four different Linux systems on a hard drive or an SSD if I create a swap partition I can reuse that swap partition for each of the Linux systems just so I don't have to keep recreating it but if I've got just a single system I'll probably just go the way of creating a swap file and the way you do this is pretty simple we've got a couple of commands and you can see the first one there I'm not quite sure how to pronounce this for locate fala kate fala kate sounds right you would do these as root or with sudo so if you wanted to create for gig swap file it would just be a case of phallic 8 - l4g and then I normally creates my swap file at forward slash so I wouldn't create it in my home directory I would create as forward slash swap file you could also use DD that was the traditional way of doing it it's a little bit slower but tends to be more reliable and the format is pretty simple you take the input of dev 0 and you out put it to a swap file I'll put it in the same place there so forward slash a swap file I said the block size is a thousand and 24 kilobits and the count therefore is four one nine four three zero four where does that come from well based on the fact that there are a thousand and twenty four bytes to a kilobyte and a thousand and twenty four kilobytes to a megabyte and a thousand and twenty four megabytes to a gigabyte do the math it works its way out after that just follow the instructions you'll find them anywhere the arch whippy wiki is particularly good do a chmod 602 a make swap swap on and stick it in your fstab to make sure that it comes on each time you boot so like me you've decided that on a just-in-case basis you're going to create some swap space at least but you want to minimize the amount of times that your system actually uses it so that it only uses it when absolutely necessary is it possible to control that sort of variable well yes it is we have a concept called swap eNOS swap eNOS can actually have a value of between naught to 100 and that value dictates how likely it will be that the kernel will use swap space the higher the value the more likely it would be that it would use it so if you set the value at a hundred the chances are your system would chug along using swap constantly that's something that you're gonna want to avoid most systems come with the value defaulting to sixty but if you want that to be less and if you have an SSD I would suggest you're gonna want it to be less in order to minimize the writes I like to set it to around ten you can use a command system CTL VM swapping us to view exactly what your system is set at and as I say most of them will be sixty but you can permanently change it by editing in arch anyway et Cie sis CTL D 99 swap eNOS Kampf you may have to create that file and you just put in an entry there of VM dot swap eNOS equals ten or whatever you want you might want to go all the way down to one completely up to yourself and say that not quite sure where the locations are different on a bun - I'm using that same location on my debian stable system but just do a quick Google and it will tell you so you can control how likely it is your kernel is gonna use swap anyway so that's pretty much it for today where did we end up as far as how you use swapper modern computers well I would say if you use hibernate create a swap partition or a swap file equivalent to your physical RAM if you don't hibernate it's up to you if you make the decision to create a small amount of space on a just in case basis fine if you decide to go with out swap altogether you're probably going to be ok you really are especially if you've got a lot of RAM the choice is yours completely in Linux of course there are always other options and if minimizing rights to disk is one of your priorities you may want to look at Z RAM and Zed swap where your physical RAM is used to compress memory to minimize disk writes it's beyond the scope of this video but the arch wiki has a really good write-up so that's it for today guys don't forget to join me on library or come and join us on our Facebook group it's getting quite active now and the guys have been playing around installing arch with my arch scripts wall script text file that I put up last week and oh yeah as an update two weeks into use inspector WM all good so far I've now got X Monad configured which I'll move to after I finish with Specter and if any one of you wants to have a look at my config file it's also on my github page that's it for today guys have a great weekend [Music] you [Music]
Info
Channel: OldTechBloke
Views: 11,150
Rating: undefined out of 5
Keywords: oldtechbloke, otb, linux, swap space, swap partition, swap space in linux, swap memory, linux swap, swap memory in linux, swap partition in linux, swap space management in linux, what is swap space, how to create swap space in linux, add swap space in linux, adding swap space in linux, swap partition vs swap file, swap partition ssd, linux swap size, what is swap space explain, swappiness, swappiness linux, vm swappiness, linux commands, how to create swap partition in linux
Id: MAy4-3ppj6Y
Channel Id: undefined
Length: 21min 52sec (1312 seconds)
Published: Sat May 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.