]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: drop inode from the donation list when the last file is closed
authorJaegeuk Kim <jaegeuk@kernel.org>
Tue, 30 Dec 2025 16:15:26 +0000 (11:15 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Jan 2026 09:14:57 +0000 (10:14 +0100)
[ Upstream commit 078cad8212ce4f4ebbafcc0936475b8215e1ca2a ]

Let's drop the inode from the donation list when there is no other
open file.

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Stable-dep-of: 10b591e7fb7c ("f2fs: fix to avoid updating compression context during writeback")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/f2fs/f2fs.h
fs/f2fs/file.c
fs/f2fs/inode.c
fs/f2fs/super.c

index 57bd3639e29a3cdea20085b221eddf92e6db6bfd..44b8cbbb5ddc7c883939cddcd8384217329175b6 100644 (file)
@@ -859,6 +859,7 @@ struct f2fs_inode_info {
        /* linked in global inode list for cache donation */
        struct list_head gdonate_list;
        pgoff_t donate_start, donate_end; /* inclusive */
+       atomic_t open_count;            /* # of open files */
 
        struct task_struct *atomic_write_task;  /* store atomic write task */
        struct extent_tree *extent_tree[NR_EXTENT_CACHES];
@@ -3600,6 +3601,7 @@ int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
 void f2fs_update_inode(struct inode *inode, struct page *node_page);
 void f2fs_update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
+void f2fs_remove_donate_inode(struct inode *inode);
 void f2fs_evict_inode(struct inode *inode);
 void f2fs_handle_failed_inode(struct inode *inode);
 
index cb4de4651451fc5b24fbf0152a58526195e59021..7af859d56d57b192d79f6da21ef7a8b1f6d626b9 100644 (file)
@@ -631,7 +631,10 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
        if (err)
                return err;
 
-       return finish_preallocate_blocks(inode);
+       err = finish_preallocate_blocks(inode);
+       if (!err)
+               atomic_inc(&F2FS_I(inode)->open_count);
+       return err;
 }
 
 void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
@@ -1992,6 +1995,9 @@ out:
 
 static int f2fs_release_file(struct inode *inode, struct file *filp)
 {
+       if (atomic_dec_and_test(&F2FS_I(inode)->open_count))
+               f2fs_remove_donate_inode(inode);
+
        /*
         * f2fs_release_file is called at every close calls. So we should
         * not drop any inmemory pages by close called by other process.
index c77184dbc71cd1e87bc81e989e83461d6637b63d..f6ba15c095f83fd5cf1ad0e3b8db441c6f2d7f79 100644 (file)
@@ -807,7 +807,7 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
        return 0;
 }
 
-static void f2fs_remove_donate_inode(struct inode *inode)
+void f2fs_remove_donate_inode(struct inode *inode)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 
index 8b09fdc0028af3a555d710c9f14a06ef6181336b..1711a3f90f720776efe2b4db7bebafa78b7fc037 100644 (file)
@@ -1425,6 +1425,7 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
        /* Initialize f2fs-specific inode info */
        atomic_set(&fi->dirty_pages, 0);
        atomic_set(&fi->i_compr_blocks, 0);
+       atomic_set(&fi->open_count, 0);
        init_f2fs_rwsem(&fi->i_sem);
        spin_lock_init(&fi->i_size_lock);
        INIT_LIST_HEAD(&fi->dirty_list);