Skip to content

Commit 078cad8

Browse files
author
Jaegeuk Kim
committed
f2fs: drop inode from the donation list when the last file is closed
Let's drop the inode from the donation list when there is no other open file. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent c8705ce commit 078cad8

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

fs/f2fs/f2fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ struct f2fs_inode_info {
876876
/* linked in global inode list for cache donation */
877877
struct list_head gdonate_list;
878878
pgoff_t donate_start, donate_end; /* inclusive */
879+
atomic_t open_count; /* # of open files */
879880

880881
struct task_struct *atomic_write_task; /* store atomic write task */
881882
struct extent_tree *extent_tree[NR_EXTENT_CACHES];
@@ -3652,6 +3653,7 @@ int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
36523653
void f2fs_update_inode(struct inode *inode, struct folio *node_folio);
36533654
void f2fs_update_inode_page(struct inode *inode);
36543655
int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
3656+
void f2fs_remove_donate_inode(struct inode *inode);
36553657
void f2fs_evict_inode(struct inode *inode);
36563658
void f2fs_handle_failed_inode(struct inode *inode);
36573659

fs/f2fs/file.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,10 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
628628
if (err)
629629
return err;
630630

631-
return finish_preallocate_blocks(inode);
631+
err = finish_preallocate_blocks(inode);
632+
if (!err)
633+
atomic_inc(&F2FS_I(inode)->open_count);
634+
return err;
632635
}
633636

634637
void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
@@ -2037,6 +2040,9 @@ static long f2fs_fallocate(struct file *file, int mode,
20372040

20382041
static int f2fs_release_file(struct inode *inode, struct file *filp)
20392042
{
2043+
if (atomic_dec_and_test(&F2FS_I(inode)->open_count))
2044+
f2fs_remove_donate_inode(inode);
2045+
20402046
/*
20412047
* f2fs_release_file is called at every close calls. So we should
20422048
* not drop any inmemory pages by close called by other process.

fs/f2fs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
821821
return 0;
822822
}
823823

824-
static void f2fs_remove_donate_inode(struct inode *inode)
824+
void f2fs_remove_donate_inode(struct inode *inode)
825825
{
826826
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
827827

fs/f2fs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,7 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
17011701
/* Initialize f2fs-specific inode info */
17021702
atomic_set(&fi->dirty_pages, 0);
17031703
atomic_set(&fi->i_compr_blocks, 0);
1704+
atomic_set(&fi->open_count, 0);
17041705
init_f2fs_rwsem(&fi->i_sem);
17051706
spin_lock_init(&fi->i_size_lock);
17061707
INIT_LIST_HEAD(&fi->dirty_list);

0 commit comments

Comments
 (0)