Skip to content

Instantly share code, notes, and snippets.

@mazgi
Last active February 27, 2016 18:43
Show Gist options
  • Save mazgi/4a2b42f0df291dab9856 to your computer and use it in GitHub Desktop.
Save mazgi/4a2b42f0df291dab9856 to your computer and use it in GitHub Desktop.
btrfs compression
# uname -a
Linux test-04 4.1.15-gentoo-r1 #1 SMP Sat Feb 27 15:52:30 2016 x86_64 Intel(R) Xeon(R) CPU E5-2650 v3 @ 2.30GHz GenuineIntel GNU/Linux
# btrfs --version
btrfs-progs v4.0.1
# gdisk -l /dev/vdb
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/vdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 447EF668-30B1-4E95-913F-C33010E4D42C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        20973567   10.0 GiB    8300  Linux filesystem
   2        20973568        41943006   10.0 GiB    8300  Linux filesystem
# mkfs.btrfs -f /dev/vdb1
btrfs-progs v4.0.1
See http://btrfs.wiki.kernel.org for more information.

Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
Turning ON incompat feature 'skinny-metadata': reduced-size metadata extent refs
fs created label (null) on /dev/vdb1
	nodesize 16384 leafsize 16384 sectorsize 4096 size 10.00GiB
# mkfs.btrfs -f /dev/vdb2
btrfs-progs v4.0.1
See http://btrfs.wiki.kernel.org for more information.

Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
Turning ON incompat feature 'skinny-metadata': reduced-size metadata extent refs
fs created label (null) on /dev/vdb2
	nodesize 16384 leafsize 16384 sectorsize 4096 size 10.00GiB
# mkdir -p /mnt/{lzo,zlib}
# mount -t btrfs -odefaults,compress=lzo /dev/vdb1 /mnt/lzo
# mount -t btrfs -odefaults,compress=zlib /dev/vdb2 /mnt/zlib
# mount | grep /dev/vdb
/dev/vdb1 on /mnt/lzo type btrfs (rw,relatime,compress=lzo,space_cache)
/dev/vdb2 on /mnt/zlib type btrfs (rw,relatime,compress=zlib,space_cache)
# df -k /mnt/*
Filesystem     1K-blocks  Used Available Use% Mounted on
/dev/vdb1       10485760 18176   8357376   1% /mnt/lzo
/dev/vdb2       10484716 17984   9405184   1% /mnt/zlib
# btrfs filesystem df /mnt/lzo
Data, single: total=1.00GiB, used=512.00KiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, DUP: total=1.00GiB, used=112.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
# btrfs filesystem df /mnt/zlib
Data, single: total=1.00GiB, used=320.00KiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, DUP: total=511.94MiB, used=112.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
# dd if=/dev/zero of=zero.img bs=1M count=4096
4096+0 records in
4096+0 records out
4294967296 bytes (4.3 GB) copied, 2.75164 s, 1.6 GB/s
# dd if=/dev/urandom of=rand.img bs=1M count=4096
4096+0 records in
4096+0 records out
4294967296 bytes (4.3 GB) copied, 360.181 s, 11.9 MB/s
# ls -l *.img
-rw-r--r-- 1 root root 4294967296 Feb 27 17:50 rand.img
-rw-r--r-- 1 root root 4294967296 Feb 27 17:44 zero.img
# for img in {zero,rand}.img
> do
> for mp in /mnt/{lzo,zlib}
> do
> rm -rf ${mp}/*
> cp ${img} ${mp}/
> ls -la ${mp}/
> df -klT ${mp}
> btrfs filesystem df ${mp}
> done
> done
total 4153872
drwxr-xr-x 1 root root         16 Feb 27 18:40 .
drwxr-xr-x 1 root root         24 Feb 27 18:10 ..
-rw-r--r-- 1 root root 4294967296 Feb 27 18:40 zero.img
Filesystem     Type  1K-blocks   Used Available Use% Mounted on
/dev/vdb1      btrfs  10485760 119712   8255904   2% /mnt/lzo
Data, single: total=1.00GiB, used=100.59MiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, DUP: total=1.00GiB, used=144.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
total 4194320
drwxr-xr-x 1 root root         16 Feb 27 18:40 .
drwxr-xr-x 1 root root         24 Feb 27 18:10 ..
-rw-r--r-- 1 root root 4294967296 Feb 27 18:40 zero.img
Filesystem     Type  1K-blocks   Used Available Use% Mounted on
/dev/vdb2      btrfs  10484716 107580   9315684   2% /mnt/zlib
Data, single: total=1.00GiB, used=88.71MiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, DUP: total=511.94MiB, used=160.00KiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
total 4052496
drwxr-xr-x 1 root root         16 Feb 27 18:40 .
drwxr-xr-x 1 root root         24 Feb 27 18:10 ..
-rw-r--r-- 1 root root 4294967296 Feb 27 18:41 rand.img
Filesystem     Type  1K-blocks    Used Available Use% Mounted on
/dev/vdb1      btrfs  10485760 1141760   7236096  14% /mnt/lzo
Data, single: total=5.00GiB, used=1.07GiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, DUP: total=1.00GiB, used=1.23MiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=0.00B
total 3932176
drwxr-xr-x 1 root root         16 Feb 27 18:41 .
drwxr-xr-x 1 root root         24 Feb 27 18:10 ..
-rw-r--r-- 1 root root 4294967296 Feb 27 18:41 rand.img
Filesystem     Type  1K-blocks    Used Available Use% Mounted on
/dev/vdb2      btrfs  10484716 2946208   6483200  32% /mnt/zlib
Data, single: total=5.00GiB, used=2.79GiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00B
Metadata, DUP: total=511.94MiB, used=3.16MiB
Metadata, single: total=8.00MiB, used=0.00B
GlobalReserve, single: total=16.00MiB, used=48.00KiB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment