Skip to content

Commit 120ac1d

Browse files
Yi SunJaegeuk Kim
authored andcommitted
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. Signed-off-by: Yi Sun <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent c84c242 commit 120ac1d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

fs/f2fs/file.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,11 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
621621
int cluster_index = 0, valid_blocks = 0;
622622
int cluster_size = F2FS_I(dn->inode)->i_cluster_size;
623623
bool released = !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks);
624+
block_t blkstart;
625+
int blklen = 0;
624626

625627
addr = get_dnode_addr(dn->inode, dn->node_page) + ofs;
628+
blkstart = le32_to_cpu(*addr);
626629

627630
/* Assumption: truncation starts with cluster */
628631
for (; count > 0; count--, addr++, dn->ofs_in_node++, cluster_index++) {
@@ -638,26 +641,44 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
638641
}
639642

640643
if (blkaddr == NULL_ADDR)
641-
continue;
644+
goto next;
642645

643646
f2fs_set_data_blkaddr(dn, NULL_ADDR);
644647

645648
if (__is_valid_data_blkaddr(blkaddr)) {
646649
if (time_to_inject(sbi, FAULT_BLKADDR_CONSISTENCE))
647-
continue;
650+
goto next;
648651
if (!f2fs_is_valid_blkaddr_raw(sbi, blkaddr,
649652
DATA_GENERIC_ENHANCE))
650-
continue;
653+
goto next;
651654
if (compressed_cluster)
652655
valid_blocks++;
653656
}
654657

655-
f2fs_invalidate_blocks(sbi, blkaddr, 1);
658+
if (blkstart + blklen == blkaddr) {
659+
blklen++;
660+
} else {
661+
f2fs_invalidate_blocks(sbi, blkstart, blklen);
662+
blkstart = blkaddr;
663+
blklen = 1;
664+
}
656665

657666
if (!released || blkaddr != COMPRESS_ADDR)
658667
nr_free++;
668+
669+
continue;
670+
671+
next:
672+
if (blklen)
673+
f2fs_invalidate_blocks(sbi, blkstart, blklen);
674+
675+
blkstart = le32_to_cpu(*(addr + 1));
676+
blklen = 0;
659677
}
660678

679+
if (blklen)
680+
f2fs_invalidate_blocks(sbi, blkstart, blklen);
681+
661682
if (compressed_cluster)
662683
f2fs_i_compr_blocks_update(dn->inode, valid_blocks, false);
663684

0 commit comments

Comments
 (0)