aboutsummaryrefslogtreecommitdiff
path: root/fs/ext4/ext4fs.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2019-01-30 12:58:05 -0700
committerTom Rini <trini@konsulko.com>2019-04-09 15:34:15 -0400
commitd5aee659f217746395ff58adf3a863627ff02ec1 (patch)
tree2d2db84b18244673371c5478fbb365560cdb071a /fs/ext4/ext4fs.c
parent4c24dab391003b99b1e0784fd41fe756cb07039e (diff)
downloadu-boot-d5aee659f217746395ff58adf3a863627ff02ec1.zip
u-boot-d5aee659f217746395ff58adf3a863627ff02ec1.tar.gz
u-boot-d5aee659f217746395ff58adf3a863627ff02ec1.tar.bz2
fs: ext4: cache extent data
When a file contains extents, U-Boot currently reads extent-related data for each block in the file, even if that data is located in the same block each time. This significantly slows down loading of files that use extents. Implement a very dumb cache to prevent repeatedly reading the same block. Files with extents now load as fast as files without. Note: There are many cases where read_allocated_block() is called. This patch only addresses one of those places; all others still read redundant data in any case they did before. This is a minimal patch to fix the load command; other cases aren't fixed. Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'fs/ext4/ext4fs.c')
-rw-r--r--fs/ext4/ext4fs.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 2a28031..26db677 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -62,6 +62,9 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
lbaint_t delayed_next = 0;
char *delayed_buf = NULL;
short status;
+ struct ext_block_cache cache;
+
+ ext_cache_init(&cache);
if (blocksize <= 0)
return -1;
@@ -77,9 +80,11 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
int blockoff = pos - (blocksize * i);
int blockend = blocksize;
int skipfirst = 0;
- blknr = read_allocated_block(&(node->inode), i);
- if (blknr < 0)
+ blknr = read_allocated_block(&node->inode, i, &cache);
+ if (blknr < 0) {
+ ext_cache_fini(&cache);
return -1;
+ }
blknr = blknr << log2_fs_blocksize;
@@ -109,8 +114,10 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
delayed_skipfirst,
delayed_extent,
delayed_buf);
- if (status == 0)
+ if (status == 0) {
+ ext_cache_fini(&cache);
return -1;
+ }
previous_block_number = blknr;
delayed_start = blknr;
delayed_extent = blockend;
@@ -136,8 +143,10 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
delayed_skipfirst,
delayed_extent,
delayed_buf);
- if (status == 0)
+ if (status == 0) {
+ ext_cache_fini(&cache);
return -1;
+ }
previous_block_number = -1;
}
/* Zero no more than `len' bytes. */
@@ -153,12 +162,15 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
status = ext4fs_devread(delayed_start,
delayed_skipfirst, delayed_extent,
delayed_buf);
- if (status == 0)
+ if (status == 0) {
+ ext_cache_fini(&cache);
return -1;
+ }
previous_block_number = -1;
}
*actread = len;
+ ext_cache_fini(&cache);
return 0;
}
@@ -252,3 +264,32 @@ int ext4fs_uuid(char *uuid_str)
return -ENOSYS;
#endif
}
+
+void ext_cache_init(struct ext_block_cache *cache)
+{
+ memset(cache, 0, sizeof(*cache));
+}
+
+void ext_cache_fini(struct ext_block_cache *cache)
+{
+ free(cache->buf);
+ ext_cache_init(cache);
+}
+
+int ext_cache_read(struct ext_block_cache *cache, lbaint_t block, int size)
+{
+ /* This could be more lenient, but this is simple and enough for now */
+ if (cache->buf && cache->block == block && cache->size == size)
+ return 1;
+ ext_cache_fini(cache);
+ cache->buf = malloc(size);
+ if (!cache->buf)
+ return 0;
+ if (!ext4fs_devread(block, 0, size, cache->buf)) {
+ free(cache->buf);
+ return 0;
+ }
+ cache->block = block;
+ cache->size = size;
+ return 1;
+}