Linux Swap | Different Kinds and How to Use It

preview_player
Показать описание
This video is about Linux Swap and the different kinds of swap that exist. This shows you how to use swap partitions, swap files, and when not to use them all together. I also go over how big swap should be and how to change how often Linux will use swap. .

Рекомендации по теме
Комментарии
Автор

A hacker tip. If you forget sudo, just type.
sudo !!

AndersJackson
Автор

Chris, you can repeat the last command with !!. In your particular case you could have done it like this.
~ $ swapoff -a -v
swapoff /dev/sda3
swapoff: Not superuser
~ $ sudo !!

!! replaces whatever you entered the last time. And yes, this is mostly used for all of us who forget to sudo. ;)

peterjansen
Автор

Arch + btrfs + swapfile user here; missing some features, but works for my purposes. Just gotta do your homework first, and I think you're right that for most it'd be easier and better just to use a separate partition.


BTW, I use swap ;3

googIesux
Автор

Didn't know BTRFS didn't support swapfiles. vm.swappiness=X actually means X% of ram left to use before swap comes in.

ryon
Автор

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.)

samuelitooooo
Автор

*HI Chris, your video is NOT complete ...you should have at the beginning of the video defined what a "swap files" is is it and why it's used" 😐😐*

terry.chootiyaa
Автор

ZFS has the same problem as BTRFS, so I use a SWAP partition too.
Default swappiness is 60 in Linux. I leave it like that, also in my 16 GB desktop running 3 or more VMs. In the past I used to set it to 10, but I stopped with this illusion. It is preferable, that the system starts swapping out pieces of code not used for some time, if the memory gets more occupied.
I prefer more free memory over more free swap space. When a VM is loaded and needs the memory space, it will already have been freed and the VM doesn't have to wait for Firefox to be swapped out.
I don't know the algorithms used to swap code in or out of memory in Linux, so I do not expect to be smarter than the system designers, who wrote the code and did choose those defaults.

bertnijhof
Автор

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).

PoeLemic
Автор

Thanks for explaining what the command does and why we use them, that helps a great deal to understand what we do and act logically and consciously.

emmanuelpoirier
Автор

Your title and description gave me the impression you'd also include SSD-saving ZRAM and running it symbiotically with file/partition swaps. A somewhat recent kernel addition was a very fast default de/compression algorithm for ZRAM and I thought you would have encountered that in your current research. It effectively gives users memory expansion through realtime, transparent, in-RAM compression. It's keeping Android smartphones and tablets with limited RAM from wearing out their fixed flash storage too soon. With a properly set up hierarchy via priority levels, whatever spills out of 1st level ZRAM can overflow into a swap file/partition on an SSD. Then when there is still memory page pressure (in a VM container beast, for eg.), a third level HDD swap file/partition as a last resort. I was looking forward to seeing an example of the real possibilities available to Linux users/admins. I really wanted to upvote this video. :(

daemakun
Автор

protip: you dont need gparted. command line command: lsblk will list all the block storage and partitions swap and everything. additionally you can use fdisk -l. It's a littel simpler especially if you're doing stuff in the terminal anyway

GradyBroyles
Автор

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.)

mmcv
Автор

You can even get away with using zram as swap devices if you have a fast CPU. It basically dynamically allocate some portion of ram as compressed swap devices. You can also set the usage priority between multiple swap devices.

oogioboogie
Автор

I like the way you reversed the video when you ran htop so you were looking at the htop not only in your room but we could see you were looking at it on this video as well, your videos are inspiring for those going through the transition to Linux.

gumbystern
Автор

This video was effective at only one thing. Educating us that btrfs and swap files don't mix. Obviously, that was a learning exercise for you as well. Unless you planned on redoing the video, I'd have changed the title and description to reflect this. Otherwise, I'd call this video a failure.

SlideRSB
Автор

My experience with linux swap is horrible. Using just Firefox I got the system to trash heavily while the swap usage a low as 1/4GB. What I'm trying to say is that if you get to use more than 1GB of swap, you are going to have a serious trashing that makes the system completely unresponsive. If you use hibernate then make RAM+1GB of swap partition.
If you are running out of RAM memory, I would recommend you to first disable THP (Transparent Huge Pages). THP allows using 4MB memory pages, however sometimes they are not broken to 4KB when userspace frees parts of them, thus still holding significant portions of physical memory that could be re-used. Swap also has/had some issues with THP support.

To be honest, even hibernate is not really that nice. I do prefer to close Firefox before hibernate, because it is faster to start it anew, than to wait for the system to bring it page per page from the swap after resume. (`htop` can also show page faults, so I've watched the process in real time.)

Using NoCOW on btrfs should not be an issue. It just means the file would be overwritten every time and this i what you want. They actually did a lot of changes to make possible the use of swap file, so ... yeh, swapfile is a little bit experimental still.
Actually NoCOW is recommended for virtual machine images too...

ИванСнежков-зй
Автор

If you want to disable your swap partition, just know that if you don't delete the partition completely, there are some situations where systemd will automatically try to locate and swapon the partition on boot, even if it's removed completely from your fstab. I remember spending some time just sitting there confused until I found an ArchWiki page that told me to mask the device. :p

Also, it would be cool to see a video on zram and zswap! I've been using either of them for a while. If you don't care about hibernation, then just having all your swap on a single zram block can be good enough (setting its size to twice the size of your RAM seems good for how much it could ever realistically hold). You can even use zram as a compressed RAM disk if you want to (filesystems with discard support are good for this).

tromino
Автор

"Standard Linux installation...." Arch Ok.

corey
Автор

I user a swap file with a btrfs filesystem on my laptopr and its working fine, you just have to make sure to be on the latest kernel and disable cow for that particular file.

albertopajuelomontes
Автор

4:13 You can disable/enable swap graphically, using GParted or GNOME Disks. Just right click on proper partition.

tomaszgasior