mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 10:31:46 +09:00
UPSTREAM: f2fs: Optimize f2fs_truncate_data_blocks_range()
Function f2fs_invalidate_blocks() can process consecutive blocks at a time, so f2fs_truncate_data_blocks_range() is optimized to use the new functionality of f2fs_invalidate_blocks(). Add two variables @blkstart and @blklen, @blkstart records the first address of the consecutive blocks, and @blkstart records the number of consecutive blocks. Bug: 394006856 Change-Id: I219866b6c60a8f23f92aee64429064a04e7282d2 Signed-off-by: Yi Sun <yi.sun@unisoc.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> (cherry picked from commit 120ac1dc322f402544423582234f441d98ea4a6e)
This commit is contained in:
@@ -621,8 +621,11 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
|
||||
int cluster_index = 0, valid_blocks = 0;
|
||||
int cluster_size = F2FS_I(dn->inode)->i_cluster_size;
|
||||
bool released = !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks);
|
||||
block_t blkstart;
|
||||
int blklen = 0;
|
||||
|
||||
addr = get_dnode_addr(dn->inode, dn->node_page) + ofs;
|
||||
blkstart = le32_to_cpu(*addr);
|
||||
|
||||
/* Assumption: truncation starts with cluster */
|
||||
for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) {
|
||||
@@ -638,28 +641,46 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
|
||||
}
|
||||
|
||||
if (blkaddr == NULL_ADDR)
|
||||
continue;
|
||||
goto next;
|
||||
|
||||
f2fs_set_data_blkaddr(dn, NULL_ADDR);
|
||||
|
||||
if (__is_valid_data_blkaddr(blkaddr)) {
|
||||
if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE))
|
||||
continue;
|
||||
goto next;
|
||||
if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr,
|
||||
DATA_GENERIC_ENHANCE)) {
|
||||
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
|
||||
continue;
|
||||
goto next;
|
||||
}
|
||||
if (compressed_cluster)
|
||||
valid_blocks++;
|
||||
}
|
||||
|
||||
f2fs_invalidate_blocks(sbi, blkaddr, 1);
|
||||
if (blkstart + blklen == blkaddr) {
|
||||
blklen++;
|
||||
} else {
|
||||
f2fs_invalidate_blocks(sbi, blkstart, blklen);
|
||||
blkstart = blkaddr;
|
||||
blklen = 1;
|
||||
}
|
||||
|
||||
if (!released || blkaddr != COMPRESS_ADDR)
|
||||
nr_free++;
|
||||
|
||||
continue;
|
||||
|
||||
next:
|
||||
if (blklen)
|
||||
f2fs_invalidate_blocks(sbi, blkstart, blklen);
|
||||
|
||||
blkstart = le32_to_cpu(*(addr + 1));
|
||||
blklen = 0;
|
||||
}
|
||||
|
||||
if (blklen)
|
||||
f2fs_invalidate_blocks(sbi, blkstart, blklen);
|
||||
|
||||
if (compressed_cluster)
|
||||
f2fs_i_compr_blocks_update(dn->inode, valid_blocks, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user