diff options
author | Ionut Nicu <ioan.nicu.ext@nsn.com> | 2014-02-04 15:48:10 +0100 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-02-21 11:33:18 -0500 |
commit | fc0fc50f38a4d7d0554558076a79dfe8b0d78cd5 (patch) | |
tree | e601cd6598fa0f21fe78c1941e8d74dd9782bedb /fs/ext4/ext4fs.c | |
parent | ee456337c6820721a7e5f7819830179fcafa9fc2 (diff) | |
download | u-boot-imx-fc0fc50f38a4d7d0554558076a79dfe8b0d78cd5.zip u-boot-imx-fc0fc50f38a4d7d0554558076a79dfe8b0d78cd5.tar.gz u-boot-imx-fc0fc50f38a4d7d0554558076a79dfe8b0d78cd5.tar.bz2 |
ext4fs: Add ext4 extent cache for read operations
In an ext4 filesystem, the inode corresponding to a file has a 60-byte
area which contains an extent header structure and up to 4 extent
structures (5 x 12 bytes).
For files that need more than 4 extents to be represented (either files
larger than 4 x 128MB = 512MB or smaller files but very fragmented),
ext4 creates extent index structures. Each extent index points to a 4KB
physical block where one extent header and additional 340 extents could
be stored.
The current u-boot ext4 code is very inefficient when it tries to load a
file which has extent indexes. For each logical file block the code will
read over and over again the same blocks of 4096 bytes from the disk.
Since the extent tree in a file is always the same, we can cache the
extent structures in memory before actually starting to read the file.
This patch creates a simple linked list of structures holding information
about all the extents used to represent a file. The list is sorted by
the logical block number (ee_block) so that we can easily find the
proper extent information for any file block.
Without this patch, a 69MB file which had just one extent index pointing
to a block with another 6 extents was read in approximately 3 minutes.
With this patch applied the same file can be read in almost 20 seconds.
Signed-off-by: Ionut Nicu <ioan.nicu.ext@nsn.com>
Diffstat (limited to 'fs/ext4/ext4fs.c')
-rw-r--r-- | fs/ext4/ext4fs.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c index 417ce7b..4f1b4c8 100644 --- a/fs/ext4/ext4fs.c +++ b/fs/ext4/ext4fs.c @@ -63,6 +63,14 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos, char *delayed_buf = NULL; short status; + if (le32_to_cpu(node->inode.flags) & EXT4_EXTENTS_FL) { + if (ext4fs_build_extent_cache(&node->inode)) { + printf("Error building extent cache!\n"); + len = -1; + goto out_exit; + } + } + /* Adjust len so it we can't read past the end of the file. */ if (len > filesize) len = filesize; @@ -75,8 +83,10 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos, int blockend = blocksize; int skipfirst = 0; blknr = read_allocated_block(&(node->inode), i); - if (blknr < 0) - return -1; + if (blknr < 0) { + len = -1; + goto out_exit; + } blknr = blknr << log2_fs_blocksize; @@ -106,8 +116,10 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos, delayed_skipfirst, delayed_extent, delayed_buf); - if (status == 0) - return -1; + if (status == 0) { + len = -1; + goto out_exit; + } previous_block_number = blknr; delayed_start = blknr; delayed_extent = blockend; @@ -132,8 +144,10 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos, delayed_skipfirst, delayed_extent, delayed_buf); - if (status == 0) - return -1; + if (status == 0) { + len = -1; + goto out_exit; + } previous_block_number = -1; } memset(buf, 0, blocksize - skipfirst); @@ -145,11 +159,17 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos, status = ext4fs_devread(delayed_start, delayed_skipfirst, delayed_extent, delayed_buf); - if (status == 0) - return -1; + if (status == 0) { + len = -1; + goto out_exit; + } previous_block_number = -1; } + +out_exit: + ext4fs_free_extent_cache(); + return len; } |