What is Linux swap?

Поділитися
Вставка
  • Опубліковано 31 січ 2019
  • If you want to learn everything about Linux swap, you have to watch this video. In the video, I cover these key points:
    • What is Linux Swap?
    • Do you need Linux Swap?
    • What are Swap Partition and swap file?
    • How to create a Swap File.
    • What is swappiness and how to adjust it?
    Commands used in the video: averagelinuxuser.com/linux-swap/
    Tags: #AverageLinuxUser #swap #swappiness
    ################################################
    Support on Patreon: / averagelinuxuser
    Donate through PayPal: www.paypal.me/Kryvokhyzha
    ################################################
    Website: averagelinuxuser.com/
    More cool Linux stuff at other social media:
    Google+ - Best Linux Stuff: plus.google.com/+AverageLinux...
    Facebook - Top Linux Tips: / averagelinuxuser
    Twitter - Daily Linux News: / avglinuxuser

КОМЕНТАРІ • 196

  • @AverageLinuxUser
    @AverageLinuxUser  5 років тому +91

    I was little incorrect when I said Linux would crash when it runs out of RAM and there is no swap. First, it will start killing processes to free up some RAM and if it doesn't help it may crash. In my experience, when I filled all RAM on my desktop, Linux just hangs for several minutes. Often it kills RAM intensive process after several minutes and I could continue to work. Rarely, I had to hard reset it by pressing a shutdown button.

    • @JamesWilson-pq9qp
      @JamesWilson-pq9qp 5 років тому +3

      Yea, during a kernel panic the system shows a black screen with some fifteen lines of code and refreshes in a few minutes. I almost killed it, being impatient. But it came back on with no lost information. And I progressed to lighten its load and continued on the rest of the day with no problems.

    • @DennisSchmitz
      @DennisSchmitz 5 років тому +1

      @@JamesWilson-pq9qp Same happened here on Manjaro Gnome which didn't setup swap for me for whatever reason (maybe because I already have 32GB of RAM).
      In the end it always hanged or crashed when it was running out of RAM using Davinci Resolve Studio.
      Solved the problem by adding 32GB of SWAP on a NVME drive which writes like 3GB/s so it still stays speedy. :)

    • @JamesWilson-pq9qp
      @JamesWilson-pq9qp 5 років тому +2

      @@DennisSchmitz Wow, that's a lot of ram, you should never need a swap. Might I suggest Kdenlive. Be careful with an SSD, they don't tolerate as many rewrites as a HHD or RAM. ua-cam.com/video/NNr8ULWnWFU/v-deo.html

    • @DennisSchmitz
      @DennisSchmitz 5 років тому +2

      @@JamesWilson-pq9qp KDEenlive is more of an entry level software which lacks hardware acceleration for H264 and H265 in 10 bit and 4K (2-3 fps in kdenlive vs 100-120 fps in Resolve Studio) ;)
      And Resolve (very much like Premiere and After Effects) uses lots of RAM, 32GB and even up to 64GB on my machine dependent on the project (working on a feature film shot end edited in 4K DCI, 10 Bit, ACES colorspace, lots of VFX and compositing in Fusion, noise reduction using Neat Video etc...).
      And btw. Resolve Studio runs way better on Linux than on my Windows 10 installation at least. No low VRAM issues and Resolve crashing caused by this issue. So am really happy I figured out Linux finally. With Windows adding a second 1080Ti with 11GB of VRAM would have been the only option. Linux basically saved my a thousand bucks! :D

    • @JamesWilson-pq9qp
      @JamesWilson-pq9qp 5 років тому

      @Subhajit Roy Dear Roy, Sorry I never wanted to disable Bluetooth, but I can understand you reason. The command line is in systemend part of the boot system. Careful now: forums.linuxmint.com/viewtopic.php?t=276996 suggests on the bottom of the page: sudo systemctl mask --now bluetooth.service With "mask" you can not start Bluetooth, and "now" you have an option, and "disable" is not as extreme as "mask." Please let us know how it worked!

  • @rajukomati7545
    @rajukomati7545 4 роки тому +3

    This video clarifies my all doubts about swappiness in Linux.

  • @pyotrleflegin7255
    @pyotrleflegin7255 5 років тому +2

    Thank you once again for a very clear and informative video. I have been using Linux of one type or another for years and although I have always included a SWAP partition, I have never been quite sure just what it did!

  • @KrishnaYadav-kz5ed
    @KrishnaYadav-kz5ed 5 років тому +3

    Very informative video,my confusion is no more.
    Great video

  • @vi__ku4748
    @vi__ku4748 3 роки тому +1

    Really a helpful vide, in a short duration of time you have explained most of the concept related to the main topic, thanks for your efforts

  • @msurajnair7149
    @msurajnair7149 4 роки тому +1

    It was instructive and informative. It was explained in simple words.
    Thank you.

  • @carina_lins
    @carina_lins 3 роки тому +1

    Perfect explanation. Thanks a million!

  • @englundm50
    @englundm50 5 років тому

    Thank you very much for the clear explanation.

  • @alicherifi9075
    @alicherifi9075 4 роки тому

    Thank you ! very clear and instructive video, i hope to see more !

  • @douglas7656
    @douglas7656 5 років тому

    Thanks for making the video, I have 48G of ram and was still using 60 swappiness. Fixed it now.

  • @dxsp1d3r
    @dxsp1d3r 5 років тому +1

    The best Linux tutorials on youtube
    Thanks am loving it
    Keep posting xD

  • @cookingtimewithkousar
    @cookingtimewithkousar 2 роки тому

    Your style and method is Good. I understand everything about swap.

  • @stefanomarini8468
    @stefanomarini8468 3 роки тому

    Thank you for sharing this!

  • @kenmurphy4259
    @kenmurphy4259 5 років тому

    Excellent tutorial! Thanks!

  • @user-ff9rx7kq2g
    @user-ff9rx7kq2g 3 дні тому

    Thank you for making this video

  • @dantar01
    @dantar01 Рік тому

    Awesome! My tablet-pc always crashed on opening Intellij. Since I added 4 GB swap memory everything works fine.
    You literally saved my money on buying a new device.

  • @mathieuberthalay21
    @mathieuberthalay21 Рік тому +1

    Thank you for your video

  • @gruesomegaijin2026
    @gruesomegaijin2026 4 роки тому

    Very nice. Thanks for the advice.

  • @alvinchris3138
    @alvinchris3138 5 років тому +4

    I get so much value from this channel!
    Big up to you man.

  • @fabiomn1965
    @fabiomn1965 5 років тому +7

    Congrats on the great video!
    Keep up the good work of making the videos on Linux systems. Your didactics is awesome! You explain everything in a simple way. Thanks from a Brazilian fan.
    By the way, what's your nationality?

  • @tpasi2020UG
    @tpasi2020UG 5 років тому

    Great tutorials please keep them coming

  • @javierCi
    @javierCi 5 років тому

    Thanks you! I do not know the swappinnes, very usefull

  • @johanb.7869
    @johanb.7869 5 років тому +6

    Thanks for explaining this. Very usefull.
    When I install Peppermint it creates a 2 GB swapfile automatically. I set swappiness to 1, because I read that when using a SSD it should always be set to 1. Why I don't know, but it works.

  • @sandokan888
    @sandokan888 2 роки тому

    thank you, very good tutorial. It def works better with a swap

  • @MonBureauLinux
    @MonBureauLinux 5 років тому

    Thanks for the video.

  • @shaharrefaelshoshany9442
    @shaharrefaelshoshany9442 2 роки тому

    So clever, amazing!

  • @IvicaAnteski
    @IvicaAnteski 3 роки тому

    Great explanation... thanks man!

  • @andresruizdc
    @andresruizdc 5 років тому

    Great video, thanks!

  • @flpolskiskifl8709
    @flpolskiskifl8709 4 роки тому +1

    Dude you saved me. I didnt want swap on my ssd. Just to give it more life.

  • @sussusamogus7831
    @sussusamogus7831 11 місяців тому

    great guide as always

  • @vani.sharmaa
    @vani.sharmaa Рік тому

    Thanks for this.

  • @satpad
    @satpad 5 років тому

    Thank you . Good work

  • @chickietv122
    @chickietv122 Рік тому

    Thank you so much!

  • @kerron_
    @kerron_ 4 роки тому

    Very good video. Very practical

  • @karanmirchandani269
    @karanmirchandani269 3 роки тому

    Very well explained

  • @apsnehithshots8122
    @apsnehithshots8122 2 роки тому

    Really useful information....learned a lot new things..... appreciate your effort brother😃

  • @Eimantasks
    @Eimantasks 5 років тому

    damn dude, this was super useful , thank you!!!

  • @albertoleo9529
    @albertoleo9529 5 років тому +8

    Thank you again ... always great and easy to understand videos, even for a newbie like me!
    Just to say ... it is probably your "fault" that I switched to linux (very determined to stay on it and make things work!)

  • @rolandrobertsons3069
    @rolandrobertsons3069 Рік тому

    very clear!

  • @rezakhakpour7549
    @rezakhakpour7549 2 роки тому

    i learned what is swap from your video

  • @jacobdurant7124
    @jacobdurant7124 5 років тому +22

    Could you do a video on Power management/Suspend and hibernate?

  • @theoriginallyrics9649
    @theoriginallyrics9649 2 роки тому

    Useful video 👍

  • @hpp6116
    @hpp6116 5 років тому

    Great video!

  • @CMxPunk
    @CMxPunk 5 років тому +3

    great video!
    just out of curiousity do you recommend ZRAM?

  • @dannielmuniz256
    @dannielmuniz256 5 місяців тому

    Thanks!!

  • @artistmaterial09
    @artistmaterial09 4 роки тому +1

    great video

  • @dipenparmar2273
    @dipenparmar2273 3 роки тому

    Informative.... 😀😄

  • @linuxlifepage
    @linuxlifepage 5 років тому

    Спасибо!! Отличное видео

  • @jairusan
    @jairusan 5 років тому +3

    Hello there ALU (^^) thank you for this really interesting tutorial. I went through it and just wanted to share my own experience, in my case I already had a partition in "/etc/fstab" /swapfile I did the following steps to increase the swap file to 4G and confirm the change. I also change the swappiness to 10 as per your recommendation and I currently have 8GB of ram in this pc.
    1. sudo swapon --show
    2. sudo swapoff -v /swapfile
    3. sudo fallocate -l 4G /swapfile
    4. sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
    5. sudo chmod 600 /swapfile
    6. sudo mkswap /swapfile
    7. sudo swapon /swapfile
    8. sudo free -m
    Hope this helps,

    • @populigaudeamus6299
      @populigaudeamus6299 3 роки тому

      Not sure what 5 & 8 did but I did it. Seems to be helping.

  • @JustLookA7
    @JustLookA7 5 років тому

    Awesome video :)

  • @Crazy--Clown
    @Crazy--Clown 3 роки тому

    Thanks Eugene

  • @pratush.mishra
    @pratush.mishra 4 роки тому

    Good one

  • @Uchiha_Madara1224
    @Uchiha_Madara1224 5 років тому

    That was useful Alu

  • @abdelilah_hmidani
    @abdelilah_hmidani 5 років тому

    thank you

  • @acefuzzball7969
    @acefuzzball7969 4 роки тому

    ty bro, you saved my life

  • @hollowaykeanho
    @hollowaykeanho 3 роки тому +2

    If you use power S4 (hibernate), you need swap and the minimum swap size must be equal to RAM size as all RAM data will be written to swap while preparing to S4.

  • @Ip_man22
    @Ip_man22 4 роки тому

    thanks :)

  • @SunnyGabe
    @SunnyGabe 3 роки тому +1

    Very useful information! But what happens if you make more swap partitions of a said space; if you have 4GB, it would help to have 2 swap partitions of 4GB?
    Also, I'm as well using Linux Mint and I'm amazed so far, as to how good it is!

  • @calefcastro9698
    @calefcastro9698 2 роки тому +1

    Good vídeo.

  • @raghavgupta1157
    @raghavgupta1157 5 років тому

    Thanks.

  • @dannytopete9703
    @dannytopete9703 3 роки тому

    I have 16GB of ram and I always wondered why having the browser and playing games crashed my computer every once in a while. I'm glad I finally did this because my computer crashed and I see that my RAM usage spiked in the last frame I saw before I realized it was frozen.

  • @alexdlveliz2394
    @alexdlveliz2394 5 років тому

    Excellent video, made me understand a few concepts but I have a problem. I'm running debian 9 with kde plasma desktop, my ram is 8GB and my swap is 16GB, the problem is that when I try to hibernate while using kde desktop, when I wake the computer up, all the effects (like transparency of the terminal) are gone and I cannot take them back (had to reinstall a lot of times) I would like to know if it's a problem with the swap partition or something else

  • @-indeed8285
    @-indeed8285 5 років тому +1

    i need that amazing wallpaper...

  • @mirageflute
    @mirageflute 5 років тому

    To apply changes of sysctl.conf you can exec sysctl -p or sysctl -p file_name. You don't need to reboot.

  • @ferrykurnia1955
    @ferrykurnia1955 5 років тому

    Excellent step by step instruction. A bit slower is better

  • @diuran1919
    @diuran1919 5 років тому

    A lot of people told me many years a go, too create first swap partition or second after system partition, to get better access and respond. I'm doing that too this day, because I Got used to , even if is not true :)

    • @igorthelight
      @igorthelight 5 років тому +1

      The beginning of an HDD is faster.
      It doesn't matter on SSD.

  • @harisankarl6292
    @harisankarl6292 4 роки тому

    Nice

  • @learnarabicwithmorabiaa8097
    @learnarabicwithmorabiaa8097 3 роки тому

    Thanks for this Very useful video, I have a 3 gigabyte ram and I want to make sure if I changed the Swapping value to 10 , would it make my Q4OS linux distribution (&my pc😊) works faster?

  • @networld8063
    @networld8063 5 років тому

    very good information on swap partition and swap file. After knowing this from your video i would prefer swap file. Can you make a video of gentoo installation?

    • @rwbimbie5854
      @rwbimbie5854 5 років тому

      What influenced your preference of File rather than Partition?
      Also, what are you using that actually requires a swap at all, that doenst get ruinous slowdown by using swap?

    • @networld8063
      @networld8063 5 років тому

      @@rwbimbie5854 if you are like me and when you are browsing i have habit of opening minimum 100 tabs when i am chasing after some information and all that constantly fill up the ram once i had opened 368 tabs and when browser crashed then i realized so...

  • @derricknyakundi1985
    @derricknyakundi1985 5 років тому +1

    I wonder what are your views on linux mint 19.1?

  • @1ex1uger-prank-calls
    @1ex1uger-prank-calls 2 роки тому +1

    Is there any advantage to using a swap partition rather than a swap file?

  • @venshar
    @venshar 3 роки тому

    nice.

  • @egeberkayimamoglu4905
    @egeberkayimamoglu4905 3 роки тому +1

    I have let it choose it automatically. I selected the erase the disc option. Do I have a problem? Should I have done it manually?

  • @7391Camel
    @7391Camel Рік тому +1

    Thank you for your effort..
    In fact , i have done all what you are saying .. expect writing the file etc/f.......
    Please tell me what will be happened and what can i do.
    From Morocco.

  • @tejaskulkarni4546
    @tejaskulkarni4546 Рік тому

    Would reducing the swappiness increase the SSD/HDD reliability? If yes, would it be significant ? Just curious!

  • @baganaakh
    @baganaakh 5 років тому

    Thanks lot super useful valuable videos now I know i over sized my swap 16GB +8GB Ram hahahah :)
    I successfully installed Debian watching your videos
    Could u make video for other partitions /var /etc /opt and their more than enough partitioning scheme

    • @Tankyard
      @Tankyard 5 років тому

      @Altanbagana Nasanjargal, do not bother with them all 3 partitions are part of / (root) there is no need to alocate special size for them. Just create / (root) swap and /home partition during install .

  • @nvcncs
    @nvcncs 4 роки тому +1

    How many spaces i need to put between /swapfile swap swap defaults 0 0 ?

  • @veto_5762
    @veto_5762 11 місяців тому

    It is possible to connect a pendrive and format it it into a swap partition? I know it would be slower than using actual ram but it could be useful to give the computer more breathing space without taking memory out of the hardrive

  • @ashgupta854
    @ashgupta854 5 років тому

    I have always used some swap space but I sometimes wonder why. In all the time I've been using linux and run system monitor, I never see any swap being used.

  • @Phoenixwizard77
    @Phoenixwizard77 2 роки тому

    Hmm. Interesting. I might make a swap file since I don't really feel like reinstalling Ubuntu all over again since I finally just got everything that I need installed and it behaving like it should.

  • @MrUniman609
    @MrUniman609 4 роки тому

    Is it possible to move a swap file to the end of the drive with Gparted?

  • @enricofr7079
    @enricofr7079 3 роки тому

    thanks for explaining, im just moving to manjaro bcs my 3GB non upgrade-able RAM cant keep up with windows... i think ill stick with 60 swappines

  • @emiliano.nucera
    @emiliano.nucera 3 роки тому

    Hello! thank for your video! I'm trying to hibernate ubuntu 20.04 on a thinpad amd t14, but non enough swapp i think.. is it possible to use a swap file? could you treat the subject? I think it is of major interest for laptop users that have to deal with shortened battery life on ubuntu, an hibernate instead of suspend could help... cheers!

  • @rukotanafreddy3444
    @rukotanafreddy3444 3 роки тому

    Thanks bro Thanks a lot???

  • @mohammedshaikh3864
    @mohammedshaikh3864 3 роки тому

    while installing a distro for dual boot... during manual partitioning... should we create swap partition first or root partition?

    • @spooky3669
      @spooky3669 3 роки тому

      Create the Root partition first

  • @fzy5128
    @fzy5128 Рік тому

    the swipe utilization rate is high (not going down) though system has enough RAM, is that a problem and how to handle it?

  • @deletedFin
    @deletedFin 3 роки тому

    if i have really fast m2 pcie 4 ssd does swap still slow your system much

  • @anilkandula4933
    @anilkandula4933 3 роки тому

    Am using Linux mint as main OS in that kali in virtualbox.. Using a external wifi adapter when i connects it to kali its disconnects automatically in main OS

  • @anythingbutcash
    @anythingbutcash 5 років тому

    очень хорошее видео

  • @suno2219
    @suno2219 3 роки тому

    I am on a system with 4 gb and swap is a live saver

  • @Catif8
    @Catif8 Рік тому

    It's usefull to create a largest swapfile ? Like I have 8Gb Ram, but I create a 16Gb SwapFile

  • @JamesWilson-pq9qp
    @JamesWilson-pq9qp 5 років тому

    Very interesting, I just ran into this problem yesterday. I had a kernel panic. I'm limited to less than 2gb of ram, and 2gb of swap is established. Should I set up a 2 gb swap file and keep my swap partition as is. Or would it be better to mess with the partition size, hoping it won't overwrite another partition. Can we have both a file and a partition accessed by the system? Where is the swap file created and is it safe not to have it in a separate partition.

    • @cldream
      @cldream 5 років тому +1

      You can have as many swap spaces as you like, whether a partition or file. When I was using Mint as a daily driver, I occasionally had a flash drive as swap file (I know it's not recommended but...) in addition to the swap partition already on system.
      You can have the swap file anywhere for the most part. Another install I did was completely on a swap file, "affectionately" named pagefil.sys (named after Windows' page file, which is what essentially swap space is).

    • @JamesWilson-pq9qp
      @JamesWilson-pq9qp 5 років тому

      @@cldream I believe this is a similar thing in Windows - Virtual memory - which I remember as being adjustable. And there was a way to use a to pen drive. ... Anyways, going by the video I believe he set it up in the - etc - folder in the system; A super saturated folder - 164 items, 20 mb. of space. I guess we could create a new folder anywhere but would the system find it and use it?

  • @Khamae77
    @Khamae77 2 роки тому +1

    Hello. I recently install Manjaro XFCE and decided to not create swap partition. Is that means that I can't modified swappiness?

    • @hb9145
      @hb9145 2 роки тому

      Bad idea. What is the point of modifying swappiness if there is nothing to swap to? Make a swap file.

  • @anisbsalah
    @anisbsalah Рік тому

    Hello, how to create a swapfile on btrfs, would you please make a new video to describe the commands needed to do so. Thank you

  • @mr.clint-1921noob
    @mr.clint-1921noob 3 роки тому +1

    Hello,
    Can you please explain how can I enable balloon driver in my Ubuntu Server?

  • @aryanvaghasiya2342
    @aryanvaghasiya2342 3 роки тому

    I have 2 GB ram and LMDE 4...
    I want to make swap in USB Pendrive and I think it should be 6-8 Gb but I also want to make swap and System Backup on same 16 Gb USB... Can I do that ?

  • @GooogleGoglee
    @GooogleGoglee 5 років тому

    Are these commands valid for all Linux distros? Because in my Manjaro I had different path and filenames to obtain same result.
    Where I have to follow the correct method/approach?

    • @AverageLinuxUser
      @AverageLinuxUser  5 років тому +1

      Oh.. I forgot to say the example was for Debian based systems. For Manjaro, watch Swappiness part in this video ua-cam.com/video/BcDGVcO_tZU/v-deo.html

    • @GooogleGoglee
      @GooogleGoglee 5 років тому

      @@AverageLinuxUser
      Thank you for your attention
      Love your videos!

  • @NoEgg4u
    @NoEgg4u 4 роки тому +2

    @3:52
    In my MX Linux distro, running as a VirtualBox guest OS, the "man" page for the "swapon" command warns:
    The swap file implementation in the kernel expects to be able to write to the file
    directly, without the assistance of the filesystem. This is a problem on preallocated
    files (e.g. fallocate(1)) on filesystems like XFS or ext4, and on copy-on-write filesys‐
    tems like btrfs.
    It is recommended to use dd(1) and /dev/zero to avoid holes on XFS and ext4.
    So it looks like using "fallocate" for creating a swap file is risky, especially on a system that has been in use for a long time (where deleted files have left holes in the file system).
    Is my concern correct? Or am I misunderstanding the warning in the man page?
    If my concern is valid, does it apply to an installation running only on SSD storage?
    I am asking, because I believe that SSDs are immune to fragmentation?
    Please advise.

    • @merkin3k
      @merkin3k 3 роки тому

      This has become even more important with Linux kernel 5.7 and above, which seems to disregard swap files created with fallocate on some file systems. Re-creating the swap file with dd and /dev/zero seems to fix the problem. (Great videos, BTW. I especially like the "Things to do after installing..." series. 👍)

  • @hb9145
    @hb9145 2 роки тому

    I have a Raspberry Pi 1 (256MB of RAM) running Debian Bullseye (headless) with transmission-daemon. One day I noticed that the process had been killed, and I could not understand why. It turned out that I had forgotten to set a Swap partition, so the kernel's OOM killed it to avoid a full crash. All issues were solved after I made a swap file.
    As for the size of RAM, it depends. My Raspberry Pi is very low on RAM, so I set swap at 1GB, in case I would like to add a huge amount of torrents. But in general, the more RAM you have, the less swap you need. However, you will need at least as much swap as you have RAM if you want to suspend to disk (hibernate), because it copies all the info in RAM to swap. The next time the system starts, it will be copied back to RAM, and we can continue where we left off.

  • @auronkardek
    @auronkardek 5 років тому

    My system never run out of RAM I only watch some UA-cam videos and chat online. On 8Go RAM I use max 4Go. Does I still need it ? And if I don't create swap, my swapiness is 0 so my computer will run slightly faster ?

    • @cldream
      @cldream 5 років тому

      You won't really need swap if you already have tons of RAM, unless you want to hibernate your computer.