2023-11-21 01:40:55

by Zhang Yi

[permalink] [raw]
Subject: [RFC PATCH 2/6] ext4: make ext4_es_lookup_extent() return the next extent if not found

From: Zhang Yi <[email protected]>

Make ext4_es_lookup_extent() return the next extent entry if we can't
find the extent that lblk belongs to, it's useful to estimate and limit
the length of a potential hole in ext4_map_blocks().

Signed-off-by: Zhang Yi <[email protected]>
---
fs/ext4/extents_status.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 1b1b1a8848a8..19a0cc904cd8 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1012,19 +1012,9 @@ int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk,
goto out;
}

- node = tree->root.rb_node;
- while (node) {
- es1 = rb_entry(node, struct extent_status, rb_node);
- if (lblk < es1->es_lblk)
- node = node->rb_left;
- else if (lblk > ext4_es_end(es1))
- node = node->rb_right;
- else {
- found = 1;
- break;
- }
- }
-
+ es1 = __es_tree_search(&tree->root, lblk);
+ if (es1 && in_range(lblk, es1->es_lblk, es1->es_len))
+ found = 1;
out:
stats = &EXT4_SB(inode->i_sb)->s_es_stats;
if (found) {
@@ -1045,6 +1035,11 @@ int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk,
*next_lblk = 0;
}
} else {
+ if (es1) {
+ es->es_lblk = es1->es_lblk;
+ es->es_len = es1->es_len;
+ es->es_pblk = es1->es_pblk;
+ }
percpu_counter_inc(&stats->es_stats_cache_misses);
}

--
2.39.2