f2fs: remove costly dirty_dir_inode operations

This patch removes list opeations in handling dirty dir inodes.
Previously, F2FS traverses whole the list of dirty dir inodes to check whether
there is an existing inode or not, resulting in heavy CPU overheads.

So this patch removes such the traverse operations by adding FI_DIRTY_DIR to
indicate the inode lies on the list or not.
Through this simple flag, we can remove redundant operations gracefully.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
This commit is contained in:
Jaegeuk Kim 2014-04-15 11:19:28 +09:00
parent 15c6e3aae6
commit ed57c27f73
3 changed files with 25 additions and 48 deletions

View File

@ -552,14 +552,13 @@ fail_no_cp:
static int __add_dirty_inode(struct inode *inode, struct dir_inode_entry *new) static int __add_dirty_inode(struct inode *inode, struct dir_inode_entry *new)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct list_head *head = &sbi->dir_inode_list;
struct dir_inode_entry *entry;
list_for_each_entry(entry, head, list) if (is_inode_flag_set(F2FS_I(inode), FI_DIRTY_DIR))
if (unlikely(entry->inode == inode)) return -EEXIST;
return -EEXIST;
list_add_tail(&new->list, head); set_inode_flag(F2FS_I(inode), FI_DIRTY_DIR);
F2FS_I(inode)->dirty_dir = new;
list_add_tail(&new->list, &sbi->dir_inode_list);
stat_inc_dirty_dir(sbi); stat_inc_dirty_dir(sbi);
return 0; return 0;
} }
@ -608,31 +607,26 @@ void add_dirty_dir_inode(struct inode *inode)
void remove_dirty_dir_inode(struct inode *inode) void remove_dirty_dir_inode(struct inode *inode)
{ {
struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct list_head *head;
struct dir_inode_entry *entry; struct dir_inode_entry *entry;
if (!S_ISDIR(inode->i_mode)) if (!S_ISDIR(inode->i_mode))
return; return;
spin_lock(&sbi->dir_inode_lock); spin_lock(&sbi->dir_inode_lock);
if (get_dirty_dents(inode)) { if (get_dirty_dents(inode) ||
!is_inode_flag_set(F2FS_I(inode), FI_DIRTY_DIR)) {
spin_unlock(&sbi->dir_inode_lock); spin_unlock(&sbi->dir_inode_lock);
return; return;
} }
head = &sbi->dir_inode_list; entry = F2FS_I(inode)->dirty_dir;
list_for_each_entry(entry, head, list) { list_del(&entry->list);
if (entry->inode == inode) { F2FS_I(inode)->dirty_dir = NULL;
list_del(&entry->list); clear_inode_flag(F2FS_I(inode), FI_DIRTY_DIR);
stat_dec_dirty_dir(sbi); stat_dec_dirty_dir(sbi);
spin_unlock(&sbi->dir_inode_lock);
kmem_cache_free(inode_entry_slab, entry);
goto done;
}
}
spin_unlock(&sbi->dir_inode_lock); spin_unlock(&sbi->dir_inode_lock);
kmem_cache_free(inode_entry_slab, entry);
done:
/* Only from the recovery routine */ /* Only from the recovery routine */
if (is_inode_flag_set(F2FS_I(inode), FI_DELAY_IPUT)) { if (is_inode_flag_set(F2FS_I(inode), FI_DELAY_IPUT)) {
clear_inode_flag(F2FS_I(inode), FI_DELAY_IPUT); clear_inode_flag(F2FS_I(inode), FI_DELAY_IPUT);
@ -640,26 +634,6 @@ done:
} }
} }
struct inode *check_dirty_dir_inode(struct f2fs_sb_info *sbi, nid_t ino)
{
struct list_head *head;
struct inode *inode = NULL;
struct dir_inode_entry *entry;
spin_lock(&sbi->dir_inode_lock);
head = &sbi->dir_inode_list;
list_for_each_entry(entry, head, list) {
if (entry->inode->i_ino == ino) {
inode = entry->inode;
break;
}
}
spin_unlock(&sbi->dir_inode_lock);
return inode;
}
void sync_dirty_dir_inodes(struct f2fs_sb_info *sbi) void sync_dirty_dir_inodes(struct f2fs_sb_info *sbi)
{ {
struct list_head *head; struct list_head *head;

View File

@ -218,6 +218,7 @@ struct f2fs_inode_info {
nid_t i_xattr_nid; /* node id that contains xattrs */ nid_t i_xattr_nid; /* node id that contains xattrs */
unsigned long long xattr_ver; /* cp version of xattr modification */ unsigned long long xattr_ver; /* cp version of xattr modification */
struct extent_info ext; /* in-memory extent cache entry */ struct extent_info ext; /* in-memory extent cache entry */
struct dir_inode_entry *dirty_dir; /* the pointer of dirty dir */
}; };
static inline void get_extent_info(struct extent_info *ext, static inline void get_extent_info(struct extent_info *ext,
@ -958,6 +959,7 @@ static inline int f2fs_clear_bit(unsigned int nr, char *addr)
enum { enum {
FI_NEW_INODE, /* indicate newly allocated inode */ FI_NEW_INODE, /* indicate newly allocated inode */
FI_DIRTY_INODE, /* indicate inode is dirty or not */ FI_DIRTY_INODE, /* indicate inode is dirty or not */
FI_DIRTY_DIR, /* indicate directory has dirty pages */
FI_INC_LINK, /* need to increment i_nlink */ FI_INC_LINK, /* need to increment i_nlink */
FI_ACL_MODE, /* indicate acl mode */ FI_ACL_MODE, /* indicate acl mode */
FI_NO_ALLOC, /* should not allocate any blocks */ FI_NO_ALLOC, /* should not allocate any blocks */
@ -1222,7 +1224,6 @@ int get_valid_checkpoint(struct f2fs_sb_info *);
void set_dirty_dir_page(struct inode *, struct page *); void set_dirty_dir_page(struct inode *, struct page *);
void add_dirty_dir_inode(struct inode *); void add_dirty_dir_inode(struct inode *);
void remove_dirty_dir_inode(struct inode *); void remove_dirty_dir_inode(struct inode *);
struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
void sync_dirty_dir_inodes(struct f2fs_sb_info *); void sync_dirty_dir_inodes(struct f2fs_sb_info *);
void write_checkpoint(struct f2fs_sb_info *, bool); void write_checkpoint(struct f2fs_sb_info *, bool);
void init_orphan_info(struct f2fs_sb_info *); void init_orphan_info(struct f2fs_sb_info *);

View File

@ -46,15 +46,17 @@ static int recover_dentry(struct page *ipage, struct inode *inode)
struct inode *dir, *einode; struct inode *dir, *einode;
int err = 0; int err = 0;
dir = check_dirty_dir_inode(F2FS_SB(inode->i_sb), pino); dir = f2fs_iget(inode->i_sb, pino);
if (!dir) { if (IS_ERR(dir)) {
dir = f2fs_iget(inode->i_sb, pino); err = PTR_ERR(dir);
if (IS_ERR(dir)) { goto out;
err = PTR_ERR(dir); }
goto out;
} if (is_inode_flag_set(F2FS_I(dir), FI_DIRTY_DIR)) {
set_inode_flag(F2FS_I(dir), FI_DELAY_IPUT); iput(dir);
} else {
add_dirty_dir_inode(dir); add_dirty_dir_inode(dir);
set_inode_flag(F2FS_I(dir), FI_DELAY_IPUT);
} }
name.len = le32_to_cpu(raw_inode->i_namelen); name.len = le32_to_cpu(raw_inode->i_namelen);