ext4fs: Add ext4 extent tree cache
PATCH 1/1 ext4fs: Add ext4 extent tree cache
From: Evan Thompson <[email protected]>
In ext4, the file inode can store up to 4 extents. If a file requires more (due to size or fragmentation), an extent index tree is used.
Currently, u-boot reads a node from each level of the extent tree for every block read, which is very inefficient when extent tree depth is > 0.
This patch adds a cache for the extent tree. We cache the 1 most-recently-seen node at each extent tree level. The typical workload is sequential block access, so once we leave a given tree node, it will not be revisited. Therefore, it makes sense to just cache one node per tree level.
Cached blocks are lazily allocated. The typical case is extent tree depth = 0, in which case no caching is needed and no allocations will occur.
For files with extent tree depth = 1, this patch produces a ~10x improvement in read speed. For deeper extent trees, the improvement is larger. On my test device, a 3MB file which previously took 9s to read now takes 150ms.
Cache size is configurable with CONFIG_EXT4_EXTENT_CACHE_SIZE. However the default of 5 (the maximum depth of well-formed extent trees) is recommended.
--- doc/README.ext4 | 7 +++++ fs/ext4/ext4_common.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 76 insertions(+), 5 deletions(-)
doc/README.ext4 +7 -0
@@ -33,6 +33,13 @@ In addition, to get the write access command "ext4write", enable: which automatically selects CONFIG_EXT4_WRITE if it wasn't defined already. +For files with extents, an ext4 extent tree cache improves performance: + + CONFIG_EXT4_EXTENT_CACHE_SIZE <#> + +The above cache size defaults to 5 if not defined. This default is +strongly recommended. 0 will turn off extent caching. + Also relevant are the generic filesystem commands, selected by: CONFIG_CMD_FS_GENERIC
fs/ext4/ext4_common.c +69 -5
104 lines not on this page · raw message
Signature · 1 line
2.14.1
PATCH 1/1 ext4fs: Add ext4 extent tree cache
Quoted 61 lines · evan.g.thompson at gmail.com
From: Evan Thompson <[email protected]>
In ext4, the file inode can store up to 4 extents. If a file requires more (due to size or fragmentation), an extent index tree is used.
Currently, u-boot reads a node from each level of the extent tree for every block read, which is very inefficient when extent tree depth is > 0.
This patch adds a cache for the extent tree. We cache the 1 most-recently-seen node at each extent tree level. The typical workload is sequential block access, so once we leave a given tree node, it will not be revisited. Therefore, it makes sense to just cache one node per tree level.
Cached blocks are lazily allocated. The typical case is extent tree depth = 0, in which case no caching is needed and no allocations will occur.
For files with extent tree depth = 1, this patch produces a ~10x improvement in read speed. For deeper extent trees, the improvement is larger. On my test device, a 3MB file which previously took 9s to read now takes 150ms.
Cache size is configurable with
CONFIG_EXT4_EXTENT_CACHE_SIZE. However the default of 5 (the maximum depth of well-formed extent trees) is recommended.Signed-off-by Evan Thompson <[email protected]>--- doc/README.ext4 | 7 +++++ fs/ext4/ext4_common.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 76 insertions(+), 5 deletions(-)doc/README.ext4 +7
-0@@ -33,6 +33,13 @@ In addition, to get the write access command "ext4write", enable: which automatically selects CONFIG_EXT4_WRITE if it wasn't defined already. +For files with extents, an ext4 extent tree cache improves performance: + + CONFIG_EXT4_EXTENT_CACHE_SIZE <#> + +The above cache size defaults to 5 if not defined. This default is +strongly recommended. 0 will turn off extent caching. + Also relevant are the generic filesystem commands, selected by: CONFIG_CMD_FS_GENERICfs/ext4/ext4_common.c +1
-0@@ -1523,6 +1523,47 @@ void ext4fs_allocate_blocks(struct ext2_inode *file_inode,#endif +/* Extent tree cache caches one entry per tree level
fs/ext4/ext4_common.c void ext4fs_allocate_blocks(struct ext2_inode *file_inode, · line 1536
Quoted 10 lines
fs/ext4/ext4_common.c +10
-0+* eg, ext_block->eh_depth is used as the index into the cache +* +* If the tree is deeper than CONFIG_EXT4_EXTENT_CACHE_SIZE (very unlikely), +* file read performance will be impacted by repeated re-reads +* of those index nodes. +*/ + +#ifndef CONFIG_EXT4_EXTENT_CACHE_SIZE +#define CONFIG_EXT4_EXTENT_CACHE_SIZE 5 +#endif
This needs to be done in Kconfig. Also, is there any sort of testing we could add to test/fs/fs-test.sh for this code? Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180510/733aa878/attachment.sig>
PATCH 1/1 ext4fs: Add ext4 extent tree cache
Quoted 8 lines · Tom Rini
fs/ext4/ext4_common.c void ext4fs_allocate_blocks(struct ext2_inode *file_inode, · line 1536
Quoted 4 lines · evan.g.thompson at gmail.com
fs/ext4/ext4_common.c +4
-0+ +#ifndef CONFIG_EXT4_EXTENT_CACHE_SIZE +#define CONFIG_EXT4_EXTENT_CACHE_SIZE 5 +#endif This needs to be done in
Kconfig.
Ok, I'll fix that.
Quoted 1 line
Also, is there any sort of testing we could add to
test/fs/fs-test.shfor this code? Thanks!
I can't think of a straightforward way, as this patch just provides a speedup for certain cases. The functionality of reading / writing files is unchanged.
- Evan
PATCH 1/1 ext4fs: Add ext4 extent tree cache
Quoted 10 lines · Evan Thompson
Quoted 8 lines · Tom Rini
fs/ext4/ext4_common.c void ext4fs_allocate_blocks(struct ext2_inode *file_inode, · line 1536
Quoted 4 lines · evan.g.thompson at gmail.com
fs/ext4/ext4_common.c +4
-0+ +#ifndef CONFIG_EXT4_EXTENT_CACHE_SIZE +#define CONFIG_EXT4_EXTENT_CACHE_SIZE 5 +#endif This needs to be done in
Kconfig.
Quoted 8 lines
Ok, I'll fix that.
Quoted 2 lines
Also, is there any sort of testing we could add to
test/fs/fs-test.shfor this code? Thanks!I can't think of a straightforward way, as this patch just provides a speedup for certain cases. The functionality of reading / writing files is unchanged.
OK. And the test suite passes as well as before, yes?
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180511/4d135427/attachment.sig>
PATCH 1/1 ext4fs: Add ext4 extent tree cache
Quoted 13 lines · Tom Rini
Quoted 12 lines · Evan Thompson
Quoted 8 lines · Tom Rini
fs/ext4/ext4_common.c void ext4fs_allocate_blocks(struct ext2_inode *file_inode, · line 1536
Quoted 4 lines · evan.g.thompson at gmail.com
fs/ext4/ext4_common.c +4
-0+ +#ifndef CONFIG_EXT4_EXTENT_CACHE_SIZE +#define CONFIG_EXT4_EXTENT_CACHE_SIZE 5 +#endif This needs to be done in
Kconfig.Ok, I'll fix that.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Also, is there any sort of testing we could add to
test/fs/fs-test.shfor this code? Thanks!I can't think of a straightforward way, as this patch just provides a speedup for certain cases. The functionality of reading / writing files is unchanged.
OK. And the test suite passes as well as before, yes?
Yes, I'm seeing the same passes and fails as before.
- Evan
PATCH 1/1 ext4fs: Add ext4 extent tree cache
Quoted 17 lines · Evan Thompson
Quoted 16 lines · Tom Rini
Quoted 15 lines · Evan Thompson
Quoted 8 lines · Tom Rini
fs/ext4/ext4_common.c void ext4fs_allocate_blocks(struct ext2_inode *file_inode, · line 1536
Quoted 4 lines · evan.g.thompson at gmail.com
fs/ext4/ext4_common.c +4
-0+ +#ifndef CONFIG_EXT4_EXTENT_CACHE_SIZE +#define CONFIG_EXT4_EXTENT_CACHE_SIZE 5 +#endif This needs to be done in
Kconfig.Ok, I'll fix that.
Quoted 2 lines
Also, is there any sort of testing we could add to
test/fs/fs-test.shfor this code? Thanks!
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
I can't think of a straightforward way, as this patch just provides a speedup for certain cases. The functionality of reading / writing files is unchanged.
OK. And the test suite passes as well as before, yes?
Yes, I'm seeing the same passes and fails as before.
btw doesn't CONFIG_BLOCK_CACHE offer similar service, but for everyone and on block level ? I recall looking for ext4 fs speed up , but then ultimately used CONFIG_BLOCK_CACHE which did it for me.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 ext4fs: Add ext4 extent tree cache
Quoted 4 lines · Marek Vasut
btw doesn't
CONFIG_BLOCK_CACHEoffer similar service, but for everyone and on block level ? I recall looking for ext4 fs speed up , but then ultimately usedCONFIG_BLOCK_CACHEwhich did it for me.
I was unaware of the existence of CONFIG_BLOCK_CACHE - yes, that will solve the same problem by caching at the block level instead of the filesystem level. So my patch is redundant, and ext4 users should just be advised to turn on CONFIG_BLOCK_CACHE.
Thanks,
Evan
PATCH 1/1 ext4fs: Add ext4 extent tree cache
Quoted 10 lines · Evan Thompson
Quoted 4 lines · Marek Vasut
btw doesn't
CONFIG_BLOCK_CACHEoffer similar service, but for everyone and on block level ? I recall looking for ext4 fs speed up , but then ultimately usedCONFIG_BLOCK_CACHEwhich did it for me.I was unaware of the existence of
CONFIG_BLOCK_CACHE- yes, that will solve the same problem by caching at the block level instead of the filesystem level. So my patch is redundant, and ext4 users should just be advised to turn onCONFIG_BLOCK_CACHE.
Maybe this block cache should be default=y (if BLK is enabled?) or we should advertise it more somehow. I ran into the exact same issue and started looking into the ext4 patches myself only to find the block cache later on.
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 ext4fs: Add ext4 extent tree cache
Quoted 12 lines · Marek Vasut
Quoted 10 lines · Evan Thompson
Quoted 4 lines · Marek Vasut
btw doesn't
CONFIG_BLOCK_CACHEoffer similar service, but for everyone and on block level ? I recall looking for ext4 fs speed up , but then ultimately usedCONFIG_BLOCK_CACHEwhich did it for me.I was unaware of the existence of
CONFIG_BLOCK_CACHE- yes, that will solve the same problem by caching at the block level instead of the filesystem level. So my patch is redundant, and ext4 users should just be advised to turn onCONFIG_BLOCK_CACHE.
Quoted 4 lines
Maybe this block cache should be default=y (if BLK is enabled?) or we should advertise it more somehow. I ran into the exact same issue and started looking into the ext4 patches myself only to find the block cache later on.
Agreed. I'm right now testing a patch or two to do that and see what the size cost is. Thanks all!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180514/7feb2a05/attachment.sig>