6 Replies Latest reply on Feb 28, 2013 10:42 PM by alvaromiranda

    btrfs compression appears to do nothing

    Terry Phelps
      I'm fooling around with btrfs these days, and have done some simple tests to determine what effect btrfs compression has on consumed disk space. Either my test is flawed, or I'm misinterpreting the results, or btrfs compression isn't doing ANYTHING.

      Someone point out my error please:

      I'm testing with kernel 2.6.39-300.28.1.el5uek, if that's a factor. Here's my test:

      I created a 25G partition and mkfs'ed it as a btrfs filesystem. I didn't use any options on the mkfs. I created a subvolume (actually, three of them, but I'm only using one right now). I mounted the subvolume without any options. My /etc/fstab line said:
      LABEL=BIGDISK /mirror btrfs subvol=@mirror 1 2

      After populating it, I asked btrfs how much of it I'm using:
      # btrfs files show /dev/sdb1
      Label: 'BIGDISK' uuid: 4af2b1f7-6d02-4d50-84c5-64a2c710b1b1
      Total devices 1 FS bytes used 6.84GB
      devid 1 size 25.00GB used 9.52GB path /dev/sdb1

      # btrfs filesys df /mirror
      Data: total=9.01GB, used=6.59GB
      System: total=4.00MB, used=4.00KB
      Metadata: total=520.00MB, used=256.23MB

      So, something over 6.5 gigs of data in use.

      Then I removed all files from /mirror, added the compression option to fstab:
      LABEL=BIGDISK /mirror btrfs subvol=@mirror,compress 1 2

      And then umount and mount /mirror. I repeated my test. The results are the same:
      # btrfs files show /dev/sdb1
      Label: 'BIGDISK' uuid: 4af2b1f7-6d02-4d50-84c5-64a2c710b1b1
      Total devices 1 FS bytes used 6.84GB
      devid 1 size 25.00GB used 9.52GB path /dev/sdb1

      Btrfs Btrfs v0.19

      Changing the fstab option "compression" to "compression=lzo" or "compression-zlib" don't change the results either. I tried those.

      What's going on? I"m very confused. Surely btrfs compression works in this kernel. Am I misinterpreting something?
        • 1. Re: btrfs compression appears to do nothing

          Compression=lzo works for me.

          From the mailing list of btrfs, i think the developers say the compression is all or nothing, not sure if you can just compress a subvol.

          can you mount /dev/sdb1 /mnt compress=lzo and give a try ?

          I have a 500GB disk mounted on /u03 where I take remote rsync backups and rotate with snapshots, and works very good.


          What I have

          [root@mirandaa00 u03]# du -sh OS/mirandaa0*
          46G     OS/mirandaa00
          23G     OS/mirandaa01
          [root@mirandaa00 u03]# df -h /u03
          Filesystem Size Used Avail Use% Mounted on
          /dev/sdb 466G 55G 394G 13% /u03
          [root@mirandaa00 u03]# grep btrfs /etc/fstab
          UUID=1b42a625-a6b7-4bbf-b920-c334900f5111 / btrfs defaults 1 1
          UUID=9d4d2956-1f84-4e6c-9c52-d8430acce13a /u03               btrfs     compress=lzo     0 0
          [root@mirandaa00 u03]# uname -a
          Linux mirandaa00 2.6.39-300.28.1.el6uek.x86_64 #1 SMP Tue Feb 5 22:51:31 PST 2013 x86_64 x86_64 x86_64 GNU/Linux
          [root@mirandaa00 u03]# cat /etc/oracle-release
          Oracle Linux Server release 6.3
          [root@mirandaa00 u03]#

          [root@mirandaa00 u03]# mount -t btrfs
          /dev/sda2 on / type btrfs (rw)
          /dev/sdb on /u03 type btrfs (rw,compress=lzo)
          [root@mirandaa00 u03]#

          Edited by: Alvaro Miranda on Feb 27, 2013 12:14 PM
          1 person found this helpful
          • 2. Re: btrfs compression appears to do nothing
            Terry Phelps
            You're doing much the same thing that I'm doing. I'm going to use "rdiff-backup" (which is similar to rsync, and, in fact, uses librsync to derive file diffs) to backup my Oracle VM virtual machines.

            Yes, I will mount the root of the filesystem somewhere, and enable compression, and let you know if that made it work. I wasn't planning to actually USE the root mount, except for snapshotting, so i haven't been keeping it mounted.
            • 3. Re: btrfs compression appears to do nothing
              hi again.

              When I started to play with btrfs, i went with create subvols for each oracle_home, so i ended having grid, db_home, oraInventory, each on his own subvol

              with an script i took snapshots and was doing nice.. but I hit couple of issues.

              first, I run out of space.. there is some underlying issues with extends, and subvol snapshots so I move my backups and snapshots out of /u01 and created a new /u03

              then, even without snapshots, i hit the same issue.. so deleted everything, and I use just a plain disk for my /u01 and I am very conservative with my snapshots on my /u03

              For the source /u01 without snapshots, you still can make reflink copies that are per file, and works very fast.. not as fast as an snapshot, but does the trick


              $ du -sh dbhome_1*
              6.3G     dbhome_1
              $ time cp -ax dbhome_1/. dbhome_1_bkp_normalcopy
              0.71 user 26.82 system 2:40.23 elapsed
              $ time cp -ax --reflink=always dbhome_1/. dbhome_1_bkp_reflink
              0.20 user 3.47 system 0:03.87 elapsed

              the /. is important to include from that point and recursive.

              For the record, I have an ssd for OS and U01.

              • 4. Re: btrfs compression appears to do nothing
                It seems to me there is a common misunderstanding about what subvolumes and snapshots are in the context of actual data. Btrfs is a copy-on-write filesystem that maintains a B-tree structure to record data transactions and data changes. Any changes to the file system are written to free or unused disk space in order not to overwrite any existing data. When you create a snapshot you add only a small amount of additional metadata to mark a certain point in time to which you can restore to undo changes or omit changed data blocks. Snapshot and subvolumes work the same way. You can mount a snapshot or subvolume and will see a private version of data. As such a snapshot is not a full backup and perhaps similar to an incremental backup although only describing where changed data has been written, or similar to a restore point in an oracle database.
                • 5. Re: btrfs compression appears to do nothing
                  Terry Phelps
                  YES, you're right. You apparently have to mount the ROOT of the filesystem with the compression option, in order to get compression on any separately mounted subvolumes.

                  My intent was to NOT mount the root at all for normal operations. I made three subvolumes, and was going to mount each one, with compression or not, as I wished. The root would then be used only when I wanted to snapshot one of the subvolumes. But testing shows that:
                  1. If you mount the root with without compression the setting is inherited by all subvolumes, even if they are separately mounted WITH compression. And similarly if the root is mounted with compression, then all subvolumes are compressed, even if separately mounted WITHOUT compression, and written through the separate mount point.
                  2. If you do NOT mount the filesystem root, then if you mount a subvolume WITH compression, you don't get compression.

                  And I did one more test:
                  Mounted the root WITH compression.
                  Mounted the subvolume WITHOUT compression.
                  UNmounted the root.
                  The subvolume DID still compress.

                  Presumably this is all by design, but I find it somewhat counter-intuitive.
                  • 6. Re: btrfs compression appears to do nothing
                    but you can have the disk you want to use for backups in a separate mount, like /u03, then inside you create volumes that will looks like directories and you can use those no need to mount them.

                    if you want to mount those in other path, yes you can, and won't hurt have that way.

                    Just run a lot of testing, in my particular case, as I have said, I have btrfs for /u01 and I rsync a copy to /u03/OS/<server>/full path

                    Good luck.