ubifs: add lz4hc compression
Subsystems (2)
cover ubifs: add lz4hc compression
From: Hyunchul Lee <[email protected]>
This patch set is for adding support for lz4hc compression. lz4hc's compression ratio is comparable to zlib, but its compression/decompression speed is faster than zlib[1].
Another compression type cannot be added any more in respect that type of ubifs_inode's compr_type is "unsigned:2" and there are 4 compression types. There may be overflow in assignment to compr_type, and prevision version of ubifs is trying to decompress file with wrong compression type.
[1] https://github.com/lz4/lz4
Brent Taylor (1):
ubifs: add lz4hc compressor
Hyunchul Lee (2):
ubifs: change type of ubifs_inode's compr_type to unsigend:16
ubifs: add "compr=lz4hc" into ubifs.txt
Documentation/filesystems/ubifs.txt | 1 + fs/ubifs/Kconfig | 10 ++++++++++ fs/ubifs/compress.c | 25 ++++++++++++++++++++++++- fs/ubifs/super.c | 2 ++ fs/ubifs/ubifs-media.h | 2 ++ fs/ubifs/ubifs.h | 2 +- 6 files changed, 40 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/3 ubifs: add lz4hc compressor
From: Brent Taylor <[email protected]>
This patch adds lz4hc compressor into ubifs. with "compr=lz4hc" mount option, default compression type is changed to "lz4hc"
This was submited by Brent Taylor[1] and not merged.
[1] http://lists.infradead.org/pipermail/linux-mtd/2013-October/048993.html
--- fs/ubifs/Kconfig | 10 ++++++++++ fs/ubifs/compress.c | 25 ++++++++++++++++++++++++- fs/ubifs/super.c | 2 ++ fs/ubifs/ubifs-media.h | 2 ++ 4 files changed, 38 insertions(+), 1 deletion(-)
fs/ubifs/Kconfig +10 -0
@@ -29,6 +29,16 @@ config UBIFS_FS_LZO LZO compressor is generally faster than zlib but compresses worse. Say 'Y' if unsure. +config UBIFS_FS_LZ4HC + bool "LZ4HC compression support" if UBIFS_FS_ADVANCED_COMPR + depends on UBIFS_FS && CRYPTO_LZ4HC + default y + help + LZ4HC generally beats LZO on decompression speed while provides a lot + better compression ratio (comparable to zlib). Compression speed is + generally slower compared to LZO, but faster compared to zlib. + Say 'Y' if unsure. + config UBIFS_FS_ZLIB bool "ZLIB compression support" if UBIFS_FS_ADVANCED_COMPR depends on UBIFS_FS
fs/ubifs/compress.c +24 -1
@@ -71,6 +71,22 @@ };#endif +#ifdef CONFIG_UBIFS_FS_LZ4HC +static DEFINE_MUTEX (lz4hc_mutex); + +static struct ubifs_compressor lz4hc_compr = { + .compr_type =UBIFS_COMPR_LZ4HC , + .comp_mutex = &lz4hc_mutex, + .name ="lz4hc" , + .capi_name ="lz4hc" , +}; +#else +static struct ubifs_compressor lz4hc_compr = { + .compr_type =UBIFS_COMPR_LZ4HC , + .name ="lz4hc" , +}; +#endif +/* All UBIFS compressors */ struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT ];
@@ -224,10 +240,14 @@ int __init ubifs_compressors_init(void) {int err; - err =compr_init (&lzo_compr); + err =compr_init (&lz4hc_compr);if (err)return err; + err =compr_init (&lzo_compr); +if (err) + goto out_lz4hc; + err =compr_init (&zlib_compr);if (err) goto out_lzo;
@@ -237,6 +257,8 @@ int __init ubifs_compressors_init(void) out_lzo:compr_exit (&lzo_compr); +out_lz4hc: +compr_exit (&lz4hc_compr);return err; }
@@ -245,6 +267,7 @@ int __init ubifs_compressors_init(void)*/ void ubifs_compressors_exit (void ) { +compr_exit (&lz4hc_compr);compr_exit (&lzo_compr);compr_exit (&zlib_compr); }
fs/ubifs/super.c +2 -0
@@ -1028,6 +1028,8 @@ static int ubifs_parse_options(struct ubifs_info *c, char *options,return -ENOMEM ;if (!strcmp (name,"none" )) c->mount_opts.compr_type =UBIFS_COMPR_NONE ; +else if (!strcmp (name,"lz4hc" )) + c->mount_opts.compr_type =UBIFS_COMPR_LZ4HC ;else if (!strcmp (name,"lzo" )) c->mount_opts.compr_type =UBIFS_COMPR_LZO ;else if (!strcmp (name,"zlib" ))
fs/ubifs/ubifs-media.h +2 -0
@@ -341,12 +341,14 @@ enum {* UBIFS_COMPR_NONE: no compression * UBIFS_COMPR_LZO: LZO compression * UBIFS_COMPR_ZLIB: ZLIB compression +* UBIFS_COMPR_LZ4HC: LZ4HC compression * UBIFS_COMPR_TYPES_CNT: count of supported compression types */ enum {UBIFS_COMPR_NONE ,UBIFS_COMPR_LZO ,UBIFS_COMPR_ZLIB , +UBIFS_COMPR_LZ4HC ,UBIFS_COMPR_TYPES_CNT , };
Signature · 1 line
1.9.1
PATCH 2/3 ubifs: change type of ubifs_inode's compr_type to unsigend:16
In reply to Hyunchul LeeFrom: Hyunchul Lee <[email protected]>
if new compression is added, UBIFS_COMPR_TYPES_CNT becomes greater than 3. so type "unsigned:2" of compr_type should be changed.
--- fs/ubifs/ubifs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ubifs/ubifs.h +1 -1
@@ -394,7 +394,7 @@ struct ubifs_inode { unsigned int dirty:1; unsigned int xattr:1; unsigned int bulk_read:1; - unsigned int compr_type:2; + unsigned int compr_type:16;struct mutex ui_mutex;spinlock_t ui_lock;loff_t synced_i_size;
Signature · 1 line
1.9.1
Quoted 7 lines · Hyunchul Lee
Another compression type cannot be added any more in respect that type of
ubifs_inode'scompr_typeis "unsigned:2" and there are 4 compression types. There may be overflow in assignment tocompr_type, and prevision
version of ubifs is trying to decompress file with wrong compression type.
But this is just an in-memory inode structure, and you can change it, just increase the size of 'compr_type'.
Quoted 11 lines · Artem Bityutskiy
Quoted 7 lines · Hyunchul Lee
Another compression type cannot be added any more in respect that type of
ubifs_inode'scompr_typeis "unsigned:2" and there are 4 compression types. There may be overflow in assignment tocompr_type, and prevision
version of ubifs is trying to decompress file with wrong compression type.But this is just an in-memory inode structure, and you can change it, just increase the size of '
compr_type'.
yes, it is an in-memory inode. but i think that there can be problem of backward compatibility. for example, if ubifs_ino_node's compr_type is 4 in flash, the previous version of ubifs could misinterpret it as 0, because ubifs_inode's compr_type(2-bit) is assigned ubifs_ino_nodes' compr_type at ubifs_iget.
thank you for comment.
Hyunchul
Quoted 7 lines · Hyunchul Lee
yes, it is an in-memory inode. but i think that there can be problem of
backward compatibility. for example, if ubifs_ino_node'scompr_typeis
4 in flash, the previous version of ubifs could misinterpret it as 0, because ubifs_inode'scompr_type(2-bit)is assignedubifs_ino_nodes'compr_typeatubifs_iget.
Good point. I guess changing the in-memory compr_type to something wider right away would be a good idea, even if no new compressors are added.
Richard Weinberger
maintainerHyunchul Lee,
Am 28.02.2017 um 06:16 schrieb Hyunchul Lee:
Quoted 5 lines
From: Hyunchul Lee <[email protected]>
This patch set is for adding support for lz4hc compression. lz4hc's compression ratio is comparable to zlib, but its compression/decompression speed is faster than zlib[1].
Do you have performance numbers that show the speedup on a common embedded system with NAND?
Quoted 4 lines
Another compression type cannot be added any more in respect that type of ubifs_inode's
compr_typeis "unsigned:2" and there are 4 compression types. There may be overflow in assignment tocompr_type, and prevision version of ubifs is trying to decompress file with wrong compression type.
As Artem noted this is only an in-memory struct.
What happens when you compress a file with lz4hc and try to access this UBIFS file with an older kernel?
AFAICT ubifs_iget() will notice and return -EINVAL but please double check.
Thanks,
//richard
Hi, Ricard
Quoted 11 lines · Richard Weinberger
Hyunchul Lee,
Am 28.02.2017 um 06:16 schrieb Hyunchul Lee:
Quoted 5 lines
From: Hyunchul Lee <[email protected]>
This patch set is for adding support for lz4hc compression. lz4hc's compression ratio is comparable to zlib, but its compression/decompression speed is faster than zlib[1].
Do you have performance numbers that show the speedup on a common embedded system with NAND?
I am trying to build environment for a common embedded system with NAND. if I am done, I will report the performance result.
Quoted 6 lines
Quoted 5 lines
Another compression type cannot be added any more in respect that type of ubifs_inode's
compr_typeis "unsigned:2" and there are 4 compression types. There may be overflow in assignment tocompr_type, and prevision version of ubifs is trying to decompress file with wrong compression type.
Quoted 6 lines
As Artem noted this is only an in-memory struct.
What happens when you compress a file with lz4hc and try to access this UBIFS file with an older kernel?
AFAICTubifs_iget()will notice and return-EINVALbut please double check.
yes, ubifs detects this. but I mean that if another compression type except lz4hc is added, ubifs cannot. because ubifs_iget() assigns ubifs_ino_node's compr_type(16-bit) to ubifs_inode's compr_type(2-bit).
I guess that the disk format version should be incremented.
Quoted 3 lines
Thanks,
//richard
Thanks,
Hyunchul
Quoted 6 lines · Hyunchul Lee
yes, ubifs detects this. but I mean that if another compression type except lz4hc
is added, ubifs cannot. becauseubifs_iget()assigns ubifs_ino_node'scompr_type(16-bit)
to ubifs_inode'scompr_type(2-bit).
I guess that the disk format version should be incremented.
Let's say that some day in the future you add the new XYZ compression support, and its type is 5. Let's say the new compressor is supported in kernel version 5.0.
Now I get your device which is running kernel 5.0 and uses XYZ compression. I downgrade the kernel to version 4.0 on this device, v4.0 does not support XYZ. What happens?
Well, not a very good thing. UBIFS will read the inode, truncate compr_type in ubifs_iget():
ui->compr_type = le16_to_cpu(ino->compr_type);
and happily continue, and later on failing to decompress.
Is this ideal? No. But we can lessen the future problem by making compr_type to be full u16 already today.
Should we change on-flash format? I think no, because UBIFS will still fail when it tries to decompress.
Artem.
Richard Weinberger
maintainerArtem,
Am 03.03.2017 um 13:00 schrieb Artem Bityutskiy:
Quoted 21 lines · Hyunchul Lee
Quoted 6 lines
yes, ubifs detects this. but I mean that if another compression type except lz4hc
is added, ubifs cannot. becauseubifs_iget()assigns ubifs_ino_node'scompr_type(16-bit)
to ubifs_inode'scompr_type(2-bit).
I guess that the disk format version should be incremented.Let's say that some day in the future you add the new XYZ compression support, and its type is 5. Let's say the new compressor is supported in kernel version 5.0.
Now I get your device which is running kernel 5.0 and uses XYZ compression. I downgrade the kernel to version 4.0 on this device, v4.0 does not support XYZ. What happens?
Well, not a very good thing. UBIFS will read the inode, truncate
compr_typeinubifs_iget():ui->compr_type = le16_to_cpu(ino->compr_type);
Quoted 7 lines
and happily continue, and later on failing to decompress.
Is this ideal? No. But we can lessen the future problem by making
compr_typeto be full u16 already today.Should we change on-flash format? I think no, because UBIFS will still fail when it tries to decompress.
We don't need to change the on-flash format.
I'd vote to add a new super block flag.
See: commit fc4b891bbefa73b496bb44b076bb5274b6bfba68
Author: Richard Weinberger <[email protected]>
Date: Wed Oct 19 23:46:39 2016 +0200
ubifs: Raise write version to 5
Starting with version 5 the following properties change:
- UBIFS_FLG_DOUBLE_HASH is mandatory
- UBIFS_FLG_ENCRYPTION is optional but depdens on UBIFS_FLG_DOUBLE_HASH
- Filesystems with unknown super block flags will be rejected, this allows us in future to add new features without raising the UBIFS write version.
Thanks,
//richard