Skip to content

Commit

Permalink
lib: fs: ext2: Optimize to load multiple contiguous blocks in one dma…
Browse files Browse the repository at this point in the history
… call

Signed-off-by: Nikita Travkin <[email protected]>
(cherry picked from commit 9c6734c)

[Fix an length check in block copying]
(cherry picked from commit 6d5ddb4)
  • Loading branch information
TravMurav committed Sep 20, 2023
1 parent 7217f26 commit 1e91f52
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/fs/ext2/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,22 @@ ssize_t ext2_read_inode(ext2_t *ext2, struct ext2_inode *inode, void *_buf, off_
while (len >= EXT2_BLOCK_SIZE(ext2->sb)) {
/* calculate the block and read it */
blocknum_t phys_block = file_block_to_fs_block(ext2, inode, file_block);
blocknum_t count_cont_blks = 1;
blocknum_t max_blocks = len / EXT2_BLOCK_SIZE(ext2->sb);
if (phys_block == 0) {
memset(buf, 0, EXT2_BLOCK_SIZE(ext2->sb));
} else {
ext2_read_block(ext2, buf, phys_block);
while (count_cont_blks < max_blocks && file_block_to_fs_block(ext2, inode, file_block + count_cont_blks) == phys_block + count_cont_blks) {
count_cont_blks++;
}
bio_read(ext2->dev, buf, EXT2_BLOCK_SIZE(ext2->sb) * phys_block, EXT2_BLOCK_SIZE(ext2->sb) * count_cont_blks);
}

/* increment our stuff */
file_block++;
len -= EXT2_BLOCK_SIZE(ext2->sb);
bytes_read += EXT2_BLOCK_SIZE(ext2->sb);
buf += EXT2_BLOCK_SIZE(ext2->sb);
file_block += count_cont_blks;
len -= EXT2_BLOCK_SIZE(ext2->sb) * count_cont_blks;
bytes_read += EXT2_BLOCK_SIZE(ext2->sb) * count_cont_blks;
buf += EXT2_BLOCK_SIZE(ext2->sb) * count_cont_blks;
}

/* handle partial last block */
Expand Down

0 comments on commit 1e91f52

Please sign in to comment.