Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: Swap - The Age Old Question

  1. #1
    Join Date
    Feb 2009
    Location
    Wasilla, Alaska
    Beans
    462
    Distro
    Kubuntu

    Swap - The Age Old Question

    I have searched the entire internet for a reasonable answer to these questions, only to find that people continue to have differing opinions on the matter.

    With a computer that has 16gb of RAM, do I need a swap file?

    I will not be using hibernate.

    If I tell the Ubuntu installer that I do not have a Swap partition, it makes a file on my SSD to use as Swap anyway...

    How do I disable this entirely, if it is okay to do so?

    Maybe I should ask a better question... What is the whole purpose of the Swap file, in a modern computer that has plenty of RAM, and will not be using hibernate? This seems like a Windows question...

    Can someone explain how Ubuntu uses Swap?
    Holy Cripes on Toast!
    Attention is the currency of internet forums. - ticopelp

  2. #2
    Join Date
    Jan 2006
    Location
    Sunny Southend-on-Sea
    Beans
    7,631
    Distro
    Kubuntu 18.04 Bionic Beaver

    Re: Swap - The Age Old Question

    Yes, you need a swap file.

    Out of memory situations are simply awful. Some applications simply misbehave. Setting aside a tiny proportion of your drive space to prevent running out of memory addresses is a trivial trade off. If it never ever gets used for anything: great!

  3. #3
    Join Date
    Apr 2014
    Beans
    635

    Re: Swap - The Age Old Question

    I dont know the technical side of things involving swap. I iust know that some things need it to exist. I keep no more than a 2gb swap on any of my machines at home. Small price to pay to avoid problems.

  4. #4
    Join Date
    Feb 2009
    Location
    Wasilla, Alaska
    Beans
    462
    Distro
    Kubuntu

    Re: Swap - The Age Old Question

    Quote Originally Posted by CatKiller View Post
    Yes, you need a swap file.

    Out of memory situations are simply awful. Some applications simply misbehave. Setting aside a tiny proportion of your drive space to prevent running out of memory addresses is a trivial trade off. If it never ever gets used for anything: great!
    Is there any way to have the file put on a different drive, or do I have to make a Swap partition for that?

    Quote Originally Posted by Tadaen_Sylvermane View Post
    I dont know the technical side of things involving swap. I iust know that some things need it to exist. I keep no more than a 2gb swap on any of my machines at home. Small price to pay to avoid problems.
    So, 2g is enough with 16g of RAM?
    Holy Cripes on Toast!
    Attention is the currency of internet forums. - ticopelp

  5. #5
    Join Date
    Jan 2006
    Location
    Sunny Southend-on-Sea
    Beans
    7,631
    Distro
    Kubuntu 18.04 Bionic Beaver

    Re: Swap - The Age Old Question

    Quote Originally Posted by Shibblet View Post
    Is there any way to have the file put on a different drive, or do I have to make a Swap partition for that?
    It's just a file that's full of zeros. I'd imagine you can put it wherever you want, although you'd want it on your fastest storage in case it ever does get used. Not having played around with it much, I think you'd just create your file wherever and then use mkswap to say that you want to use that file as swap, and use fstab so that it gets used automatically at boot.
    None but ourselves can free our minds

  6. #6
    Join Date
    Apr 2011
    Location
    Mystletainn Kick!
    Beans
    11,145
    Distro
    Ubuntu

    Re: Swap - The Age Old Question

    Set the swappiness to a low usage number.
    The default is 60 (or last I checked it was), setting it to 10 will make it swap less.
    https://help.ubuntu.com/community/Sw...I_change_it.3F
    That should allow it to be less aggressive.
    Splat Double Splat Triple Splat
    Earn Your Keep
    Don't mind me, I'm only passing through.
    Once in a blue moon, I'm actually helpful
    .

  7. #7
    Join Date
    Aug 2009
    Beans
    Hidden!
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Swap - The Age Old Question

    I had a quad core for 10 years and it never used 1% of swap, now on an i7 with SSD it still never uses %1 of swap.
    But, rather than finding any alternative, I setup a 4GB (2GB as mentioned above would do) swap file just because every Linux system there is wants a swap file.

    So, it's like you need one to install but, it doesn't really get used. Maybe swap files will not be needed in the future.

    I have 16GB RAM and suspend rather than hibernate and that works great.

  8. #8
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    19,796
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Swap - The Age Old Question

    There are many opinions about swap and there are some technical mandates that are dependent on settings and the specific kernel.

    • Purpose of swap is to provide feedback when a system is running low on real RAM, but not crash.
    • To that end, "some" swap is necessary.
    • About a year ago, there was a bug in the kernels that cause all sorts of performance problems when zero swap was setup. A token amount was needed to avoid
    • 4.1G is the easy answer for all desktop systems related to swap.
    • Heavy modern browsers can easily grow to use that amount of RAM and crash a system w/ 1-4G of RAM
    • 6+GB RAM systems might have many "cheese" programs open, so we need the swap to warn us, before a system crash.
    • 12-64GB systems need it because users of those computers will quickly become complacent, use more RAM than available and crash.

    The best feedback from swap comes by using slower storage. Users need to "feel" that the system is getting slower so they can take action, usually by closing some hog program, but certainly by saving any unsaved work.

    People doing video or audio editing will quickly discover that 16G isn't sufficient for all but the most trivial files.

    These days, very few systems are storage constrained. 4.1G for swap is easily setup just after an install.
    https://help.ubuntu.com/community/SwapFaq for the "community" version.

    On my servers, i specifically setup the RAM to ensure peek workloads don't ever swap or need swap. For desktops, the workloads are just too variable. I’ve tried 1, 2, 4, 8GB of swap on systems w/ 384M, 512M, 1G, 2G, 4G, 6G, 8G, 16G of RAM and found that 4.1GB is the best compromise.

    IMHO. Lots of different needs, so there isn't 1, true, correct, perfect, answer that meets all requirements.
    Last edited by TheFu; March 20th, 2020 at 08:42 PM.

  9. #9
    Join Date
    Aug 2009
    Beans
    Hidden!
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Swap - The Age Old Question

    I have not ever seen any of my swap file being used. I've monitored it too. I seen someone with a 1 core processor need to and did use swap but, not here on any systems: an old and a newer computer.

    I know it's required and I'm not trying to argue here.
    I have never seen any of my swap file used. I suspend and it suspends in < 5 seconds. It wakes about as fast too.

    I don't believe the 2 are even related but, I have used 1MB of swap and it was fine. The old PC had 4GB RAM so I decided to make it that same size 4GB and have done that for the past several years without difficulty.
    New PC has 16GB RAM and the 9 Linux systems on this PC all use the same 4GB swap file.

  10. #10
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    19,796
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Swap - The Age Old Question

    Code:
    $ free -mh
                  total        used        free      shared  buff/cache   available
    Mem:            15G        9.7G        200M        7.5M        5.7G        5.2G
    Swap:          4.3G        2.2G        2.0G
    Just saying.

    And on another machine:
    Code:
    $ free -hm
                  total        used        free      shared  buff/cache   available
    Mem:           7.5G        4.8G        275M         24M        2.4G        2.3G
    Swap:          3.6G        2.4G        1.2G
    And on another machine:
    Code:
    free -hm
                  total        used        free      shared  buff/cache   available
    Mem:           3.9G        2.3G        494M        130M        1.1G        1.0G
    Swap:          3.1G        1.4G        1.7G
    and ...
    Code:
    $ free -hm
                  total        used        free      shared  buff/cache   available
    Mem:           996M        648M        109M        6.3M        238M        194M
    Swap:          2.0G        775M        1.2G
    and
    Code:
    $ free -hm
                  total        used        free      shared  buff/cache   available
    Mem:           991M         78M        119M         10M        793M        648M
    Swap:          1.0G        2.0M        1.0G
    and
    Code:
    $ free -hm
                  total        used        free      shared  buff/cache   available
    Mem:           992M        235M         94M         21M        662M        531M
    Swap:          1.0G        147M        874M
    and
    Code:
    $ free -m
                 total       used       free     shared    buffers     cached
    Mem:          1191        960        231          0        182        332
    -/+ buffers/cache:        445        746
    Swap:            0          0          0
    And email server:
    Code:
    $ free -hm
                  total        used        free      shared  buff/cache   available
    Mem:           2.9G        2.0G        261M         18M        683M        736M
    Swap:          979M        201M        778M
    Guess which are desktops and which are servers.
    The 3rd one is the desktop. All the others are servers without any GUI running.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •