Commit 84bc926c authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: check the largest extent at look-up time

Because of the extent shrinker or other -ENOMEM scenarios, it cannot guarantee
that the largest extent would be cached in the tree all the time.

Instead of relying on extent_tree, we can simply check the cached one in extent
tree accordingly.
Reviewed-by: default avatarChao Yu <chao2.yu@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 3e72f721
...@@ -512,12 +512,22 @@ static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs, ...@@ -512,12 +512,22 @@ static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct extent_tree *et = F2FS_I(inode)->extent_tree; struct extent_tree *et = F2FS_I(inode)->extent_tree;
struct extent_node *en; struct extent_node *en;
bool ret = false;
f2fs_bug_on(sbi, !et); f2fs_bug_on(sbi, !et);
trace_f2fs_lookup_extent_tree_start(inode, pgofs); trace_f2fs_lookup_extent_tree_start(inode, pgofs);
read_lock(&et->lock); read_lock(&et->lock);
if (et->largest.fofs <= pgofs &&
et->largest.fofs + et->largest.len > pgofs) {
*ei = et->largest;
ret = true;
stat_inc_read_hit(sbi->sb);
goto out;
}
en = __lookup_extent_tree(et, pgofs); en = __lookup_extent_tree(et, pgofs);
if (en) { if (en) {
*ei = en->ei; *ei = en->ei;
...@@ -526,13 +536,15 @@ static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs, ...@@ -526,13 +536,15 @@ static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
list_move_tail(&en->list, &sbi->extent_list); list_move_tail(&en->list, &sbi->extent_list);
et->cached_en = en; et->cached_en = en;
spin_unlock(&sbi->extent_lock); spin_unlock(&sbi->extent_lock);
ret = true;
stat_inc_read_hit(sbi->sb); stat_inc_read_hit(sbi->sb);
} }
out:
stat_inc_total_hit(sbi->sb); stat_inc_total_hit(sbi->sb);
read_unlock(&et->lock); read_unlock(&et->lock);
trace_f2fs_lookup_extent_tree_end(inode, pgofs, en); trace_f2fs_lookup_extent_tree_end(inode, pgofs, ei);
return en ? true : false; return ret;
} }
/* return true, if on-disk extent should be updated */ /* return true, if on-disk extent should be updated */
......
...@@ -1099,11 +1099,11 @@ TRACE_EVENT(f2fs_lookup_extent_tree_start, ...@@ -1099,11 +1099,11 @@ TRACE_EVENT(f2fs_lookup_extent_tree_start,
TRACE_EVENT_CONDITION(f2fs_lookup_extent_tree_end, TRACE_EVENT_CONDITION(f2fs_lookup_extent_tree_end,
TP_PROTO(struct inode *inode, unsigned int pgofs, TP_PROTO(struct inode *inode, unsigned int pgofs,
struct extent_node *en), struct extent_info *ei),
TP_ARGS(inode, pgofs, en), TP_ARGS(inode, pgofs, ei),
TP_CONDITION(en), TP_CONDITION(ei),
TP_STRUCT__entry( TP_STRUCT__entry(
__field(dev_t, dev) __field(dev_t, dev)
...@@ -1118,9 +1118,9 @@ TRACE_EVENT_CONDITION(f2fs_lookup_extent_tree_end, ...@@ -1118,9 +1118,9 @@ TRACE_EVENT_CONDITION(f2fs_lookup_extent_tree_end,
__entry->dev = inode->i_sb->s_dev; __entry->dev = inode->i_sb->s_dev;
__entry->ino = inode->i_ino; __entry->ino = inode->i_ino;
__entry->pgofs = pgofs; __entry->pgofs = pgofs;
__entry->fofs = en->ei.fofs; __entry->fofs = ei->fofs;
__entry->blk = en->ei.blk; __entry->blk = ei->blk;
__entry->len = en->ei.len; __entry->len = ei->len;
), ),
TP_printk("dev = (%d,%d), ino = %lu, pgofs = %u, " TP_printk("dev = (%d,%d), ino = %lu, pgofs = %u, "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment