f2fs: allocate the extent_cache by default

Let's allocate it to remove the runtime complexity.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Jaegeuk Kim 2022-12-02 13:51:09 -08:00
parent e7547daccd
commit 72840cccc0
4 changed files with 27 additions and 24 deletions

View File

@ -47,20 +47,23 @@ static bool __may_read_extent_tree(struct inode *inode)
return S_ISREG(inode->i_mode);
}
static bool __init_may_extent_tree(struct inode *inode, enum extent_type type)
{
if (type == EX_READ)
return __may_read_extent_tree(inode);
return false;
}
static bool __may_extent_tree(struct inode *inode, enum extent_type type)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
/*
* for recovered files during mount do not create extents
* if shrinker is not registered.
*/
if (list_empty(&sbi->s_list))
if (list_empty(&F2FS_I_SB(inode)->s_list))
return false;
if (type == EX_READ)
return __may_read_extent_tree(inode);
return false;
return __init_may_extent_tree(inode, type);
}
static void __try_update_largest_extent(struct extent_tree *et,
@ -439,20 +442,18 @@ static void __drop_largest_extent(struct extent_tree *et,
}
}
/* return true, if inode page is changed */
static void __f2fs_init_extent_tree(struct inode *inode, struct page *ipage,
enum extent_type type)
void f2fs_init_read_extent_tree(struct inode *inode, struct page *ipage)
{
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
struct extent_tree_info *eti = &sbi->extent_tree[type];
struct f2fs_extent *i_ext = ipage ? &F2FS_INODE(ipage)->i_ext : NULL;
struct extent_tree_info *eti = &sbi->extent_tree[EX_READ];
struct f2fs_extent *i_ext = &F2FS_INODE(ipage)->i_ext;
struct extent_tree *et;
struct extent_node *en;
struct extent_info ei;
if (!__may_extent_tree(inode, type)) {
if (!__may_extent_tree(inode, EX_READ)) {
/* drop largest read extent */
if (type == EX_READ && i_ext && i_ext->len) {
if (i_ext && i_ext->len) {
f2fs_wait_on_page_writeback(ipage, NODE, true, true);
i_ext->len = 0;
set_page_dirty(ipage);
@ -460,13 +461,11 @@ static void __f2fs_init_extent_tree(struct inode *inode, struct page *ipage,
goto out;
}
et = __grab_extent_tree(inode, type);
et = __grab_extent_tree(inode, EX_READ);
if (!i_ext || !i_ext->len)
goto out;
BUG_ON(type != EX_READ);
get_read_extent_info(&ei, i_ext);
write_lock(&et->lock);
@ -486,14 +485,15 @@ static void __f2fs_init_extent_tree(struct inode *inode, struct page *ipage,
unlock_out:
write_unlock(&et->lock);
out:
if (type == EX_READ && !F2FS_I(inode)->extent_tree[EX_READ])
if (!F2FS_I(inode)->extent_tree[EX_READ])
set_inode_flag(inode, FI_NO_EXTENT);
}
void f2fs_init_extent_tree(struct inode *inode, struct page *ipage)
void f2fs_init_extent_tree(struct inode *inode)
{
/* initialize read cache */
__f2fs_init_extent_tree(inode, ipage, EX_READ);
if (__init_may_extent_tree(inode, EX_READ))
__grab_extent_tree(inode, EX_READ);
}
static bool __lookup_extent_tree(struct inode *inode, pgoff_t pgofs,

View File

@ -4150,7 +4150,7 @@ struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root,
bool force, bool *leftmost);
bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi,
struct rb_root_cached *root, bool check_key);
void f2fs_init_extent_tree(struct inode *inode, struct page *ipage);
void f2fs_init_extent_tree(struct inode *inode);
void f2fs_drop_extent_tree(struct inode *inode);
void f2fs_destroy_extent_node(struct inode *inode);
void f2fs_destroy_extent_tree(struct inode *inode);
@ -4159,6 +4159,7 @@ int __init f2fs_create_extent_cache(void);
void f2fs_destroy_extent_cache(void);
/* read extent cache ops */
void f2fs_init_read_extent_tree(struct inode *inode, struct page *ipage);
bool f2fs_lookup_read_extent_cache(struct inode *inode, pgoff_t pgofs,
struct extent_info *ei);
void f2fs_update_read_extent_cache(struct dnode_of_data *dn);

View File

@ -392,8 +392,6 @@ static int do_read_inode(struct inode *inode)
fi->i_pino = le32_to_cpu(ri->i_pino);
fi->i_dir_level = ri->i_dir_level;
f2fs_init_extent_tree(inode, node_page);
get_inline_info(inode, ri);
fi->i_extra_isize = f2fs_has_extra_attr(inode) ?
@ -479,6 +477,10 @@ static int do_read_inode(struct inode *inode)
}
init_idisk_time(inode);
/* Need all the flag bits */
f2fs_init_read_extent_tree(inode, node_page);
f2fs_put_page(node_page, 1);
stat_inc_inline_xattr(inode);

View File

@ -284,8 +284,6 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns,
}
F2FS_I(inode)->i_inline_xattr_size = xattr_size;
f2fs_init_extent_tree(inode, NULL);
F2FS_I(inode)->i_flags =
f2fs_mask_flags(mode, F2FS_I(dir)->i_flags & F2FS_FL_INHERITED);
@ -311,6 +309,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns,
f2fs_set_inode_flags(inode);
f2fs_init_extent_tree(inode);
trace_f2fs_new_inode(inode, 0);
return inode;