Re: [U-Boot] [PATCH] fs: ext4: cache extent data

2019-02-21 Thread Tom Rini
On Wed, Feb 20, 2019 at 02:37:39PM -0700, Stephen Warren wrote:
> On 1/30/19 12:58 PM, Stephen Warren wrote:
> >From: Stephen Warren 
> >
> >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.
> 
> Any thoughts here? Thanks.

Seems better than today, was planning to grab this and the symlink stuff
for the next release.  Thanks!

-- 
Tom


signature.asc
Description: PGP signature
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH] fs: ext4: cache extent data

2019-02-20 Thread Stephen Warren

On 1/30/19 12:58 PM, Stephen Warren wrote:

From: Stephen Warren 

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.


Any thoughts here? Thanks.
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH] fs: ext4: cache extent data

2019-01-30 Thread Stephen Warren
From: Stephen Warren 

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 
---
 fs/ext4/ext4_common.c  | 45 ++---
 fs/ext4/ext4_journal.c | 22 +-
 fs/ext4/ext4_write.c   |  6 ++---
 fs/ext4/ext4fs.c   | 51 +-
 include/ext4fs.h   | 12 +-
 5 files changed, 99 insertions(+), 37 deletions(-)

diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 67e2471bd388..29308e3b4474 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -510,7 +510,8 @@ restart:
 
 restart_read:
/* read the block no allocated to a file */
-   first_block_no_of_root = read_allocated_block(g_parent_inode, blk_idx);
+   first_block_no_of_root = read_allocated_block(g_parent_inode, blk_idx,
+ NULL);
if (first_block_no_of_root <= 0)
goto fail;
 
@@ -646,7 +647,7 @@ static int search_dir(struct ext2_inode *parent_inode, char 
*dirname)
 
/* get the block no allocated to a file */
for (blk_idx = 0; blk_idx < directory_blocks; blk_idx++) {
-   blknr = read_allocated_block(parent_inode, blk_idx);
+   blknr = read_allocated_block(parent_inode, blk_idx, NULL);
if (blknr <= 0)
goto fail;
 
@@ -943,7 +944,7 @@ int ext4fs_filename_unlink(char *filename)
 
/* read the block no allocated to a file */
for (blk_idx = 0; blk_idx < directory_blocks; blk_idx++) {
-   blknr = read_allocated_block(g_parent_inode, blk_idx);
+   blknr = read_allocated_block(g_parent_inode, blk_idx, NULL);
if (blknr <= 0)
break;
inodeno = unlink_filename(filename, blknr);
@@ -1522,7 +1523,7 @@ void ext4fs_allocate_blocks(struct ext2_inode *file_inode,
 #endif
 
 static struct ext4_extent_header *ext4fs_get_extent_block
-   (struct ext2_data *data, char *buf,
+   (struct ext2_data *data, struct ext_block_cache *cache,
struct ext4_extent_header *ext_block,
uint32_t fileblock, int log2_blksz)
 {
@@ -1551,12 +1552,10 @@ static struct ext4_extent_header 
*ext4fs_get_extent_block
 
block = le16_to_cpu(index[i].ei_leaf_hi);
block = (block << 32) + le32_to_cpu(index[i].ei_leaf_lo);
-
-   if (ext4fs_devread((lbaint_t)block << log2_blksz, 0, blksz,
-  buf))
-   ext_block = (struct ext4_extent_header *)buf;
-   else
+   block <<= log2_blksz;
+   if (!ext_cache_read(cache, (lbaint_t)block, blksz))
return NULL;
+   ext_block = (struct ext4_extent_header *)cache->buf;
}
 }
 
@@ -1613,7 +1612,8 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, 
struct ext2_inode *inode)
return 1;
 }
 
-long int read_allocated_block(struct ext2_inode *inode, int fileblock)
+long int read_allocated_block(struct ext2_inode *inode, int fileblock,
+ struct ext_block_cache *cache)
 {
long int blknr;
int blksz;
@@ -1630,20 +1630,26 @@ long int read_allocated_block(struct ext2_inode *inode, 
int fileblock)
 
if (le32_to_cpu(inode->flags) & EXT4_EXTENTS_FL) {
long int startblock, endblock;
-   char *buf = zalloc(blksz);
-   if (!buf)
-   return -ENOMEM;
+   struct ext_block_cache *c, cd;
struct ext4_extent_header *ext_block;
struct ext4_extent *extent;
int i;
+
+   if (cache) {
+   c = cache;
+   } else {
+   c = &cd;
+   ext_cache_init(c);
+   }
ext_block =
-   ext4fs_get_extent_block(ext4fs_root, buf,
+   ext4fs_get_extent_block(ext4fs_root, c,
(struct ext4_extent_header *)
inode->b.blocks.dir_blocks,
fileblock, log2_blksz);
if (!ext_block) {
printf("invalid extent block\n");
-   free(buf);
+