f2fs: support data compression
Subsystems (3)
RFC PATCH v4 1/1 f2fs: support data compression
This patch tries to support compression in f2fs.
- New term named cluster is defined as basic unit of compression, file can be divided into multiple clusters logically. One cluster includes 4 << n (n >= 0) logical pages, compression size is also cluster size, each of cluster can be compressed or not.
- In cluster metadata layout, one special flag is used to indicate cluster is compressed one or normal one, for compressed cluster, following metadata maps cluster to [1, 4 << n - 1] physical blocks, in where f2fs stores data including compress header and compressed data.
- In order to eliminate write amplification during overwrite, F2FS only support compression on write-once file, data can be compressed only when all logical blocks in file are valid and cluster compress ratio is lower than specified threshold.
- To enable compression on regular inode, there are three ways:
* chattr +c file
* chattr +c dir; touch dir/file
* mount w/ -o compress_extension=ext; touch file.ext
Compress metadata layout:
[Dnode Structure]
+-----------------------------------------------+
| cluster 1 | cluster 2 | ......... | cluster N |
+-----------------------------------------------+
. . . .
. . . .
. Compressed Cluster . . Normal Cluster .
+----------+---------+---------+---------+ +---------+---------+---------+---------+
|compr flag| block 1 | block 2 | block 3 | | block 1 | block 2 | block 3 | block 4 |
+----------+---------+---------+---------+ +---------+---------+---------+---------+
. .
. .
. .
+-------------+-------------+----------+----------------------------+
| data length | data chksum | reserved | compressed data |
+-------------+-------------+----------+----------------------------+Changelog:
20190326:
- fix error handling of read_end_io().
- remove unneeded comments in f2fs_encrypt_one_page().
20190327:
- fix wrong use of f2fs_cluster_is_full() in f2fs_mpage_readpages().
- don't jump into loop directly to avoid uninitialized variables.
- add TODO tag in error path of f2fs_write_cache_pages().
20190328:
- fix wrong merge condition in f2fs_read_multi_pages().
- check compressed file in f2fs_post_read_required().
20190401
- allow overwrite on non-compressed cluster.
- check cluster meta before writing compressed data.
20190402
- don't preallocate blocks for compressed file.
- add lz4 compress algorithm
- process multiple post read works in one workqueue
Now f2fs supports processing post read work in multiple workqueue, it shows low performance due to schedule overhead of multiple workqueue executing orderly.
20190921
- compress: support buffered overwrite
C: compress cluster flag
V: valid block address
N: NEW_ADDR
One cluster contain 4 blocks
before overwrite after overwrite
- VVVV -> CVNN
- CVNN -> VVVV
- CVNN -> CVNN
- CVNN -> CVVV
- CVVV -> CVNN
- CVVV -> CVVV
20191029
- add kconfig F2FS_FS_COMPRESSION to isolate compression related codes, add kconfig F2FS_FS_{LZO,LZ4} to cover backend algorithm. note that: will remove lzo backend if Jaegeuk agreed that too.
- update codes according to Eric's comments.
20191101
- apply fixes from Jaegeuk
20191113
- apply fixes from Jaegeuk
- split workqueue for fsverity
[Jaegeuk Kim]
- add tracepoint for f2fs_{,de}compress_pages()
- fix many bugs and add some compression stats
--- Documentation/filesystems/f2fs.txt | 52 ++ fs/f2fs/Kconfig | 23 + fs/f2fs/Makefile | 1 + fs/f2fs/compress.c | 1115 ++++++++++++++++++++++++++++ fs/f2fs/data.c | 611 +++++++++++++-- fs/f2fs/debug.c | 6 + fs/f2fs/f2fs.h | 245 +++++- fs/f2fs/file.c | 191 ++++- fs/f2fs/inode.c | 43 ++ fs/f2fs/namei.c | 59 ++ fs/f2fs/segment.c | 5 +- fs/f2fs/segment.h | 12 - fs/f2fs/super.c | 112 ++- fs/f2fs/sysfs.c | 7 + include/linux/f2fs_fs.h | 11 + include/trace/events/f2fs.h | 99 +++ 16 files changed, 2478 insertions(+), 114 deletions(-) create mode 100644 fs/f2fs/compress.c
Documentation/filesystems/f2fs.txt +52 -0
@@ -235,6 +235,17 @@ checkpoint=%s[:%u[%]] Set to "disable" to turn off checkpointing. Set to "en hide up to all remaining free space. The actual space that would be unusable can be viewed at /sys/fs/f2fs/<disk>/unusable This space is reclaimed once checkpoint=enable. +compress_algorithm=%s Control compress algorithm, currently f2fs supports "lzo" + and "lz4" algorithm. +compress_log_size=%u Support configuring compress cluster size, the size will + be 4KB * (1 << %u), 16KB is minimum size, also it's + default size. +compress_extension=%s Support adding specified extension, so that f2fs can enable + compression on those corresponding files, e.g. if all files + with '.ext' has high compression rate, we can set the '.ext' + on compression extension list and enable compression on + these file by default rather than to enable it via ioctl. + For other files, we can still enable compression via ioctl. ================================================================================ DEBUGFS ENTRIES
@@ -837,3 +848,44 @@ zero or random data, which is useful to the below scenario where: 4. address = fibmap(fd, offset) 5. open(blkdev) 6. write(blkdev, address) + +Compression implementation +-------------------------- + +- New term named cluster is defined as basic unit of compression, file can +be divided into multiple clusters logically. One cluster includes 4 << n +(n >= 0) logical pages, compression size is also cluster size, each of +cluster can be compressed or not. + +- In cluster metadata layout, one special block address is used to indicate +cluster is compressed one or normal one, for compressed cluster, following +metadata maps cluster to [1, 4 << n - 1] physical blocks, in where f2fs +stores data including compress header and compressed data. + +- In order to eliminate write amplification during overwrite, F2FS only +support compression on write-once file, data can be compressed only when +all logical blocks in file are valid and cluster compress ratio is lower +than specified threshold. + +- To enable compression on regular inode, there are three ways: +* chattr +c file +* chattr +c dir; touch dir/file +* mount w/ -o compress_extension=ext; touch file.ext + +Compress metadata layout: + [Dnode Structure] + +-----------------------------------------------+ + | cluster 1 | cluster 2 | ......... | cluster N | + +-----------------------------------------------+ + . . . . + . . . . + . Compressed Cluster . . Normal Cluster . ++----------+---------+---------+---------+ +---------+---------+---------+---------+ +|compr flag| block 1 | block 2 | block 3 | | block 1 | block 2 | block 3 | block 4 | ++----------+---------+---------+---------+ +---------+---------+---------+---------+ + . . + . . + . . + +-------------+-------------+----------+----------------------------+ + | data length | data chksum | reserved | compressed data | + +-------------+-------------+----------+----------------------------+
fs/f2fs/Kconfig +23 -0
@@ -92,3 +92,26 @@ config F2FS_FAULT_INJECTION Test F2FS to inject faults such as ENOMEM, ENOSPC, and so on. If unsure, say N. + +config F2FS_FS_COMPRESSION + bool "F2FS compression feature" + depends on F2FS_FS + help + Enable filesystem-level compression on f2fs regular files, + multiple back-end compression algorithms are supported. + +config F2FS_FS_LZO + bool "LZO compression support" if F2FS_FS_COMPRESSION + select LZO_COMPRESS + select LZO_DECOMPRESS + default y + help + Support LZO compress algorithm, if unsure, say Y. + +config F2FS_FS_LZ4 + bool "LZ4 compression support" if F2FS_FS_COMPRESSION + select LZ4_COMPRESS + select LZ4_DECOMPRESS + default y + help + Support LZ4 compress algorithm, if unsure, say Y.
fs/f2fs/Makefile +1 -0
@@ -9,3 +9,4 @@ f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o f2fs-$(CONFIG_F2FS_IO_TRACE) += trace.o f2fs-$(CONFIG_FS_VERITY) += verity.o +f2fs-$(CONFIG_F2FS_FS_COMPRESSION) += compress.o
fs/f2fs/compress.c new file +1115 -0
1,116 lines not on this page · raw message
fs/f2fs/data.c +539 -72
954 lines not on this page · raw message
fs/f2fs/debug.c +6 -0
@@ -94,6 +94,8 @@ static void update_general_status(struct f2fs_sb_info *sbi) si->inline_xattr =atomic_read (&sbi->inline_xattr); si->inline_inode =atomic_read (&sbi->inline_inode); si->inline_dir =atomic_read (&sbi->inline_dir); + si->compr_inode =atomic_read (&sbi->compr_inode); + si->compr_blocks =atomic_read (&sbi->compr_blocks); si->append = sbi->im[APPEND_INO ].ino_num; si->update = sbi->im[UPDATE_INO ].ino_num; si->orphans = sbi->im[ORPHAN_INO ].ino_num;
@@ -315,6 +317,8 @@ static int stat_show(struct seq_file *s, void *v) si->inline_inode);seq_printf (s," - Inline_dentry Inode: %u\n" , si->inline_dir); +seq_printf (s," - Compressed Inode: %u, Blocks: %u\n" , + si->compr_inode, si->compr_blocks);seq_printf (s," - Orphan/Append/Update Inode: %u, %u, %u\n" , si->orphans, si->append, si->update); seq_printf(s, "\nMain area: %d segs, %d secs %d zones\n",
@@ -491,6 +495,8 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi)atomic_set (&sbi->inline_xattr,0 );atomic_set (&sbi->inline_inode,0 );atomic_set (&sbi->inline_dir,0 ); +atomic_set (&sbi->compr_inode,0 ); +atomic_set (&sbi->compr_blocks,0 );atomic_set (&sbi->inplace_count,0 );for (i =META_CP ; i <META_MAX ; i++)atomic_set (&sbi->meta_count[i],0 );
fs/f2fs/f2fs.h +237 -8
437 lines not on this page · raw message
fs/f2fs/file.c +172 -19
360 lines not on this page · raw message
fs/f2fs/inode.c +43 -0
18 lines not on this page · raw message
fs/f2fs/namei.c +59 -0
59 lines not on this page · raw message
fs/f2fs/super.c +111 -1
112 lines not on this page · raw message
include/trace/events/f2fs.h +99 -0
99 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 8 lines
2.18.0.rc1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Part of the diff is not shown here. View the raw message.