
Linux Swap - Different Kinds and How to Use It - Chris Titus Tech
video description
Date: 2022-03-21
Related videos
Comments and reviews: 10
Samuel
What stood out to me is the suggestion of 6 GB swap for 2 GB RAM. It-s usually suggested to make your swap equal to or 1.5x amount of the RAM you have. I never understood this. I mean yeah it helps with hibernate, etc. but as -extra RAM-, 1-2 GB swap may not be enough assistance for computers with 2 GB RAM, while those with 8 GB RAM should not have to worry anymore when it comes to basic use/needs. So I-m going to try Chris- recommendation because I have a computer with 1 GB RAM that I-m gonna upgrade to 2 GB really soon and super cheap and easy on this particular computer I have. Unfortunately I-m still limited to lighter DEs like XFCE whereas I really want to try GNOME but oh well. XFCE is fun. (I-m a Linux newbie.)
reply
What stood out to me is the suggestion of 6 GB swap for 2 GB RAM. It-s usually suggested to make your swap equal to or 1.5x amount of the RAM you have. I never understood this. I mean yeah it helps with hibernate, etc. but as -extra RAM-, 1-2 GB swap may not be enough assistance for computers with 2 GB RAM, while those with 8 GB RAM should not have to worry anymore when it comes to basic use/needs. So I-m going to try Chris- recommendation because I have a computer with 1 GB RAM that I-m gonna upgrade to 2 GB really soon and super cheap and easy on this particular computer I have. Unfortunately I-m still limited to lighter DEs like XFCE whereas I really want to try GNOME but oh well. XFCE is fun. (I-m a Linux newbie.)
reply
Peter
Well, hibernation or system standby is not the only purpose swap serves. Disabling swap is totally wrong. Running out of RAM is completely normal. Not running out of RAM could equally well be described as -wasting RAM-.
What happens when you eventually run out of RAM?
The operating system starts to evict clean pages. This causes thrashing and poor performance. When there are no more clean pages to evict, the OS will be refusing to permit operations that require memory (such as mmap and fork). Eventually it will start killing processes. Not a pretty sight.
So disabling swap on your -play at home machine- may be OK, however on a production server - you are bound for disaster.
reply
Well, hibernation or system standby is not the only purpose swap serves. Disabling swap is totally wrong. Running out of RAM is completely normal. Not running out of RAM could equally well be described as -wasting RAM-.
What happens when you eventually run out of RAM?
The operating system starts to evict clean pages. This causes thrashing and poor performance. When there are no more clean pages to evict, the OS will be refusing to permit operations that require memory (such as mmap and fork). Eventually it will start killing processes. Not a pretty sight.
So disabling swap on your -play at home machine- may be OK, however on a production server - you are bound for disaster.
reply
Cuttlefish
If you're not running vms, and still want to control swappiness, does that still work because swap is a sort of -virtual RAM?-
I'm running an 8-year-old laptop with 6GB of memory, and noticed my system would crash if I ran it longer than 2 days, hibernating twice. After seeing this, I immediately changed my swap partition from 2GB to 10GB (didn't have to resize in separate environment because I left 32GB free for future dual-booting plans), tested my memory by opening up several tabs in firefox until I saw swap being used in htop, and noticed that swap still wasn't being used.
Great video, but I'll look elsewhere for more information on how swap is supposed to work.
reply
If you're not running vms, and still want to control swappiness, does that still work because swap is a sort of -virtual RAM?-
I'm running an 8-year-old laptop with 6GB of memory, and noticed my system would crash if I ran it longer than 2 days, hibernating twice. After seeing this, I immediately changed my swap partition from 2GB to 10GB (didn't have to resize in separate environment because I left 32GB free for future dual-booting plans), tested my memory by opening up several tabs in firefox until I saw swap being used in htop, and noticed that swap still wasn't being used.
Great video, but I'll look elsewhere for more information on how swap is supposed to work.
reply
Marcel
good explaination, Only example where a swap partition has an edge over a swapfile is when you have more then a single disk installed in an system with swappiness for all partitions, and also important to check the priority, if all those values are identical you basically are operating a stripped configuration and depending on your interface this could speed up you swap, I used to do this back in 2006-2009. I stopped this practice when memory became cheaper. (swapfile in such case would agravate the disk caching mechanism which utilizes most free memory (as it should) and FS overhead which is neglectable today but has been a thing in the past.)
reply
good explaination, Only example where a swap partition has an edge over a swapfile is when you have more then a single disk installed in an system with swappiness for all partitions, and also important to check the priority, if all those values are identical you basically are operating a stripped configuration and depending on your interface this could speed up you swap, I used to do this back in 2006-2009. I stopped this practice when memory became cheaper. (swapfile in such case would agravate the disk caching mechanism which utilizes most free memory (as it should) and FS overhead which is neglectable today but has been a thing in the past.)
reply
Mark
I am in dire need to create a ginormous swapfile for my Cities: Skylines game. In 6-years woth of Expansion DLC for the game, it can get over 20GB of memory, plus another 8-16 GB of workshop mods and assets.
Well, My linux Mint Cinnamon 20.1, with 16 GB RAM is choking on the game. I tried making the swapfile bigger as I only have 2GB created by default install.
Can you go further into this, I think the swap partition is maybe the way to go, but I just can't find a way. Or maybe I can set it during linux install with a flag?
Any help would be awesome. And thanks again for your videos. I find them very helpful.
reply
I am in dire need to create a ginormous swapfile for my Cities: Skylines game. In 6-years woth of Expansion DLC for the game, it can get over 20GB of memory, plus another 8-16 GB of workshop mods and assets.
Well, My linux Mint Cinnamon 20.1, with 16 GB RAM is choking on the game. I tried making the swapfile bigger as I only have 2GB created by default install.
Can you go further into this, I think the swap partition is maybe the way to go, but I just can't find a way. Or maybe I can set it during linux install with a flag?
Any help would be awesome. And thanks again for your videos. I find them very helpful.
reply
Poe
Chris:
This video is exactly some of my prior experiences in Linux. I started doing something, made progress, then realized that I didn't know something that I needed to know -- from the beginning. But, again, I am thinking about giving it -Another Go- and trying to build a good skillset in Linux. But, thanks for filming this and being honest. What happened to you with creating a swap in btrfs, was my common, daily experience in Ubuntu Linux. But, that was before I tried Mint, and Mint seemed to be easier, kinder to me, and less of a learning curve to get things going (especially the packet manager).
reply
Chris:
This video is exactly some of my prior experiences in Linux. I started doing something, made progress, then realized that I didn't know something that I needed to know -- from the beginning. But, again, I am thinking about giving it -Another Go- and trying to build a good skillset in Linux. But, thanks for filming this and being honest. What happened to you with creating a swap in btrfs, was my common, daily experience in Ubuntu Linux. But, that was before I tried Mint, and Mint seemed to be easier, kinder to me, and less of a learning curve to get things going (especially the packet manager).
reply
Thomas
Swappiness isn't just for swap files as you stated. All of your descriptions and explanations and recommendations on this video are horrible. Didn't even mention zram, zswap, zcache or any alternatives. No mention of different distros may or may not have swap setup completely different than each other on a default install. Kinda funny BTRFS got in the way though (it usually does) and as always followed by a defense, lol. Not be too negative, I like you videos in general but this was just bad. Hardly three sentences go by with out being wrong, arguable, or misleading in some way.
reply
Swappiness isn't just for swap files as you stated. All of your descriptions and explanations and recommendations on this video are horrible. Didn't even mention zram, zswap, zcache or any alternatives. No mention of different distros may or may not have swap setup completely different than each other on a default install. Kinda funny BTRFS got in the way though (it usually does) and as always followed by a defense, lol. Not be too negative, I like you videos in general but this was just bad. Hardly three sentences go by with out being wrong, arguable, or misleading in some way.
reply
Andrew
You only need 1.5x your physical memory of swap (if you have 4G of memory and using more than 6G of swap, you are either doing something wrong, or you are doing something of which your system simply is not capable) until you get to beyond 8G of memory. There are very few use cases (that I can think of, anyway) where a 16G system needs any swap at all. I have heard that there are software packages out there that take advantage of swap regardless of your actual system memory; if that is the case, it is probably a good idea to have SOME.
reply
You only need 1.5x your physical memory of swap (if you have 4G of memory and using more than 6G of swap, you are either doing something wrong, or you are doing something of which your system simply is not capable) until you get to beyond 8G of memory. There are very few use cases (that I can think of, anyway) where a 16G system needs any swap at all. I have heard that there are software packages out there that take advantage of swap regardless of your actual system memory; if that is the case, it is probably a good idea to have SOME.
reply
Official
You don't actually need as much swap space as you have RAM installed to hibernate.
When hibernating, the kernel tries to create an image that is by default 2/5 as big as your maximum RAM. You can see that number by doing sudo cat /sys/power/image_size. It will try to achieve that size, as I said, but it doesn't mean that it will be exactly that size. The image could be even under that size or go over that size. By setting the value to 0 before hibernating, the kernel will try to produce the smallest image possible.
reply
You don't actually need as much swap space as you have RAM installed to hibernate.
When hibernating, the kernel tries to create an image that is by default 2/5 as big as your maximum RAM. You can see that number by doing sudo cat /sys/power/image_size. It will try to achieve that size, as I said, but it doesn't mean that it will be exactly that size. The image could be even under that size or go over that size. By setting the value to 0 before hibernating, the kernel will try to produce the smallest image possible.
reply
John
Why not make a btrfs video - I'm using one on my server mirrored over 4 hard drives, my experience is largely positive I'm also using snapper. I found it all a bit of a learning curve. However, the snapshots are great, I had a massive problem with Seagate hard drives sleeping and corrupting the mirroring, nevertheless scrubbing worked perfectly and I lost no data (I am now running some decent WD hard drives).
reply
Why not make a btrfs video - I'm using one on my server mirrored over 4 hard drives, my experience is largely positive I'm also using snapper. I found it all a bit of a learning curve. However, the snapshots are great, I had a massive problem with Seagate hard drives sleeping and corrupting the mirroring, nevertheless scrubbing worked perfectly and I lost no data (I am now running some decent WD hard drives).
reply
Add a review, comment
Other channel videos















