Skip to content

Commit a6fa6fa

Browse files
author
Li Zefan
committed
btrfs: Add lzo compression support
Lzo is a much faster compression algorithm than gzib, so would allow more users to enable transparent compression, and some users can choose from compression ratio and speed for different applications Usage: # mount -t btrfs -o compress[=<zlib,lzo>] dev /mnt or # mount -t btrfs -o compress-force[=<zlib,lzo>] dev /mnt "-o compress" without argument is still allowed for compatability. Compatibility: If we mount a filesystem with lzo compression, it will not be able be mounted in old kernels. One reason is, otherwise btrfs will directly dump compressed data, which sits in inline extent, to user. Performance: The test copied a linux source tarball (~400M) from an ext4 partition to the btrfs partition, and then extracted it. (time in second) lzo zlib nocompress copy: 10.6 21.7 14.9 extract: 70.1 94.4 66.6 (data size in MB) lzo zlib nocompress copy: 185.87 108.69 394.49 extract: 193.80 132.36 381.21 Changelog: v1 -> v2: - Select LZO_COMPRESS and LZO_DECOMPRESS in btrfs Kconfig. - Add incompability flag. - Fix error handling in compress code. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
1 parent 261507a commit a6fa6fa

8 files changed

Lines changed: 527 additions & 8 deletions

File tree

‎fs/btrfs/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ config BTRFS_FS
44
select LIBCRC32C
55
select ZLIB_INFLATE
66
select ZLIB_DEFLATE
7+
select LZO_COMPRESS
8+
select LZO_DECOMPRESS
79
help
810
Btrfs is a new filesystem with extents, writable snapshotting,
911
support for multiple devices and many more features.

‎fs/btrfs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
66
transaction.o inode.o file.o tree-defrag.o \
77
extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \
88
extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \
9-
export.o tree-log.o acl.o free-space-cache.o zlib.o \
9+
export.o tree-log.o acl.o free-space-cache.o zlib.o lzo.o \
1010
compression.o delayed-ref.o relocation.o

‎fs/btrfs/compression.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ static wait_queue_head_t comp_workspace_wait[BTRFS_COMPRESS_TYPES];
691691

692692
struct btrfs_compress_op *btrfs_compress_op[] = {
693693
&btrfs_zlib_compress,
694+
&btrfs_lzo_compress,
694695
};
695696

696697
int __init btrfs_init_compress(void)

‎fs/btrfs/compression.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,6 @@ struct btrfs_compress_op {
7373
};
7474

7575
extern struct btrfs_compress_op btrfs_zlib_compress;
76+
extern struct btrfs_compress_op btrfs_lzo_compress;
7677

7778
#endif

‎fs/btrfs/ctree.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,15 @@ struct btrfs_super_block {
398398
#define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
399399
#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
400400
#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
401+
#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
401402

402403
#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
403404
#define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL
404405
#define BTRFS_FEATURE_INCOMPAT_SUPP \
405406
(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
406407
BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
407-
BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
408+
BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
409+
BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO)
408410

409411
/*
410412
* A leaf is full of items. offset and size tell us where to find
@@ -553,8 +555,9 @@ struct btrfs_timespec {
553555
enum btrfs_compression_type {
554556
BTRFS_COMPRESS_NONE = 0,
555557
BTRFS_COMPRESS_ZLIB = 1,
556-
BTRFS_COMPRESS_TYPES = 1,
557-
BTRFS_COMPRESS_LAST = 2,
558+
BTRFS_COMPRESS_LZO = 2,
559+
BTRFS_COMPRESS_TYPES = 2,
560+
BTRFS_COMPRESS_LAST = 3,
558561
};
559562

560563
struct btrfs_inode_item {

‎fs/btrfs/disk-io.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,10 +1744,10 @@ struct btrfs_root *open_ctree(struct super_block *sb,
17441744
}
17451745

17461746
features = btrfs_super_incompat_flags(disk_super);
1747-
if (!(features & BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF)) {
1748-
features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF;
1749-
btrfs_set_super_incompat_flags(disk_super, features);
1750-
}
1747+
features |= BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF;
1748+
if (tree_root->fs_info->compress_type & BTRFS_COMPRESS_LZO)
1749+
features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
1750+
btrfs_set_super_incompat_flags(disk_super, features);
17511751

17521752
features = btrfs_super_compat_ro_flags(disk_super) &
17531753
~BTRFS_FEATURE_COMPAT_RO_SUPP;

0 commit comments

Comments
 (0)