Announcement

Collapse
No announcement yet.

Swap File and btrfs

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Swap File and btrfs

    I've heard that btrfs doesn't use a swap partition, and doesn't use a swap file. I accept that at face value. But...

    I just created a new Virtual Machine (VM); Oracle VirtualBox; and chose Manual and selected the whole drive; no separate /home; and specified btrfs as the file system. Installation proceeded as expected and without any issues. On reboot however, I saw a quick message about swapon, so decided to look at the /etc/fstab file. Sure enough, there is an entry for swap specifying a swap file at /swapfile:

    Click image for larger version

Name:	fstab.png
Views:	1
Size:	45.9 KB
ID:	649264

    So, does btrfs use swap; a swapfile; or no? And if 'no', why did the installation process end up creating one?
    [#]btrfs[/#]
    Using Kubuntu Linux since March 23, 2007
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    #2
    I believe the installer creates a swap file if no swap partition is present by default, regardless of file system. I think what you're seeing is a logical disconnect between the Ubiquity and btrfs developers. Ubiquity has never been very robust but it's gotten better over the years. However. I think more options should be built-in and obvious - like the option to create a swap partition if none exists and to select to not install grub.

    It is not a good idea to use a swap file with BTRFS unless you turn off Copy-On-Write (mount with NODATACOW option), which drastically reduces performance. This is because corruption can occur within the swap file. Likewise for virtual disks (as a host, not when installed to) if they are dynamic rather than fixed size. @here, I use swap partitions and have a single ext4 partition that holds my virtualbox dynamically allocated disks.

    If you're going to continue to play with this VM, I suggest turning off swap within it to avoid any issues. If you choose to install, use a swap partition and fixed-sized Vbox drives.

    Please Read Me

    Comment


      #3
      Thank you.

      My VM’s are always created as ‘fixed size’. I will be removing the swapfile:

      sudo swapoff /swapfile
      delete the entry in /etc/fstab
      sudo rm -f /swapfile
      Using Kubuntu Linux since March 23, 2007
      "It is a capital mistake to theorize before one has data." - Sherlock Holmes

      Comment


        #4
        When I said "If you choose to install" I should have said "If you choose to install using btrfs" - meaning if you decide to use btrfs on bare metal rather than within virtualbox - then, the dynamically allocated virtual drives are an issue on a btrfs host. I don't think there is any problem with using btrfs within a dynamically allocated virtual drive as a client- at least not that I am aware of.

        I wanted to try and be more precise in case anyone else reads this thread.

        Please Read Me

        Comment


          #5
          Originally posted by oshunluvr View Post
          I wanted to try and be more precise in case anyone else reads this thread.
          What!? Other people read our threads!?
          Using Kubuntu Linux since March 23, 2007
          "It is a capital mistake to theorize before one has data." - Sherlock Holmes

          Comment


            #6
            Well, I did say "in case..."

            Please Read Me

            Comment


              #7
              Sorry to be a stickler for terminology, but btrfs neither requires nor "uses" swap space.

              Your operating system uses swap space, and the need for swap is determined by your useage scenario and system ram, as well as your desire to use hibernate. It had nothing to do with the filesystem chosen.

              Your swap space may be a swap partition or a swap file. The only caveat is that a swap file cannot reside in a btrfs file system. However you can create a separate swap partition alongside btrfs partitions.

              The default behaviour for the installer was to create a swap partition until 16.10. as of 17.04 it creates a swap file, but unfortunately is agnostic to the actually root file system.

              The solution is manually specify a swap partition if so desired.

              Sent from my ONEPLUS A5010 using Tapatalk

              Comment


                #8
                Well, that brings us back full circle!

                Everything you wanted to know about swap but didn't know who to ask:
                https://www.kernel.org/doc/gorman/ht...rstand014.html

                My experience was that even with a swap file equal to twice my RAM it was never used during the time I used Kubuntu. When I switched to Neon I decided not to create a swap partition and have never noticed a performance degradation because of it.
                It is important to note that swap is not without its drawbacks and the most important one is the most obvious one; Disk is slow, very very slow. If processes are frequently addressing a large amount of memory, no amount of swap or expensive high-performance disks will make it run within a reasonable time, only more RAM will help.
                Unless you have SSD you will notice the swap file kick in.

                For my use case 6GB of RAM seems to be sufficient, and Btrfs gets 12GB more disk space.
                "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                – John F. Kennedy, February 26, 1962.

                Comment


                  #9
                  I have 16GB or RAM and 2 SSDs. I have set tmpfs into RAM so I maintain 2 8GB swap partitions on my SSDs. Twice I have hit swap - once due to a memory leak in a browser and yesterday due to a graphics program over-allocating itself and taking all 16GB of RAM.

                  Both times, when swap was being accessed - even on the SSDs - the system became unusable. In my view, actually using swap is not possible from a practical point of view, with the exception of hibernation which I don't use.

                  Possibly my experience is poorer than normal due to the nature of the times I have run into using it. If the programs that I was not interacting with but were running were swapped out and the desktop stayed active, maybe I would have had a better experience.

                  Please Read Me

                  Comment


                    #10
                    It really depends on your useage scenario. I have a windows 7 and 10 guest in VirtualBox sometimes. So even with 16 gigs of ram i hit the swap file sometimes. However. I set my swap to 4096mbs not 2×RAM which is just ridiculous.

                    On my laptop which has 8 gigs of ram, I use no swap since it does not run any heavy software.

                    People who do massive photo or video editing may need more swap space.

                    Sent from my ONEPLUS A5010 using Tapatalk

                    Comment

                    Working...
                    X