* [PATCH] f2fs: call __add_ino_entry out of the eviction path
@ 2026-08-04 0:20 Jaegeuk Kim
2026-08-05 1:28 ` [f2fs-dev] [PATCH v2] " Jaegeuk Kim
2026-08-16 12:06 ` [PATCH] " kernel test robot
0 siblings, 2 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2026-08-04 0:20 UTC (permalink / raw)
To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim
The f2fs_evict_inode() can be called during the direct reclaim path, but
__add_ino_entry requires allocating some memory. Since we don't need to
do that in that context, let's migrate it in other workqueue context.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/checkpoint.c | 15 ++++++++
fs/f2fs/data.c | 13 ++++++-
fs/f2fs/f2fs.h | 4 ++
fs/f2fs/inode.c | 88 +++++++++++++++++++++++++++++++++++++++++---
fs/f2fs/super.c | 9 ++++-
5 files changed, 122 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 064f5b537423..2d00b718974f 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -766,6 +766,15 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
spin_unlock(&im->ino_lock);
}
+static void f2fs_wait_for_inode_record(struct f2fs_sb_info *sbi, int mode)
+{
+ if (mode != APPEND_INO && mode != UPDATE_INO)
+ return;
+
+ /* Let's wait for some pending updates for APPEND_INO and UPDATE_INO. */
+ flush_workqueue(sbi->evict_wq);
+}
+
void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
{
/* add new dirty ino entry into list */
@@ -774,6 +783,8 @@ void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
{
+ f2fs_wait_for_inode_record(sbi, type);
+
/* remove dirty ino entry from list */
__remove_ino_entry(sbi, ino, type);
}
@@ -784,6 +795,8 @@ bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode)
struct inode_management *im = &sbi->im[mode];
struct ino_entry *e;
+ f2fs_wait_for_inode_record(sbi, mode);
+
spin_lock(&im->ino_lock);
e = radix_tree_lookup(&im->ino_root, ino);
spin_unlock(&im->ino_lock);
@@ -798,6 +811,8 @@ void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all)
for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) {
struct inode_management *im = &sbi->im[i];
+ f2fs_wait_for_inode_record(sbi, i);
+
spin_lock(&im->ino_lock);
list_for_each_entry_safe(e, tmp, &im->ino_list, list) {
list_del(&e->list);
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index c219ea76a3a7..6ae0eb37d20f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -4558,13 +4558,24 @@ int f2fs_init_wq(struct f2fs_sb_info *sbi)
{
sbi->wq = alloc_workqueue("f2fs_wq", WQ_UNBOUND | WQ_HIGHPRI,
num_online_cpus());
- return sbi->wq ? 0 : -ENOMEM;
+ if (!sbi->wq)
+ return -ENOMEM;
+
+ sbi->evict_wq = alloc_workqueue("f2fs_evict_wq",
+ WQ_UNBOUND | WQ_HIGHPRI, num_online_cpus());
+ if (!sbi->evict_wq) {
+ destroy_workqueue(sbi->wq);
+ return -ENOMEM;
+ }
+ return 0;
}
void f2fs_destroy_wq(struct f2fs_sb_info *sbi)
{
if (sbi->wq)
destroy_workqueue(sbi->wq);
+ if (sbi->evict_wq)
+ destroy_workqueue(sbi->evict_wq);
}
int __init f2fs_init_bio_entry_cache(void)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index c44908258dc1..54f9d3856b5c 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2016,6 +2016,8 @@ struct f2fs_sb_info {
struct workqueue_struct *wq; /* bio completion workqueue */
+ struct workqueue_struct *evict_wq; /* inode eviction workqueue */
+
/*
* If we are in irq context, let's update error information into
* on-disk superblock in the work.
@@ -3875,6 +3877,8 @@ 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, struct f2fs_lock_context *lc);
+int f2fs_init_evict_inode_work(void);
+void f2fs_destroy_evict_inode_work(void);
/*
* namei.c
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index c95e0b126da4..ed67eed3675e 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -24,6 +24,18 @@
extern const struct address_space_operations f2fs_compress_aops;
#endif
+#define NUM_PREALLOC_EVICT_INODE_WORK 8
+
+static struct kmem_cache *evict_inode_work_cache;
+static mempool_t *evict_inode_work_pool;
+
+struct evict_inode_work {
+ struct work_struct work;
+ struct f2fs_sb_info *sbi;
+ nid_t ino;
+ unsigned int add_ino_entry_bits;
+};
+
void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync)
{
if (is_inode_flag_set(inode, FI_NEW_INODE))
@@ -854,6 +866,25 @@ void f2fs_remove_donate_inode(struct inode *inode)
spin_unlock(&sbi->inode_lock[DONATE_INODE]);
}
+static void f2fs_record_inode_state(struct f2fs_sb_info *sbi, nid_t ino,
+ unsigned int bits)
+{
+ if (bits & BIT(APPEND_INO))
+ f2fs_add_ino_entry(sbi, ino, APPEND_INO);
+ if (bits & BIT(UPDATE_INO))
+ f2fs_add_ino_entry(sbi, ino, UPDATE_INO);
+}
+
+static void f2fs_evict_inode_work(struct work_struct *work)
+{
+ struct evict_inode_work *ew =
+ container_of(work, struct evict_inode_work, work);
+
+ f2fs_record_inode_state(ew->sbi, ew->ino, ew->add_ino_entry_bits);
+
+ mempool_free(ew, evict_inode_work_pool);
+}
+
/*
* Called at the last iput() if i_nlink is zero
*/
@@ -864,6 +895,7 @@ void f2fs_evict_inode(struct inode *inode)
nid_t xnid = fi->i_xattr_nid;
int err = 0;
bool freeze_protected = false;
+ unsigned int record_bits = 0;
f2fs_abort_atomic_write(inode, true);
@@ -1003,12 +1035,32 @@ void f2fs_evict_inode(struct inode *inode)
inode->i_ino);
if (xnid)
invalidate_mapping_pages(NODE_MAPPING(sbi), xnid, xnid);
- if (inode->i_nlink) {
- if (is_inode_flag_set(inode, FI_APPEND_WRITE))
- f2fs_add_ino_entry(sbi, inode->i_ino, APPEND_INO);
- if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
- f2fs_add_ino_entry(sbi, inode->i_ino, UPDATE_INO);
+
+ if (!inode->i_nlink)
+ goto skip_record;
+
+ if (is_inode_flag_set(inode, FI_APPEND_WRITE))
+ record_bits = BIT(APPEND_INO);
+ if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
+ record_bits = BIT(UPDATE_INO);
+
+ if (!record_bits)
+ goto skip_record;
+
+ /* Let's do this in workqueue out of the direct reclaim path. */
+ if (current_is_kswapd()) {
+ f2fs_record_inode_state(sbi, inode->i_ino, record_bits);
+ } else {
+ struct evict_inode_work *ew =
+ mempool_alloc(evict_inode_work_pool, GFP_NOFS);
+
+ ew->sbi = sbi;
+ ew->ino = inode->i_ino;
+ ew->add_ino_entry_bits = record_bits;
+ INIT_WORK(&ew->work, f2fs_evict_inode_work);
+ queue_work(sbi->evict_wq, &ew->work);
}
+skip_record:
if (is_inode_flag_set(inode, FI_FREE_NID)) {
f2fs_alloc_nid_failed(sbi, inode->i_ino);
clear_inode_flag(inode, FI_FREE_NID);
@@ -1079,3 +1131,29 @@ void f2fs_handle_failed_inode(struct inode *inode, struct f2fs_lock_context *lc)
/* iput will drop the inode object */
iput(inode);
}
+
+int __init f2fs_init_evict_inode_work(void)
+{
+ evict_inode_work_cache =
+ kmem_cache_create("f2fs_evict_inode_work",
+ sizeof(struct evict_inode_work), 0, 0, NULL);
+ if (!evict_inode_work_cache)
+ goto fail;
+ evict_inode_work_pool =
+ mempool_create_slab_pool(NUM_PREALLOC_EVICT_INODE_WORK,
+ evict_inode_work_cache);
+ if (!evict_inode_work_pool)
+ goto fail_free_cache;
+ return 0;
+
+fail_free_cache:
+ kmem_cache_destroy(evict_inode_work_cache);
+fail:
+ return -ENOMEM;
+}
+
+void f2fs_destroy_evict_inode_work(void)
+{
+ mempool_destroy(evict_inode_work_pool);
+ kmem_cache_destroy(evict_inode_work_cache);
+}
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 67abbf7ab477..6b55c30f0daa 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -5763,10 +5763,16 @@ static int __init init_f2fs_fs(void)
err = f2fs_init_xattr_cache();
if (err)
goto free_casefold_cache;
- err = register_filesystem(&f2fs_fs_type);
+ err = f2fs_init_evict_inode_work();
if (err)
goto free_xattr_cache;
+ err = register_filesystem(&f2fs_fs_type);
+ if (err)
+ goto free_evict_inode_cache;
return 0;
+
+free_evict_inode_cache:
+ f2fs_destroy_evict_inode_work();
free_xattr_cache:
f2fs_destroy_xattr_cache();
free_casefold_cache:
@@ -5809,6 +5815,7 @@ static int __init init_f2fs_fs(void)
static void __exit exit_f2fs_fs(void)
{
unregister_filesystem(&f2fs_fs_type);
+ f2fs_destroy_evict_inode_work();
f2fs_destroy_xattr_cache();
f2fs_destroy_casefold_cache();
f2fs_destroy_compress_cache();
--
2.55.0.571.g244d577d93-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: call __add_ino_entry out of the eviction path
2026-08-04 0:20 [PATCH] f2fs: call __add_ino_entry out of the eviction path Jaegeuk Kim
@ 2026-08-05 1:28 ` Jaegeuk Kim
2026-08-06 2:38 ` Chao Yu
2026-08-16 12:06 ` [PATCH] " kernel test robot
1 sibling, 1 reply; 5+ messages in thread
From: Jaegeuk Kim @ 2026-08-05 1:28 UTC (permalink / raw)
To: linux-kernel, linux-f2fs-devel
The f2fs_evict_inode() can be called during the direct reclaim path, but
__add_ino_entry requires allocating some memory. Since we don't need to
do that in that context, let's migrate it in other workqueue context.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
Change log from v1:
- fix a bug on the wait logic
fs/f2fs/checkpoint.c | 11 ++++++
fs/f2fs/data.c | 13 ++++++-
fs/f2fs/f2fs.h | 4 ++
fs/f2fs/inode.c | 91 +++++++++++++++++++++++++++++++++++++++++---
fs/f2fs/super.c | 9 ++++-
5 files changed, 121 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 064f5b537423..4413eccb5ecb 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -766,6 +766,15 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
spin_unlock(&im->ino_lock);
}
+static void f2fs_wait_for_inode_record(struct f2fs_sb_info *sbi, int mode)
+{
+ if (mode != APPEND_INO && mode != UPDATE_INO)
+ return;
+
+ /* Let's wait for some pending updates for APPEND_INO and UPDATE_INO. */
+ flush_workqueue(sbi->evict_wq);
+}
+
void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
{
/* add new dirty ino entry into list */
@@ -798,6 +807,8 @@ void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all)
for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) {
struct inode_management *im = &sbi->im[i];
+ f2fs_wait_for_inode_record(sbi, i);
+
spin_lock(&im->ino_lock);
list_for_each_entry_safe(e, tmp, &im->ino_list, list) {
list_del(&e->list);
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index c219ea76a3a7..6ae0eb37d20f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -4558,13 +4558,24 @@ int f2fs_init_wq(struct f2fs_sb_info *sbi)
{
sbi->wq = alloc_workqueue("f2fs_wq", WQ_UNBOUND | WQ_HIGHPRI,
num_online_cpus());
- return sbi->wq ? 0 : -ENOMEM;
+ if (!sbi->wq)
+ return -ENOMEM;
+
+ sbi->evict_wq = alloc_workqueue("f2fs_evict_wq",
+ WQ_UNBOUND | WQ_HIGHPRI, num_online_cpus());
+ if (!sbi->evict_wq) {
+ destroy_workqueue(sbi->wq);
+ return -ENOMEM;
+ }
+ return 0;
}
void f2fs_destroy_wq(struct f2fs_sb_info *sbi)
{
if (sbi->wq)
destroy_workqueue(sbi->wq);
+ if (sbi->evict_wq)
+ destroy_workqueue(sbi->evict_wq);
}
int __init f2fs_init_bio_entry_cache(void)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index c44908258dc1..54f9d3856b5c 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2016,6 +2016,8 @@ struct f2fs_sb_info {
struct workqueue_struct *wq; /* bio completion workqueue */
+ struct workqueue_struct *evict_wq; /* inode eviction workqueue */
+
/*
* If we are in irq context, let's update error information into
* on-disk superblock in the work.
@@ -3875,6 +3877,8 @@ 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, struct f2fs_lock_context *lc);
+int f2fs_init_evict_inode_work(void);
+void f2fs_destroy_evict_inode_work(void);
/*
* namei.c
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index c95e0b126da4..0d30489cf083 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -24,6 +24,18 @@
extern const struct address_space_operations f2fs_compress_aops;
#endif
+#define NUM_PREALLOC_EVICT_INODE_WORK 8
+
+static struct kmem_cache *evict_inode_work_cache;
+static mempool_t *evict_inode_work_pool;
+
+struct evict_inode_work {
+ struct work_struct work;
+ struct f2fs_sb_info *sbi;
+ nid_t ino;
+ unsigned int add_ino_entry_bits;
+};
+
void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync)
{
if (is_inode_flag_set(inode, FI_NEW_INODE))
@@ -637,6 +649,9 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
inode->i_fop = &f2fs_dir_operations;
inode->i_mapping->a_ops = &f2fs_dblock_aops;
mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
+
+ /* Let's prepare APPEND/UPDATE_INO before future access. */
+ flush_workqueue(sbi->evict_wq);
} else if (S_ISLNK(inode->i_mode)) {
if (file_is_encrypt(inode))
inode->i_op = &f2fs_encrypted_symlink_inode_operations;
@@ -854,6 +869,25 @@ void f2fs_remove_donate_inode(struct inode *inode)
spin_unlock(&sbi->inode_lock[DONATE_INODE]);
}
+static void f2fs_record_inode_state(struct f2fs_sb_info *sbi, nid_t ino,
+ unsigned int bits)
+{
+ if (bits & BIT(APPEND_INO))
+ f2fs_add_ino_entry(sbi, ino, APPEND_INO);
+ if (bits & BIT(UPDATE_INO))
+ f2fs_add_ino_entry(sbi, ino, UPDATE_INO);
+}
+
+static void f2fs_evict_inode_work(struct work_struct *work)
+{
+ struct evict_inode_work *ew =
+ container_of(work, struct evict_inode_work, work);
+
+ f2fs_record_inode_state(ew->sbi, ew->ino, ew->add_ino_entry_bits);
+
+ mempool_free(ew, evict_inode_work_pool);
+}
+
/*
* Called at the last iput() if i_nlink is zero
*/
@@ -864,6 +898,7 @@ void f2fs_evict_inode(struct inode *inode)
nid_t xnid = fi->i_xattr_nid;
int err = 0;
bool freeze_protected = false;
+ unsigned int record_bits = 0;
f2fs_abort_atomic_write(inode, true);
@@ -1003,12 +1038,32 @@ void f2fs_evict_inode(struct inode *inode)
inode->i_ino);
if (xnid)
invalidate_mapping_pages(NODE_MAPPING(sbi), xnid, xnid);
- if (inode->i_nlink) {
- if (is_inode_flag_set(inode, FI_APPEND_WRITE))
- f2fs_add_ino_entry(sbi, inode->i_ino, APPEND_INO);
- if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
- f2fs_add_ino_entry(sbi, inode->i_ino, UPDATE_INO);
+
+ if (!inode->i_nlink)
+ goto skip_record;
+
+ if (is_inode_flag_set(inode, FI_APPEND_WRITE))
+ record_bits = BIT(APPEND_INO);
+ if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
+ record_bits = BIT(UPDATE_INO);
+
+ if (!record_bits)
+ goto skip_record;
+
+ /* Let's do this in workqueue out of the direct reclaim path. */
+ if (current_is_kswapd()) {
+ f2fs_record_inode_state(sbi, inode->i_ino, record_bits);
+ } else {
+ struct evict_inode_work *ew =
+ mempool_alloc(evict_inode_work_pool, GFP_NOFS);
+
+ ew->sbi = sbi;
+ ew->ino = inode->i_ino;
+ ew->add_ino_entry_bits = record_bits;
+ INIT_WORK(&ew->work, f2fs_evict_inode_work);
+ queue_work(sbi->evict_wq, &ew->work);
}
+skip_record:
if (is_inode_flag_set(inode, FI_FREE_NID)) {
f2fs_alloc_nid_failed(sbi, inode->i_ino);
clear_inode_flag(inode, FI_FREE_NID);
@@ -1079,3 +1134,29 @@ void f2fs_handle_failed_inode(struct inode *inode, struct f2fs_lock_context *lc)
/* iput will drop the inode object */
iput(inode);
}
+
+int __init f2fs_init_evict_inode_work(void)
+{
+ evict_inode_work_cache =
+ kmem_cache_create("f2fs_evict_inode_work",
+ sizeof(struct evict_inode_work), 0, 0, NULL);
+ if (!evict_inode_work_cache)
+ goto fail;
+ evict_inode_work_pool =
+ mempool_create_slab_pool(NUM_PREALLOC_EVICT_INODE_WORK,
+ evict_inode_work_cache);
+ if (!evict_inode_work_pool)
+ goto fail_free_cache;
+ return 0;
+
+fail_free_cache:
+ kmem_cache_destroy(evict_inode_work_cache);
+fail:
+ return -ENOMEM;
+}
+
+void f2fs_destroy_evict_inode_work(void)
+{
+ mempool_destroy(evict_inode_work_pool);
+ kmem_cache_destroy(evict_inode_work_cache);
+}
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 67abbf7ab477..6b55c30f0daa 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -5763,10 +5763,16 @@ static int __init init_f2fs_fs(void)
err = f2fs_init_xattr_cache();
if (err)
goto free_casefold_cache;
- err = register_filesystem(&f2fs_fs_type);
+ err = f2fs_init_evict_inode_work();
if (err)
goto free_xattr_cache;
+ err = register_filesystem(&f2fs_fs_type);
+ if (err)
+ goto free_evict_inode_cache;
return 0;
+
+free_evict_inode_cache:
+ f2fs_destroy_evict_inode_work();
free_xattr_cache:
f2fs_destroy_xattr_cache();
free_casefold_cache:
@@ -5809,6 +5815,7 @@ static int __init init_f2fs_fs(void)
static void __exit exit_f2fs_fs(void)
{
unregister_filesystem(&f2fs_fs_type);
+ f2fs_destroy_evict_inode_work();
f2fs_destroy_xattr_cache();
f2fs_destroy_casefold_cache();
f2fs_destroy_compress_cache();
--
2.55.0.571.g244d577d93-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: call __add_ino_entry out of the eviction path
2026-08-05 1:28 ` [f2fs-dev] [PATCH v2] " Jaegeuk Kim
@ 2026-08-06 2:38 ` Chao Yu
2026-08-07 22:03 ` Jaegeuk Kim
0 siblings, 1 reply; 5+ messages in thread
From: Chao Yu @ 2026-08-06 2:38 UTC (permalink / raw)
To: Jaegeuk Kim, linux-kernel, linux-f2fs-devel; +Cc: chao
On 8/5/26 09:28, Jaegeuk Kim via Linux-f2fs-devel wrote:
> The f2fs_evict_inode() can be called during the direct reclaim path, but
> __add_ino_entry requires allocating some memory. Since we don't need to
> do that in that context, let's migrate it in other workqueue context.
>
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> ---
> Change log from v1:
> - fix a bug on the wait logic
>
> fs/f2fs/checkpoint.c | 11 ++++++
> fs/f2fs/data.c | 13 ++++++-
> fs/f2fs/f2fs.h | 4 ++
> fs/f2fs/inode.c | 91 +++++++++++++++++++++++++++++++++++++++++---
> fs/f2fs/super.c | 9 ++++-
> 5 files changed, 121 insertions(+), 7 deletions(-)
>
> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
> index 064f5b537423..4413eccb5ecb 100644
> --- a/fs/f2fs/checkpoint.c
> +++ b/fs/f2fs/checkpoint.c
> @@ -766,6 +766,15 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
> spin_unlock(&im->ino_lock);
> }
>
> +static void f2fs_wait_for_inode_record(struct f2fs_sb_info *sbi, int mode)
> +{
> + if (mode != APPEND_INO && mode != UPDATE_INO)
> + return;
> +
> + /* Let's wait for some pending updates for APPEND_INO and UPDATE_INO. */
> + flush_workqueue(sbi->evict_wq);
> +}
> +
> void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
> {
> /* add new dirty ino entry into list */
> @@ -798,6 +807,8 @@ void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all)
> for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) {
> struct inode_management *im = &sbi->im[i];
>
> + f2fs_wait_for_inode_record(sbi, i);
> +
> spin_lock(&im->ino_lock);
> list_for_each_entry_safe(e, tmp, &im->ino_list, list) {
> list_del(&e->list);
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index c219ea76a3a7..6ae0eb37d20f 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -4558,13 +4558,24 @@ int f2fs_init_wq(struct f2fs_sb_info *sbi)
> {
> sbi->wq = alloc_workqueue("f2fs_wq", WQ_UNBOUND | WQ_HIGHPRI,
> num_online_cpus());
> - return sbi->wq ? 0 : -ENOMEM;
> + if (!sbi->wq)
> + return -ENOMEM;
> +
> + sbi->evict_wq = alloc_workqueue("f2fs_evict_wq",
> + WQ_UNBOUND | WQ_HIGHPRI, num_online_cpus());
> + if (!sbi->evict_wq) {
> + destroy_workqueue(sbi->wq);
> + return -ENOMEM;
> + }
> + return 0;
> }
>
> void f2fs_destroy_wq(struct f2fs_sb_info *sbi)
> {
> if (sbi->wq)
> destroy_workqueue(sbi->wq);
> + if (sbi->evict_wq)
> + destroy_workqueue(sbi->evict_wq);
> }
>
> int __init f2fs_init_bio_entry_cache(void)
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index c44908258dc1..54f9d3856b5c 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -2016,6 +2016,8 @@ struct f2fs_sb_info {
>
> struct workqueue_struct *wq; /* bio completion workqueue */
>
> + struct workqueue_struct *evict_wq; /* inode eviction workqueue */
> +
> /*
> * If we are in irq context, let's update error information into
> * on-disk superblock in the work.
> @@ -3875,6 +3877,8 @@ 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, struct f2fs_lock_context *lc);
> +int f2fs_init_evict_inode_work(void);
> +void f2fs_destroy_evict_inode_work(void);
>
> /*
> * namei.c
> diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
> index c95e0b126da4..0d30489cf083 100644
> --- a/fs/f2fs/inode.c
> +++ b/fs/f2fs/inode.c
> @@ -24,6 +24,18 @@
> extern const struct address_space_operations f2fs_compress_aops;
> #endif
>
> +#define NUM_PREALLOC_EVICT_INODE_WORK 8
> +
> +static struct kmem_cache *evict_inode_work_cache;
> +static mempool_t *evict_inode_work_pool;
> +
> +struct evict_inode_work {
> + struct work_struct work;
> + struct f2fs_sb_info *sbi;
> + nid_t ino;
> + unsigned int add_ino_entry_bits;
> +};
> +
> void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync)
> {
> if (is_inode_flag_set(inode, FI_NEW_INODE))
> @@ -637,6 +649,9 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
> inode->i_fop = &f2fs_dir_operations;
> inode->i_mapping->a_ops = &f2fs_dblock_aops;
> mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
> +
> + /* Let's prepare APPEND/UPDATE_INO before future access. */
> + flush_workqueue(sbi->evict_wq);
> } else if (S_ISLNK(inode->i_mode)) {
> if (file_is_encrypt(inode))
> inode->i_op = &f2fs_encrypted_symlink_inode_operations;
> @@ -854,6 +869,25 @@ void f2fs_remove_donate_inode(struct inode *inode)
> spin_unlock(&sbi->inode_lock[DONATE_INODE]);
> }
>
> +static void f2fs_record_inode_state(struct f2fs_sb_info *sbi, nid_t ino,
> + unsigned int bits)
> +{
> + if (bits & BIT(APPEND_INO))
> + f2fs_add_ino_entry(sbi, ino, APPEND_INO);
> + if (bits & BIT(UPDATE_INO))
> + f2fs_add_ino_entry(sbi, ino, UPDATE_INO);
> +}
> +
> +static void f2fs_evict_inode_work(struct work_struct *work)
> +{
> + struct evict_inode_work *ew =
> + container_of(work, struct evict_inode_work, work);
> +
> + f2fs_record_inode_state(ew->sbi, ew->ino, ew->add_ino_entry_bits);
> +
> + mempool_free(ew, evict_inode_work_pool);
> +}
> +
> /*
> * Called at the last iput() if i_nlink is zero
> */
> @@ -864,6 +898,7 @@ void f2fs_evict_inode(struct inode *inode)
> nid_t xnid = fi->i_xattr_nid;
> int err = 0;
> bool freeze_protected = false;
> + unsigned int record_bits = 0;
>
> f2fs_abort_atomic_write(inode, true);
>
> @@ -1003,12 +1038,32 @@ void f2fs_evict_inode(struct inode *inode)
> inode->i_ino);
> if (xnid)
> invalidate_mapping_pages(NODE_MAPPING(sbi), xnid, xnid);
> - if (inode->i_nlink) {
> - if (is_inode_flag_set(inode, FI_APPEND_WRITE))
> - f2fs_add_ino_entry(sbi, inode->i_ino, APPEND_INO);
> - if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
> - f2fs_add_ino_entry(sbi, inode->i_ino, UPDATE_INO);
> +
> + if (!inode->i_nlink)
> + goto skip_record;
> +
> + if (is_inode_flag_set(inode, FI_APPEND_WRITE))
> + record_bits = BIT(APPEND_INO);
> + if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
> + record_bits = BIT(UPDATE_INO);
> +
> + if (!record_bits)
> + goto skip_record;
> +
> + /* Let's do this in workqueue out of the direct reclaim path. */
> + if (current_is_kswapd()) {
> + f2fs_record_inode_state(sbi, inode->i_ino, record_bits);
> + } else {
> + struct evict_inode_work *ew =
> + mempool_alloc(evict_inode_work_pool, GFP_NOFS);
> +
> + ew->sbi = sbi;
> + ew->ino = inode->i_ino;
> + ew->add_ino_entry_bits = record_bits;
> + INIT_WORK(&ew->work, f2fs_evict_inode_work);
> + queue_work(sbi->evict_wq, &ew->work);
> }
> +skip_record:
What do you think of wrapping above codes into a static function for cleanup?
Thanks,
> if (is_inode_flag_set(inode, FI_FREE_NID)) {
> f2fs_alloc_nid_failed(sbi, inode->i_ino);
> clear_inode_flag(inode, FI_FREE_NID);
> @@ -1079,3 +1134,29 @@ void f2fs_handle_failed_inode(struct inode *inode, struct f2fs_lock_context *lc)
> /* iput will drop the inode object */
> iput(inode);
> }
> +
> +int __init f2fs_init_evict_inode_work(void)
> +{
> + evict_inode_work_cache =
> + kmem_cache_create("f2fs_evict_inode_work",
> + sizeof(struct evict_inode_work), 0, 0, NULL);
> + if (!evict_inode_work_cache)
> + goto fail;
> + evict_inode_work_pool =
> + mempool_create_slab_pool(NUM_PREALLOC_EVICT_INODE_WORK,
> + evict_inode_work_cache);
> + if (!evict_inode_work_pool)
> + goto fail_free_cache;
> + return 0;
> +
> +fail_free_cache:
> + kmem_cache_destroy(evict_inode_work_cache);
> +fail:
> + return -ENOMEM;
> +}
> +
> +void f2fs_destroy_evict_inode_work(void)
> +{
> + mempool_destroy(evict_inode_work_pool);
> + kmem_cache_destroy(evict_inode_work_cache);
> +}
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 67abbf7ab477..6b55c30f0daa 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -5763,10 +5763,16 @@ static int __init init_f2fs_fs(void)
> err = f2fs_init_xattr_cache();
> if (err)
> goto free_casefold_cache;
> - err = register_filesystem(&f2fs_fs_type);
> + err = f2fs_init_evict_inode_work();
> if (err)
> goto free_xattr_cache;
> + err = register_filesystem(&f2fs_fs_type);
> + if (err)
> + goto free_evict_inode_cache;
> return 0;
> +
> +free_evict_inode_cache:
> + f2fs_destroy_evict_inode_work();
> free_xattr_cache:
> f2fs_destroy_xattr_cache();
> free_casefold_cache:
> @@ -5809,6 +5815,7 @@ static int __init init_f2fs_fs(void)
> static void __exit exit_f2fs_fs(void)
> {
> unregister_filesystem(&f2fs_fs_type);
> + f2fs_destroy_evict_inode_work();
> f2fs_destroy_xattr_cache();
> f2fs_destroy_casefold_cache();
> f2fs_destroy_compress_cache();
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: call __add_ino_entry out of the eviction path
2026-08-06 2:38 ` Chao Yu
@ 2026-08-07 22:03 ` Jaegeuk Kim
0 siblings, 0 replies; 5+ messages in thread
From: Jaegeuk Kim @ 2026-08-07 22:03 UTC (permalink / raw)
To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel
On 08/06, Chao Yu via Linux-f2fs-devel wrote:
> On 8/5/26 09:28, Jaegeuk Kim via Linux-f2fs-devel wrote:
> > The f2fs_evict_inode() can be called during the direct reclaim path, but
> > __add_ino_entry requires allocating some memory. Since we don't need to
> > do that in that context, let's migrate it in other workqueue context.
> >
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > ---
> > Change log from v1:
> > - fix a bug on the wait logic
> >
> > fs/f2fs/checkpoint.c | 11 ++++++
> > fs/f2fs/data.c | 13 ++++++-
> > fs/f2fs/f2fs.h | 4 ++
> > fs/f2fs/inode.c | 91 +++++++++++++++++++++++++++++++++++++++++---
> > fs/f2fs/super.c | 9 ++++-
> > 5 files changed, 121 insertions(+), 7 deletions(-)
> >
> > diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
> > index 064f5b537423..4413eccb5ecb 100644
> > --- a/fs/f2fs/checkpoint.c
> > +++ b/fs/f2fs/checkpoint.c
> > @@ -766,6 +766,15 @@ static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
> > spin_unlock(&im->ino_lock);
> > }
> >
> > +static void f2fs_wait_for_inode_record(struct f2fs_sb_info *sbi, int mode)
> > +{
> > + if (mode != APPEND_INO && mode != UPDATE_INO)
> > + return;
> > +
> > + /* Let's wait for some pending updates for APPEND_INO and UPDATE_INO. */
> > + flush_workqueue(sbi->evict_wq);
> > +}
> > +
> > void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
> > {
> > /* add new dirty ino entry into list */
> > @@ -798,6 +807,8 @@ void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all)
> > for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) {
> > struct inode_management *im = &sbi->im[i];
> >
> > + f2fs_wait_for_inode_record(sbi, i);
> > +
> > spin_lock(&im->ino_lock);
> > list_for_each_entry_safe(e, tmp, &im->ino_list, list) {
> > list_del(&e->list);
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > index c219ea76a3a7..6ae0eb37d20f 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -4558,13 +4558,24 @@ int f2fs_init_wq(struct f2fs_sb_info *sbi)
> > {
> > sbi->wq = alloc_workqueue("f2fs_wq", WQ_UNBOUND | WQ_HIGHPRI,
> > num_online_cpus());
> > - return sbi->wq ? 0 : -ENOMEM;
> > + if (!sbi->wq)
> > + return -ENOMEM;
> > +
> > + sbi->evict_wq = alloc_workqueue("f2fs_evict_wq",
> > + WQ_UNBOUND | WQ_HIGHPRI, num_online_cpus());
> > + if (!sbi->evict_wq) {
> > + destroy_workqueue(sbi->wq);
> > + return -ENOMEM;
> > + }
> > + return 0;
> > }
> >
> > void f2fs_destroy_wq(struct f2fs_sb_info *sbi)
> > {
> > if (sbi->wq)
> > destroy_workqueue(sbi->wq);
> > + if (sbi->evict_wq)
> > + destroy_workqueue(sbi->evict_wq);
> > }
> >
> > int __init f2fs_init_bio_entry_cache(void)
> > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> > index c44908258dc1..54f9d3856b5c 100644
> > --- a/fs/f2fs/f2fs.h
> > +++ b/fs/f2fs/f2fs.h
> > @@ -2016,6 +2016,8 @@ struct f2fs_sb_info {
> >
> > struct workqueue_struct *wq; /* bio completion workqueue */
> >
> > + struct workqueue_struct *evict_wq; /* inode eviction workqueue */
> > +
> > /*
> > * If we are in irq context, let's update error information into
> > * on-disk superblock in the work.
> > @@ -3875,6 +3877,8 @@ 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, struct f2fs_lock_context *lc);
> > +int f2fs_init_evict_inode_work(void);
> > +void f2fs_destroy_evict_inode_work(void);
> >
> > /*
> > * namei.c
> > diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
> > index c95e0b126da4..0d30489cf083 100644
> > --- a/fs/f2fs/inode.c
> > +++ b/fs/f2fs/inode.c
> > @@ -24,6 +24,18 @@
> > extern const struct address_space_operations f2fs_compress_aops;
> > #endif
> >
> > +#define NUM_PREALLOC_EVICT_INODE_WORK 8
> > +
> > +static struct kmem_cache *evict_inode_work_cache;
> > +static mempool_t *evict_inode_work_pool;
> > +
> > +struct evict_inode_work {
> > + struct work_struct work;
> > + struct f2fs_sb_info *sbi;
> > + nid_t ino;
> > + unsigned int add_ino_entry_bits;
> > +};
> > +
> > void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync)
> > {
> > if (is_inode_flag_set(inode, FI_NEW_INODE))
> > @@ -637,6 +649,9 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
> > inode->i_fop = &f2fs_dir_operations;
> > inode->i_mapping->a_ops = &f2fs_dblock_aops;
> > mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
> > +
> > + /* Let's prepare APPEND/UPDATE_INO before future access. */
> > + flush_workqueue(sbi->evict_wq);
> > } else if (S_ISLNK(inode->i_mode)) {
> > if (file_is_encrypt(inode))
> > inode->i_op = &f2fs_encrypted_symlink_inode_operations;
> > @@ -854,6 +869,25 @@ void f2fs_remove_donate_inode(struct inode *inode)
> > spin_unlock(&sbi->inode_lock[DONATE_INODE]);
> > }
> >
> > +static void f2fs_record_inode_state(struct f2fs_sb_info *sbi, nid_t ino,
> > + unsigned int bits)
> > +{
> > + if (bits & BIT(APPEND_INO))
> > + f2fs_add_ino_entry(sbi, ino, APPEND_INO);
> > + if (bits & BIT(UPDATE_INO))
> > + f2fs_add_ino_entry(sbi, ino, UPDATE_INO);
> > +}
> > +
> > +static void f2fs_evict_inode_work(struct work_struct *work)
> > +{
> > + struct evict_inode_work *ew =
> > + container_of(work, struct evict_inode_work, work);
> > +
> > + f2fs_record_inode_state(ew->sbi, ew->ino, ew->add_ino_entry_bits);
> > +
> > + mempool_free(ew, evict_inode_work_pool);
> > +}
> > +
> > /*
> > * Called at the last iput() if i_nlink is zero
> > */
> > @@ -864,6 +898,7 @@ void f2fs_evict_inode(struct inode *inode)
> > nid_t xnid = fi->i_xattr_nid;
> > int err = 0;
> > bool freeze_protected = false;
> > + unsigned int record_bits = 0;
> >
> > f2fs_abort_atomic_write(inode, true);
> >
> > @@ -1003,12 +1038,32 @@ void f2fs_evict_inode(struct inode *inode)
> > inode->i_ino);
> > if (xnid)
> > invalidate_mapping_pages(NODE_MAPPING(sbi), xnid, xnid);
> > - if (inode->i_nlink) {
> > - if (is_inode_flag_set(inode, FI_APPEND_WRITE))
> > - f2fs_add_ino_entry(sbi, inode->i_ino, APPEND_INO);
> > - if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
> > - f2fs_add_ino_entry(sbi, inode->i_ino, UPDATE_INO);
> > +
> > + if (!inode->i_nlink)
> > + goto skip_record;
> > +
> > + if (is_inode_flag_set(inode, FI_APPEND_WRITE))
> > + record_bits = BIT(APPEND_INO);
> > + if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
> > + record_bits = BIT(UPDATE_INO);
> > +
> > + if (!record_bits)
> > + goto skip_record;
> > +
> > + /* Let's do this in workqueue out of the direct reclaim path. */
> > + if (current_is_kswapd()) {
> > + f2fs_record_inode_state(sbi, inode->i_ino, record_bits);
> > + } else {
> > + struct evict_inode_work *ew =
> > + mempool_alloc(evict_inode_work_pool, GFP_NOFS);
> > +
> > + ew->sbi = sbi;
> > + ew->ino = inode->i_ino;
> > + ew->add_ino_entry_bits = record_bits;
> > + INIT_WORK(&ew->work, f2fs_evict_inode_work);
> > + queue_work(sbi->evict_wq, &ew->work);
> > }
> > +skip_record:
>
> What do you think of wrapping above codes into a static function for cleanup?
Sumbitted another patch series having the refactoring patch. Thanks,
>
> Thanks,
>
> > if (is_inode_flag_set(inode, FI_FREE_NID)) {
> > f2fs_alloc_nid_failed(sbi, inode->i_ino);
> > clear_inode_flag(inode, FI_FREE_NID);
> > @@ -1079,3 +1134,29 @@ void f2fs_handle_failed_inode(struct inode *inode, struct f2fs_lock_context *lc)
> > /* iput will drop the inode object */
> > iput(inode);
> > }
> > +
> > +int __init f2fs_init_evict_inode_work(void)
> > +{
> > + evict_inode_work_cache =
> > + kmem_cache_create("f2fs_evict_inode_work",
> > + sizeof(struct evict_inode_work), 0, 0, NULL);
> > + if (!evict_inode_work_cache)
> > + goto fail;
> > + evict_inode_work_pool =
> > + mempool_create_slab_pool(NUM_PREALLOC_EVICT_INODE_WORK,
> > + evict_inode_work_cache);
> > + if (!evict_inode_work_pool)
> > + goto fail_free_cache;
> > + return 0;
> > +
> > +fail_free_cache:
> > + kmem_cache_destroy(evict_inode_work_cache);
> > +fail:
> > + return -ENOMEM;
> > +}
> > +
> > +void f2fs_destroy_evict_inode_work(void)
> > +{
> > + mempool_destroy(evict_inode_work_pool);
> > + kmem_cache_destroy(evict_inode_work_cache);
> > +}
> > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> > index 67abbf7ab477..6b55c30f0daa 100644
> > --- a/fs/f2fs/super.c
> > +++ b/fs/f2fs/super.c
> > @@ -5763,10 +5763,16 @@ static int __init init_f2fs_fs(void)
> > err = f2fs_init_xattr_cache();
> > if (err)
> > goto free_casefold_cache;
> > - err = register_filesystem(&f2fs_fs_type);
> > + err = f2fs_init_evict_inode_work();
> > if (err)
> > goto free_xattr_cache;
> > + err = register_filesystem(&f2fs_fs_type);
> > + if (err)
> > + goto free_evict_inode_cache;
> > return 0;
> > +
> > +free_evict_inode_cache:
> > + f2fs_destroy_evict_inode_work();
> > free_xattr_cache:
> > f2fs_destroy_xattr_cache();
> > free_casefold_cache:
> > @@ -5809,6 +5815,7 @@ static int __init init_f2fs_fs(void)
> > static void __exit exit_f2fs_fs(void)
> > {
> > unregister_filesystem(&f2fs_fs_type);
> > + f2fs_destroy_evict_inode_work();
> > f2fs_destroy_xattr_cache();
> > f2fs_destroy_casefold_cache();
> > f2fs_destroy_compress_cache();
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] f2fs: call __add_ino_entry out of the eviction path
2026-08-04 0:20 [PATCH] f2fs: call __add_ino_entry out of the eviction path Jaegeuk Kim
2026-08-05 1:28 ` [f2fs-dev] [PATCH v2] " Jaegeuk Kim
@ 2026-08-16 12:06 ` kernel test robot
1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2026-08-16 12:06 UTC (permalink / raw)
To: Jaegeuk Kim, linux-kernel, linux-f2fs-devel
Cc: llvm, oe-kbuild-all, Jaegeuk Kim
Hi Jaegeuk,
kernel test robot noticed the following build errors:
[auto build test ERROR on v7.2-rc7]
[also build test ERROR on linus/master]
[cannot apply to jaegeuk-f2fs/dev-test jaegeuk-f2fs/dev next-20260814]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jaegeuk-Kim/f2fs-call-__add_ino_entry-out-of-the-eviction-path/20260815-151820
base: v7.2-rc7
patch link: https://lore.kernel.org/r/20260804002027.2196300-1-jaegeuk%40kernel.org
patch subject: [PATCH] f2fs: call __add_ino_entry out of the eviction path
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260816/202608161433.5IIhxngb-lkp@intel.com/config)
compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260816/202608161433.5IIhxngb-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202608161433.5IIhxngb-lkp@intel.com/
All errors (new ones prefixed by >>):
>> fs/f2fs/inode.c:1051:6: error: call to undeclared function 'current_is_kswapd'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
1051 | if (current_is_kswapd()) {
| ^
1 error generated.
vim +/current_is_kswapd +1051 fs/f2fs/inode.c
887
888 /*
889 * Called at the last iput() if i_nlink is zero
890 */
891 void f2fs_evict_inode(struct inode *inode)
892 {
893 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
894 struct f2fs_inode_info *fi = F2FS_I(inode);
895 nid_t xnid = fi->i_xattr_nid;
896 int err = 0;
897 bool freeze_protected = false;
898 unsigned int record_bits = 0;
899
900 f2fs_abort_atomic_write(inode, true);
901
902 if (fi->cow_inode && f2fs_is_cow_file(fi->cow_inode)) {
903 struct inode *cow_inode = fi->cow_inode;
904
905 f2fs_down_write(&F2FS_I(cow_inode)->i_sem);
906 clear_inode_flag(cow_inode, FI_COW_FILE);
907 F2FS_I(cow_inode)->atomic_inode = NULL;
908 fi->cow_inode = NULL;
909 f2fs_up_write(&F2FS_I(cow_inode)->i_sem);
910
911 iput(cow_inode);
912 }
913
914 trace_f2fs_evict_inode(inode);
915 truncate_inode_pages_final(&inode->i_data);
916
917 if ((inode->i_nlink || is_bad_inode(inode)) &&
918 test_opt(sbi, COMPRESS_CACHE) && f2fs_compressed_file(inode))
919 f2fs_invalidate_compress_pages(sbi, inode->i_ino);
920
921 if (inode->i_ino == F2FS_NODE_INO(sbi) ||
922 inode->i_ino == F2FS_META_INO(sbi) ||
923 inode->i_ino == F2FS_COMPRESS_INO(sbi))
924 goto out_clear;
925
926 f2fs_bug_on(sbi, get_dirty_pages(inode));
927 f2fs_remove_dirty_inode(inode);
928 f2fs_remove_donate_inode(inode);
929
930 if (!IS_DEVICE_ALIASING(inode))
931 f2fs_destroy_extent_tree(inode);
932
933 if (inode->i_nlink || is_bad_inode(inode))
934 goto no_delete;
935
936 err = f2fs_dquot_initialize(inode);
937 if (err) {
938 err = 0;
939 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
940 }
941
942 f2fs_remove_ino_entry(sbi, inode->i_ino, APPEND_INO);
943 f2fs_remove_ino_entry(sbi, inode->i_ino, UPDATE_INO);
944 f2fs_remove_ino_entry(sbi, inode->i_ino, FLUSH_INO);
945
946 if (!is_sbi_flag_set(sbi, SBI_IS_FREEZING)) {
947 sb_start_intwrite(inode->i_sb);
948 freeze_protected = true;
949 }
950 set_inode_flag(inode, FI_NO_ALLOC);
951 i_size_write(inode, 0);
952 retry:
953 if (F2FS_HAS_BLOCKS(inode))
954 err = f2fs_truncate(inode);
955
956 if (time_to_inject(sbi, FAULT_EVICT_INODE))
957 err = -EIO;
958
959 if (!err) {
960 struct f2fs_lock_context lc;
961
962 f2fs_lock_op(sbi, &lc);
963 err = f2fs_remove_inode_page(inode);
964 f2fs_unlock_op(sbi, &lc);
965 if (err == -ENOENT) {
966 err = 0;
967
968 /*
969 * in fuzzed image, another node may has the same
970 * block address as inode's, if it was truncated
971 * previously, truncation of inode node will fail.
972 */
973 if (is_inode_flag_set(inode, FI_DIRTY_INODE)) {
974 f2fs_warn(F2FS_I_SB(inode),
975 "f2fs_evict_inode: inconsistent node id, ino:%llu",
976 inode->i_ino);
977 f2fs_inode_synced(inode);
978 set_sbi_flag(sbi, SBI_NEED_FSCK);
979 }
980 }
981 }
982
983 /* give more chances, if ENOMEM case */
984 if (err == -ENOMEM) {
985 err = 0;
986 goto retry;
987 }
988
989 if (IS_DEVICE_ALIASING(inode))
990 f2fs_destroy_extent_tree(inode);
991
992 if (err) {
993 f2fs_update_inode_page(inode);
994 if (dquot_initialize_needed(inode))
995 set_sbi_flag(sbi, SBI_QUOTA_NEED_REPAIR);
996
997 /*
998 * If both f2fs_truncate() and f2fs_update_inode_page() failed
999 * due to fuzzed corrupted inode, call f2fs_inode_synced() to
1000 * avoid triggering later f2fs_bug_on().
1001 */
1002 if (is_inode_flag_set(inode, FI_DIRTY_INODE)) {
1003 f2fs_warn(sbi,
1004 "f2fs_evict_inode: inode is dirty, ino:%llu",
1005 inode->i_ino);
1006 f2fs_inode_synced(inode);
1007 set_sbi_flag(sbi, SBI_NEED_FSCK);
1008 }
1009 }
1010 if (freeze_protected)
1011 sb_end_intwrite(inode->i_sb);
1012 no_delete:
1013 dquot_drop(inode);
1014
1015 stat_dec_inline_xattr(inode);
1016 stat_dec_inline_dir(inode);
1017 stat_dec_inline_inode(inode);
1018 stat_dec_compr_inode(inode);
1019 stat_sub_compr_blocks(inode,
1020 atomic_read(&fi->i_compr_blocks));
1021
1022 if (likely(!f2fs_cp_error(sbi) &&
1023 !is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
1024 f2fs_bug_on(sbi, is_inode_flag_set(inode, FI_DIRTY_INODE));
1025
1026 /*
1027 * anyway, it needs to remove the inode from sbi->inode_list[DIRTY_META]
1028 * list to avoid UAF in f2fs_sync_inode_meta() during checkpoint.
1029 */
1030 f2fs_inode_synced(inode);
1031
1032 /* for the case f2fs_new_inode() was failed, .i_ino is zero, skip it */
1033 if (inode->i_ino)
1034 invalidate_mapping_pages(NODE_MAPPING(sbi), inode->i_ino,
1035 inode->i_ino);
1036 if (xnid)
1037 invalidate_mapping_pages(NODE_MAPPING(sbi), xnid, xnid);
1038
1039 if (!inode->i_nlink)
1040 goto skip_record;
1041
1042 if (is_inode_flag_set(inode, FI_APPEND_WRITE))
1043 record_bits = BIT(APPEND_INO);
1044 if (is_inode_flag_set(inode, FI_UPDATE_WRITE))
1045 record_bits = BIT(UPDATE_INO);
1046
1047 if (!record_bits)
1048 goto skip_record;
1049
1050 /* Let's do this in workqueue out of the direct reclaim path. */
> 1051 if (current_is_kswapd()) {
1052 f2fs_record_inode_state(sbi, inode->i_ino, record_bits);
1053 } else {
1054 struct evict_inode_work *ew =
1055 mempool_alloc(evict_inode_work_pool, GFP_NOFS);
1056
1057 ew->sbi = sbi;
1058 ew->ino = inode->i_ino;
1059 ew->add_ino_entry_bits = record_bits;
1060 INIT_WORK(&ew->work, f2fs_evict_inode_work);
1061 queue_work(sbi->evict_wq, &ew->work);
1062 }
1063 skip_record:
1064 if (is_inode_flag_set(inode, FI_FREE_NID)) {
1065 f2fs_alloc_nid_failed(sbi, inode->i_ino);
1066 clear_inode_flag(inode, FI_FREE_NID);
1067 } else {
1068 /*
1069 * If xattr nid is corrupted, we can reach out error condition,
1070 * err & !f2fs_exist_written_data(sbi, inode->i_ino, ORPHAN_INO)).
1071 * In that case, f2fs_check_nid_range() is enough to give a clue.
1072 */
1073 }
1074 out_clear:
1075 fscrypt_put_encryption_info(inode);
1076 clear_inode(inode);
1077 }
1078
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-16 12:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-04 0:20 [PATCH] f2fs: call __add_ino_entry out of the eviction path Jaegeuk Kim
2026-08-05 1:28 ` [f2fs-dev] [PATCH v2] " Jaegeuk Kim
2026-08-06 2:38 ` Chao Yu
2026-08-07 22:03 ` Jaegeuk Kim
2026-08-16 12:06 ` [PATCH] " kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®