Skip to contentSkip to conversation

f2fs: introduce metadata cache

PATCH Superseded Chao Yu 3 participants 27 messages Sep 16 – Sep 17 Page 1 of 2

Subsystems (2)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

v8 cover f2fs: introduce metadata cache

This patchset introduces a self-managed metadata block cache in f2fs, decoupling meta blocks, node blocks, and compressed data blocks from the Linux VFS page cache and fake internal inodes.

=== 1. Background & Motivation ===

Currently, F2FS uses fake VFS inodes (meta_inode, node_inode, and compress_inode) to manage internal block caching through the VFS page cache. Because of this implementation, the f2fs block size was historically coupled to the kernel page size.

We now want to unbind block size from page size to support configurations where block size <= PAGE_SIZE (e.g., mounting a 4KB-block F2FS image on a 16KB or 64KB page system).

One possible approach is to continue using the VFS page cache to store metadata blocks. However, doing so introduces three major architectural issues (illustrated by a 4KB block on a 16KB page system):

1. Memory Overhead:
Metadata access patterns are typically random and sparse. Caching a single 4KB metadata block inside a page cache folio forces the allocation of an entire 16KB folio, resulting in 4x memory waste.

2. Folio and Sub-block Conversion Complexity:
Using larger folios requires tracking individual sub-block dirty/uptodate states within each folio and performing index-to-offset conversions across function boundaries. Because core metadata structures (e.g., f2fs_checkpoint, f2fs_sit_block, f2fs_nat_block, f2fs_summary_block, f2fs_node) are accessed extensively throughout the filesystem, this sub-block management and offset calculation complexity would spread across the entire F2FS codebase.

3. Lock Contention:
Multiple independent node blocks (e.g., dnode blocks belonging to different files) can reside within the same folio. Concurrent fsync() calls on unrelated files would contend on the same folio_lock(), serializing metadata updates and degrading multi-threaded performance.

Decoupling metadata caching from PAGE_SIZE by allocating exact block-sized cache entries is the critical first step toward supporting 4KB-block F2FS images on 16KB/64KB page systems.

=== 2. Metadata Cache Architecture & Design ===

This patchset introduces a dedicated, block-size-aligned caching infrastructure with the following key components:

- Block-Size Aligned Allocation:
Allocates memory buffers matching exactly the filesystem block size (4KB or 16KB) via kzalloc(), fully independent of the host architecture's PAGE_SIZE.

- Radix Tree Indexing with Fast Tag Scanning:
Each cache instance (META_CACHE, NODE_CACHE, COMPRESS_CACHE) indexes cached blocks via a radix tree (keyed by Physical Block Address for meta/ compress cache, and Node ID for node cache). Radix tree tags (F2FS_CACHE_TAG_DIRTY, F2FS_CACHE_TAG_WRITEBACK) provide O(1) batch gang lookups for flushing and writeback without dual-list shuffling.

- Lightweight Bit-Locking:
Individual entries use atomic bit locks (F2FS_BLOCK_LOCKED via wait_on_bit_lock() / clear_and_wake_up_bit()) rather than heavyweight embedded mutexes/semaphores, minimizing memory footprint per entry.

- Direct BIO Read/Write & BIO Merging:
Decouples metadata/node I/O from VFS address spaces by submitting direct BIOs (f2fs_submit_cache_read / f2fs_submit_cache_write) with chained adjacent vector merging (entry->next_entry) and dedicated completion handlers.

- Memory Reclamation Shrinker:
Integrates with the kernel shrinker subsystem via a 3-phase isolation algorithm (isolate unreferenced clean entries -> truncate from radix tree under lock -> splice un-reclaimed entries back to LRU) to safely reclaim clean cached blocks under system memory pressure.

- Background Writeback Kthread & Checkpoint Integration:
Provides a dedicated background kthread (f2fs_writeback-X:Y) for periodic dirty cache flushing, combined with synchronous flushing during checkpoint commit.

- Fault Injection, Tracepoints & Debugfs Observability:
Integrates FAULT_KALLOC fault injection, tracepoints for cache state transitions and batch writeback, and per-cache memory breakdowns in debugfs.

=== 3. Patchset Organization ===

- Patch 01: Implement the core metadata cache infrastructure & direct BIO I/O.
- Patch 02: Initialize and teardown META_CACHE in sb_info.
- Patch 03: Integrate metadata cache into the memory shrinker subsystem.
- Patch 04: Introduce the background writeback kernel thread.
- Patch 05: Migrate metadata block caching (SIT, NAT, SSA, CP, recovery, GC) from meta_inode to META_CACHE.
- Patch 06: Initialize and teardown NODE_CACHE in sb_info.
- Patch 07: Migrate node and inode block caching from node_inode to NODE_CACHE.
- Patch 08: Initialize and teardown COMPRESS_CACHE in sb_info.
- Patch 09: Migrate compressed cluster caching from compress_inode to COMPRESS_CACHE.
- Patch 10: Add fault injection support for cache allocation paths.
- Patch 11: Introduce ftrace tracepoints for cache dirty and writeback events.
- Patch 12: Expose per-cache memory usage in debugfs.

Changelog:

v7->v8
- clean up comments in checkpoint.c based on Jaegeuk's patch
- fix to detect readonly, freezing status in f2fs_writeback thread
- drop unused cache_wb_trigger in f2fs_cache_kthread
- fix to access cache_thread->cache_wb_interval in wrtieback loop correctly
- avoid to handle error paths for f2fs_init_cache()
- fix typo FAULT_KMALLOC in commit message in "f2fs: cache: support fault injection"
- add missing tracepoint in f2fs_writeback_node_caches()
- drop undefined f2fs_writeback_cache()
- clean up IS_{META,NODE,COMPRESS}_CACHE() macro
- drop redundant f2fs_{start,stop}_cache_wb_thread() declaration

Chao Yu (12):
f2fs: cache: implement metadata cache
f2fs: cache: initialize meta cache
f2fs: cache: introduce shrinker
f2fs: cache: introduce writeback thread
f2fs: cache: use meta cache
f2fs: cache: initialize node cache
f2fs: cache: use node cache
f2fs: cache: initialize compress cache
f2fs: cache: use compress cache
f2fs: cache: support fault injection
f2fs: cache: introduce tracepoints
f2fs: cache: show per-cache usage in debugfs

 Documentation/ABI/testing/sysfs-fs-f2fs |    6 +
 fs/f2fs/Makefile                        |    2 +-
 fs/f2fs/acl.c                           |   26 +-
 fs/f2fs/acl.h                           |    8 +-
 fs/f2fs/cache.c                         |  721 +++++++++++++++
 fs/f2fs/cache.h                         |  238 +++++
 fs/f2fs/checkpoint.c                    |  448 +++++----
 fs/f2fs/compress.c                      |  165 ++--
 fs/f2fs/data.c                          |  521 +++++++----
 fs/f2fs/debug.c                         |   70 +-
 fs/f2fs/dir.c                           |  170 ++--
 fs/f2fs/extent_cache.c                  |   14 +-
 fs/f2fs/f2fs.h                          |  376 ++++----
 fs/f2fs/file.c                          |   82 +-
 fs/f2fs/gc.c                            |  185 ++--
 fs/f2fs/inline.c                        |  284 +++---
 fs/f2fs/inode.c                         |  217 ++---
 fs/f2fs/iostat.h                        |   11 +
 fs/f2fs/namei.c                         |  114 +--
 fs/f2fs/node.c                          | 1104 +++++++++++------------
 fs/f2fs/node.h                          |  118 +--
 fs/f2fs/recovery.c                      |  251 +++---
 fs/f2fs/segment.c                       |  305 ++++---
 fs/f2fs/segment.h                       |   37 +-
 fs/f2fs/shrinker.c                      |   14 +
 fs/f2fs/super.c                         |  140 ++-
 fs/f2fs/sysfs.c                         |   15 +-
 fs/f2fs/xattr.c                         |  123 ++-
 fs/f2fs/xattr.h                         |   12 +-
 include/linux/f2fs_fs.h                 |    3 -
 include/trace/events/f2fs.h             |   71 ++
 31 files changed, 3520 insertions(+), 2331 deletions(-)
 create mode 100644 fs/f2fs/cache.c
 create mode 100644 fs/f2fs/cache.h
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH v8 1/12 f2fs: cache: implement metadata cache

From: Chao Yu <[email protected]>

This patch introduces the core metadata block caching infrastructure to manage f2fs metadata independently of the page cache.

It implements:
- core cache APIs: get, create, put, drop, backed by a radix tree and a single global LRU list.
- support multiple status of cached block: LOCKED, UPTODATE, DIRTY, WRITEBACK, INLINE.
- internal bio based read/write helpers with adjacent block vector merging.

---
 fs/f2fs/Makefile |   2 +-
 fs/f2fs/cache.c  | 539 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/f2fs/cache.h  | 196 +++++++++++++++++
 fs/f2fs/data.c   | 281 +++++++++++++++++++++---
 fs/f2fs/f2fs.h   |  24 +++
 fs/f2fs/iostat.h |  11 +
 6 files changed, 1026 insertions(+), 27 deletions(-)
 create mode 100644 fs/f2fs/cache.c
 create mode 100644 fs/f2fs/cache.h
fs/f2fs/Makefile +1 -1
index 8a7322d229e4..fbf49c30b066 100644
@@ -3,7 +3,7 @@ obj-$(CONFIG_F2FS_FS) += f2fs.o
 
 f2fs-y		:= dir.o file.o inode.o namei.o hash.o super.o inline.o
 f2fs-y		+= checkpoint.o gc.o data.o node.o segment.o recovery.o
-f2fs-y		+= shrinker.o extent_cache.o sysfs.o
+f2fs-y		+= shrinker.o extent_cache.o sysfs.o cache.o
 f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o
 f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o
 f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
fs/f2fs/cache.c new file +539 -0

539 lines not on this page · raw message

fs/f2fs/cache.h new file +196 -0

196 lines not on this page · raw message

fs/f2fs/data.c +255 -26

346 lines not on this page · raw message

fs/f2fs/f2fs.h +24 -0
index ebc621f302e1..c0c7d51c830f 100644
@@ -222,6 +222,8 @@ struct f2fs_rwsem {
 #endif
 };
 
+#include "cache.h"
+
 struct f2fs_mount_info {
 	unsigned long long opt;
 	block_t root_reserved_blocks;	/* root reserved blocks */
@@ -1362,8 +1364,10 @@ struct f2fs_io_info {
 	unsigned int in_list:1;		/* indicate fio is in io_list */
 	unsigned int is_por:1;		/* indicate IO is from recovery or not */
 	unsigned int meta_gc:1;		/* require meta inode GC */
+	unsigned int is_cache:1;	/* indicate IO is from internal cache */
 	enum iostat_type io_type;	/* io type */
 	struct writeback_control *io_wbc; /* writeback control */
+	struct f2fs_cached_block *cache_entry;
 	struct bio **bio;		/* bio for ipu */
 	sector_t *last_block;		/* last block number in bio */
 };
@@ -1773,6 +1777,12 @@ struct f2fs_gc_kthread {
 	unsigned int boost_gc_greedy;
 };
 
+struct f2fs_bio {
+	struct work_struct work;
+	struct f2fs_cached_block *entry;
+	struct bio bio;
+};
+
 struct f2fs_sb_info {
 	struct super_block *sb;			/* pointer to VFS super block */
 	struct proc_dir_entry *s_proc;		/* proc entry */
@@ -2381,6 +2391,16 @@ static inline bool is_node_folio(struct f2fs_sb_info *sbi, struct folio *folio)
 	return folio->mapping == NODE_MAPPING(sbi);
 }
 
+static inline struct f2fs_bio *F2FS_BIO(struct bio *bio)
+{
+	return container_of(bio, struct f2fs_bio, bio);
+}
+
+static inline bool f2fs_is_cache_bio(struct bio *bio)
+{
+	return F2FS_BIO(bio)->entry != NULL;
+}
+
 static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
 {
 	return test_bit(type, &sbi->s_flag);
@@ -4312,6 +4332,8 @@ void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
 				nid_t ino, enum page_type type);
 void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
 				struct folio *folio, enum page_type type);
+bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
+				enum page_type type);
 void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
 					struct bio **bio, struct folio *folio);
 void f2fs_submit_all_merged_ipu_writes(struct f2fs_sb_info *sbi);
@@ -4319,6 +4341,8 @@ void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
 int f2fs_submit_page_bio(struct f2fs_io_info *fio);
 int f2fs_merge_page_bio(struct f2fs_io_info *fio);
 void f2fs_submit_page_write(struct f2fs_io_info *fio);
+int f2fs_submit_cache_read(struct f2fs_io_info *fio);
+void f2fs_submit_cache_write(struct f2fs_io_info *fio);
 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
 		block_t blk_addr, sector_t *sector);
 int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
fs/f2fs/iostat.h +11 -0
index 2025225b5bed..61c6bc8e3119 100644
@@ -60,6 +60,13 @@ static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
 	return iostat_ctx->post_read_ctx;
 }
 
+static inline void iostat_set_post_read_ctx(struct bio *bio, void *ctx)
+{
+	struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
+
+	iostat_ctx->post_read_ctx = ctx;
+}
+
 extern void iostat_update_and_unbind_ctx(struct bio *bio);
 extern void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
 		struct bio *bio, struct bio_post_read_ctx *ctx);
@@ -81,6 +88,10 @@ static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
 {
 	return bio->bi_private;
 }
+static inline void iostat_set_post_read_ctx(struct bio *bio, void *ctx)
+{
+	bio->bi_private = ctx;
+}
 static inline int f2fs_init_iostat_processing(void) { return 0; }
 static inline void f2fs_destroy_iostat_processing(void) {}
 static inline int f2fs_init_iostat(struct f2fs_sb_info *sbi) { return 0; }
Signature · 1 line
2.49.0
Reviewed-by on v8 1/12
#2 lore raw

Re: [f2fs-dev] [PATCH v8 01/12] f2fs: cache: implement metadata cache

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 6 lines · 于2026年9月16日周三 09:59写道:

From: Chao Yu <[email protected]>

This patch introduces the core metadata block caching infrastructure to manage f2fs metadata independently of the page cache.

Quoted 8 lines

It implements:
- core cache APIs: get, create, put, drop, backed by a radix tree and a single global LRU list.
- support multiple status of cached block: LOCKED, UPTODATE, DIRTY, WRITEBACK, INLINE.
- internal bio based read/write helpers with adjacent block vector merging.

thanks!

Quoted 1,241 lines
---
 fs/f2fs/Makefile |   2 +-
 fs/f2fs/cache.c  | 539 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/f2fs/cache.h  | 196 +++++++++++++++++
 fs/f2fs/data.c   | 281 +++++++++++++++++++++---
 fs/f2fs/f2fs.h   |  24 +++
 fs/f2fs/iostat.h |  11 +
 6 files changed, 1026 insertions(+), 27 deletions(-)
 create mode 100644 fs/f2fs/cache.c
 create mode 100644 fs/f2fs/cache.h
fs/f2fs/Makefile +1 -1
index 8a7322d229e4..fbf49c30b066 100644
@@ -3,7 +3,7 @@ obj-$(CONFIG_F2FS_FS) += f2fs.o
 
 f2fs-y         := dir.o file.o inode.o namei.o hash.o super.o inline.o
 f2fs-y         += checkpoint.o gc.o data.o node.o segment.o recovery.o
-f2fs-y         += shrinker.o extent_cache.o sysfs.o
+f2fs-y         += shrinker.o extent_cache.o sysfs.o cache.o
 f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o
 f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o
 f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
fs/f2fs/cache.c new file +539 -0
new file mode 100644
index 000000000000..fb0ab77d3b49
@@ -0,0 +1,539 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 Google LLC
+ * Author: Chao Yu <[email protected]>
+ */
+#include <linux/fs.h>
+#include <linux/f2fs_fs.h>
+#include <linux/radix-tree.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+#include <linux/pagemap.h>
+#include <linux/kthread.h>
+#include <linux/freezer.h>
+#include <linux/delay.h>
+#include "f2fs.h"
+#include "cache.h"
+#include "node.h"
+#include "segment.h"
+
+void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
+                                       enum page_type type)
+{
+       /* in case the entry was truncated or on-going shrink */
+       if (!entry->cache)
+               return;
+
+       if (!f2fs_cache_test_writeback(entry))
+               return;
+
+       /* submit cached bio */
+       f2fs_submit_merged_write_cache(entry, type);
+
+       wait_on_bit_io(&entry->state, F2FS_BLOCK_WRITEBACK,
+                                       TASK_UNINTERRUPTIBLE);
+}
+
+void f2fs_cache_wait_writeback(struct f2fs_cached_block *entry)
+{
+       /* in case the entry was truncated or on-going shrink */
+       if (!entry->cache)
+               return;
+
+       f2fs_cache_wait_writeback_cond(entry,
+                       IS_META_CACHE(entry->cache) ? META : NODE);
+}
+
+void f2fs_cache_update_tag(struct f2fs_cached_block *entry,
+               unsigned int clear_from, unsigned int set_to)
+{
+       struct f2fs_cached_block_list *cache = entry->cache;
+       unsigned long flags;
+
+       spin_lock_irqsave(&cache->tree_lock, flags);
+       if (clear_from != F2FS_CACHE_TAG_NONE)
+               radix_tree_tag_clear(&cache->root, entry->index, clear_from);
+       if (set_to != F2FS_CACHE_TAG_NONE)
+               radix_tree_tag_set(&cache->root, entry->index, set_to);
+       spin_unlock_irqrestore(&cache->tree_lock, flags);
+}
+
+bool f2fs_mark_cache_dirty(struct f2fs_cached_block *entry)
+{
+       struct f2fs_cached_block_list *cache = entry->cache;
+
+       f2fs_cache_set_uptodate(entry);
+
+#ifdef CONFIG_F2FS_CHECK_FS
+       if (cache->type == F2FS_NODE_CACHE && IS_INODE(cache->sbi, cache_folio(entry)))
+               f2fs_inode_chksum_set(cache->sbi, cache_folio(entry));
+#endif
+
+       if (!f2fs_cache_test_and_set_dirty(entry)) {
+               enum count_type type = IS_META_CACHE(cache) ?
+                               F2FS_DIRTY_META : F2FS_DIRTY_NODES;
+
+               f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_NONE,
+                                               F2FS_CACHE_TAG_DIRTY);
+               inc_page_count(cache->sbi, type);
+               return true;
+       }
+
+       return false;
+}
+
+void f2fs_drop_cache_dirty(struct f2fs_cached_block *entry)
+{
+
+       struct f2fs_cached_block_list *cache = entry->cache;
+       enum count_type type = IS_META_CACHE(cache) ?
+                               F2FS_DIRTY_META : F2FS_DIRTY_NODES;
+
+       f2fs_cache_clear_uptodate(entry);
+
+       if (!f2fs_cache_test_and_clear_dirty(entry))
+               return;
+
+       f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_DIRTY,
+                                       F2FS_CACHE_TAG_NONE);
+       dec_page_count(cache->sbi, type);
+}
+
+void f2fs_start_cache_writeback(struct f2fs_cached_block *entry)
+{
+       f2fs_cache_set_writeback(entry);
+       f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_DIRTY,
+                               F2FS_CACHE_TAG_WRITEBACK);
+}
+
+void f2fs_end_cache_writeback(struct f2fs_cached_block *entry)
+{
+       /*
+        * should call f2fs_cache_update_tag() before clearing writeback bit,
+        * in case f2fs_truncate_cache() set entry->cache to NULL.
+        */
+       f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_WRITEBACK,
+                                               F2FS_CACHE_TAG_NONE);
+       clear_and_wake_up_bit(F2FS_BLOCK_WRITEBACK, &entry->state);
+}
+
+static int f2fs_cache_refcount(struct f2fs_cached_block *entry)
+{
+       return atomic_read(&entry->refcount);
+}
+
+static void f2fs_do_free_cache(struct f2fs_cached_block *entry)
+{
+       kfree(entry->data);
+       kfree(entry);
+}
+
+static void f2fs_free_cache(struct f2fs_cached_block *entry)
+{
+       WARN_ON_ONCE(!list_empty(&entry->list));
+       WARN_ON_ONCE(f2fs_cache_refcount(entry));
+       f2fs_do_free_cache(entry);
+}
+
+void f2fs_cache_get(struct f2fs_cached_block *entry)
+{
+       atomic_inc(&entry->refcount);
+}
+
+static bool f2fs_cache_put(struct f2fs_cached_block *entry)
+{
+       WARN_ON_ONCE(!f2fs_cache_refcount(entry));
+       if (atomic_dec_and_test(&entry->refcount)) {
+               f2fs_free_cache(entry);
+               return true;
+       }
+       return false;
+}
+
+static struct f2fs_cached_block *f2fs_create_cache(
+               struct f2fs_cached_block_list *cache,
+               unsigned long index, bool nofail)
+{
+       struct f2fs_cached_block *entry;
+       unsigned int flags = GFP_NOFS;
+
+       if (index == ULONG_MAX)
+               return ERR_PTR(-ERANGE);
+
+       if (nofail)
+               flags |= __GFP_NOFAIL;
+
+       entry = kzalloc_obj(*entry, flags);
+       if (!entry)
+               return ERR_PTR(-ENOMEM);
+
+       entry->data = kmalloc(cache->sbi->blocksize, flags);
+       if (!entry->data) {
+               kfree(entry);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       entry->index = index;
+
+       atomic_set(&entry->refcount, 0);
+       entry->next_entry = NULL;
+       INIT_LIST_HEAD(&entry->list);
+
+       entry->cache = cache;
+
+       return entry;
+}
+
+static struct f2fs_cached_block *f2fs_insert_cache(
+                       struct f2fs_cached_block_list *cache,
+                       unsigned long index,
+                       struct f2fs_cached_block *new)
+{
+       struct f2fs_cached_block *e;
+       int ret;
+       unsigned long flags;
+
+       ret = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
+       f2fs_bug_on(cache->sbi, ret);
+
+       spin_lock(&cache->list_lock);
+       spin_lock_irqsave(&cache->tree_lock, flags);
+       e = radix_tree_lookup(&cache->root, index);
+       if (!e) {
+               e = new;
+               f2fs_bug_on(cache->sbi, f2fs_cache_refcount(e));
+
+               ret = radix_tree_insert(&cache->root, index, e);
+               f2fs_bug_on(cache->sbi, ret);
+
+               /* radix tree referenced cache entry */
+               f2fs_cache_get(e);
+               f2fs_bug_on(cache->sbi, !list_empty(&e->list));
+               list_add_tail(&e->list, &cache->lru_list);
+               cache->num_entries++;
+       }
+       f2fs_cache_get(e);
+       spin_unlock_irqrestore(&cache->tree_lock, flags);
+       spin_unlock(&cache->list_lock);
+       radix_tree_preload_end();
+
+       if (new != e) {
+               f2fs_bug_on(cache->sbi, f2fs_cache_refcount(new));
+               f2fs_do_free_cache(new);
+       }
+
+       return e;
+}
+
+struct f2fs_cached_block *f2fs_find_cache(
+                       struct f2fs_cached_block_list *cache,
+                       unsigned long index,
+                       enum f2fs_cache_request_flag rflag)
+{
+       struct f2fs_cached_block *entry;
+       unsigned long flags;
+       bool access = rflag & F2FS_CACHE_ACCESS;
+
+       spin_lock_irqsave(&cache->tree_lock, flags);
+       entry = radix_tree_lookup(&cache->root, index);
+       if (entry) {
+               f2fs_bug_on(cache->sbi, !f2fs_cache_refcount(entry));
+               f2fs_cache_get(entry);
+               if (access && !f2fs_cache_test_referenced(entry))
+                       f2fs_cache_set_referenced(entry);
+       } else {
+               entry = ERR_PTR(-ENOENT);
+       }
+       spin_unlock_irqrestore(&cache->tree_lock, flags);
+
+       return entry;
+}
+
+struct f2fs_cached_block *f2fs_grab_cache(
+                       struct f2fs_cached_block_list *cache,
+                       unsigned long index, int flags)
+
+{
+       struct f2fs_cached_block *entry, *new;
+       bool create = flags & F2FS_CACHE_CREATE;
+       bool nofail = flags & F2FS_CACHE_NOFAIL;
+       bool lock = flags & F2FS_CACHE_LOCK;
+
+repeat:
+       entry = f2fs_find_cache(cache, index, F2FS_CACHE_ACCESS);
+       if (!IS_ERR(entry))
+               goto found;
+
+       if (!create)
+               return ERR_PTR(-ENOENT);
+
+       new = f2fs_create_cache(cache, index, nofail);
+       if (IS_ERR(new))
+               return new;
+
+       entry = f2fs_insert_cache(cache, index, new);
+found:
+       if (lock) {
+               f2fs_lock_cache(entry);
+               /* has been truncated */
+               if (entry->cache != cache) {
+                       f2fs_put_cache(entry, true);
+                       goto repeat;
+               }
+       }
+       return entry;
+}
+
+bool f2fs_trylock_cache(struct f2fs_cached_block *entry)
+{
+       return !test_and_set_bit(F2FS_BLOCK_LOCKED, &entry->state);
+}
+
+void f2fs_lock_cache(struct f2fs_cached_block *entry)
+{
+       wait_on_bit_lock(&entry->state, F2FS_BLOCK_LOCKED,
+                                       TASK_UNINTERRUPTIBLE);
+}
+
+void f2fs_unlock_cache(struct f2fs_cached_block *entry)
+{
+       clear_and_wake_up_bit(F2FS_BLOCK_LOCKED, &entry->state);
+}
+
+bool f2fs_put_cache(struct f2fs_cached_block *entry, bool unlock)
+{
+       if (IS_ERR_OR_NULL(entry))
+               return false;
+       if (unlock)
+               f2fs_unlock_cache(entry);
+       return f2fs_cache_put(entry);
+}
+
+unsigned int f2fs_cache_gang_lookup(struct f2fs_cached_block_list *cache,
+                               struct f2fs_cached_block **entries,
+                               pgoff_t *index, unsigned long end)
+{
+       unsigned long flags;
+       unsigned int max_nr = min((unsigned long)F2FS_ONSTACK_CACHES, end - *index);
+       int nr, i;
+
+       if (*index >= end || *index == ULONG_MAX)
+               return 0;
+
+       spin_lock_irqsave(&cache->tree_lock, flags);
+       nr = radix_tree_gang_lookup(&cache->root, (void **)entries,
+                               *index, max_nr);
+       if (!nr)
+               goto out_unlock;
+
+       for (i = 0; i < nr; i++) {
+               struct f2fs_cached_block *entry = entries[i];
+
+               if (entry->index >= end) {
+                       nr = i;
+                       break;
+               }
+               f2fs_cache_get(entry);
+       }
+       if (nr)
+               *index = entries[nr - 1]->index + 1;
+out_unlock:
+       spin_unlock_irqrestore(&cache->tree_lock, flags);
+       return nr;
+}
+
+unsigned int f2fs_cache_gang_lookup_tag(struct f2fs_cached_block_list *cache,
+                               struct f2fs_cached_block **entries,
+                               pgoff_t *index, unsigned int max_nr,
+                               int tag)
+{
+       unsigned long flags;
+       int nr, i;
+
+       if (*index == ULONG_MAX)
+               return 0;
+
+       spin_lock_irqsave(&cache->tree_lock, flags);
+       nr = radix_tree_gang_lookup_tag(&cache->root, (void **)entries,
+                               *index, max_nr, tag);
+       if (!nr)
+               goto out;
+
+       for (i = 0; i < nr; i++)
+               f2fs_cache_get(entries[i]);
+       *index = entries[nr - 1]->index + 1;
+out:
+       spin_unlock_irqrestore(&cache->tree_lock, flags);
+       return nr;
+}
+
+void f2fs_cache_gang_release(struct f2fs_cached_block **entries,
+                               unsigned int nr_entries)
+{
+       int i;
+
+       for (i = 0; i < nr_entries; i++)
+               f2fs_put_cache(entries[i], false);
+}
+
+void f2fs_cache_wait_on_all_writeback(struct f2fs_cached_block_list *cache)
+{
+       unsigned long index = 0;
+       struct f2fs_cached_block *entries[F2FS_ONSTACK_CACHES];
+       int nr, i;
+
+next:
+       nr = f2fs_cache_gang_lookup_tag(cache, entries, &index,
+                       F2FS_ONSTACK_CACHES, F2FS_CACHE_TAG_WRITEBACK);
+       if (!nr)
+               return;
+
+       for (i = 0; i < nr; i++)
+               f2fs_cache_wait_writeback(entries[i]);
+       f2fs_cache_gang_release(entries, nr);
+
+       cond_resched();
+       goto next;
+}
+
+static void f2fs_do_truncate_cache(struct f2fs_cached_block *entry,
+                                               bool drop_dirty)
+{
+       struct f2fs_cached_block_list *cache = entry->cache;
+       unsigned long flags;
+
+       if (drop_dirty)
+               goto drop_it;
+
+       if (f2fs_cache_test_dirty(entry) ||
+           f2fs_cache_test_writeback(entry))
+               return;
+
+drop_it:
+       f2fs_cache_wait_writeback(entry);
+       f2fs_drop_cache_dirty(entry);
+
+       spin_lock(&cache->list_lock);
+       spin_lock_irqsave(&cache->tree_lock, flags);
+
+       f2fs_bug_on(cache->sbi, !entry->cache);
+       if (!radix_tree_delete(&cache->root, entry->index))
+               f2fs_bug_on(cache->sbi, !entry->cache);
+
+       entry->cache = NULL;
+       cache->num_entries--;
+
+       atomic_dec(&entry->refcount);
+       f2fs_bug_on(cache->sbi, !f2fs_cache_refcount(entry));
+
+       f2fs_bug_on(cache->sbi, list_empty(&entry->list));
+       list_del_init(&entry->list);
+
+       spin_unlock_irqrestore(&cache->tree_lock, flags);
+       spin_unlock(&cache->list_lock);
+}
+
+void f2fs_truncate_locked_cache(struct f2fs_cached_block *entry,
+                               bool drop_dirty)
+{
+       if (!entry->cache)
+               return;
+       f2fs_do_truncate_cache(entry, drop_dirty);
+}
+
+void f2fs_truncate_cache(struct f2fs_cached_block *entry, bool drop_dirty)
+{
+       f2fs_lock_cache(entry);
+       f2fs_truncate_locked_cache(entry, drop_dirty);
+       f2fs_unlock_cache(entry);
+}
+
+static void f2fs_drop_cache(struct f2fs_cached_block_list *cache,
+                       block_t blkaddr, bool drop_dirty)
+{
+       struct f2fs_cached_block *entry;
+
+       entry = f2fs_find_cache(cache, blkaddr, 0);
+       if (IS_ERR(entry))
+               return;
+
+       f2fs_truncate_cache(entry, drop_dirty);
+       f2fs_put_cache(entry, false);
+}
+
+void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
+               unsigned long start, unsigned long len, bool drop_dirty)
+{
+       unsigned long index = start;
+       unsigned long end = (ULONG_MAX - start < len) ?
+                               ULONG_MAX : (start + len);
+       struct f2fs_cached_block *entries[F2FS_ONSTACK_CACHES];
+       int nr, i;
+
+       if (len == 1)
+               return f2fs_drop_cache(cache, index, drop_dirty);
+
+next:
+       nr = f2fs_cache_gang_lookup(cache, entries, &index, end);
+       if (!nr)
+               return;
+
+       for (i = 0; i < nr; i++)
+               f2fs_truncate_cache(entries[i], drop_dirty);
+       f2fs_cache_gang_release(entries, nr);
+
+       if (index < end) {
+               cond_resched();
+               goto next;
+       }
+}
+
+int f2fs_init_cache(struct f2fs_sb_info *sbi,
+               struct f2fs_cached_block_list *cache,
+               enum f2fs_cache_type type)
+{
+       cache->sbi = sbi;
+       cache->type = type;
+       INIT_RADIX_TREE(&cache->root, GFP_ATOMIC);
+       spin_lock_init(&cache->tree_lock);
+       spin_lock_init(&cache->list_lock);
+       INIT_LIST_HEAD(&cache->lru_list);
+       cache->num_entries = 0;
+
+       return 0;
+}
+
+void f2fs_destroy_cache(struct f2fs_cached_block_list *cache)
+{
+       struct list_head *head = &cache->lru_list;
+       struct f2fs_cached_block *entry;
+       unsigned long flags;
+
+       f2fs_cache_wait_on_all_writeback(cache);
+next:
+       spin_lock(&cache->list_lock);
+       if (list_empty(head)) {
+               spin_unlock(&cache->list_lock);
+               return;
+       }
+       entry = list_first_entry(head, struct f2fs_cached_block, list);
+
+       spin_lock_irqsave(&cache->tree_lock, flags);
+       radix_tree_delete(&cache->root, entry->index);
+       cache->num_entries--;
+       list_del_init(&entry->list);
+       spin_unlock_irqrestore(&cache->tree_lock, flags);
+
+       spin_unlock(&cache->list_lock);
+
+       /* wait on read cache IO */
+       f2fs_lock_cache(entry);
+       /* wait on write cache IO */
+       f2fs_cache_wait_writeback(entry);
+       f2fs_bug_on(cache->sbi, f2fs_cache_test_dirty(entry));
+       f2fs_bug_on(cache->sbi, f2fs_cache_test_writeback(entry));
+       f2fs_bug_on(cache->sbi, !list_empty(&entry->list));
+       f2fs_bug_on(cache->sbi, f2fs_cache_refcount(entry) != 1);
+       f2fs_put_cache(entry, true);
+       goto next;
+}
fs/f2fs/cache.h new file +196 -0
new file mode 100644
index 000000000000..1fa279f9d69e
@@ -0,0 +1,196 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Google LLC
+ * Author: Chao Yu <[email protected]>
+ */
+#ifndef _LINUX_F2FS_CACHE_H
+#define _LINUX_F2FS_CACHE_H
+
+#include <linux/pagemap.h>
+#include <linux/mm.h>
+#include <linux/list.h>
+#include <linux/radix-tree.h>
+#include <linux/spinlock.h>
+#include <linux/wait.h>
+#include <linux/types.h>
+
+struct f2fs_rwsem;
+struct f2fs_io_info;
+enum page_type;
+
+/* Represents a single cached block (meta, node) */
+struct f2fs_cached_block {
+       struct list_head list;          /* LRU list head */
+       struct f2fs_cached_block_list *cache;   /* parent cache list */
+       struct f2fs_cached_block *next_entry;   /* chain for merged BIO */
+       unsigned long index;            /* key in radix tree, (meta: pba, node: nid) */
+       unsigned long state;            /* cache entry state (e.g., Dirty, UpToDate) */
+       void *data;                     /* blocksize-aligned memory (4KB or 16KB) */
+       atomic_t refcount;              /* reference count */
+};
+
+struct f2fs_sb_info;
+
+enum f2fs_cache_type {
+       F2FS_META_CACHE,
+       F2FS_NODE_CACHE,
+};
+
+/* Main cache control structure (per sb_info) */
+struct f2fs_cached_block_list {
+       struct f2fs_sb_info *sbi;       /* Pointer to f2fs_sb_info */
+       struct radix_tree_root root;    /* Radix tree for cache lookup */
+       spinlock_t tree_lock;           /* Lock for radix tree */
+       struct list_head lru_list;      /* Single global LRU list */
+       spinlock_t list_lock;           /* Lock for LRU list */
+       enum f2fs_cache_type type;      /* Cache type (Node or Meta) */
+       unsigned long num_entries;      /* Current number of entries */
+};
+
+#define IS_META_CACHE(cache) ((cache)->type == F2FS_META_CACHE)
+
+/* Flags for f2fs_cached_block state */
+enum f2fs_cached_state {
+       F2FS_BLOCK_LOCKED,              /* cache entry is locked */
+       F2FS_BLOCK_UPTODATE,            /* cache data is valid */
+       F2FS_BLOCK_DIRTY,               /* cache data is dirty, need to writeback the data */
+       F2FS_BLOCK_WRITEBACK,           /* cache data is writeback state */
+       F2FS_BLOCK_REFERENCED,          /* cache was accessed recently, shrinker will skip it for once */
+       F2FS_BLOCK_INLINE_DATA,         /* indicate inline data */
+};
+
+enum {
+       __F2FS_CACHE_CREATE,            /* create the cache if there is no cache entry */
+       __F2FS_CACHE_LOCK,              /* get and lock the cache entry */
+       __F2FS_CACHE_NOFAIL,            /* do not allow failure */
+       __F2FS_CACHE_ACCESS,            /* give a chance to add referenced tag */
+};
+
+enum f2fs_cache_request_flag {
+       F2FS_CACHE_CREATE       = 1 << __F2FS_CACHE_CREATE,
+       F2FS_CACHE_LOCK         = 1 << __F2FS_CACHE_LOCK,
+       F2FS_CACHE_NOFAIL       = 1 << __F2FS_CACHE_NOFAIL,
+       F2FS_CACHE_ACCESS       = 1 << __F2FS_CACHE_ACCESS,
+};
+
+#define F2FS_CACHE_LOCK_CREATE (F2FS_CACHE_LOCK | F2FS_CACHE_CREATE)
+
+#define F2FS_ONSTACK_CACHES            (32)
+
+#define F2FS_CACHE_FLAG_TEST_FUNC(name, flagname)                      \
+static inline bool f2fs_cache_test_##name(                             \
+                       const struct f2fs_cached_block *entry)          \
+{                                                                      \
+       return test_bit(F2FS_BLOCK_##flagname, &entry->state);          \
+}                                                                      \
+
+#define F2FS_CACHE_FLAG_SET_FUNC(name, flagname)                       \
+static inline void f2fs_cache_set_##name(                              \
+                       struct f2fs_cached_block *entry)                \
+{                                                                      \
+       set_bit(F2FS_BLOCK_##flagname, &entry->state);                  \
+}                                                                      \
+
+#define F2FS_CACHE_FLAG_CLEAR_FUNC(name, flagname)                     \
+static inline void f2fs_cache_clear_##name(                            \
+                       struct f2fs_cached_block *entry)                \
+{                                                                      \
+       clear_bit(F2FS_BLOCK_##flagname, &entry->state);                \
+}                                                                      \
+
+#define F2FS_CACHE_FLAG_TEST_AND_SET_FUNC(name, flagname)              \
+static inline bool f2fs_cache_test_and_set_##name(                     \
+                       struct f2fs_cached_block *entry)                \
+{                                                                      \
+       return test_and_set_bit(F2FS_BLOCK_##flagname, &entry->state);  \
+}                                                                      \
+
+#define F2FS_CACHE_FLAG_TEST_AND_CLEAR_FUNC(name, flagname)            \
+static inline bool f2fs_cache_test_and_clear_##name(                   \
+                       struct f2fs_cached_block *entry)                \
+{                                                                      \
+       return test_and_clear_bit(F2FS_BLOCK_##flagname, &entry->state);\
+}                                                                      \
+
+F2FS_CACHE_FLAG_TEST_FUNC(locked, LOCKED);
+F2FS_CACHE_FLAG_SET_FUNC(locked, LOCKED);
+F2FS_CACHE_FLAG_CLEAR_FUNC(locked, LOCKED);
+
+F2FS_CACHE_FLAG_TEST_FUNC(uptodate, UPTODATE);
+F2FS_CACHE_FLAG_SET_FUNC(uptodate, UPTODATE);
+F2FS_CACHE_FLAG_CLEAR_FUNC(uptodate, UPTODATE);
+
+F2FS_CACHE_FLAG_TEST_FUNC(dirty, DIRTY);
+F2FS_CACHE_FLAG_SET_FUNC(dirty, DIRTY);
+F2FS_CACHE_FLAG_CLEAR_FUNC(dirty, DIRTY);
+F2FS_CACHE_FLAG_TEST_AND_SET_FUNC(dirty, DIRTY);
+F2FS_CACHE_FLAG_TEST_AND_CLEAR_FUNC(dirty, DIRTY);
+
+F2FS_CACHE_FLAG_TEST_FUNC(writeback, WRITEBACK);
+F2FS_CACHE_FLAG_SET_FUNC(writeback, WRITEBACK);
+F2FS_CACHE_FLAG_CLEAR_FUNC(writeback, WRITEBACK);
+
+F2FS_CACHE_FLAG_TEST_FUNC(inline, INLINE_DATA);
+F2FS_CACHE_FLAG_SET_FUNC(inline, INLINE_DATA);
+F2FS_CACHE_FLAG_CLEAR_FUNC(inline, INLINE_DATA);
+
+F2FS_CACHE_FLAG_TEST_FUNC(referenced, REFERENCED);
+F2FS_CACHE_FLAG_SET_FUNC(referenced, REFERENCED);
+F2FS_CACHE_FLAG_TEST_AND_CLEAR_FUNC(referenced, REFERENCED);
+
+static inline void *cache_address(const struct f2fs_cached_block *entry)
+{
+       return entry->data;
+}
+
+#define CACHED_NODE(entry)     ((struct f2fs_node *)(cache_address(entry)))
+
+static inline struct folio *cache_folio(const struct f2fs_cached_block *entry)
+{
+       return virt_to_folio(entry->data);
+}
+
+int f2fs_init_cache(struct f2fs_sb_info *sbi,
+                               struct f2fs_cached_block_list *cache,
+                               enum f2fs_cache_type type);
+void f2fs_destroy_cache(struct f2fs_cached_block_list *cache);
+void f2fs_cache_get(struct f2fs_cached_block *entry);
+struct f2fs_cached_block *f2fs_find_cache(
+                       struct f2fs_cached_block_list *cache,
+                       unsigned long index,
+                       enum f2fs_cache_request_flag rflag);
+#define F2FS_CACHE_TAG_NONE            0
+#define F2FS_CACHE_TAG_DIRTY           1
+#define F2FS_CACHE_TAG_WRITEBACK       2
+
+bool f2fs_trylock_cache(struct f2fs_cached_block *entry);
+void f2fs_lock_cache(struct f2fs_cached_block *entry);
+void f2fs_unlock_cache(struct f2fs_cached_block *entry);
+bool f2fs_put_cache(struct f2fs_cached_block *entry, bool unlock);
+bool f2fs_mark_cache_dirty(struct f2fs_cached_block *entry);
+void f2fs_drop_cache_dirty(struct f2fs_cached_block *entry);
+void f2fs_start_cache_writeback(struct f2fs_cached_block *entry);
+void f2fs_end_cache_writeback(struct f2fs_cached_block *entry);
+unsigned int f2fs_cache_gang_lookup(struct f2fs_cached_block_list *cache,
+                               struct f2fs_cached_block **entries,
+                               pgoff_t *index, unsigned long end);
+unsigned int f2fs_cache_gang_lookup_tag(struct f2fs_cached_block_list *cache,
+               struct f2fs_cached_block **results, pgoff_t *first_index,
+               unsigned int max_items, int tag);
+void f2fs_cache_gang_release(struct f2fs_cached_block **entries,
+                               unsigned int nr_entries);
+void f2fs_cache_wait_on_all_writeback(struct f2fs_cached_block_list *cache);
+void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
+                                       enum page_type type);
+void f2fs_cache_wait_writeback(struct f2fs_cached_block *entry);
+void f2fs_cache_update_tag(struct f2fs_cached_block *entry,
+               unsigned int clear_from, unsigned int set_to);
+struct f2fs_cached_block *f2fs_grab_cache(struct f2fs_cached_block_list *cache,
+                               unsigned long index, int flags);
+void f2fs_truncate_locked_cache(struct f2fs_cached_block *entry,
+                               bool drop_dirty);
+void f2fs_truncate_cache(struct f2fs_cached_block *entry, bool drop_dirty);
+void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
+               unsigned long start, unsigned long len, bool drop_dirty);
+
+#endif /* _LINUX_F2FS_CACHE_H */
fs/f2fs/data.c +255 -26
index a3b02c067e89..d868b939caee 100644
@@ -41,11 +41,6 @@ struct f2fs_folio_state {
        unsigned int            read_pages_pending;
 };
 
-struct f2fs_bio {
-       struct work_struct work;
-       struct bio bio;
-};
-
 #define        F2FS_BIO_POOL_SIZE      NR_CURSEG_TYPE
 
 int __init f2fs_init_bioset(void)
@@ -411,6 +406,65 @@ static void f2fs_write_end_io(struct bio *bio)
        }
 }
 
+static void f2fs_cache_read_end_io(struct bio *bio)
+{
+       struct f2fs_cached_block *entry = F2FS_BIO(bio)->entry;
+       struct f2fs_sb_info *sbi = entry->cache->sbi;
+       enum count_type io_type = IS_META_CACHE(entry->cache) ?
+                                       F2FS_RD_META : F2FS_RD_NODE;
+       struct f2fs_cached_block *next;
+
+       iostat_update_and_unbind_ctx(bio);
+
+       if (time_to_inject(sbi, FAULT_READ_IO))
+               bio->bi_status = BLK_STS_IOERR;
+
+       while (entry) {
+               next = entry->next_entry;
+               entry->next_entry = NULL;
+
+               if (bio->bi_status == BLK_STS_OK)
+                       f2fs_cache_set_uptodate(entry);
+
+               dec_page_count(sbi, io_type);
+
+               f2fs_unlock_cache(entry);
+               entry = next;
+       }
+       bio_put(bio);
+}
+
+static void f2fs_cache_write_end_io(struct bio *bio)
+{
+       struct f2fs_cached_block *entry = F2FS_BIO(bio)->entry;
+       struct f2fs_sb_info *sbi = entry->cache->sbi;
+       struct f2fs_cached_block *next;
+
+       iostat_update_and_unbind_ctx(bio);
+
+       if (time_to_inject(sbi, FAULT_WRITE_IO))
+               bio->bi_status = BLK_STS_IOERR;
+
+       if (bio->bi_status != BLK_STS_OK)
+               f2fs_stop_checkpoint(sbi, true,
+                       STOP_CP_REASON_WRITE_FAIL);
+
+       while (entry) {
+               next = entry->next_entry;
+               entry->next_entry = NULL;
+
+               dec_page_count(sbi, F2FS_WB_CP_DATA);
+
+               if (!get_pages(sbi, F2FS_WB_CP_DATA) &&
+                               wq_has_sleeper(&sbi->cp_wait))
+                       wake_up(&sbi->cp_wait);
+
+               f2fs_end_cache_writeback(entry);
+               entry = next;
+       }
+       bio_put(bio);
+}
+
 #ifdef CONFIG_BLK_DEV_ZONED
 static void f2fs_zone_write_end_io(struct bio *bio)
 {
@@ -418,7 +472,10 @@ static void f2fs_zone_write_end_io(struct bio *bio)
 
        bio->bi_private = io->bi_private;
        complete(&io->zone_wait);
-       f2fs_write_end_io(bio);
+       if (f2fs_is_cache_bio(bio))
+               f2fs_cache_write_end_io(bio);
+       else
+               f2fs_write_end_io(bio);
 }
 #endif
 
@@ -505,12 +562,21 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)
                                fio->op | fio->op_flags | f2fs_io_flags(fio),
                                GFP_NOIO, &f2fs_bioset);
        bio->bi_iter.bi_sector = sector;
+       F2FS_BIO(bio)->entry = NULL;
+       bio->bi_private = NULL;
        if (is_read_io(fio->op)) {
-               bio->bi_end_io = f2fs_read_end_io;
-               bio->bi_private = NULL;
+               if (fio->is_cache)
+                       bio->bi_end_io = f2fs_cache_read_end_io;
+               else
+                       bio->bi_end_io = f2fs_read_end_io;
        } else {
-               bio->bi_end_io = f2fs_write_end_io;
-               bio->bi_private = sbi;
+               if (fio->is_cache) {
+                       bio->bi_end_io = f2fs_cache_write_end_io;
+               } else {
+                       bio->bi_end_io = f2fs_write_end_io;
+                       bio->bi_private = sbi;
+               }
+
                bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi,
                                                fio->type, fio->temp);
                bio->bi_write_stream = f2fs_io_type_to_write_stream(bdev, fio->type,
@@ -533,7 +599,7 @@ static void f2fs_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,
         * The f2fs garbage collector sets ->encrypted_page when it wants to
         * read/write raw data without encryption.
         */
-       if (!fio || !fio->encrypted_page)
+       if (!fio || (!fio->encrypted_page && !fio->is_cache))
                fscrypt_set_bio_crypt_ctx(bio, inode,
                                (loff_t)first_idx << inode->i_blkbits,
                                gfp_mask);
@@ -738,6 +804,53 @@ void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
        __submit_merged_write_cond(sbi, NULL, folio, 0, type, true);
 }
 
+static bool __has_merged_cache(struct bio *bio,
+               struct f2fs_cached_block *target)
+{
+       struct f2fs_cached_block *entry;
+
+       if (!bio)
+               return false;
+
+       entry = F2FS_BIO(bio)->entry;
+
+       while (entry) {
+               if (target && entry == target)
+                       return true;
+               entry = entry->next_entry;
+       }
+       return false;
+}
+
+bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
+                               enum page_type type)
+{
+       struct f2fs_sb_info *sbi = entry->cache->sbi;
+       enum temp_type temp;
+       bool ret = false;
+
+       for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
+               enum page_type btype = PAGE_TYPE_OF_BIO(type);
+               struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
+               struct f2fs_lock_context lc;
+               bool merged;
+
+               f2fs_down_read_trace(&io->io_rwsem, &lc);
+               merged = __has_merged_cache(io->bio, entry);
+               f2fs_up_read_trace(&io->io_rwsem, &lc);
+
+               if (merged) {
+                       __f2fs_submit_merged_write(sbi, type, temp);
+                       ret = true;
+               }
+
+               /* TODO: use HOT temp only for meta pages now. */
+               if (type >= META)
+                       break;
+       }
+       return ret;
+}
+
 void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi)
 {
        f2fs_submit_merged_write(sbi, DATA);
@@ -801,6 +914,8 @@ static bool io_type_is_mergeable(struct f2fs_bio_info *io,
 
        if (io->fio.op != fio->op)
                return false;
+       if (io->fio.is_cache != fio->is_cache)
+               return false;
        return (io->fio.op_flags & mask) == (fio->op_flags & mask);
 }
 
@@ -1032,6 +1147,33 @@ static bool is_end_zone_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr)
                f2fs_blkz_is_seq(sbi, devi, blkaddr) &&
                (blkaddr % sbi->blocks_per_blkz == sbi->blocks_per_blkz - 1);
 }
+
+static void f2fs_wait_zone_io_completion(struct f2fs_sb_info *sbi,
+                       struct f2fs_bio_info *io, enum page_type btype)
+{
+       if (f2fs_sb_has_blkzoned(sbi) && btype < META && io->zone_pending_bio) {
+               wait_for_completion_io(&io->zone_wait);
+               bio_put(io->zone_pending_bio);
+               io->zone_pending_bio = NULL;
+               io->bi_private = NULL;
+       }
+}
+
+static void f2fs_submit_zone_io(struct f2fs_sb_info *sbi,
+                       struct f2fs_io_info *fio, struct f2fs_bio_info *io,
+                       enum page_type btype)
+{
+       if (f2fs_sb_has_blkzoned(sbi) && btype < META &&
+                       is_end_zone_blkaddr(sbi, fio->new_blkaddr)) {
+               bio_get(io->bio);
+               reinit_completion(&io->zone_wait);
+               io->bi_private = io->bio->bi_private;
+               io->bio->bi_private = io;
+               io->bio->bi_end_io = f2fs_zone_write_end_io;
+               io->zone_pending_bio = io->bio;
+               __submit_merged_bio(io);
+       }
+}
 #endif
 
 void f2fs_submit_page_write(struct f2fs_io_info *fio)
@@ -1048,14 +1190,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
        f2fs_down_write_trace(&io->io_rwsem, &lc);
 next:
 #ifdef CONFIG_BLK_DEV_ZONED
-       if (f2fs_sb_has_blkzoned(sbi) && btype < META && io->zone_pending_bio) {
-               wait_for_completion_io(&io->zone_wait);
-               bio_put(io->zone_pending_bio);
-               io->zone_pending_bio = NULL;
-               io->bi_private = NULL;
-       }
+       f2fs_wait_zone_io_completion(sbi, io, btype);
 #endif
-
        if (fio->in_list) {
                spin_lock(&io->io_lock);
                if (list_empty(&io->io_list)) {
@@ -1110,16 +1246,109 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
 
        trace_f2fs_submit_folio_write(fio->folio, fio);
 #ifdef CONFIG_BLK_DEV_ZONED
-       if (f2fs_sb_has_blkzoned(sbi) && btype < META &&
-                       is_end_zone_blkaddr(sbi, fio->new_blkaddr)) {
-               bio_get(io->bio);
-               reinit_completion(&io->zone_wait);
-               io->bi_private = io->bio->bi_private;
-               io->bio->bi_private = io;
-               io->bio->bi_end_io = f2fs_zone_write_end_io;
-               io->zone_pending_bio = io->bio;
+       f2fs_submit_zone_io(sbi, fio, io, btype);
+#endif
+
+       if (fio->in_list)
+               goto next;
+out:
+       if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) ||
+                               !f2fs_is_checkpoint_ready(sbi))
                __submit_merged_bio(io);
+       f2fs_up_write_trace(&io->io_rwsem, &lc);
+}
+
+static void f2fs_bio_add_cache(struct f2fs_io_info *fio, struct bio *bio)
+{
+       struct f2fs_bio *fbio = F2FS_BIO(bio);
+       struct f2fs_cached_block *head = fbio->entry;
+       struct f2fs_cached_block *new = fio->cache_entry;
+
+       new->next_entry = head;
+       fbio->entry = new;
+}
+
+int f2fs_submit_cache_read(struct f2fs_io_info *fio)
+{
+       struct f2fs_sb_info *sbi = fio->sbi;
+       struct f2fs_cached_block *entry = fio->cache_entry;
+       struct bio *bio;
+       enum count_type io_type = IS_META_CACHE(entry->cache) ?
+                               F2FS_RD_META : F2FS_RD_NODE;
+
+       if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
+                       fio->is_por ? META_POR : (__is_meta_io(fio) ?
+                       META_GENERIC : DATA_GENERIC_ENHANCE)))
+               return -EFSCORRUPTED;
+
+       bio = __bio_alloc(fio, 1);
+
+       bio_add_virt_nofail(bio, cache_address(entry), sbi->blocksize);
+       f2fs_bio_add_cache(fio, bio);
+       inc_page_count(sbi, io_type);
+
+       f2fs_submit_read_bio(sbi, bio, fio->type);
+       return 0;
+}
+
+void f2fs_submit_cache_write(struct f2fs_io_info *fio)
+{
+       struct f2fs_sb_info *sbi = fio->sbi;
+       enum page_type btype = PAGE_TYPE_OF_BIO(fio->type);
+       struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp;
+       struct f2fs_lock_context lc;
+       struct folio *folio;
+
+       f2fs_bug_on(sbi, is_read_io(fio->op));
+
+       f2fs_down_write_trace(&io->io_rwsem, &lc);
+next:
+#ifdef CONFIG_BLK_DEV_ZONED
+       f2fs_wait_zone_io_completion(sbi, io, btype);
+#endif
+       if (fio->in_list) {
+               spin_lock(&io->io_lock);
+               if (list_empty(&io->io_list)) {
+                       spin_unlock(&io->io_lock);
+                       goto out;
+               }
+               fio = list_first_entry(&io->io_list,
+                                               struct f2fs_io_info, list);
+               list_del(&fio->list);
+               spin_unlock(&io->io_lock);
        }
+
+       verify_fio_blkaddr(fio);
+
+       fio->submitted = 1;
+       inc_page_count(sbi, F2FS_WB_CP_DATA);
+
+       if (io->bio &&
+           (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio,
+                             fio->new_blkaddr)))
+               __submit_merged_bio(io);
+alloc_new:
+       if (io->bio == NULL) {
+               io->bio = __bio_alloc(fio, BIO_MAX_VECS);
+               io->fio = *fio;
+       }
+
+       folio = cache_folio(fio->cache_entry);
+
+       if (!bio_add_folio(io->bio, folio, sbi->blocksize,
+                       offset_in_folio(folio, cache_address(fio->cache_entry)))) {
+               f2fs_bug_on(sbi, !F2FS_BIO(io->bio)->entry);
+
+               __submit_merged_bio(io);
+               goto alloc_new;
+       }
+
+       f2fs_bio_add_cache(fio, io->bio);
+
+       io->last_block_in_bio = fio->new_blkaddr;
+
+#ifdef CONFIG_BLK_DEV_ZONED
+       f2fs_submit_zone_io(sbi, fio, io, btype);
 #endif
        if (fio->in_list)
                goto next;
fs/f2fs/f2fs.h +24 -0
index ebc621f302e1..c0c7d51c830f 100644
@@ -222,6 +222,8 @@ struct f2fs_rwsem {
 #endif
 };
 
+#include "cache.h"
+
 struct f2fs_mount_info {
        unsigned long long opt;
        block_t root_reserved_blocks;   /* root reserved blocks */
@@ -1362,8 +1364,10 @@ struct f2fs_io_info {
        unsigned int in_list:1;         /* indicate fio is in io_list */
        unsigned int is_por:1;          /* indicate IO is from recovery or not */
        unsigned int meta_gc:1;         /* require meta inode GC */
+       unsigned int is_cache:1;        /* indicate IO is from internal cache */
        enum iostat_type io_type;       /* io type */
        struct writeback_control *io_wbc; /* writeback control */
+       struct f2fs_cached_block *cache_entry;
        struct bio **bio;               /* bio for ipu */
        sector_t *last_block;           /* last block number in bio */
 };
@@ -1773,6 +1777,12 @@ struct f2fs_gc_kthread {
        unsigned int boost_gc_greedy;
 };
 
+struct f2fs_bio {
+       struct work_struct work;
+       struct f2fs_cached_block *entry;
+       struct bio bio;
+};
+
 struct f2fs_sb_info {
        struct super_block *sb;                 /* pointer to VFS super block */
        struct proc_dir_entry *s_proc;          /* proc entry */
@@ -2381,6 +2391,16 @@ static inline bool is_node_folio(struct f2fs_sb_info *sbi, struct folio *folio)
        return folio->mapping == NODE_MAPPING(sbi);
 }
 
+static inline struct f2fs_bio *F2FS_BIO(struct bio *bio)
+{
+       return container_of(bio, struct f2fs_bio, bio);
+}
+
+static inline bool f2fs_is_cache_bio(struct bio *bio)
+{
+       return F2FS_BIO(bio)->entry != NULL;
+}
+
 static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
 {
        return test_bit(type, &sbi->s_flag);
@@ -4312,6 +4332,8 @@ void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
                                nid_t ino, enum page_type type);
 void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
                                struct folio *folio, enum page_type type);
+bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
+                               enum page_type type);
 void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
                                        struct bio **bio, struct folio *folio);
 void f2fs_submit_all_merged_ipu_writes(struct f2fs_sb_info *sbi);
@@ -4319,6 +4341,8 @@ void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
 int f2fs_submit_page_bio(struct f2fs_io_info *fio);
 int f2fs_merge_page_bio(struct f2fs_io_info *fio);
 void f2fs_submit_page_write(struct f2fs_io_info *fio);
+int f2fs_submit_cache_read(struct f2fs_io_info *fio);
+void f2fs_submit_cache_write(struct f2fs_io_info *fio);
 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
                block_t blk_addr, sector_t *sector);
 int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
fs/f2fs/iostat.h +11 -1
index 2025225b5bed..61c6bc8e3119 100644
@@ -60,6 +60,13 @@ static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
        return iostat_ctx->post_read_ctx;
 }
 
+static inline void iostat_set_post_read_ctx(struct bio *bio, void *ctx)
+{
+       struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
+
+       iostat_ctx->post_read_ctx = ctx;
+}
+
 extern void iostat_update_and_unbind_ctx(struct bio *bio);
 extern void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
                struct bio *bio, struct bio_post_read_ctx *ctx);
@@ -81,6 +88,10 @@ static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
 {
        return bio->bi_private;
 }
+static inline void iostat_set_post_read_ctx(struct bio *bio, void *ctx)
+{
+       bio->bi_private = ctx;
+}
 static inline int f2fs_init_iostat_processing(void) { return 0; }
 static inline void f2fs_destroy_iostat_processing(void) {}
 static inline int f2fs_init_iostat(struct f2fs_sb_info *sbi) { return 0; }
--

2.49.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer
#3 lore raw

Re: [f2fs-dev] [PATCH v8 01/12] f2fs: cache: implement metadata cache

In reply to Chao Yu
Quoted 101 lines · On 09/16, Chao Yu via Linux-f2fs-devel wrote:

From: Chao Yu <[email protected]>

This patch introduces the core metadata block caching infrastructure to manage f2fs metadata independently of the page cache.

It implements:
- core cache APIs: get, create, put, drop, backed by a radix tree and a single global LRU list.
- support multiple status of cached block: LOCKED, UPTODATE, DIRTY, WRITEBACK, INLINE.
- internal bio based read/write helpers with adjacent block vector merging.

---
 fs/f2fs/Makefile |   2 +-
 fs/f2fs/cache.c  | 539 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/f2fs/cache.h  | 196 +++++++++++++++++
 fs/f2fs/data.c   | 281 +++++++++++++++++++++---
 fs/f2fs/f2fs.h   |  24 +++
 fs/f2fs/iostat.h |  11 +
 6 files changed, 1026 insertions(+), 27 deletions(-)
 create mode 100644 fs/f2fs/cache.c
 create mode 100644 fs/f2fs/cache.h
fs/f2fs/Makefile +1 -1
index 8a7322d229e4..fbf49c30b066 100644
@@ -3,7 +3,7 @@ obj-$(CONFIG_F2FS_FS) += f2fs.o
 
 f2fs-y		:= dir.o file.o inode.o namei.o hash.o super.o inline.o
 f2fs-y		+= checkpoint.o gc.o data.o node.o segment.o recovery.o
-f2fs-y		+= shrinker.o extent_cache.o sysfs.o
+f2fs-y		+= shrinker.o extent_cache.o sysfs.o cache.o
 f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o
 f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o
 f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
fs/f2fs/cache.c new file +58 -0
new file mode 100644
index 000000000000..fb0ab77d3b49
@@ -0,0 +1,539 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 Google LLC
+ * Author: Chao Yu <[email protected]>
+ */
+#include <linux/fs.h>
+#include <linux/f2fs_fs.h>
+#include <linux/radix-tree.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+#include <linux/pagemap.h>
+#include <linux/kthread.h>
+#include <linux/freezer.h>
+#include <linux/delay.h>
+#include "f2fs.h"
+#include "cache.h"
+#include "node.h"
+#include "segment.h"
+
+void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
+					enum page_type type)
+{
+	/* in case the entry was truncated or on-going shrink */
+	if (!entry->cache)
+		return;
+
+	if (!f2fs_cache_test_writeback(entry))
+		return;
+
+	/* submit cached bio */
+	f2fs_submit_merged_write_cache(entry, type);
+
+	wait_on_bit_io(&entry->state, F2FS_BLOCK_WRITEBACK,
+					TASK_UNINTERRUPTIBLE);
+}
+
+void f2fs_cache_wait_writeback(struct f2fs_cached_block *entry)
+{
+	/* in case the entry was truncated or on-going shrink */
+	if (!entry->cache)
+		return;
+
+	f2fs_cache_wait_writeback_cond(entry,
+			IS_META_CACHE(entry->cache) ? META : NODE);
+}
+
+void f2fs_cache_update_tag(struct f2fs_cached_block *entry,
+		unsigned int clear_from, unsigned int set_to)
+{
+	struct f2fs_cached_block_list *cache = entry->cache;
+	unsigned long flags;
+
+	spin_lock_irqsave(&cache->tree_lock, flags);
+	if (clear_from != F2FS_CACHE_TAG_NONE)
+		radix_tree_tag_clear(&cache->root, entry->index, clear_from);
+	if (set_to != F2FS_CACHE_TAG_NONE)
+		radix_tree_tag_set(&cache->root, entry->index, set_to);
+	spin_unlock_irqrestore(&cache->tree_lock, flags);

fs/f2fs/cache.c line 68

Quoted 10 lines
fs/f2fs/cache.c new file +10 -0
+}
+
+bool f2fs_mark_cache_dirty(struct f2fs_cached_block *entry)
+{
+	struct f2fs_cached_block_list *cache = entry->cache;
+
+	f2fs_cache_set_uptodate(entry);
+
+#ifdef CONFIG_F2FS_CHECK_FS
+	if (cache->type == F2FS_NODE_CACHE && IS_INODE(cache->sbi, cache_folio(entry)))

Very minor correction needing to avoid >80 column.

Quoted 1,143 lines
fs/f2fs/cache.c new file +471 -0
+		f2fs_inode_chksum_set(cache->sbi, cache_folio(entry));
+#endif
+
+	if (!f2fs_cache_test_and_set_dirty(entry)) {
+		enum count_type type = IS_META_CACHE(cache) ?
+				F2FS_DIRTY_META : F2FS_DIRTY_NODES;
+
+		f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_NONE,
+						F2FS_CACHE_TAG_DIRTY);
+		inc_page_count(cache->sbi, type);
+		return true;
+	}
+
+	return false;
+}
+
+void f2fs_drop_cache_dirty(struct f2fs_cached_block *entry)
+{
+
+	struct f2fs_cached_block_list *cache = entry->cache;
+	enum count_type type = IS_META_CACHE(cache) ?
+				F2FS_DIRTY_META : F2FS_DIRTY_NODES;
+
+	f2fs_cache_clear_uptodate(entry);
+
+	if (!f2fs_cache_test_and_clear_dirty(entry))
+		return;
+
+	f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_DIRTY,
+					F2FS_CACHE_TAG_NONE);
+	dec_page_count(cache->sbi, type);
+}
+
+void f2fs_start_cache_writeback(struct f2fs_cached_block *entry)
+{
+	f2fs_cache_set_writeback(entry);
+	f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_DIRTY,
+				F2FS_CACHE_TAG_WRITEBACK);
+}
+
+void f2fs_end_cache_writeback(struct f2fs_cached_block *entry)
+{
+	/*
+	 * should call f2fs_cache_update_tag() before clearing writeback bit,
+	 * in case f2fs_truncate_cache() set entry->cache to NULL.
+	 */
+	f2fs_cache_update_tag(entry, F2FS_CACHE_TAG_WRITEBACK,
+						F2FS_CACHE_TAG_NONE);
+	clear_and_wake_up_bit(F2FS_BLOCK_WRITEBACK, &entry->state);
+}
+
+static int f2fs_cache_refcount(struct f2fs_cached_block *entry)
+{
+	return atomic_read(&entry->refcount);
+}
+
+static void f2fs_do_free_cache(struct f2fs_cached_block *entry)
+{
+	kfree(entry->data);
+	kfree(entry);
+}
+
+static void f2fs_free_cache(struct f2fs_cached_block *entry)
+{
+	WARN_ON_ONCE(!list_empty(&entry->list));
+	WARN_ON_ONCE(f2fs_cache_refcount(entry));
+	f2fs_do_free_cache(entry);
+}
+
+void f2fs_cache_get(struct f2fs_cached_block *entry)
+{
+	atomic_inc(&entry->refcount);
+}
+
+static bool f2fs_cache_put(struct f2fs_cached_block *entry)
+{
+	WARN_ON_ONCE(!f2fs_cache_refcount(entry));
+	if (atomic_dec_and_test(&entry->refcount)) {
+		f2fs_free_cache(entry);
+		return true;
+	}
+	return false;
+}
+
+static struct f2fs_cached_block *f2fs_create_cache(
+		struct f2fs_cached_block_list *cache,
+		unsigned long index, bool nofail)
+{
+	struct f2fs_cached_block *entry;
+	unsigned int flags = GFP_NOFS;
+
+	if (index == ULONG_MAX)
+		return ERR_PTR(-ERANGE);
+
+	if (nofail)
+		flags |= __GFP_NOFAIL;
+
+	entry = kzalloc_obj(*entry, flags);
+	if (!entry)
+		return ERR_PTR(-ENOMEM);
+
+	entry->data = kmalloc(cache->sbi->blocksize, flags);
+	if (!entry->data) {
+		kfree(entry);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	entry->index = index;
+
+	atomic_set(&entry->refcount, 0);
+	entry->next_entry = NULL;
+	INIT_LIST_HEAD(&entry->list);
+
+	entry->cache = cache;
+
+	return entry;
+}
+
+static struct f2fs_cached_block *f2fs_insert_cache(
+			struct f2fs_cached_block_list *cache,
+			unsigned long index,
+			struct f2fs_cached_block *new)
+{
+	struct f2fs_cached_block *e;
+	int ret;
+	unsigned long flags;
+
+	ret = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
+	f2fs_bug_on(cache->sbi, ret);
+
+	spin_lock(&cache->list_lock);
+	spin_lock_irqsave(&cache->tree_lock, flags);
+	e = radix_tree_lookup(&cache->root, index);
+	if (!e) {
+		e = new;
+		f2fs_bug_on(cache->sbi, f2fs_cache_refcount(e));
+
+		ret = radix_tree_insert(&cache->root, index, e);
+		f2fs_bug_on(cache->sbi, ret);
+
+		/* radix tree referenced cache entry */
+		f2fs_cache_get(e);
+		f2fs_bug_on(cache->sbi, !list_empty(&e->list));
+		list_add_tail(&e->list, &cache->lru_list);
+		cache->num_entries++;
+	}
+	f2fs_cache_get(e);
+	spin_unlock_irqrestore(&cache->tree_lock, flags);
+	spin_unlock(&cache->list_lock);
+	radix_tree_preload_end();
+
+	if (new != e) {
+		f2fs_bug_on(cache->sbi, f2fs_cache_refcount(new));
+		f2fs_do_free_cache(new);
+	}
+
+	return e;
+}
+
+struct f2fs_cached_block *f2fs_find_cache(
+			struct f2fs_cached_block_list *cache,
+			unsigned long index,
+			enum f2fs_cache_request_flag rflag)
+{
+	struct f2fs_cached_block *entry;
+	unsigned long flags;
+	bool access = rflag & F2FS_CACHE_ACCESS;
+
+	spin_lock_irqsave(&cache->tree_lock, flags);
+	entry = radix_tree_lookup(&cache->root, index);
+	if (entry) {
+		f2fs_bug_on(cache->sbi, !f2fs_cache_refcount(entry));
+		f2fs_cache_get(entry);
+		if (access && !f2fs_cache_test_referenced(entry))
+			f2fs_cache_set_referenced(entry);
+	} else {
+		entry = ERR_PTR(-ENOENT);
+	}
+	spin_unlock_irqrestore(&cache->tree_lock, flags);
+
+	return entry;
+}
+
+struct f2fs_cached_block *f2fs_grab_cache(
+			struct f2fs_cached_block_list *cache,
+			unsigned long index, int flags)
+
+{
+	struct f2fs_cached_block *entry, *new;
+	bool create = flags & F2FS_CACHE_CREATE;
+	bool nofail = flags & F2FS_CACHE_NOFAIL;
+	bool lock = flags & F2FS_CACHE_LOCK;
+
+repeat:
+	entry = f2fs_find_cache(cache, index, F2FS_CACHE_ACCESS);
+	if (!IS_ERR(entry))
+		goto found;
+
+	if (!create)
+		return ERR_PTR(-ENOENT);
+
+	new = f2fs_create_cache(cache, index, nofail);
+	if (IS_ERR(new))
+		return new;
+
+	entry = f2fs_insert_cache(cache, index, new);
+found:
+	if (lock) {
+		f2fs_lock_cache(entry);
+		/* has been truncated */
+		if (entry->cache != cache) {
+			f2fs_put_cache(entry, true);
+			goto repeat;
+		}
+	}
+	return entry;
+}
+
+bool f2fs_trylock_cache(struct f2fs_cached_block *entry)
+{
+	return !test_and_set_bit(F2FS_BLOCK_LOCKED, &entry->state);
+}
+
+void f2fs_lock_cache(struct f2fs_cached_block *entry)
+{
+	wait_on_bit_lock(&entry->state, F2FS_BLOCK_LOCKED,
+					TASK_UNINTERRUPTIBLE);
+}
+
+void f2fs_unlock_cache(struct f2fs_cached_block *entry)
+{
+	clear_and_wake_up_bit(F2FS_BLOCK_LOCKED, &entry->state);
+}
+
+bool f2fs_put_cache(struct f2fs_cached_block *entry, bool unlock)
+{
+	if (IS_ERR_OR_NULL(entry))
+		return false;
+	if (unlock)
+		f2fs_unlock_cache(entry);
+	return f2fs_cache_put(entry);
+}
+
+unsigned int f2fs_cache_gang_lookup(struct f2fs_cached_block_list *cache,
+				struct f2fs_cached_block **entries,
+				pgoff_t *index, unsigned long end)
+{
+	unsigned long flags;
+	unsigned int max_nr = min((unsigned long)F2FS_ONSTACK_CACHES, end - *index);
+	int nr, i;
+
+	if (*index >= end || *index == ULONG_MAX)
+		return 0;
+
+	spin_lock_irqsave(&cache->tree_lock, flags);
+	nr = radix_tree_gang_lookup(&cache->root, (void **)entries,
+				*index, max_nr);
+	if (!nr)
+		goto out_unlock;
+
+	for (i = 0; i < nr; i++) {
+		struct f2fs_cached_block *entry = entries[i];
+
+		if (entry->index >= end) {
+			nr = i;
+			break;
+		}
+		f2fs_cache_get(entry);
+	}
+	if (nr)
+		*index = entries[nr - 1]->index + 1;
+out_unlock:
+	spin_unlock_irqrestore(&cache->tree_lock, flags);
+	return nr;
+}
+
+unsigned int f2fs_cache_gang_lookup_tag(struct f2fs_cached_block_list *cache,
+				struct f2fs_cached_block **entries,
+				pgoff_t *index, unsigned int max_nr,
+				int tag)
+{
+	unsigned long flags;
+	int nr, i;
+
+	if (*index == ULONG_MAX)
+		return 0;
+
+	spin_lock_irqsave(&cache->tree_lock, flags);
+	nr = radix_tree_gang_lookup_tag(&cache->root, (void **)entries,
+				*index, max_nr, tag);
+	if (!nr)
+		goto out;
+
+	for (i = 0; i < nr; i++)
+		f2fs_cache_get(entries[i]);
+	*index = entries[nr - 1]->index + 1;
+out:
+	spin_unlock_irqrestore(&cache->tree_lock, flags);
+	return nr;
+}
+
+void f2fs_cache_gang_release(struct f2fs_cached_block **entries,
+				unsigned int nr_entries)
+{
+	int i;
+
+	for (i = 0; i < nr_entries; i++)
+		f2fs_put_cache(entries[i], false);
+}
+
+void f2fs_cache_wait_on_all_writeback(struct f2fs_cached_block_list *cache)
+{
+	unsigned long index = 0;
+	struct f2fs_cached_block *entries[F2FS_ONSTACK_CACHES];
+	int nr, i;
+
+next:
+	nr = f2fs_cache_gang_lookup_tag(cache, entries, &index,
+			F2FS_ONSTACK_CACHES, F2FS_CACHE_TAG_WRITEBACK);
+	if (!nr)
+		return;
+
+	for (i = 0; i < nr; i++)
+		f2fs_cache_wait_writeback(entries[i]);
+	f2fs_cache_gang_release(entries, nr);
+
+	cond_resched();
+	goto next;
+}
+
+static void f2fs_do_truncate_cache(struct f2fs_cached_block *entry,
+						bool drop_dirty)
+{
+	struct f2fs_cached_block_list *cache = entry->cache;
+	unsigned long flags;
+
+	if (drop_dirty)
+		goto drop_it;
+
+	if (f2fs_cache_test_dirty(entry) ||
+	    f2fs_cache_test_writeback(entry))
+		return;
+
+drop_it:
+	f2fs_cache_wait_writeback(entry);
+	f2fs_drop_cache_dirty(entry);
+
+	spin_lock(&cache->list_lock);
+	spin_lock_irqsave(&cache->tree_lock, flags);
+
+	f2fs_bug_on(cache->sbi, !entry->cache);
+	if (!radix_tree_delete(&cache->root, entry->index))
+		f2fs_bug_on(cache->sbi, !entry->cache);
+
+	entry->cache = NULL;
+	cache->num_entries--;
+
+	atomic_dec(&entry->refcount);
+	f2fs_bug_on(cache->sbi, !f2fs_cache_refcount(entry));
+
+	f2fs_bug_on(cache->sbi, list_empty(&entry->list));
+	list_del_init(&entry->list);
+
+	spin_unlock_irqrestore(&cache->tree_lock, flags);
+	spin_unlock(&cache->list_lock);
+}
+
+void f2fs_truncate_locked_cache(struct f2fs_cached_block *entry,
+				bool drop_dirty)
+{
+	if (!entry->cache)
+		return;
+	f2fs_do_truncate_cache(entry, drop_dirty);
+}
+
+void f2fs_truncate_cache(struct f2fs_cached_block *entry, bool drop_dirty)
+{
+	f2fs_lock_cache(entry);
+	f2fs_truncate_locked_cache(entry, drop_dirty);
+	f2fs_unlock_cache(entry);
+}
+
+static void f2fs_drop_cache(struct f2fs_cached_block_list *cache,
+			block_t blkaddr, bool drop_dirty)
+{
+	struct f2fs_cached_block *entry;
+
+	entry = f2fs_find_cache(cache, blkaddr, 0);
+	if (IS_ERR(entry))
+		return;
+
+	f2fs_truncate_cache(entry, drop_dirty);
+	f2fs_put_cache(entry, false);
+}
+
+void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
+		unsigned long start, unsigned long len, bool drop_dirty)
+{
+	unsigned long index = start;
+	unsigned long end = (ULONG_MAX - start < len) ?
+				ULONG_MAX : (start + len);
+	struct f2fs_cached_block *entries[F2FS_ONSTACK_CACHES];
+	int nr, i;
+
+	if (len == 1)
+		return f2fs_drop_cache(cache, index, drop_dirty);
+
+next:
+	nr = f2fs_cache_gang_lookup(cache, entries, &index, end);
+	if (!nr)
+		return;
+
+	for (i = 0; i < nr; i++)
+		f2fs_truncate_cache(entries[i], drop_dirty);
+	f2fs_cache_gang_release(entries, nr);
+
+	if (index < end) {
+		cond_resched();
+		goto next;
+	}
+}
+
+int f2fs_init_cache(struct f2fs_sb_info *sbi,
+		struct f2fs_cached_block_list *cache,
+		enum f2fs_cache_type type)
+{
+	cache->sbi = sbi;
+	cache->type = type;
+	INIT_RADIX_TREE(&cache->root, GFP_ATOMIC);
+	spin_lock_init(&cache->tree_lock);
+	spin_lock_init(&cache->list_lock);
+	INIT_LIST_HEAD(&cache->lru_list);
+	cache->num_entries = 0;
+
+	return 0;
+}
+
+void f2fs_destroy_cache(struct f2fs_cached_block_list *cache)
+{
+	struct list_head *head = &cache->lru_list;
+	struct f2fs_cached_block *entry;
+	unsigned long flags;
+
+	f2fs_cache_wait_on_all_writeback(cache);
+next:
+	spin_lock(&cache->list_lock);
+	if (list_empty(head)) {
+		spin_unlock(&cache->list_lock);
+		return;
+	}
+	entry = list_first_entry(head, struct f2fs_cached_block, list);
+
+	spin_lock_irqsave(&cache->tree_lock, flags);
+	radix_tree_delete(&cache->root, entry->index);
+	cache->num_entries--;
+	list_del_init(&entry->list);
+	spin_unlock_irqrestore(&cache->tree_lock, flags);
+
+	spin_unlock(&cache->list_lock);
+
+	/* wait on read cache IO */
+	f2fs_lock_cache(entry);
+	/* wait on write cache IO */
+	f2fs_cache_wait_writeback(entry);
+	f2fs_bug_on(cache->sbi, f2fs_cache_test_dirty(entry));
+	f2fs_bug_on(cache->sbi, f2fs_cache_test_writeback(entry));
+	f2fs_bug_on(cache->sbi, !list_empty(&entry->list));
+	f2fs_bug_on(cache->sbi, f2fs_cache_refcount(entry) != 1);
+	f2fs_put_cache(entry, true);
+	goto next;
+}
fs/f2fs/cache.h new file +196 -0
new file mode 100644
index 000000000000..1fa279f9d69e
@@ -0,0 +1,196 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 Google LLC
+ * Author: Chao Yu <[email protected]>
+ */
+#ifndef _LINUX_F2FS_CACHE_H
+#define _LINUX_F2FS_CACHE_H
+
+#include <linux/pagemap.h>
+#include <linux/mm.h>
+#include <linux/list.h>
+#include <linux/radix-tree.h>
+#include <linux/spinlock.h>
+#include <linux/wait.h>
+#include <linux/types.h>
+
+struct f2fs_rwsem;
+struct f2fs_io_info;
+enum page_type;
+
+/* Represents a single cached block (meta, node) */
+struct f2fs_cached_block {
+	struct list_head list;		/* LRU list head */
+	struct f2fs_cached_block_list *cache;	/* parent cache list */
+	struct f2fs_cached_block *next_entry;	/* chain for merged BIO */
+	unsigned long index;		/* key in radix tree, (meta: pba, node: nid) */
+	unsigned long state;		/* cache entry state (e.g., Dirty, UpToDate) */
+	void *data;			/* blocksize-aligned memory (4KB or 16KB) */
+	atomic_t refcount;		/* reference count */
+};
+
+struct f2fs_sb_info;
+
+enum f2fs_cache_type {
+	F2FS_META_CACHE,
+	F2FS_NODE_CACHE,
+};
+
+/* Main cache control structure (per sb_info) */
+struct f2fs_cached_block_list {
+	struct f2fs_sb_info *sbi;	/* Pointer to f2fs_sb_info */
+	struct radix_tree_root root;	/* Radix tree for cache lookup */
+	spinlock_t tree_lock;		/* Lock for radix tree */
+	struct list_head lru_list;	/* Single global LRU list */
+	spinlock_t list_lock;		/* Lock for LRU list */
+	enum f2fs_cache_type type;	/* Cache type (Node or Meta) */
+	unsigned long num_entries;	/* Current number of entries */
+};
+
+#define IS_META_CACHE(cache) ((cache)->type == F2FS_META_CACHE)
+
+/* Flags for f2fs_cached_block state */
+enum f2fs_cached_state {
+	F2FS_BLOCK_LOCKED,		/* cache entry is locked */
+	F2FS_BLOCK_UPTODATE,		/* cache data is valid */
+	F2FS_BLOCK_DIRTY,		/* cache data is dirty, need to writeback the data */
+	F2FS_BLOCK_WRITEBACK,		/* cache data is writeback state */
+	F2FS_BLOCK_REFERENCED,		/* cache was accessed recently, shrinker will skip it for once */
+	F2FS_BLOCK_INLINE_DATA,		/* indicate inline data */
+};
+
+enum {
+	__F2FS_CACHE_CREATE,		/* create the cache if there is no cache entry */
+	__F2FS_CACHE_LOCK,		/* get and lock the cache entry */
+	__F2FS_CACHE_NOFAIL,		/* do not allow failure */
+	__F2FS_CACHE_ACCESS,		/* give a chance to add referenced tag */
+};
+
+enum f2fs_cache_request_flag {
+	F2FS_CACHE_CREATE	= 1 << __F2FS_CACHE_CREATE,
+	F2FS_CACHE_LOCK		= 1 << __F2FS_CACHE_LOCK,
+	F2FS_CACHE_NOFAIL	= 1 << __F2FS_CACHE_NOFAIL,
+	F2FS_CACHE_ACCESS	= 1 << __F2FS_CACHE_ACCESS,
+};
+
+#define F2FS_CACHE_LOCK_CREATE	(F2FS_CACHE_LOCK | F2FS_CACHE_CREATE)
+
+#define F2FS_ONSTACK_CACHES		(32)
+
+#define F2FS_CACHE_FLAG_TEST_FUNC(name, flagname)			\
+static inline bool f2fs_cache_test_##name(				\
+			const struct f2fs_cached_block *entry)		\
+{									\
+	return test_bit(F2FS_BLOCK_##flagname, &entry->state);		\
+}									\
+
+#define F2FS_CACHE_FLAG_SET_FUNC(name, flagname)			\
+static inline void f2fs_cache_set_##name(				\
+			struct f2fs_cached_block *entry)		\
+{									\
+	set_bit(F2FS_BLOCK_##flagname, &entry->state);			\
+}									\
+
+#define F2FS_CACHE_FLAG_CLEAR_FUNC(name, flagname)			\
+static inline void f2fs_cache_clear_##name(				\
+			struct f2fs_cached_block *entry)		\
+{									\
+	clear_bit(F2FS_BLOCK_##flagname, &entry->state);		\
+}									\
+
+#define F2FS_CACHE_FLAG_TEST_AND_SET_FUNC(name, flagname)		\
+static inline bool f2fs_cache_test_and_set_##name(			\
+			struct f2fs_cached_block *entry)		\
+{									\
+	return test_and_set_bit(F2FS_BLOCK_##flagname, &entry->state);	\
+}									\
+
+#define F2FS_CACHE_FLAG_TEST_AND_CLEAR_FUNC(name, flagname)		\
+static inline bool f2fs_cache_test_and_clear_##name(			\
+			struct f2fs_cached_block *entry)		\
+{									\
+	return test_and_clear_bit(F2FS_BLOCK_##flagname, &entry->state);\
+}									\
+
+F2FS_CACHE_FLAG_TEST_FUNC(locked, LOCKED);
+F2FS_CACHE_FLAG_SET_FUNC(locked, LOCKED);
+F2FS_CACHE_FLAG_CLEAR_FUNC(locked, LOCKED);
+
+F2FS_CACHE_FLAG_TEST_FUNC(uptodate, UPTODATE);
+F2FS_CACHE_FLAG_SET_FUNC(uptodate, UPTODATE);
+F2FS_CACHE_FLAG_CLEAR_FUNC(uptodate, UPTODATE);
+
+F2FS_CACHE_FLAG_TEST_FUNC(dirty, DIRTY);
+F2FS_CACHE_FLAG_SET_FUNC(dirty, DIRTY);
+F2FS_CACHE_FLAG_CLEAR_FUNC(dirty, DIRTY);
+F2FS_CACHE_FLAG_TEST_AND_SET_FUNC(dirty, DIRTY);
+F2FS_CACHE_FLAG_TEST_AND_CLEAR_FUNC(dirty, DIRTY);
+
+F2FS_CACHE_FLAG_TEST_FUNC(writeback, WRITEBACK);
+F2FS_CACHE_FLAG_SET_FUNC(writeback, WRITEBACK);
+F2FS_CACHE_FLAG_CLEAR_FUNC(writeback, WRITEBACK);
+
+F2FS_CACHE_FLAG_TEST_FUNC(inline, INLINE_DATA);
+F2FS_CACHE_FLAG_SET_FUNC(inline, INLINE_DATA);
+F2FS_CACHE_FLAG_CLEAR_FUNC(inline, INLINE_DATA);
+
+F2FS_CACHE_FLAG_TEST_FUNC(referenced, REFERENCED);
+F2FS_CACHE_FLAG_SET_FUNC(referenced, REFERENCED);
+F2FS_CACHE_FLAG_TEST_AND_CLEAR_FUNC(referenced, REFERENCED);
+
+static inline void *cache_address(const struct f2fs_cached_block *entry)
+{
+	return entry->data;
+}
+
+#define CACHED_NODE(entry)	((struct f2fs_node *)(cache_address(entry)))
+
+static inline struct folio *cache_folio(const struct f2fs_cached_block *entry)
+{
+	return virt_to_folio(entry->data);
+}
+
+int f2fs_init_cache(struct f2fs_sb_info *sbi,
+				struct f2fs_cached_block_list *cache,
+				enum f2fs_cache_type type);
+void f2fs_destroy_cache(struct f2fs_cached_block_list *cache);
+void f2fs_cache_get(struct f2fs_cached_block *entry);
+struct f2fs_cached_block *f2fs_find_cache(
+			struct f2fs_cached_block_list *cache,
+			unsigned long index,
+			enum f2fs_cache_request_flag rflag);
+#define F2FS_CACHE_TAG_NONE		0
+#define F2FS_CACHE_TAG_DIRTY		1
+#define F2FS_CACHE_TAG_WRITEBACK	2
+
+bool f2fs_trylock_cache(struct f2fs_cached_block *entry);
+void f2fs_lock_cache(struct f2fs_cached_block *entry);
+void f2fs_unlock_cache(struct f2fs_cached_block *entry);
+bool f2fs_put_cache(struct f2fs_cached_block *entry, bool unlock);
+bool f2fs_mark_cache_dirty(struct f2fs_cached_block *entry);
+void f2fs_drop_cache_dirty(struct f2fs_cached_block *entry);
+void f2fs_start_cache_writeback(struct f2fs_cached_block *entry);
+void f2fs_end_cache_writeback(struct f2fs_cached_block *entry);
+unsigned int f2fs_cache_gang_lookup(struct f2fs_cached_block_list *cache,
+				struct f2fs_cached_block **entries,
+				pgoff_t *index, unsigned long end);
+unsigned int f2fs_cache_gang_lookup_tag(struct f2fs_cached_block_list *cache,
+		struct f2fs_cached_block **results, pgoff_t *first_index,
+		unsigned int max_items, int tag);
+void f2fs_cache_gang_release(struct f2fs_cached_block **entries,
+				unsigned int nr_entries);
+void f2fs_cache_wait_on_all_writeback(struct f2fs_cached_block_list *cache);
+void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
+					enum page_type type);
+void f2fs_cache_wait_writeback(struct f2fs_cached_block *entry);
+void f2fs_cache_update_tag(struct f2fs_cached_block *entry,
+		unsigned int clear_from, unsigned int set_to);
+struct f2fs_cached_block *f2fs_grab_cache(struct f2fs_cached_block_list *cache,
+				unsigned long index, int flags);
+void f2fs_truncate_locked_cache(struct f2fs_cached_block *entry,
+				bool drop_dirty);
+void f2fs_truncate_cache(struct f2fs_cached_block *entry, bool drop_dirty);
+void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
+		unsigned long start, unsigned long len, bool drop_dirty);
+
+#endif /* _LINUX_F2FS_CACHE_H */
fs/f2fs/data.c +255 -26
index a3b02c067e89..d868b939caee 100644
@@ -41,11 +41,6 @@ struct f2fs_folio_state {
 	unsigned int		read_pages_pending;
 };
 
-struct f2fs_bio {
-	struct work_struct work;
-	struct bio bio;
-};
-
 #define	F2FS_BIO_POOL_SIZE	NR_CURSEG_TYPE
 
 int __init f2fs_init_bioset(void)
@@ -411,6 +406,65 @@ static void f2fs_write_end_io(struct bio *bio)
 	}
 }
 
+static void f2fs_cache_read_end_io(struct bio *bio)
+{
+	struct f2fs_cached_block *entry = F2FS_BIO(bio)->entry;
+	struct f2fs_sb_info *sbi = entry->cache->sbi;
+	enum count_type io_type = IS_META_CACHE(entry->cache) ?
+					F2FS_RD_META : F2FS_RD_NODE;
+	struct f2fs_cached_block *next;
+
+	iostat_update_and_unbind_ctx(bio);
+
+	if (time_to_inject(sbi, FAULT_READ_IO))
+		bio->bi_status = BLK_STS_IOERR;
+
+	while (entry) {
+		next = entry->next_entry;
+		entry->next_entry = NULL;
+
+		if (bio->bi_status == BLK_STS_OK)
+			f2fs_cache_set_uptodate(entry);
+
+		dec_page_count(sbi, io_type);
+
+		f2fs_unlock_cache(entry);
+		entry = next;
+	}
+	bio_put(bio);
+}
+
+static void f2fs_cache_write_end_io(struct bio *bio)
+{
+	struct f2fs_cached_block *entry = F2FS_BIO(bio)->entry;
+	struct f2fs_sb_info *sbi = entry->cache->sbi;
+	struct f2fs_cached_block *next;
+
+	iostat_update_and_unbind_ctx(bio);
+
+	if (time_to_inject(sbi, FAULT_WRITE_IO))
+		bio->bi_status = BLK_STS_IOERR;
+
+	if (bio->bi_status != BLK_STS_OK)
+		f2fs_stop_checkpoint(sbi, true,
+			STOP_CP_REASON_WRITE_FAIL);
+
+	while (entry) {
+		next = entry->next_entry;
+		entry->next_entry = NULL;
+
+		dec_page_count(sbi, F2FS_WB_CP_DATA);
+
+		if (!get_pages(sbi, F2FS_WB_CP_DATA) &&
+				wq_has_sleeper(&sbi->cp_wait))
+			wake_up(&sbi->cp_wait);
+
+		f2fs_end_cache_writeback(entry);
+		entry = next;
+	}
+	bio_put(bio);
+}
+
 #ifdef CONFIG_BLK_DEV_ZONED
 static void f2fs_zone_write_end_io(struct bio *bio)
 {
@@ -418,7 +472,10 @@ static void f2fs_zone_write_end_io(struct bio *bio)
 
 	bio->bi_private = io->bi_private;
 	complete(&io->zone_wait);
-	f2fs_write_end_io(bio);
+	if (f2fs_is_cache_bio(bio))
+		f2fs_cache_write_end_io(bio);
+	else
+		f2fs_write_end_io(bio);
 }
 #endif
 
@@ -505,12 +562,21 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)
 				fio->op | fio->op_flags | f2fs_io_flags(fio),
 				GFP_NOIO, &f2fs_bioset);
 	bio->bi_iter.bi_sector = sector;
+	F2FS_BIO(bio)->entry = NULL;
+	bio->bi_private = NULL;
 	if (is_read_io(fio->op)) {
-		bio->bi_end_io = f2fs_read_end_io;
-		bio->bi_private = NULL;
+		if (fio->is_cache)
+			bio->bi_end_io = f2fs_cache_read_end_io;
+		else
+			bio->bi_end_io = f2fs_read_end_io;
 	} else {
-		bio->bi_end_io = f2fs_write_end_io;
-		bio->bi_private = sbi;
+		if (fio->is_cache) {
+			bio->bi_end_io = f2fs_cache_write_end_io;
+		} else {
+			bio->bi_end_io = f2fs_write_end_io;
+			bio->bi_private = sbi;
+		}
+
 		bio->bi_write_hint = f2fs_io_type_to_rw_hint(sbi,
 						fio->type, fio->temp);
 		bio->bi_write_stream = f2fs_io_type_to_write_stream(bdev, fio->type,
@@ -533,7 +599,7 @@ static void f2fs_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,
 	 * The f2fs garbage collector sets ->encrypted_page when it wants to
 	 * read/write raw data without encryption.
 	 */
-	if (!fio || !fio->encrypted_page)
+	if (!fio || (!fio->encrypted_page && !fio->is_cache))
 		fscrypt_set_bio_crypt_ctx(bio, inode,
 				(loff_t)first_idx << inode->i_blkbits,
 				gfp_mask);
@@ -738,6 +804,53 @@ void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
 	__submit_merged_write_cond(sbi, NULL, folio, 0, type, true);
 }
 
+static bool __has_merged_cache(struct bio *bio,
+		struct f2fs_cached_block *target)
+{
+	struct f2fs_cached_block *entry;
+
+	if (!bio)
+		return false;
+
+	entry = F2FS_BIO(bio)->entry;
+
+	while (entry) {
+		if (target && entry == target)
+			return true;
+		entry = entry->next_entry;
+	}
+	return false;
+}
+
+bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
+				enum page_type type)
+{
+	struct f2fs_sb_info *sbi = entry->cache->sbi;
+	enum temp_type temp;
+	bool ret = false;
+
+	for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
+		enum page_type btype = PAGE_TYPE_OF_BIO(type);
+		struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
+		struct f2fs_lock_context lc;
+		bool merged;
+
+		f2fs_down_read_trace(&io->io_rwsem, &lc);
+		merged = __has_merged_cache(io->bio, entry);
+		f2fs_up_read_trace(&io->io_rwsem, &lc);
+
+		if (merged) {
+			__f2fs_submit_merged_write(sbi, type, temp);
+			ret = true;
+		}
+
+		/* TODO: use HOT temp only for meta pages now. */
+		if (type >= META)
+			break;
+	}
+	return ret;
+}
+
 void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi)
 {
 	f2fs_submit_merged_write(sbi, DATA);
@@ -801,6 +914,8 @@ static bool io_type_is_mergeable(struct f2fs_bio_info *io,
 
 	if (io->fio.op != fio->op)
 		return false;
+	if (io->fio.is_cache != fio->is_cache)
+		return false;
 	return (io->fio.op_flags & mask) == (fio->op_flags & mask);
 }
 
@@ -1032,6 +1147,33 @@ static bool is_end_zone_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr)
 		f2fs_blkz_is_seq(sbi, devi, blkaddr) &&
 		(blkaddr % sbi->blocks_per_blkz == sbi->blocks_per_blkz - 1);
 }
+
+static void f2fs_wait_zone_io_completion(struct f2fs_sb_info *sbi,
+			struct f2fs_bio_info *io, enum page_type btype)
+{
+	if (f2fs_sb_has_blkzoned(sbi) && btype < META && io->zone_pending_bio) {
+		wait_for_completion_io(&io->zone_wait);
+		bio_put(io->zone_pending_bio);
+		io->zone_pending_bio = NULL;
+		io->bi_private = NULL;
+	}
+}
+
+static void f2fs_submit_zone_io(struct f2fs_sb_info *sbi,
+			struct f2fs_io_info *fio, struct f2fs_bio_info *io,
+			enum page_type btype)
+{
+	if (f2fs_sb_has_blkzoned(sbi) && btype < META &&
+			is_end_zone_blkaddr(sbi, fio->new_blkaddr)) {
+		bio_get(io->bio);
+		reinit_completion(&io->zone_wait);
+		io->bi_private = io->bio->bi_private;
+		io->bio->bi_private = io;
+		io->bio->bi_end_io = f2fs_zone_write_end_io;
+		io->zone_pending_bio = io->bio;
+		__submit_merged_bio(io);
+	}
+}
 #endif
 
 void f2fs_submit_page_write(struct f2fs_io_info *fio)
@@ -1048,14 +1190,8 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
 	f2fs_down_write_trace(&io->io_rwsem, &lc);
 next:
 #ifdef CONFIG_BLK_DEV_ZONED
-	if (f2fs_sb_has_blkzoned(sbi) && btype < META && io->zone_pending_bio) {
-		wait_for_completion_io(&io->zone_wait);
-		bio_put(io->zone_pending_bio);
-		io->zone_pending_bio = NULL;
-		io->bi_private = NULL;
-	}
+	f2fs_wait_zone_io_completion(sbi, io, btype);
 #endif
-
 	if (fio->in_list) {
 		spin_lock(&io->io_lock);
 		if (list_empty(&io->io_list)) {
@@ -1110,16 +1246,109 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
 
 	trace_f2fs_submit_folio_write(fio->folio, fio);
 #ifdef CONFIG_BLK_DEV_ZONED
-	if (f2fs_sb_has_blkzoned(sbi) && btype < META &&
-			is_end_zone_blkaddr(sbi, fio->new_blkaddr)) {
-		bio_get(io->bio);
-		reinit_completion(&io->zone_wait);
-		io->bi_private = io->bio->bi_private;
-		io->bio->bi_private = io;
-		io->bio->bi_end_io = f2fs_zone_write_end_io;
-		io->zone_pending_bio = io->bio;
+	f2fs_submit_zone_io(sbi, fio, io, btype);
+#endif
+
+	if (fio->in_list)
+		goto next;
+out:
+	if (is_sbi_flag_set(sbi, SBI_IS_SHUTDOWN) ||
+				!f2fs_is_checkpoint_ready(sbi))
 		__submit_merged_bio(io);
+	f2fs_up_write_trace(&io->io_rwsem, &lc);
+}
+
+static void f2fs_bio_add_cache(struct f2fs_io_info *fio, struct bio *bio)
+{
+	struct f2fs_bio *fbio = F2FS_BIO(bio);
+	struct f2fs_cached_block *head = fbio->entry;
+	struct f2fs_cached_block *new = fio->cache_entry;
+
+	new->next_entry = head;
+	fbio->entry = new;
+}
+
+int f2fs_submit_cache_read(struct f2fs_io_info *fio)
+{
+	struct f2fs_sb_info *sbi = fio->sbi;
+	struct f2fs_cached_block *entry = fio->cache_entry;
+	struct bio *bio;
+	enum count_type io_type = IS_META_CACHE(entry->cache) ?
+				F2FS_RD_META : F2FS_RD_NODE;
+
+	if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr,
+			fio->is_por ? META_POR : (__is_meta_io(fio) ?
+			META_GENERIC : DATA_GENERIC_ENHANCE)))
+		return -EFSCORRUPTED;
+
+	bio = __bio_alloc(fio, 1);
+
+	bio_add_virt_nofail(bio, cache_address(entry), sbi->blocksize);
+	f2fs_bio_add_cache(fio, bio);
+	inc_page_count(sbi, io_type);
+
+	f2fs_submit_read_bio(sbi, bio, fio->type);
+	return 0;
+}
+
+void f2fs_submit_cache_write(struct f2fs_io_info *fio)
+{
+	struct f2fs_sb_info *sbi = fio->sbi;
+	enum page_type btype = PAGE_TYPE_OF_BIO(fio->type);
+	struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp;
+	struct f2fs_lock_context lc;
+	struct folio *folio;
+
+	f2fs_bug_on(sbi, is_read_io(fio->op));
+
+	f2fs_down_write_trace(&io->io_rwsem, &lc);
+next:
+#ifdef CONFIG_BLK_DEV_ZONED
+	f2fs_wait_zone_io_completion(sbi, io, btype);
+#endif
+	if (fio->in_list) {
+		spin_lock(&io->io_lock);
+		if (list_empty(&io->io_list)) {
+			spin_unlock(&io->io_lock);
+			goto out;
+		}
+		fio = list_first_entry(&io->io_list,
+						struct f2fs_io_info, list);
+		list_del(&fio->list);
+		spin_unlock(&io->io_lock);
 	}
+
+	verify_fio_blkaddr(fio);
+
+	fio->submitted = 1;
+	inc_page_count(sbi, F2FS_WB_CP_DATA);
+
+	if (io->bio &&
+	    (!io_is_mergeable(sbi, io->bio, io, fio, io->last_block_in_bio,
+			      fio->new_blkaddr)))
+		__submit_merged_bio(io);
+alloc_new:
+	if (io->bio == NULL) {
+		io->bio = __bio_alloc(fio, BIO_MAX_VECS);
+		io->fio = *fio;
+	}
+
+	folio = cache_folio(fio->cache_entry);
+
+	if (!bio_add_folio(io->bio, folio, sbi->blocksize,
+			offset_in_folio(folio, cache_address(fio->cache_entry)))) {
+		f2fs_bug_on(sbi, !F2FS_BIO(io->bio)->entry);
+
+		__submit_merged_bio(io);
+		goto alloc_new;
+	}
+
+	f2fs_bio_add_cache(fio, io->bio);
+
+	io->last_block_in_bio = fio->new_blkaddr;
+
+#ifdef CONFIG_BLK_DEV_ZONED
+	f2fs_submit_zone_io(sbi, fio, io, btype);
 #endif
 	if (fio->in_list)
 		goto next;
fs/f2fs/f2fs.h +24 -0
index ebc621f302e1..c0c7d51c830f 100644
@@ -222,6 +222,8 @@ struct f2fs_rwsem {
 #endif
 };
 
+#include "cache.h"
+
 struct f2fs_mount_info {
 	unsigned long long opt;
 	block_t root_reserved_blocks;	/* root reserved blocks */
@@ -1362,8 +1364,10 @@ struct f2fs_io_info {
 	unsigned int in_list:1;		/* indicate fio is in io_list */
 	unsigned int is_por:1;		/* indicate IO is from recovery or not */
 	unsigned int meta_gc:1;		/* require meta inode GC */
+	unsigned int is_cache:1;	/* indicate IO is from internal cache */
 	enum iostat_type io_type;	/* io type */
 	struct writeback_control *io_wbc; /* writeback control */
+	struct f2fs_cached_block *cache_entry;
 	struct bio **bio;		/* bio for ipu */
 	sector_t *last_block;		/* last block number in bio */
 };
@@ -1773,6 +1777,12 @@ struct f2fs_gc_kthread {
 	unsigned int boost_gc_greedy;
 };
 
+struct f2fs_bio {
+	struct work_struct work;
+	struct f2fs_cached_block *entry;
+	struct bio bio;
+};
+
 struct f2fs_sb_info {
 	struct super_block *sb;			/* pointer to VFS super block */
 	struct proc_dir_entry *s_proc;		/* proc entry */
@@ -2381,6 +2391,16 @@ static inline bool is_node_folio(struct f2fs_sb_info *sbi, struct folio *folio)
 	return folio->mapping == NODE_MAPPING(sbi);
 }
 
+static inline struct f2fs_bio *F2FS_BIO(struct bio *bio)
+{
+	return container_of(bio, struct f2fs_bio, bio);
+}
+
+static inline bool f2fs_is_cache_bio(struct bio *bio)
+{
+	return F2FS_BIO(bio)->entry != NULL;
+}
+
 static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
 {
 	return test_bit(type, &sbi->s_flag);
@@ -4312,6 +4332,8 @@ void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
 				nid_t ino, enum page_type type);
 void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
 				struct folio *folio, enum page_type type);
+bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
+				enum page_type type);
 void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
 					struct bio **bio, struct folio *folio);
 void f2fs_submit_all_merged_ipu_writes(struct f2fs_sb_info *sbi);
@@ -4319,6 +4341,8 @@ void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
 int f2fs_submit_page_bio(struct f2fs_io_info *fio);
 int f2fs_merge_page_bio(struct f2fs_io_info *fio);
 void f2fs_submit_page_write(struct f2fs_io_info *fio);
+int f2fs_submit_cache_read(struct f2fs_io_info *fio);
+void f2fs_submit_cache_write(struct f2fs_io_info *fio);
 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
 		block_t blk_addr, sector_t *sector);
 int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
fs/f2fs/iostat.h +11 -0
index 2025225b5bed..61c6bc8e3119 100644
@@ -60,6 +60,13 @@ static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
 	return iostat_ctx->post_read_ctx;
 }
 
+static inline void iostat_set_post_read_ctx(struct bio *bio, void *ctx)
+{
+	struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
+
+	iostat_ctx->post_read_ctx = ctx;
+}
+
 extern void iostat_update_and_unbind_ctx(struct bio *bio);
 extern void iostat_alloc_and_bind_ctx(struct f2fs_sb_info *sbi,
 		struct bio *bio, struct bio_post_read_ctx *ctx);
@@ -81,6 +88,10 @@ static inline struct bio_post_read_ctx *get_post_read_ctx(struct bio *bio)
 {
 	return bio->bi_private;
 }
+static inline void iostat_set_post_read_ctx(struct bio *bio, void *ctx)
+{
+	bio->bi_private = ctx;
+}
 static inline int f2fs_init_iostat_processing(void) { return 0; }
 static inline void f2fs_destroy_iostat_processing(void) {}
 static inline int f2fs_init_iostat(struct f2fs_sb_info *sbi) { return 0; }
Signature · 8 lines
2.49.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
author maintainer
#4 lore raw

PATCH v8 2/12 f2fs: cache: initialize meta cache

In reply to Chao Yu

From: Chao Yu <[email protected]>

This patch introduces meta_blocks in f2fs_sb_info structure, initializes and destroys the meta cache during filesystem mount and unmount.

It also introduces helper wrappers for meta cache operation.

---
 fs/f2fs/cache.h | 9 +++++++++
 fs/f2fs/data.c  | 3 +++
 fs/f2fs/f2fs.h  | 3 +++
 fs/f2fs/super.c | 9 +++++++--
 4 files changed, 22 insertions(+), 2 deletions(-)
fs/f2fs/cache.h +9 -0
index 1fa279f9d69e..d8123a86cdf8 100644
@@ -193,4 +193,13 @@ void f2fs_truncate_cache(struct f2fs_cached_block *entry, bool drop_dirty);
 void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 		unsigned long start, unsigned long len, bool drop_dirty);
 
+#define META_CACHE(sbi)		(&(sbi)->meta_blocks)
+
+#define f2fs_find_meta_cache(sbi, blkaddr)		\
+	f2fs_find_cache(META_CACHE(sbi), blkaddr)
+#define f2fs_invalidate_meta_caches(sbi, start, len)	\
+	f2fs_drop_cache_range(META_CACHE(sbi), start, len, false)
+#define f2fs_truncate_meta_caches(sbi, start, len)	\
+	f2fs_drop_cache_range(META_CACHE(sbi), start, len, true)
+
 #endif /* _LINUX_F2FS_CACHE_H */
fs/f2fs/data.c +3 -0
index d868b939caee..59fef2132177 100644
@@ -670,6 +670,9 @@ static bool __has_merged_page(struct f2fs_sb_info *sbi, struct bio *bio,
 	if (!inode && !folio && !ino)
 		return true;
 
+	if (f2fs_is_cache_bio(bio))
+		return false;
+
 	bio_for_each_folio_all(fi, bio) {
 		struct folio *target = fi.folio;
 
fs/f2fs/f2fs.h +3 -0
index c0c7d51c830f..85c4bf40b4aa 100644
@@ -2107,6 +2107,9 @@ struct f2fs_sb_info {
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 	struct lock_class_key cp_global_sem_key;
 #endif
+
+	/* f2fs internal cache */
+	struct f2fs_cached_block_list meta_blocks;
 };
 
 /* Definitions to access f2fs_sb_info */
fs/f2fs/super.c +7 -2
index 6a2f09c61dcd..bc3d378371e5 100644
@@ -2094,6 +2094,8 @@ static void f2fs_put_super(struct super_block *sb)
 	iput(sbi->meta_inode);
 	sbi->meta_inode = NULL;
 
+	f2fs_destroy_cache(META_CACHE(sbi));
+
 	/* Should check the page counts after dropping all node/meta pages */
 	for (i = 0; i < NR_COUNT_TYPE; i++) {
 		if (!get_pages(sbi, i))
@@ -5263,12 +5265,14 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 	if (err)
 		goto free_percpu;
 
+	f2fs_init_cache(sbi, META_CACHE(sbi), F2FS_META_CACHE);
+
 	/* get an inode for meta space */
 	sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
 	if (IS_ERR(sbi->meta_inode)) {
 		f2fs_err(sbi, "Failed to read F2FS meta data inode");
 		err = PTR_ERR(sbi->meta_inode);
-		goto free_page_array_cache;
+		goto free_meta_cache;
 	}
 
 	err = f2fs_get_valid_checkpoint(sbi);
@@ -5596,7 +5600,8 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 	make_bad_inode(sbi->meta_inode);
 	iput(sbi->meta_inode);
 	sbi->meta_inode = NULL;
-free_page_array_cache:
+free_meta_cache:
+	f2fs_destroy_cache(META_CACHE(sbi));
 	f2fs_destroy_page_array_cache(sbi);
 free_percpu:
 	destroy_percpu_info(sbi);
Signature · 1 line
2.49.0
Reviewed-by on v8 2/12
#5 lore raw

Re: [f2fs-dev] [PATCH v8 02/12] f2fs: cache: initialize meta cache

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 9 lines · 于2026年9月16日周三 09:59写道:

From: Chao Yu <[email protected]>

This patch introduces meta_blocks in f2fs_sb_info structure, initializes and destroys the meta cache during filesystem mount and unmount.

It also introduces helper wrappers for meta cache operation.

thanks!

Quoted 101 lines
---
 fs/f2fs/cache.h | 9 +++++++++
 fs/f2fs/data.c  | 3 +++
 fs/f2fs/f2fs.h  | 3 +++
 fs/f2fs/super.c | 9 +++++++--
 4 files changed, 22 insertions(+), 2 deletions(-)
fs/f2fs/cache.h +9 -0
index 1fa279f9d69e..d8123a86cdf8 100644
@@ -193,4 +193,13 @@ void f2fs_truncate_cache(struct f2fs_cached_block *entry, bool drop_dirty);
 void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
                unsigned long start, unsigned long len, bool drop_dirty);
 
+#define META_CACHE(sbi)                (&(sbi)->meta_blocks)
+
+#define f2fs_find_meta_cache(sbi, blkaddr)             \
+       f2fs_find_cache(META_CACHE(sbi), blkaddr)
+#define f2fs_invalidate_meta_caches(sbi, start, len)   \
+       f2fs_drop_cache_range(META_CACHE(sbi), start, len, false)
+#define f2fs_truncate_meta_caches(sbi, start, len)     \
+       f2fs_drop_cache_range(META_CACHE(sbi), start, len, true)
+
 #endif /* _LINUX_F2FS_CACHE_H */
fs/f2fs/data.c +3 -0
index d868b939caee..59fef2132177 100644
@@ -670,6 +670,9 @@ static bool __has_merged_page(struct f2fs_sb_info *sbi, struct bio *bio,
        if (!inode && !folio && !ino)
                return true;
 
+       if (f2fs_is_cache_bio(bio))
+               return false;
+
        bio_for_each_folio_all(fi, bio) {
                struct folio *target = fi.folio;
 
fs/f2fs/f2fs.h +3 -0
index c0c7d51c830f..85c4bf40b4aa 100644
@@ -2107,6 +2107,9 @@ struct f2fs_sb_info {
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
        struct lock_class_key cp_global_sem_key;
 #endif
+
+       /* f2fs internal cache */
+       struct f2fs_cached_block_list meta_blocks;
 };
 
 /* Definitions to access f2fs_sb_info */
fs/f2fs/super.c +7 -3
index 6a2f09c61dcd..bc3d378371e5 100644
@@ -2094,6 +2094,8 @@ static void f2fs_put_super(struct super_block *sb)
        iput(sbi->meta_inode);
        sbi->meta_inode = NULL;
 
+       f2fs_destroy_cache(META_CACHE(sbi));
+
        /* Should check the page counts after dropping all node/meta pages */
        for (i = 0; i < NR_COUNT_TYPE; i++) {
                if (!get_pages(sbi, i))
@@ -5263,12 +5265,14 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
        if (err)
                goto free_percpu;
 
+       f2fs_init_cache(sbi, META_CACHE(sbi), F2FS_META_CACHE);
+
        /* get an inode for meta space */
        sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
        if (IS_ERR(sbi->meta_inode)) {
                f2fs_err(sbi, "Failed to read F2FS meta data inode");
                err = PTR_ERR(sbi->meta_inode);
-               goto free_page_array_cache;
+               goto free_meta_cache;
        }
 
        err = f2fs_get_valid_checkpoint(sbi);
@@ -5596,7 +5600,8 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
        make_bad_inode(sbi->meta_inode);
        iput(sbi->meta_inode);
        sbi->meta_inode = NULL;
-free_page_array_cache:
+free_meta_cache:
+       f2fs_destroy_cache(META_CACHE(sbi));
        f2fs_destroy_page_array_cache(sbi);
 free_percpu:
        destroy_percpu_info(sbi);
--

2.49.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#6 lore raw

PATCH v8 3/12 f2fs: cache: introduce shrinker

In reply to Chao Yu

From: Chao Yu <[email protected]>

This patch integrates the metadata cache into the F2FS memory shrinker subsystem to reclaim clean, unreferenced cached blocks under memory pressure.

It implements f2fs_shrink_cache() using a 3-phase cache reclamin method:
1. isolate clean entries from lru list
2. truncate from radix tree under lock
3. splice un-reclaimed entries back

And hooks the new interface into f2fs_shrink_count() and f2fs_shrink_scan().

---
 fs/f2fs/cache.c    | 89 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/f2fs/cache.h    |  3 ++
 fs/f2fs/shrinker.c | 12 +++++++
 3 files changed, 104 insertions(+)
fs/f2fs/cache.c +89 -0
index fb0ab77d3b49..563615761d11 100644
@@ -537,3 +537,92 @@ void f2fs_destroy_cache(struct f2fs_cached_block_list *cache)
 	f2fs_put_cache(entry, true);
 	goto next;
 }
+
+static unsigned long f2fs_do_shrink_cache(struct f2fs_cached_block_list *cache,
+						unsigned long nr_to_scan)
+{
+	struct f2fs_cached_block *entry, *next;
+	LIST_HEAD(dispose_list);
+	LIST_HEAD(keep_list);
+	unsigned long freed = 0;
+	unsigned long scanned = 0;
+
+	/* Phase 1: Isolate candidate entries from LRU list into dispose_list */
+	spin_lock(&cache->list_lock);
+	list_for_each_entry_safe(entry, next, &cache->lru_list, list) {
+		if (scanned >= cache->num_entries)
+			break;
+		if (scanned++ >= nr_to_scan)
+			break;
+
+		/* If accessed, give it a second chance to rotate to tail */
+		if (f2fs_cache_test_and_clear_referenced(entry)) {
+			list_move_tail(&entry->list, &cache->lru_list);
+			continue;
+		}
+
+		if (f2fs_cache_test_dirty(entry) ||
+		    f2fs_cache_test_writeback(entry) ||
+		    f2fs_cache_test_locked(entry))
+			continue;
+
+		if (f2fs_cache_refcount(entry) != 1)
+			continue;
+
+		list_move_tail(&entry->list, &dispose_list);
+	}
+	spin_unlock(&cache->list_lock);
+
+	/* Phase 2: Process isolated candidates one by one */
+	while (1) {
+		spin_lock(&cache->list_lock);
+		entry = list_first_entry_or_null(&dispose_list,
+						struct f2fs_cached_block, list);
+		if (!entry) {
+			spin_unlock(&cache->list_lock);
+			break;
+		}
+		f2fs_cache_get(entry);
+		list_move_tail(&entry->list, &keep_list);
+		spin_unlock(&cache->list_lock);
+
+		if (!f2fs_trylock_cache(entry)) {
+			f2fs_put_cache(entry, false);
+			continue;
+		}
+
+		/* the entry has been truncated */
+		if (!entry->cache) {
+			f2fs_put_cache(entry, true);
+			continue;
+		}
+		/*
+		 * at least there are shrinker, radix tree and another user
+		 * has referenced the entry.
+		 */
+		if (f2fs_cache_refcount(entry) >= 3) {
+			f2fs_put_cache(entry, true);
+			continue;
+		}
+
+		f2fs_do_truncate_cache(entry, false);
+
+		if (f2fs_put_cache(entry, true))
+			freed++;
+	}
+
+	/* Phase 3: Splice un-reclaimed entries back onto cache->lru_list */
+	if (!list_empty(&keep_list)) {
+		spin_lock(&cache->list_lock);
+		list_splice_tail(&keep_list, &cache->lru_list);
+		spin_unlock(&cache->list_lock);
+	}
+
+	return freed;
+}
+
+unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
+					unsigned long nr_to_scan)
+{
+	return f2fs_do_shrink_cache(META_CACHE(sbi), nr_to_scan);
+}
fs/f2fs/cache.h +3 -0
index d8123a86cdf8..6c38fc9e18f6 100644
@@ -202,4 +202,7 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 #define f2fs_truncate_meta_caches(sbi, start, len)	\
 	f2fs_drop_cache_range(META_CACHE(sbi), start, len, true)
 
+unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
+				unsigned long nr_to_scan);
+
 #endif /* _LINUX_F2FS_CACHE_H */
fs/f2fs/shrinker.c +12 -0
index e3e0a7e89406..baa09bc63585 100644
@@ -37,6 +37,11 @@ static unsigned long __count_extent_cache(struct f2fs_sb_info *sbi,
 				atomic_read(&eti->total_ext_node);
 }
 
+static unsigned long __count_cache(struct f2fs_sb_info *sbi)
+{
+	return META_CACHE(sbi)->num_entries;
+}
+
 unsigned long f2fs_shrink_count(struct shrinker *shrink,
 				struct shrink_control *sc)
 {
@@ -68,6 +73,9 @@ unsigned long f2fs_shrink_count(struct shrinker *shrink,
 		/* count free nids cache entries */
 		count += __count_free_nids(sbi);
 
+		/* count generic cache entries */
+		count += __count_cache(sbi);
+
 		spin_lock(&f2fs_list_lock);
 		p = p->next;
 		mutex_unlock(&sbi->umount_mutex);
@@ -120,6 +128,10 @@ unsigned long f2fs_shrink_scan(struct shrinker *shrink,
 		if (freed < nr)
 			freed += f2fs_try_to_free_nids(sbi, nr - freed);
 
+		/* shrink generic cache entries */
+		if (freed < nr)
+			freed += f2fs_shrink_cache(sbi, nr - freed);
+
 		spin_lock(&f2fs_list_lock);
 		p = p->next;
 		list_move_tail(&sbi->s_list, &f2fs_list);
Signature · 1 line
2.49.0
author maintainer
#7 lore raw

PATCH v8 4/12 f2fs: cache: introduce writeback thread

In reply to Chao Yu

From: Chao Yu <[email protected]>

This patch introduces a background writeback kthread (f2fs_writeback-x:y) to periodically flush dirty metadata cache entries with a default interval of 5 seconds.

It manages thread lifecycle across mount, unmount, and remount (rw/ro) transitions.

It introduces a sysfs entry /sys/fs/f2fs/<disk>/cache_wb_interval to control writeback interval.

---
 Documentation/ABI/testing/sysfs-fs-f2fs |  6 +++
 fs/f2fs/cache.c                         | 69 +++++++++++++++++++++++++
 fs/f2fs/cache.h                         | 11 ++++
 fs/f2fs/f2fs.h                          |  3 ++
 fs/f2fs/super.c                         | 33 +++++++++++-
 fs/f2fs/sysfs.c                         | 13 ++++-
 6 files changed, 132 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
index 0cebc89799dd..d2665b7f1f14 100644
@@ -1020,3 +1020,9 @@ Contact:	"Daeho Jeong" <[email protected]>
 Description:	This is a read-only entry to show the upper bound section number
 		for pinned files. Pinned files will only be allocated within
 		sections 0 to pinned_area_max_secno - 1.
+
+What:		/sys/fs/f2fs/<disk>/cache_wb_interval
+Date:		August 2026
+Contact:	"Chao Yu" <[email protected]>
+Description:	This is a writable entry to control writeback interval of
+		f2fs_writeback-x:y, by default the value is 5000, unit is ms.
fs/f2fs/cache.c +69 -0

72 lines not on this page · raw message

fs/f2fs/cache.h +11 -0
index 6c38fc9e18f6..9a7053a9af66 100644
@@ -205,4 +205,15 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
 				unsigned long nr_to_scan);
 
+#define DEF_DIRTY_CACHE_TIMEOUT 5000
+
+struct f2fs_cache_kthread {
+	struct task_struct *cache_wb_task;
+	wait_queue_head_t cache_wb_wq;
+	unsigned int cache_wb_interval;
+};
+
+int f2fs_start_cache_wb_thread(struct f2fs_sb_info *sbi);
+void f2fs_stop_cache_wb_thread(struct f2fs_sb_info *sbi);
+
 #endif /* _LINUX_F2FS_CACHE_H */
fs/f2fs/f2fs.h +3 -0
index 85c4bf40b4aa..c0f82b63d732 100644
@@ -2110,6 +2110,9 @@ struct f2fs_sb_info {
 
 	/* f2fs internal cache */
 	struct f2fs_cached_block_list meta_blocks;
+
+	/* internal cache flush thread */
+	struct f2fs_cache_kthread cache_thread;
 };
 
 /* Definitions to access f2fs_sb_info */
fs/f2fs/super.c +31 -2
index bc3d378371e5..9004456b079d 100644
@@ -2039,6 +2039,7 @@ static void f2fs_put_super(struct super_block *sb)
 	 * flush all issued checkpoints and stop checkpoint issue thread.
 	 * after then, all checkpoints should be done by each process context.
 	 */
+	f2fs_stop_cache_wb_thread(sbi);
 	f2fs_stop_ckpt_thread(sbi);
 
 	/*
@@ -2845,6 +2846,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 	unsigned int flags = fc->sb_flags;
 	int err;
 	bool need_restart_gc = false, need_stop_gc = false;
+	bool need_restart_wb = false, need_stop_wb = false;
 	bool need_restart_flush = false, need_stop_flush = false;
 	bool need_restart_discard = false, need_stop_discard = false;
 	bool need_enable_checkpoint = false, need_disable_checkpoint = false;
@@ -3004,6 +3006,18 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 		need_stop_gc = true;
 	}
 
+	if (flags & SB_RDONLY) {
+		if (sbi->cache_thread.cache_wb_task) {
+			f2fs_stop_cache_wb_thread(sbi);
+			need_restart_wb = true;
+		}
+	} else if (!sbi->cache_thread.cache_wb_task) {
+		err = f2fs_start_cache_wb_thread(sbi);
+		if (err)
+			goto restore_gc;
+		need_stop_wb = true;
+	}
+
 	if (flags & SB_RDONLY) {
 		sync_inodes_sb(sb);
 
@@ -3011,7 +3025,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 		set_sbi_flag(sbi, SBI_IS_CLOSE);
 		err = f2fs_sync_fs(sb, 1);
 		if (err)
-			goto restore_gc;
+			goto restore_wb;
 		clear_sbi_flag(sbi, SBI_IS_CLOSE);
 	}
 
@@ -3026,7 +3040,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 	} else {
 		err = f2fs_create_flush_cmd_control(sbi);
 		if (err)
-			goto restore_gc;
+			goto restore_wb;
 		need_stop_flush = true;
 	}
 
@@ -3123,6 +3137,13 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 		clear_opt(sbi, FLUSH_MERGE);
 		f2fs_destroy_flush_cmd_control(sbi, false);
 	}
+restore_wb:
+	if (need_restart_wb) {
+		if (f2fs_start_cache_wb_thread(sbi))
+			f2fs_warn(sbi, "background cache writeback thread has stopped");
+	} else if (need_stop_wb) {
+		f2fs_stop_cache_wb_thread(sbi);
+	}
 restore_gc:
 	if (need_restart_gc) {
 		if (f2fs_start_gc_thread(sbi))
@@ -5527,6 +5548,12 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 			goto sync_free_meta;
 	}
 
+	if (!f2fs_readonly(sb)) {
+		err = f2fs_start_cache_wb_thread(sbi);
+		if (err)
+			goto stop_gc_thread;
+	}
+
 	/* recover broken superblock */
 	if (recovery) {
 		err = f2fs_commit_super(sbi, true);
@@ -5549,6 +5576,8 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 	sbi->umount_lock_holder = NULL;
 	return 0;
 
+stop_gc_thread:
+	f2fs_stop_gc_thread(sbi);
 sync_free_meta:
 	/* safe to flush all the data */
 	sync_filesystem(sbi->sb);
fs/f2fs/sysfs.c +12 -1
index aaca9ed9b169..ad25733e32c0 100644
@@ -40,6 +40,7 @@ enum {
 	RESERVED_BLOCKS,	/* struct f2fs_sb_info */
 	CPRC_INFO,	/* struct ckpt_req_control */
 	ATGC_INFO,	/* struct atgc_management */
+	WB_THREAD,	/* struct f2fs_cache_kthread */
 };
 
 static const char *gc_mode_names[MAX_GC_MODE] = {
@@ -98,6 +99,8 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
 		return (unsigned char *)&sbi->cprc_info;
 	else if (struct_type == ATGC_INFO)
 		return (unsigned char *)&sbi->am;
+	else if (struct_type == WB_THREAD)
+		return (unsigned char *)&sbi->cache_thread;
 	return NULL;
 }
 
@@ -1008,7 +1011,8 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
 	bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
 					a->struct_type == GC_THREAD);
 	bool thread_entry = !strcmp(a->attr.name, "ckpt_thread_ioprio") ||
-			!strcmp(a->attr.name, "critical_task_priority");
+			!strcmp(a->attr.name, "critical_task_priority") ||
+			!strcmp(a->attr.name, "cache_wb_interval");
 
 	if (gc_entry || thread_entry) {
 		if (!down_read_trylock(&sbi->sb->s_umount))
@@ -1218,6 +1222,9 @@ static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
 #define ATGC_INFO_RW_ATTR(name, elname)				\
 	F2FS_RW_ATTR(ATGC_INFO, atgc_management, name, elname)
 
+#define WB_THREAD_RW_ATTR(name, elname)				\
+	F2FS_RW_ATTR(WB_THREAD, f2fs_cache_kthread, name, elname)
+
 /* GC_THREAD ATTR */
 GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time);
 GC_THREAD_RW_ATTR(gc_min_sleep_time, min_sleep_time);
@@ -1347,6 +1354,9 @@ ATGC_INFO_RW_ATTR(atgc_candidate_count, max_candidate_count);
 ATGC_INFO_RW_ATTR(atgc_age_weight, age_weight);
 ATGC_INFO_RW_ATTR(atgc_age_threshold, age_threshold);
 
+/* WB_THREAD ATTR */
+WB_THREAD_RW_ATTR(cache_wb_interval, cache_wb_interval);
+
 F2FS_GENERAL_RO_ATTR(dirty_segments);
 F2FS_GENERAL_RO_ATTR(free_segments);
 F2FS_GENERAL_RO_ATTR(ovp_segments);
@@ -1533,6 +1543,7 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(lock_duration_priority),
 	ATTR_LIST(adjust_lock_priority),
 	ATTR_LIST(critical_task_priority),
+	ATTR_LIST(cache_wb_interval),
 	NULL,
 };
 ATTRIBUTE_GROUPS(f2fs);
Signature · 1 line
2.49.0
Reviewed-by on v8 4/12
#8 lore raw

Re: [f2fs-dev] [PATCH v8 04/12] f2fs: cache: introduce writeback thread

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 7 lines · 于2026年9月16日周三 09:57写道:

From: Chao Yu <[email protected]>

This patch introduces a background writeback kthread (f2fs_writeback-x:y) to periodically flush dirty metadata cache entries with a default interval of 5 seconds.

Quoted 7 lines

It manages thread lifecycle across mount, unmount, and remount (rw/ro) transitions.

It introduces a sysfs entry /sys/fs/f2fs/<disk>/cache_wb_interval to control writeback interval.

thanks!

Quoted 295 lines
---
 Documentation/ABI/testing/sysfs-fs-f2fs |  6 +++
 fs/f2fs/cache.c                         | 69 +++++++++++++++++++++++++
 fs/f2fs/cache.h                         | 11 ++++
 fs/f2fs/f2fs.h                          |  3 ++
 fs/f2fs/super.c                         | 33 +++++++++++-
 fs/f2fs/sysfs.c                         | 13 ++++-
 6 files changed, 132 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
index 0cebc89799dd..d2665b7f1f14 100644
@@ -1020,3 +1020,9 @@ Contact:  "Daeho Jeong" <[email protected]>
 Description:   This is a read-only entry to show the upper bound section number
                for pinned files. Pinned files will only be allocated within
                sections 0 to pinned_area_max_secno - 1.
+
+What:          /sys/fs/f2fs/<disk>/cache_wb_interval
+Date:          August 2026
+Contact:       "Chao Yu" <[email protected]>
+Description:   This is a writable entry to control writeback interval of
+               f2fs_writeback-x:y, by default the value is 5000, unit is ms.
fs/f2fs/cache.c +69 -0
index 563615761d11..d8504f7dd692 100644
@@ -626,3 +626,72 @@ unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
 {
        return f2fs_do_shrink_cache(META_CACHE(sbi), nr_to_scan);
 }
+
+static int f2fs_cache_writeback_kthread(void *data)
+{
+       struct f2fs_sb_info *sbi = data;
+       struct f2fs_cache_kthread *cache_thread = &sbi->cache_thread;
+       wait_queue_head_t *wq = &cache_thread->cache_wb_wq;
+
+       set_freezable();
+
+       while (!kthread_should_stop()) {
+               unsigned int interval = cache_thread->cache_wb_interval;
+
+               wait_event_freezable_timeout(*wq,
+                               kthread_should_stop(),
+                               msecs_to_jiffies(interval));
+
+               if (kthread_should_stop())
+                       break;
+
+               if (f2fs_readonly(sbi->sb))
+                       continue;
+
+               if (f2fs_cp_error(sbi))
+                       continue;
+
+               if (unlikely(freezing(current)))
+                       continue;
+
+               if (!sb_start_write_trylock(sbi->sb))
+                       continue;
+
+               sb_end_write(sbi->sb);
+       }
+       return 0;
+}
+
+int f2fs_start_cache_wb_thread(struct f2fs_sb_info *sbi)
+{
+       struct f2fs_cache_kthread *cache_thread = &sbi->cache_thread;
+       struct task_struct *task;
+       dev_t dev = sbi->sb->s_dev;
+       char name[36];
+
+       if (cache_thread->cache_wb_task)
+               return 0;
+
+       init_waitqueue_head(&cache_thread->cache_wb_wq);
+       cache_thread->cache_wb_interval = DEF_DIRTY_CACHE_TIMEOUT;
+       snprintf(name, sizeof(name), "f2fs_writeback-%u:%u",
+                       MAJOR(dev), MINOR(dev));
+
+       task = kthread_run(f2fs_cache_writeback_kthread, sbi, "%s", name);
+       if (IS_ERR(task))
+               return PTR_ERR(task);
+
+       cache_thread->cache_wb_task = task;
+       return 0;
+}
+
+void f2fs_stop_cache_wb_thread(struct f2fs_sb_info *sbi)
+{
+       struct f2fs_cache_kthread *cache_thread = &sbi->cache_thread;
+
+       if (!cache_thread->cache_wb_task)
+               return;
+
+       kthread_stop(cache_thread->cache_wb_task);
+       cache_thread->cache_wb_task = NULL;
+}
fs/f2fs/cache.h +11 -0
index 6c38fc9e18f6..9a7053a9af66 100644
@@ -205,4 +205,15 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
                                unsigned long nr_to_scan);
 
+#define DEF_DIRTY_CACHE_TIMEOUT 5000
+
+struct f2fs_cache_kthread {
+       struct task_struct *cache_wb_task;
+       wait_queue_head_t cache_wb_wq;
+       unsigned int cache_wb_interval;
+};
+
+int f2fs_start_cache_wb_thread(struct f2fs_sb_info *sbi);
+void f2fs_stop_cache_wb_thread(struct f2fs_sb_info *sbi);
+
 #endif /* _LINUX_F2FS_CACHE_H */
fs/f2fs/f2fs.h +3 -0
index 85c4bf40b4aa..c0f82b63d732 100644
@@ -2110,6 +2110,9 @@ struct f2fs_sb_info {
 
        /* f2fs internal cache */
        struct f2fs_cached_block_list meta_blocks;
+
+       /* internal cache flush thread */
+       struct f2fs_cache_kthread cache_thread;
 };
 
 /* Definitions to access f2fs_sb_info */
fs/f2fs/super.c +31 -2
index bc3d378371e5..9004456b079d 100644
@@ -2039,6 +2039,7 @@ static void f2fs_put_super(struct super_block *sb)
         * flush all issued checkpoints and stop checkpoint issue thread.
         * after then, all checkpoints should be done by each process context.
         */
+       f2fs_stop_cache_wb_thread(sbi);
        f2fs_stop_ckpt_thread(sbi);
 
        /*
@@ -2845,6 +2846,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
        unsigned int flags = fc->sb_flags;
        int err;
        bool need_restart_gc = false, need_stop_gc = false;
+       bool need_restart_wb = false, need_stop_wb = false;
        bool need_restart_flush = false, need_stop_flush = false;
        bool need_restart_discard = false, need_stop_discard = false;
        bool need_enable_checkpoint = false, need_disable_checkpoint = false;
@@ -3004,6 +3006,18 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
                need_stop_gc = true;
        }
 
+       if (flags & SB_RDONLY) {
+               if (sbi->cache_thread.cache_wb_task) {
+                       f2fs_stop_cache_wb_thread(sbi);
+                       need_restart_wb = true;
+               }
+       } else if (!sbi->cache_thread.cache_wb_task) {
+               err = f2fs_start_cache_wb_thread(sbi);
+               if (err)
+                       goto restore_gc;
+               need_stop_wb = true;
+       }
+
        if (flags & SB_RDONLY) {
                sync_inodes_sb(sb);
 
@@ -3011,7 +3025,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
                set_sbi_flag(sbi, SBI_IS_CLOSE);
                err = f2fs_sync_fs(sb, 1);
                if (err)
-                       goto restore_gc;
+                       goto restore_wb;
                clear_sbi_flag(sbi, SBI_IS_CLOSE);
        }
 
@@ -3026,7 +3040,7 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
        } else {
                err = f2fs_create_flush_cmd_control(sbi);
                if (err)
-                       goto restore_gc;
+                       goto restore_wb;
                need_stop_flush = true;
        }
 
@@ -3123,6 +3137,13 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
                clear_opt(sbi, FLUSH_MERGE);
                f2fs_destroy_flush_cmd_control(sbi, false);
        }
+restore_wb:
+       if (need_restart_wb) {
+               if (f2fs_start_cache_wb_thread(sbi))
+                       f2fs_warn(sbi, "background cache writeback thread has stopped");
+       } else if (need_stop_wb) {
+               f2fs_stop_cache_wb_thread(sbi);
+       }
 restore_gc:
        if (need_restart_gc) {
                if (f2fs_start_gc_thread(sbi))
@@ -5527,6 +5548,12 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
                        goto sync_free_meta;
        }
 
+       if (!f2fs_readonly(sb)) {
+               err = f2fs_start_cache_wb_thread(sbi);
+               if (err)
+                       goto stop_gc_thread;
+       }
+
        /* recover broken superblock */
        if (recovery) {
                err = f2fs_commit_super(sbi, true);
@@ -5549,6 +5576,8 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
        sbi->umount_lock_holder = NULL;
        return 0;
 
+stop_gc_thread:
+       f2fs_stop_gc_thread(sbi);
 sync_free_meta:
        /* safe to flush all the data */
        sync_filesystem(sbi->sb);
fs/f2fs/sysfs.c +12 -2
index aaca9ed9b169..ad25733e32c0 100644
@@ -40,6 +40,7 @@ enum {
        RESERVED_BLOCKS,        /* struct f2fs_sb_info */
        CPRC_INFO,      /* struct ckpt_req_control */
        ATGC_INFO,      /* struct atgc_management */
+       WB_THREAD,      /* struct f2fs_cache_kthread */
 };
 
 static const char *gc_mode_names[MAX_GC_MODE] = {
@@ -98,6 +99,8 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
                return (unsigned char *)&sbi->cprc_info;
        else if (struct_type == ATGC_INFO)
                return (unsigned char *)&sbi->am;
+       else if (struct_type == WB_THREAD)
+               return (unsigned char *)&sbi->cache_thread;
        return NULL;
 }
 
@@ -1008,7 +1011,8 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
        bool gc_entry = (!strcmp(a->attr.name, "gc_urgent") ||
                                        a->struct_type == GC_THREAD);
        bool thread_entry = !strcmp(a->attr.name, "ckpt_thread_ioprio") ||
-                       !strcmp(a->attr.name, "critical_task_priority");
+                       !strcmp(a->attr.name, "critical_task_priority") ||
+                       !strcmp(a->attr.name, "cache_wb_interval");
 
        if (gc_entry || thread_entry) {
                if (!down_read_trylock(&sbi->sb->s_umount))
@@ -1218,6 +1222,9 @@ static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
 #define ATGC_INFO_RW_ATTR(name, elname)                                \
        F2FS_RW_ATTR(ATGC_INFO, atgc_management, name, elname)
 
+#define WB_THREAD_RW_ATTR(name, elname)                                \
+       F2FS_RW_ATTR(WB_THREAD, f2fs_cache_kthread, name, elname)
+
 /* GC_THREAD ATTR */
 GC_THREAD_RW_ATTR(gc_urgent_sleep_time, urgent_sleep_time);
 GC_THREAD_RW_ATTR(gc_min_sleep_time, min_sleep_time);
@@ -1347,6 +1354,9 @@ ATGC_INFO_RW_ATTR(atgc_candidate_count, max_candidate_count);
 ATGC_INFO_RW_ATTR(atgc_age_weight, age_weight);
 ATGC_INFO_RW_ATTR(atgc_age_threshold, age_threshold);
 
+/* WB_THREAD ATTR */
+WB_THREAD_RW_ATTR(cache_wb_interval, cache_wb_interval);
+
 F2FS_GENERAL_RO_ATTR(dirty_segments);
 F2FS_GENERAL_RO_ATTR(free_segments);
 F2FS_GENERAL_RO_ATTR(ovp_segments);
@@ -1533,6 +1543,7 @@ static struct attribute *f2fs_attrs[] = {
        ATTR_LIST(lock_duration_priority),
        ATTR_LIST(adjust_lock_priority),
        ATTR_LIST(critical_task_priority),
+       ATTR_LIST(cache_wb_interval),
        NULL,
 };
 ATTRIBUTE_GROUPS(f2fs);
--

2.49.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#9 lore raw

PATCH v8 5/12 f2fs: cache: use meta cache

In reply to Chao Yu

From: Chao Yu <[email protected]>

This patch migrates F2FS meta block caching from the fake VFS inode page cache (sbi->meta_inode) to meta cache (sbi->meta_blocks).

It converts CP, SIT, NAT, SSA, recovery, and GC metadata I/O paths to operate on struct f2fs_cached_block instead of folio, and removes sbi->meta_inode.

---
 fs/f2fs/cache.c         |   2 +
 fs/f2fs/cache.h         |   2 +-
 fs/f2fs/checkpoint.c    | 429 ++++++++++++++++++----------------------
 fs/f2fs/compress.c      |   4 +-
 fs/f2fs/data.c          |  14 +-
 fs/f2fs/debug.c         |  12 +-
 fs/f2fs/f2fs.h          |  90 +++------
 fs/f2fs/file.c          |   4 +-
 fs/f2fs/gc.c            | 135 +++++++------
 fs/f2fs/inline.c        |   9 +-
 fs/f2fs/inode.c         |   9 +-
 fs/f2fs/node.c          | 157 ++++++++-------
 fs/f2fs/node.h          |   8 +-
 fs/f2fs/recovery.c      | 196 +++++++++---------
 fs/f2fs/segment.c       | 243 ++++++++++++-----------
 fs/f2fs/segment.h       |  29 ++-
 fs/f2fs/super.c         |  33 +---
 fs/f2fs/sysfs.c         |   2 +-
 include/linux/f2fs_fs.h |   1 -
 19 files changed, 658 insertions(+), 721 deletions(-)
fs/f2fs/cache.c +2 -0
index d8504f7dd692..4d82697060d0 100644
@@ -657,6 +657,8 @@ static int f2fs_cache_writeback_kthread(void *data)
 		if (!sb_start_write_trylock(sbi->sb))
 			continue;
 
+		f2fs_write_meta_caches(sbi);
+
 		sb_end_write(sbi->sb);
 	}
 	return 0;
fs/f2fs/cache.h +1 -1
index 9a7053a9af66..1e84e66eca79 100644
@@ -196,7 +196,7 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 #define META_CACHE(sbi)		(&(sbi)->meta_blocks)
 
 #define f2fs_find_meta_cache(sbi, blkaddr)		\
-	f2fs_find_cache(META_CACHE(sbi), blkaddr)
+	f2fs_find_cache(META_CACHE(sbi), blkaddr, 0)
 #define f2fs_invalidate_meta_caches(sbi, start, len)	\
 	f2fs_drop_cache_range(META_CACHE(sbi), start, len, false)
 #define f2fs_truncate_meta_caches(sbi, start, len)	\
fs/f2fs/checkpoint.c +197 -232

850 lines not on this page · raw message

fs/f2fs/compress.c +2 -2
index b71107604012..f85bbadde53f 100644
@@ -1150,7 +1150,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 		f2fs_compress_ctx_add_page(cc, folio);
 
 		if (!folio_test_uptodate(folio)) {
-			f2fs_handle_page_eio(sbi, folio, DATA);
+			f2fs_handle_page_eio(sbi, folio->index, DATA);
 release_and_retry:
 			f2fs_put_rpages(cc);
 			f2fs_unlock_rpages(cc, i + 1);
@@ -1357,7 +1357,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
 		fio.old_blkaddr = data_blkaddr(dn.inode, dn.node_folio,
 						dn.ofs_in_node + i + 1);
 
-		/* wait for GCed page writeback via META_MAPPING */
+		/* wait for GCed page writeback via generic cache */
 		f2fs_wait_on_block_writeback(inode, fio.old_blkaddr);
 	}
 
fs/f2fs/data.c +4 -10
index 59fef2132177..674d1b8e33d8 100644
@@ -63,8 +63,7 @@ bool f2fs_is_cp_guaranteed(const struct folio *folio)
 	inode = mapping->host;
 	sbi = F2FS_I_SB(inode);
 
-	if (inode->i_ino == F2FS_META_INO(sbi) ||
-			inode->i_ino == F2FS_NODE_INO(sbi) ||
+	if (inode->i_ino == F2FS_NODE_INO(sbi) ||
 			S_ISDIR(inode->i_mode))
 		return true;
 
@@ -82,9 +81,6 @@ static enum count_type __read_io_type(struct folio *folio)
 		struct inode *inode = mapping->host;
 		struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 
-		if (inode->i_ino == F2FS_META_INO(sbi))
-			return F2FS_RD_META;
-
 		if (inode->i_ino == F2FS_NODE_INO(sbi))
 			return F2FS_RD_NODE;
 	}
@@ -1418,7 +1414,7 @@ static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,
 	bio = f2fs_grab_read_bio(inode, vi, blkaddr, 1, op_flags, folio->index,
 				 for_write);
 
-	/* wait for GCed page writeback via META_MAPPING */
+	/* wait for GCed page writeback via generic cache */
 	f2fs_wait_on_block_writeback(inode, blkaddr);
 
 	if (!bio_add_folio(bio, folio, PAGE_SIZE, 0))
@@ -3241,7 +3237,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
 		goto out_writepage;
 	}
 
-	/* wait for GCed page writeback via META_MAPPING */
+	/* wait for GCed page writeback via generic cache */
 	if (fio->meta_gc)
 		f2fs_wait_on_block_writeback(inode, fio->old_blkaddr);
 
@@ -4314,9 +4310,7 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
 		return;
 
 	if (folio_test_dirty(folio)) {
-		if (inode->i_ino == F2FS_META_INO(sbi)) {
-			dec_page_count(sbi, F2FS_DIRTY_META);
-		} else if (inode->i_ino == F2FS_NODE_INO(sbi)) {
+		if (inode->i_ino == F2FS_NODE_INO(sbi)) {
 			dec_page_count(sbi, F2FS_DIRTY_NODES);
 		} else {
 			inode_dec_dirty_pages(inode);
fs/f2fs/debug.c +4 -8
index a6cfceafe2fe..24819d4c0d55 100644
@@ -224,8 +224,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
 	si->dirty_count = dirty_segments(sbi);
 	if (sbi->node_inode)
 		si->node_pages = NODE_MAPPING(sbi)->nrpages;
-	if (sbi->meta_inode)
-		si->meta_pages = META_MAPPING(sbi)->nrpages;
+	si->meta_caches = META_CACHE(sbi)->num_entries;
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	if (sbi->compress_inode) {
 		si->compress_pages = COMPRESS_MAPPING(sbi)->nrpages;
@@ -388,11 +387,8 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
 
 		si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
 	}
-	if (sbi->meta_inode) {
-		unsigned long npages = META_MAPPING(sbi)->nrpages;
-
-		si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
-	}
+	si->page_mem += (unsigned long long)META_CACHE(sbi)->num_entries << PAGE_SHIFT;
+	si->cache_mem += META_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	if (sbi->compress_inode) {
 		unsigned long npages = COMPRESS_MAPPING(sbi)->nrpages;
@@ -708,7 +704,7 @@ static int stat_show(struct seq_file *s, void *v)
 		seq_printf(s, "  - quota data: %4d in quota files:%4d\n",
 			   si->ndirty_qdata, si->nquota_files);
 		seq_printf(s, "  - meta: %4d in %4d\n",
-			   si->ndirty_meta, si->meta_pages);
+			   si->ndirty_meta, si->meta_caches);
 		seq_printf(s, "  - imeta: %4d\n",
 			   si->ndirty_imeta);
 		seq_printf(s, "  - fsync mark: %4lld\n",
fs/f2fs/f2fs.h +27 -63

198 lines not on this page · raw message

fs/f2fs/file.c +2 -2
index b0bdc7a977b9..7c2bfa0e63d2 100644
@@ -215,7 +215,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
 
 	f2fs_folio_wait_writeback(folio, DATA, false, true);
 
-	/* wait for GCed page writeback via META_MAPPING */
+	/* wait for GCed page writeback via generic cache */
 	f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
 
 	/*
@@ -2567,7 +2567,7 @@ int f2fs_do_shutdown(struct f2fs_sb_info *sbi, unsigned int flag,
 		f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN);
 		break;
 	case F2FS_GOING_DOWN_METAFLUSH:
-		f2fs_sync_meta_pages(sbi, LONG_MAX, FS_META_IO);
+		f2fs_sync_meta_caches(sbi, LONG_MAX, true, FS_META_IO);
 		f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN);
 		break;
 	case F2FS_GOING_DOWN_NEED_FSCK:
fs/f2fs/gc.c +74 -61

292 lines not on this page · raw message

fs/f2fs/inline.c +5 -4
index 925bdaad013c..d10acb5042e3 100644
@@ -293,7 +293,7 @@ int f2fs_write_inline_data(struct inode *inode, struct folio *folio)
 	return 0;
 }
 
-int f2fs_recover_inline_data(struct inode *inode, struct folio *nfolio)
+int f2fs_recover_inline_data(struct inode *inode, struct f2fs_cached_block *entry)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct f2fs_inode *ri = NULL;
@@ -307,12 +307,13 @@ int f2fs_recover_inline_data(struct inode *inode, struct folio *nfolio)
 	 *    x       o  -> remove data blocks, and then recover inline_data
 	 *    x       x  -> recover data blocks
 	 */
-	if (IS_INODE(F2FS_I_SB(inode), nfolio))
-		ri = F2FS_INODE(nfolio);
+	if (IS_INODE(sbi, cache_folio(entry)))
+		ri = &CACHED_NODE(entry)->i;
 
 	if (f2fs_has_inline_data(inode) &&
 			ri && (ri->i_inline & F2FS_INLINE_DATA)) {
 		struct folio *ifolio;
+
 process_inline:
 		ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
 		if (IS_ERR(ifolio))
@@ -320,7 +321,7 @@ int f2fs_recover_inline_data(struct inode *inode, struct folio *nfolio)
 
 		f2fs_folio_wait_writeback(ifolio, NODE, true, true);
 
-		src_addr = inline_data_addr(inode, nfolio);
+		src_addr = inline_data_addr(inode, cache_folio(entry));
 		dst_addr = inline_data_addr(inode, ifolio);
 		memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
 
fs/f2fs/inode.c +2 -7
index 24205a35be04..f2e1d8b50f8c 100644
@@ -578,7 +578,7 @@ static int do_read_inode(struct inode *inode)
 
 static bool is_meta_ino(struct f2fs_sb_info *sbi, unsigned int ino)
 {
-	if (ino == F2FS_NODE_INO(sbi) || ino == F2FS_META_INO(sbi))
+	if (ino == F2FS_NODE_INO(sbi))
 		return true;
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	if (test_opt(sbi, COMPRESS_CACHE) && ino == F2FS_COMPRESS_INO(sbi))
@@ -625,9 +625,6 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
 	if (ino == F2FS_NODE_INO(sbi)) {
 		inode->i_mapping->a_ops = &f2fs_node_aops;
 		mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
-	} else if (ino == F2FS_META_INO(sbi)) {
-		inode->i_mapping->a_ops = &f2fs_meta_aops;
-		mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
 	} else if (ino == F2FS_COMPRESS_INO(sbi)) {
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 		inode->i_mapping->a_ops = &f2fs_compress_aops;
@@ -827,8 +824,7 @@ int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 
-	if (inode->i_ino == F2FS_NODE_INO(sbi) ||
-			inode->i_ino == F2FS_META_INO(sbi))
+	if (inode->i_ino == F2FS_NODE_INO(sbi))
 		return 0;
 
 	/*
@@ -922,7 +918,6 @@ static bool f2fs_pre_evict_inode(struct inode *inode)
 		f2fs_invalidate_compress_pages(sbi, inode->i_ino);
 
 	if (inode->i_ino == F2FS_NODE_INO(sbi) ||
-	    inode->i_ino == F2FS_META_INO(sbi) ||
 	    inode->i_ino == F2FS_COMPRESS_INO(sbi))
 		return true;
 
fs/f2fs/node.c +78 -79

363 lines not on this page · raw message

fs/f2fs/node.h +4 -4
index 901b9e60fed5..e37fb0d63120 100644
@@ -17,15 +17,15 @@ static inline nid_t f2fs_start_nid(struct f2fs_sb_info *sbi, nid_t nid)
 #define	NAT_BLOCK_OFFSET(sbi, start_nid) \
 	((start_nid) / NAT_ENTRY_PER_BLOCK(sbi))
 
-/* # of pages to perform synchronous readahead before building free nids */
-#define FREE_NID_PAGES	8
+/* # of blocks to perform synchronous readahead before building free nids */
+#define FREE_NID_BLOCKS	8
 #define MAX_FREE_NIDS(sbi)	((unsigned long)NAT_ENTRY_PER_BLOCK(sbi) * \
-				 FREE_NID_PAGES)
+				 FREE_NID_BLOCKS)
 
 /* size of free nid batch when shrinking */
 #define SHRINK_NID_BATCH_SIZE	8
 
-#define DEF_RA_NID_PAGES	0	/* # of nid pages to be readaheaded */
+#define DEF_RA_NID_BLOCKS	0	/* # of nid blocks to be readaheaded */
 
 /* maximum readahead size for node during getting data blocks */
 #define MAX_RA_NODE		128
fs/f2fs/recovery.c +98 -98

427 lines not on this page · raw message

fs/f2fs/segment.c +123 -120

538 lines not on this page · raw message

fs/f2fs/segment.h +26 -3
index cc0428b614da..3083069c9092 100644
@@ -96,6 +96,8 @@ static inline void sanity_check_seg_type(struct f2fs_sb_info *sbi,
 #define GET_SUM_BLKOFF(sbi, segno) (segno % (sbi)->sums_per_block)
 #define SUM_BLK_PAGE_ADDR(sbi, folio, segno)	\
 	(folio_address(folio) + GET_SUM_BLKOFF(sbi, segno) * (sbi)->sum_blocksize)
+#define SUM_BLK_ENTRY_ADDR(sbi, entry, segno)	\
+	(cache_address(entry) + GET_SUM_BLKOFF(sbi, segno) * (sbi)->sum_blocksize)
 
 #define GET_SUM_TYPE(footer) ((footer)->entry_type)
 #define SET_SUM_TYPE(footer, type) ((footer)->entry_type = (type))
@@ -421,8 +423,8 @@ static inline void __seg_info_to_raw_sit(struct seg_entry *se,
 	rs->mtime = cpu_to_le64(se->mtime);
 }
 
-static inline void seg_info_to_sit_folio(struct f2fs_sb_info *sbi,
-				struct folio *folio, unsigned int start)
+static inline void seg_info_to_sit_block(struct f2fs_sb_info *sbi,
+			struct f2fs_cached_block *entry, unsigned int start)
 {
 	struct f2fs_sit_block *raw_sit;
 	struct seg_entry *se;
@@ -431,7 +433,7 @@ static inline void seg_info_to_sit_folio(struct f2fs_sb_info *sbi,
 					(unsigned long)MAIN_SEGS(sbi));
 	int i;
 
-	raw_sit = folio_address(folio);
+	raw_sit = cache_address(entry);
 	memset(raw_sit, 0, F2FS_BLKSIZE(sbi));
 	for (i = 0; i < end - start; i++) {
 		rs = &raw_sit->entries[i];
@@ -996,6 +998,27 @@ static inline int nr_pages_to_skip(struct f2fs_sb_info *sbi, int type)
 		return 0;
 }
 
+/*
+ * When writing cache asynchronously, align nr_to_write to BIO_MAX_VECS.
+ */
+static inline long adjust_flush_cache_number(struct f2fs_sb_info *sbi, int type)
+{
+	long nr_to_write;
+
+	switch (type) {
+	case META:
+		nr_to_write = BIO_MAX_VECS;
+		break;
+	case NODE:
+		nr_to_write = BIO_MAX_VECS << 1;
+		break;
+	default:
+		f2fs_bug_on(sbi, 1);
+		return 0;
+	}
+	return nr_to_write;
+}
+
 /*
  * When writing pages, it'd better align nr_to_write for segment size.
  */
fs/f2fs/super.c +8 -25
index 9004456b079d..1e6b9374df97 100644
@@ -1880,8 +1880,7 @@ static int f2fs_drop_inode(struct inode *inode)
 	 * drop useless meta/node dirty pages.
 	 */
 	if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
-		if (inode->i_ino == F2FS_NODE_INO(sbi) ||
-			inode->i_ino == F2FS_META_INO(sbi)) {
+		if (inode->i_ino == F2FS_NODE_INO(sbi)) {
 			trace_f2fs_drop_inode(inode, 1);
 			return 1;
 		}
@@ -1983,8 +1982,7 @@ static void f2fs_dirty_inode(struct inode *inode, int flags)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 
-	if (inode->i_ino == F2FS_NODE_INO(sbi) ||
-			inode->i_ino == F2FS_META_INO(sbi))
+	if (inode->i_ino == F2FS_NODE_INO(sbi))
 		return;
 
 	if (is_inode_flag_set(inode, FI_AUTO_RECOVER))
@@ -2078,11 +2076,12 @@ static void f2fs_put_super(struct super_block *sb)
 	/* our cp_error case, we can wait for any writeback page */
 	f2fs_flush_merged_writes(sbi);
 
-	f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
+	f2fs_sync_dirty_data(sbi, F2FS_WB_CP_DATA);
 
-	if (err || f2fs_cp_error(sbi)) {
+	if (err || f2fs_cp_error(sbi) ||
+		unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
 		truncate_inode_pages_final(NODE_MAPPING(sbi));
-		truncate_inode_pages_final(META_MAPPING(sbi));
+		f2fs_truncate_meta_caches(sbi, 0, ULONG_MAX);
 	}
 
 	f2fs_bug_on(sbi, sbi->fsync_node_num);
@@ -2092,9 +2091,6 @@ static void f2fs_put_super(struct super_block *sb)
 	iput(sbi->node_inode);
 	sbi->node_inode = NULL;
 
-	iput(sbi->meta_inode);
-	sbi->meta_inode = NULL;
-
 	f2fs_destroy_cache(META_CACHE(sbi));
 
 	/* Should check the page counts after dropping all node/meta pages */
@@ -4449,7 +4445,6 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
 	sbi->allocate_section_policy = ALLOCATE_FORWARD_NOHINT;
 	F2FS_ROOT_INO(sbi) = le32_to_cpu(raw_super->root_ino);
 	F2FS_NODE_INO(sbi) = le32_to_cpu(raw_super->node_ino);
-	F2FS_META_INO(sbi) = le32_to_cpu(raw_super->meta_ino);
 	sbi->cur_victim_sec = NULL_SECNO;
 	sbi->gc_mode = GC_NORMAL;
 	sbi->next_victim_seg[BG_GC] = NULL_SEGNO;
@@ -5288,18 +5283,10 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 
 	f2fs_init_cache(sbi, META_CACHE(sbi), F2FS_META_CACHE);
 
-	/* get an inode for meta space */
-	sbi->meta_inode = f2fs_iget(sb, F2FS_META_INO(sbi));
-	if (IS_ERR(sbi->meta_inode)) {
-		f2fs_err(sbi, "Failed to read F2FS meta data inode");
-		err = PTR_ERR(sbi->meta_inode);
-		goto free_meta_cache;
-	}
-
 	err = f2fs_get_valid_checkpoint(sbi);
 	if (err) {
 		f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
-		goto free_meta_inode;
+		goto free_meta_cache;
 	}
 
 	if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
@@ -5595,7 +5582,7 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 	 * followed by f2fs_write_checkpoint() through f2fs_write_node_pages(), which
 	 * falls into an infinite loop in f2fs_sync_meta_pages().
 	 */
-	truncate_inode_pages_final(META_MAPPING(sbi));
+	f2fs_truncate_meta_caches(sbi, 0, ULONG_MAX);
 	/* evict some inodes being cached by GC */
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

fs/f2fs/sysfs.c +1 -1
index ad25733e32c0..cd7ed210cad5 100644

Lines of this file are not shown. View the raw message.

include/linux/f2fs_fs.h +0 -1
index f38558279e86..c325904f461e 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.49.0

Part of the diff is not shown here. View the raw message.

author maintainer
#10 lore raw

PATCH v8 6/12 f2fs: cache: initialize node cache

In reply to Chao Yu

From: Chao Yu <[email protected]>

This patch introduces node_blocks in f2fs_sb_info structure, initializes and destroys the node cache during filesystem mount and unmount.

It also introduces helper wrappers for node cache operation, and registers node cache into the memory shrinker and writeback kthread.

---
 fs/f2fs/cache.c |  9 ++++++++-
 fs/f2fs/cache.h | 11 +++++++++++
 fs/f2fs/f2fs.h  |  1 +
 fs/f2fs/super.c |  7 +++++--
 4 files changed, 25 insertions(+), 3 deletions(-)
fs/f2fs/cache.c +8 -1
index 4d82697060d0..8ab5e0e46b4e 100644
@@ -624,7 +624,14 @@ static unsigned long f2fs_do_shrink_cache(struct f2fs_cached_block_list *cache,
 unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
 					unsigned long nr_to_scan)
 {
-	return f2fs_do_shrink_cache(META_CACHE(sbi), nr_to_scan);
+	unsigned long freed;
+
+	freed = f2fs_do_shrink_cache(META_CACHE(sbi), nr_to_scan);
+	if (freed >= nr_to_scan)
+		return freed;
+
+	freed += f2fs_do_shrink_cache(NODE_CACHE(sbi), nr_to_scan - freed);
+	return freed;
 }
 
 static int f2fs_cache_writeback_kthread(void *data)
fs/f2fs/cache.h +11 -0
index 1e84e66eca79..1eabd787b4b7 100644
@@ -194,6 +194,7 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 		unsigned long start, unsigned long len, bool drop_dirty);
 
 #define META_CACHE(sbi)		(&(sbi)->meta_blocks)
+#define NODE_CACHE(sbi)		(&(sbi)->node_blocks)
 
 #define f2fs_find_meta_cache(sbi, blkaddr)		\
 	f2fs_find_cache(META_CACHE(sbi), blkaddr, 0)
@@ -202,6 +203,16 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 #define f2fs_truncate_meta_caches(sbi, start, len)	\
 	f2fs_drop_cache_range(META_CACHE(sbi), start, len, true)
 
+#define f2fs_grab_node_cache(sbi, blkaddr)		\
+	f2fs_grab_cache(NODE_CACHE(sbi), blkaddr,	\
+	F2FS_CACHE_LOCK_CREATE)
+#define f2fs_find_node_cache(sbi, blkaddr)		\
+	f2fs_find_cache(NODE_CACHE(sbi), blkaddr)
+#define f2fs_invalidate_node_cache(sbi, blkaddr)	\
+	f2fs_drop_cache_range(NODE_CACHE(sbi), blkaddr, 1, false)
+#define f2fs_truncate_node_caches(sbi, start, len)	\
+	f2fs_drop_cache_range(NODE_CACHE(sbi), start, len, true)
+
 unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
 				unsigned long nr_to_scan);
 
fs/f2fs/f2fs.h +1 -0
index e2b29067eb0a..51c191c514bc 100644
@@ -2108,6 +2108,7 @@ struct f2fs_sb_info {
 
 	/* f2fs internal cache */
 	struct f2fs_cached_block_list meta_blocks;
+	struct f2fs_cached_block_list node_blocks;
 
 	/* internal cache flush thread */
 	struct f2fs_cache_kthread cache_thread;
fs/f2fs/super.c +5 -2
index 1e6b9374df97..fa19152cd4da 100644
@@ -2092,6 +2092,7 @@ static void f2fs_put_super(struct super_block *sb)
 	sbi->node_inode = NULL;
 
 	f2fs_destroy_cache(META_CACHE(sbi));
+	f2fs_destroy_cache(NODE_CACHE(sbi));
 
 	/* Should check the page counts after dropping all node/meta pages */
 	for (i = 0; i < NR_COUNT_TYPE; i++) {
@@ -5282,11 +5283,12 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 		goto free_percpu;
 
 	f2fs_init_cache(sbi, META_CACHE(sbi), F2FS_META_CACHE);
+	f2fs_init_cache(sbi, NODE_CACHE(sbi), F2FS_NODE_CACHE);
 
 	err = f2fs_get_valid_checkpoint(sbi);
 	if (err) {
 		f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
-		goto free_meta_cache;
+		goto free_node_cache;
 	}
 
 	if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
@@ -5612,7 +5614,8 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 free_devices:
 	destroy_device_list(sbi);
 	kvfree(sbi->ckpt);
-free_meta_cache:
+free_node_cache:
+	f2fs_destroy_cache(NODE_CACHE(sbi));
 	f2fs_destroy_cache(META_CACHE(sbi));
 	f2fs_destroy_page_array_cache(sbi);
 free_percpu:
Signature · 1 line
2.49.0
Reviewed-by on v8 6/12
#11 lore raw

Re: [f2fs-dev] [PATCH v8 06/12] f2fs: cache: initialize node cache

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 10 lines · 于2026年9月16日周三 09:57写道:

From: Chao Yu <[email protected]>

This patch introduces node_blocks in f2fs_sb_info structure, initializes and destroys the node cache during filesystem mount and unmount.

It also introduces helper wrappers for node cache operation, and registers node cache into the memory shrinker and writeback kthread.

thanks!

Quoted 113 lines
---
 fs/f2fs/cache.c |  9 ++++++++-
 fs/f2fs/cache.h | 11 +++++++++++
 fs/f2fs/f2fs.h  |  1 +
 fs/f2fs/super.c |  7 +++++--
 4 files changed, 25 insertions(+), 3 deletions(-)
fs/f2fs/cache.c +8 -1
index 4d82697060d0..8ab5e0e46b4e 100644
@@ -624,7 +624,14 @@ static unsigned long f2fs_do_shrink_cache(struct f2fs_cached_block_list *cache,
 unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
                                        unsigned long nr_to_scan)
 {
-       return f2fs_do_shrink_cache(META_CACHE(sbi), nr_to_scan);
+       unsigned long freed;
+
+       freed = f2fs_do_shrink_cache(META_CACHE(sbi), nr_to_scan);
+       if (freed >= nr_to_scan)
+               return freed;
+
+       freed += f2fs_do_shrink_cache(NODE_CACHE(sbi), nr_to_scan - freed);
+       return freed;
 }
 
 static int f2fs_cache_writeback_kthread(void *data)
fs/f2fs/cache.h +11 -0
index 1e84e66eca79..1eabd787b4b7 100644
@@ -194,6 +194,7 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
                unsigned long start, unsigned long len, bool drop_dirty);
 
 #define META_CACHE(sbi)                (&(sbi)->meta_blocks)
+#define NODE_CACHE(sbi)                (&(sbi)->node_blocks)
 
 #define f2fs_find_meta_cache(sbi, blkaddr)             \
        f2fs_find_cache(META_CACHE(sbi), blkaddr, 0)
@@ -202,6 +203,16 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 #define f2fs_truncate_meta_caches(sbi, start, len)     \
        f2fs_drop_cache_range(META_CACHE(sbi), start, len, true)
 
+#define f2fs_grab_node_cache(sbi, blkaddr)             \
+       f2fs_grab_cache(NODE_CACHE(sbi), blkaddr,       \
+       F2FS_CACHE_LOCK_CREATE)
+#define f2fs_find_node_cache(sbi, blkaddr)             \
+       f2fs_find_cache(NODE_CACHE(sbi), blkaddr)
+#define f2fs_invalidate_node_cache(sbi, blkaddr)       \
+       f2fs_drop_cache_range(NODE_CACHE(sbi), blkaddr, 1, false)
+#define f2fs_truncate_node_caches(sbi, start, len)     \
+       f2fs_drop_cache_range(NODE_CACHE(sbi), start, len, true)
+
 unsigned long f2fs_shrink_cache(struct f2fs_sb_info *sbi,
                                unsigned long nr_to_scan);
 
fs/f2fs/f2fs.h +1 -0
index e2b29067eb0a..51c191c514bc 100644
@@ -2108,6 +2108,7 @@ struct f2fs_sb_info {
 
        /* f2fs internal cache */
        struct f2fs_cached_block_list meta_blocks;
+       struct f2fs_cached_block_list node_blocks;
 
        /* internal cache flush thread */
        struct f2fs_cache_kthread cache_thread;
fs/f2fs/super.c +5 -3
index 1e6b9374df97..fa19152cd4da 100644
@@ -2092,6 +2092,7 @@ static void f2fs_put_super(struct super_block *sb)
        sbi->node_inode = NULL;
 
        f2fs_destroy_cache(META_CACHE(sbi));
+       f2fs_destroy_cache(NODE_CACHE(sbi));
 
        /* Should check the page counts after dropping all node/meta pages */
        for (i = 0; i < NR_COUNT_TYPE; i++) {
@@ -5282,11 +5283,12 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
                goto free_percpu;
 
        f2fs_init_cache(sbi, META_CACHE(sbi), F2FS_META_CACHE);
+       f2fs_init_cache(sbi, NODE_CACHE(sbi), F2FS_NODE_CACHE);
 
        err = f2fs_get_valid_checkpoint(sbi);
        if (err) {
                f2fs_err(sbi, "Failed to get valid F2FS checkpoint");
-               goto free_meta_cache;
+               goto free_node_cache;
        }
 
        if (__is_set_ckpt_flags(F2FS_CKPT(sbi), CP_QUOTA_NEED_FSCK_FLAG))
@@ -5612,7 +5614,8 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 free_devices:
        destroy_device_list(sbi);
        kvfree(sbi->ckpt);
-free_meta_cache:
+free_node_cache:
+       f2fs_destroy_cache(NODE_CACHE(sbi));
        f2fs_destroy_cache(META_CACHE(sbi));
        f2fs_destroy_page_array_cache(sbi);
 free_percpu:
--

2.49.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#12 lore raw

PATCH v8 7/12 f2fs: cache: use node cache

In reply to Chao Yu

From: Chao Yu <[email protected]>

This patch migrates F2FS node block caching from the fake VFS inode page cache (sbi->node_inode) to node cache (sbi->node_blocks).

It updates node related helpers to use node cache APIs and reference to struct f2fs_cached_block, and removes sbi->node_inode, especially, unifies inline and regular dentry block handling via struct f2fs_dentry_block_ref.

---
 fs/f2fs/acl.c           |  26 +-
 fs/f2fs/acl.h           |   8 +-
 fs/f2fs/cache.c         |   7 +-
 fs/f2fs/cache.h         |   3 +-
 fs/f2fs/checkpoint.c    |  17 +-
 fs/f2fs/compress.c      |  18 +-
 fs/f2fs/data.c          | 249 +++++------
 fs/f2fs/debug.c         |  12 +-
 fs/f2fs/dir.c           | 170 +++----
 fs/f2fs/extent_cache.c  |  14 +-
 fs/f2fs/f2fs.h          | 259 ++++++-----
 fs/f2fs/file.c          |  78 ++--
 fs/f2fs/gc.c            |  50 +--
 fs/f2fs/inline.c        | 279 ++++++------
 fs/f2fs/inode.c         | 167 ++++---
 fs/f2fs/namei.c         | 114 ++---
 fs/f2fs/node.c          | 953 +++++++++++++++++++---------------------
 fs/f2fs/node.h          | 108 ++---
 fs/f2fs/recovery.c      | 117 ++---
 fs/f2fs/segment.c       |  59 ++-
 fs/f2fs/segment.h       |  20 -
 fs/f2fs/shrinker.c      |   3 +-
 fs/f2fs/super.c         |  56 +--
 fs/f2fs/xattr.c         | 123 +++---
 fs/f2fs/xattr.h         |  12 +-
 include/linux/f2fs_fs.h |   1 -
 26 files changed, 1420 insertions(+), 1503 deletions(-)
fs/f2fs/acl.c +13 -13
index d3253549173e..34c9aa279040 100644
@@ -181,7 +181,7 @@ static void *f2fs_acl_to_disk(struct f2fs_sb_info *sbi,
 }
 
 static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type,
-						struct folio *dfolio)
+						struct f2fs_cached_block *entry)
 {
 	int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT;
 	void *value = NULL;
@@ -191,13 +191,13 @@ static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type,
 	if (type == ACL_TYPE_ACCESS)
 		name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
 
-	retval = f2fs_getxattr(inode, name_index, "", NULL, 0, dfolio);
+	retval = f2fs_getxattr(inode, name_index, "", NULL, 0, entry);
 	if (retval > 0) {
 		value = f2fs_kmalloc(F2FS_I_SB(inode), retval, GFP_F2FS_ZERO);
 		if (!value)
 			return ERR_PTR(-ENOMEM);
 		retval = f2fs_getxattr(inode, name_index, "", value,
-							retval, dfolio);
+							retval, entry);
 	}
 
 	if (retval > 0)
@@ -242,7 +242,7 @@ static int f2fs_acl_update_mode(struct mnt_idmap *idmap,
 
 static int __f2fs_set_acl(struct mnt_idmap *idmap,
 			struct inode *inode, int type,
-			struct posix_acl *acl, struct folio *ifolio)
+			struct posix_acl *acl, struct f2fs_cached_block *ientry)
 {
 	int name_index;
 	void *value = NULL;
@@ -253,7 +253,7 @@ static int __f2fs_set_acl(struct mnt_idmap *idmap,
 	switch (type) {
 	case ACL_TYPE_ACCESS:
 		name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
-		if (acl && !ifolio) {
+		if (acl && !ientry) {
 			error = f2fs_acl_update_mode(idmap, inode, &mode, &acl);
 			if (error)
 				return error;
@@ -279,7 +279,7 @@ static int __f2fs_set_acl(struct mnt_idmap *idmap,
 		}
 	}
 
-	error = f2fs_setxattr(inode, name_index, "", value, size, ifolio, 0);
+	error = f2fs_setxattr(inode, name_index, "", value, size, ientry, 0);
 
 	kfree(value);
 	if (!error)
@@ -374,7 +374,7 @@ static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
 
 static int f2fs_acl_create(struct inode *dir, umode_t *mode,
 		struct posix_acl **default_acl, struct posix_acl **acl,
-		struct folio *dfolio)
+		struct f2fs_cached_block *entry)
 {
 	struct posix_acl *p;
 	struct posix_acl *clone;
@@ -386,7 +386,7 @@ static int f2fs_acl_create(struct inode *dir, umode_t *mode,
 	if (S_ISLNK(*mode) || !IS_POSIXACL(dir))
 		return 0;
 
-	p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, dfolio);
+	p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, entry);
 	if (!p || p == ERR_PTR(-EOPNOTSUPP)) {
 		*mode &= ~current_umask();
 		return 0;
@@ -423,13 +423,13 @@ static int f2fs_acl_create(struct inode *dir, umode_t *mode,
 	return ret;
 }
 
-int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
-							struct folio *dfolio)
+int f2fs_init_acl(struct inode *inode, struct inode *dir, struct f2fs_cached_block *ientry,
+							struct f2fs_cached_block *dentry)
 {
 	struct posix_acl *default_acl = NULL, *acl = NULL;
 	int error;
 
-	error = f2fs_acl_create(dir, &inode->i_mode, &default_acl, &acl, dfolio);
+	error = f2fs_acl_create(dir, &inode->i_mode, &default_acl, &acl, dentry);
 	if (error)
 		return error;
 
@@ -437,7 +437,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
 
 	if (default_acl) {
 		error = __f2fs_set_acl(NULL, inode, ACL_TYPE_DEFAULT,
-				default_acl, ifolio);
+				default_acl, ientry);
 		posix_acl_release(default_acl);
 	} else {
 		inode->i_default_acl = NULL;
@@ -445,7 +445,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
 	if (acl) {
 		if (!error)
 			error = __f2fs_set_acl(NULL, inode, ACL_TYPE_ACCESS,
-					acl, ifolio);
+					acl, ientry);
 		posix_acl_release(acl);
 	} else {
 		inode->i_acl = NULL;
fs/f2fs/acl.h +5 -3
index 20e87e63c089..0f639367a0ab 100644
@@ -36,14 +36,16 @@ struct f2fs_acl_header {
 struct posix_acl *f2fs_get_acl(struct inode *, int, bool);
 int f2fs_set_acl(struct mnt_idmap *, struct dentry *,
 			struct posix_acl *, int);
-int f2fs_init_acl(struct inode *, struct inode *, struct folio *ifolio,
-		struct folio *dfolio);
+int f2fs_init_acl(struct inode *inode, struct inode *dir,
+			struct f2fs_cached_block *ientry,
+			struct f2fs_cached_block *dentry);
 #else
 #define f2fs_get_acl	NULL
 #define f2fs_set_acl	NULL
 
 static inline int f2fs_init_acl(struct inode *inode, struct inode *dir,
-				struct folio *ifolio, struct folio *dfolio)
+				struct f2fs_cached_block *ientry,
+				struct f2fs_cached_block *dentry)
 {
 	return 0;
 }
fs/f2fs/cache.c +4 -3
index 8ab5e0e46b4e..3abd469dc011 100644
@@ -28,7 +28,7 @@ void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
 		return;
 
 	/* submit cached bio */
-	f2fs_submit_merged_write_cache(entry, type);
+	f2fs_submit_merged_write_cache(entry->cache->sbi, entry, 0, type);
 
 	wait_on_bit_io(&entry->state, F2FS_BLOCK_WRITEBACK,
 					TASK_UNINTERRUPTIBLE);
@@ -65,8 +65,8 @@ bool f2fs_mark_cache_dirty(struct f2fs_cached_block *entry)
 	f2fs_cache_set_uptodate(entry);
 
 #ifdef CONFIG_F2FS_CHECK_FS
-	if (cache->type == F2FS_NODE_CACHE && IS_INODE(cache->sbi, cache_folio(entry)))
-		f2fs_inode_chksum_set(cache->sbi, cache_folio(entry));
+	if (f2fs_is_node_cache(entry) && IS_INODE(cache->sbi, entry))
+		f2fs_inode_chksum_set(cache->sbi, entry);
 #endif
 
 	if (!f2fs_cache_test_and_set_dirty(entry)) {
@@ -665,6 +665,7 @@ static int f2fs_cache_writeback_kthread(void *data)
 			continue;
 
 		f2fs_write_meta_caches(sbi);
+		f2fs_write_node_caches(sbi);
 
 		sb_end_write(sbi->sb);
 	}
fs/f2fs/cache.h +2 -1
index 1eabd787b4b7..a36ee57adb1a 100644
@@ -48,6 +48,7 @@ struct f2fs_cached_block_list {
 };
 
 #define IS_META_CACHE(cache) ((cache)->type == F2FS_META_CACHE)
+#define IS_NODE_CACHE(cache) ((cache)->type == F2FS_NODE_CACHE)
 
 /* Flags for f2fs_cached_block state */
 enum f2fs_cached_state {
@@ -207,7 +208,7 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
 	f2fs_grab_cache(NODE_CACHE(sbi), blkaddr,	\
 	F2FS_CACHE_LOCK_CREATE)
 #define f2fs_find_node_cache(sbi, blkaddr)		\
-	f2fs_find_cache(NODE_CACHE(sbi), blkaddr)
+	f2fs_find_cache(NODE_CACHE(sbi), blkaddr, F2FS_CACHE_ACCESS)
 #define f2fs_invalidate_node_cache(sbi, blkaddr)	\
 	f2fs_drop_cache_range(NODE_CACHE(sbi), blkaddr, 1, false)
 #define f2fs_truncate_node_caches(sbi, start, len)	\
fs/f2fs/checkpoint.c +7 -10
index 8e524d9860a2..fe7e8bab644b 100644
@@ -927,7 +927,7 @@ void f2fs_add_orphan_inode(struct inode *inode)
 {
 	/* add new orphan ino entry into list */
 	f2fs_add_ino_entry(F2FS_I_SB(inode), inode->i_ino, ORPHAN_INO);
-	f2fs_update_inode_page(inode);
+	f2fs_update_inode_cache(inode);
 }
 
 void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
@@ -1428,7 +1428,7 @@ static int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
 
 			/* it's on eviction */
 			if (is_inode_flag_set(inode, FI_DIRTY_INODE))
-				f2fs_update_inode_page(inode);
+				f2fs_update_inode_cache(inode);
 			iput(inode);
 		} else {
 			cond_resched();
@@ -1483,14 +1483,10 @@ static bool __need_flush_quota(struct f2fs_sb_info *sbi)
  */
 static int block_operations(struct f2fs_sb_info *sbi)
 {
-	struct writeback_control wbc = {
-		.sync_mode = WB_SYNC_ALL,
-		.nr_to_write = LONG_MAX,
-	};
 	int err = 0, cnt = 0;
 
 	/*
-	 * Let's flush inline_data in dirty node pages.
+	 * Let's flush inline_data in dirty node caches.
 	 */
 	f2fs_flush_inline_data(sbi);
 
@@ -1529,7 +1525,7 @@ static int block_operations(struct f2fs_sb_info *sbi)
 	}
 
 	/*
-	 * POR: we should ensure that there are no dirty node pages
+	 * POR: we should ensure that there are no dirty node caches
 	 * until finishing nat/sit flush. inode->i_blocks can be updated.
 	 */
 	f2fs_down_write(&sbi->node_change);
@@ -1550,7 +1546,8 @@ static int block_operations(struct f2fs_sb_info *sbi)
 	if (get_pages(sbi, F2FS_DIRTY_NODES)) {
 		f2fs_up_write(&sbi->node_write);
 		atomic_inc(&sbi->wb_sync_req[NODE]);
-		err = f2fs_sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO);
+		err = f2fs_writeback_node_caches(sbi, LONG_MAX,
+			true, false, FS_CP_NODE_IO);
 		atomic_dec(&sbi->wb_sync_req[NODE]);
 		if (err) {
 			f2fs_up_write(&sbi->node_change);
@@ -1900,7 +1897,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	__set_cp_next_pack(sbi);
 
 	/*
-	 * redirty superblock if metadata like node page or inode cache is
+	 * redirty superblock if metadata like node caches or inode cache is
 	 * updated during writing checkpoint.
 	 */
 	if (get_pages(sbi, F2FS_DIRTY_NODES) ||
fs/f2fs/compress.c +9 -9
index f85bbadde53f..d7f7c35e710f 100644
@@ -909,7 +909,7 @@ bool f2fs_sanity_check_cluster(struct dnode_of_data *dn)
 	}
 
 	for (i = 1, count = 1; i < cluster_size; i++, count++) {
-		block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+		block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
 							dn->ofs_in_node + i);
 
 		/* [COMPR_ADDR, ..., COMPR_ADDR] */
@@ -950,7 +950,7 @@ static int __f2fs_get_cluster_blocks(struct inode *inode,
 	int count, i;
 
 	for (i = 0, count = 0; i < cluster_size; i++) {
-		block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+		block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
 							dn->ofs_in_node + i);
 
 		if (__is_valid_data_blkaddr(blkaddr))
@@ -1146,7 +1146,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
 			goto release_and_retry;
 		}
 
-		f2fs_folio_wait_writeback(folio, DATA, true, true);
+		f2fs_folio_wait_writeback(folio, true, true);
 		f2fs_compress_ctx_add_page(cc, folio);
 
 		if (!folio_test_uptodate(folio)) {
@@ -1322,7 +1322,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
 		goto out_unlock_op;
 
 	for (i = 0; i < cc->cluster_size; i++) {
-		if (data_blkaddr(dn.inode, dn.node_folio,
+		if (data_blkaddr(dn.inode, dn.node_entry,
 					dn.ofs_in_node + i) == NULL_ADDR)
 			goto out_put_dnode;
 	}
@@ -1354,7 +1354,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
 				page_folio(cc->rpages[i + 1])->index, cic);
 		fio.compressed_page = cc->cpages[i];
 
-		fio.old_blkaddr = data_blkaddr(dn.inode, dn.node_folio,
+		fio.old_blkaddr = data_blkaddr(dn.inode, dn.node_entry,
 						dn.ofs_in_node + i + 1);
 
 		/* wait for GCed page writeback via generic cache */
@@ -1542,7 +1542,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
 		if (folio_test_writeback(folio)) {
 			if (wbc->sync_mode == WB_SYNC_NONE)
 				goto continue_unlock;
-			f2fs_folio_wait_writeback(folio, DATA, true, true);
+			f2fs_folio_wait_writeback(folio, true, true);
 		}
 
 		if (!folio_clear_dirty_for_io(folio))
@@ -1874,14 +1874,14 @@ void f2fs_put_folio_dic(struct folio *folio, bool in_task)
 unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn,
 						unsigned int ofs_in_node)
 {
-	bool compressed = data_blkaddr(dn->inode, dn->node_folio,
+	bool compressed = data_blkaddr(dn->inode, dn->node_entry,
 					ofs_in_node) == COMPRESS_ADDR;
 	int i = compressed ? 1 : 0;
-	block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+	block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_entry,
 							ofs_in_node + i);
 
 	for (i += 1; i < F2FS_I(dn->inode)->i_cluster_size; i++) {
-		block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+		block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
 							ofs_in_node + i);
 
 		if (!__is_valid_data_blkaddr(blkaddr))
fs/f2fs/data.c +117 -132

566 lines not on this page · raw message

fs/f2fs/debug.c +4 -8
index 24819d4c0d55..c09c5f700c89 100644
@@ -222,8 +222,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
 	si->free_secs = free_sections(sbi);
 	si->prefree_count = prefree_segments(sbi);
 	si->dirty_count = dirty_segments(sbi);
-	if (sbi->node_inode)
-		si->node_pages = NODE_MAPPING(sbi)->nrpages;
+	si->node_caches = NODE_CACHE(sbi)->num_entries;
 	si->meta_caches = META_CACHE(sbi)->num_entries;
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	if (sbi->compress_inode) {
@@ -382,13 +381,10 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
 	}
 
 	si->page_mem = 0;
-	if (sbi->node_inode) {
-		unsigned long npages = NODE_MAPPING(sbi)->nrpages;
-
-		si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
-	}
 	si->page_mem += (unsigned long long)META_CACHE(sbi)->num_entries << PAGE_SHIFT;
 	si->cache_mem += META_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
+	si->page_mem += (unsigned long long)NODE_CACHE(sbi)->num_entries << PAGE_SHIFT;
+	si->cache_mem += NODE_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
 #ifdef CONFIG_F2FS_FS_COMPRESSION
 	if (sbi->compress_inode) {
 		unsigned long npages = COMPRESS_MAPPING(sbi)->nrpages;
@@ -696,7 +692,7 @@ static int stat_show(struct seq_file *s, void *v)
 			   si->aw_cnt, si->max_aw_cnt);
 		seq_printf(s, "  - compress: %4d, hit:%8d\n", si->compress_pages, si->compress_page_hit);
 		seq_printf(s, "  - nodes: %4d in %4d\n",
-			   si->ndirty_node, si->node_pages);
+			   si->ndirty_node, si->node_caches);
 		seq_printf(s, "  - dents: %4d in dirs:%4d (%4d)\n",
 			   si->ndirty_dent, si->ndirty_dirs, si->ndirty_all);
 		seq_printf(s, "  - data: %4d in files:%4d\n",
fs/f2fs/dir.c +93 -77

416 lines not on this page · raw message

fs/f2fs/extent_cache.c +7 -7
index 40cd87940961..5a944428aca0 100644
@@ -20,10 +20,10 @@
 #include "segment.h"
 #include <trace/events/f2fs.h>
 
-bool sanity_check_extent_cache(struct inode *inode, struct folio *ifolio)
+bool sanity_check_extent_cache(struct inode *inode, struct f2fs_cached_block *ientry)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-	struct f2fs_extent *i_ext = &F2FS_INODE(ifolio)->i_ext;
+	struct f2fs_extent *i_ext = &F2FS_INODE(ientry)->i_ext;
 	struct extent_info ei;
 	int devi;
 
@@ -416,11 +416,11 @@ static void __drop_largest_extent(struct extent_tree *et,
 	}
 }
 
-void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
+void f2fs_init_read_extent_tree(struct inode *inode, struct f2fs_cached_block *ientry)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct extent_tree_info *eti = &sbi->extent_tree[EX_READ];
-	struct f2fs_extent *i_ext = &F2FS_INODE(ifolio)->i_ext;
+	struct f2fs_extent *i_ext = &F2FS_INODE(ientry)->i_ext;
 	struct extent_tree *et;
 	struct extent_node *en;
 	struct extent_info ei = {0};
@@ -428,9 +428,9 @@ void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
 	if (!__may_extent_tree(inode, EX_READ)) {
 		/* drop largest read extent */
 		if (i_ext->len) {
-			f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+			f2fs_cache_wait_writeback(ientry);
 			i_ext->len = 0;
-			folio_mark_dirty(ifolio);
+			f2fs_mark_cache_dirty(ientry);
 		}
 		set_inode_flag(inode, FI_NO_EXTENT);
 		return;
@@ -958,7 +958,7 @@ static void __update_extent_cache(struct dnode_of_data *dn, enum extent_type typ
 		return;
 
 	ei.fofs = f2fs_start_bidx_of_node(ofs_of_node(F2FS_I_SB(dn->inode),
-				dn->node_folio), dn->inode) + dn->ofs_in_node;
+				dn->node_entry), dn->inode) + dn->ofs_in_node;
 	ei.len = 1;
 
 	if (type == EX_READ) {
fs/f2fs/f2fs.h +142 -117

524 lines not on this page · raw message

fs/f2fs/file.c +37 -41

274 lines not on this page · raw message

fs/f2fs/gc.c +25 -25

150 lines not on this page · raw message

fs/f2fs/inline.c +141 -138

674 lines not on this page · raw message

fs/f2fs/inode.c +78 -89

45 lines not on this page · raw message

fs/f2fs/namei.c +59 -55

114 lines not on this page · raw message

fs/f2fs/node.c +446 -507

953 lines not on this page · raw message

fs/f2fs/node.h +56 -52

108 lines not on this page · raw message

fs/f2fs/recovery.c +59 -58

117 lines not on this page · raw message

fs/f2fs/segment.c +35 -24

59 lines not on this page · raw message

fs/f2fs/segment.h +0 -20
index 3083069c9092..b11461acc520 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/shrinker.c +2 -1
index baa09bc63585..499717cd693c 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/super.c +12 -44

56 lines not on this page · raw message

fs/f2fs/xattr.c +61 -62

123 lines not on this page · raw message

fs/f2fs/xattr.h +6 -6
index 75beab2d1ee3..870524b667ed 100644

Lines of this file are not shown. View the raw message.

include/linux/f2fs_fs.h +0 -1
index c325904f461e..ac87446cc086 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.49.0

Part of the diff is not shown here. View the raw message.

Reviewed-by on v8 7/12
#13 lore raw

Re: [f2fs-dev] [PATCH v8 07/12] f2fs: cache: use node cache

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 496 lines · 于2026年9月16日周三 09:57写道:

From: Chao Yu <[email protected]>

This patch migrates F2FS node block caching from the fake VFS inode page cache (sbi->node_inode) to node cache (sbi->node_blocks).

It updates node related helpers to use node cache APIs and reference to struct f2fs_cached_block, and removes sbi->node_inode, especially, unifies inline and regular dentry block handling via struct f2fs_dentry_block_ref.

---
 fs/f2fs/acl.c           |  26 +-
 fs/f2fs/acl.h           |   8 +-
 fs/f2fs/cache.c         |   7 +-
 fs/f2fs/cache.h         |   3 +-
 fs/f2fs/checkpoint.c    |  17 +-
 fs/f2fs/compress.c      |  18 +-
 fs/f2fs/data.c          | 249 +++++------
 fs/f2fs/debug.c         |  12 +-
 fs/f2fs/dir.c           | 170 +++----
 fs/f2fs/extent_cache.c  |  14 +-
 fs/f2fs/f2fs.h          | 259 ++++++-----
 fs/f2fs/file.c          |  78 ++--
 fs/f2fs/gc.c            |  50 +--
 fs/f2fs/inline.c        | 279 ++++++------
 fs/f2fs/inode.c         | 167 ++++---
 fs/f2fs/namei.c         | 114 ++---
 fs/f2fs/node.c          | 953 +++++++++++++++++++---------------------
 fs/f2fs/node.h          | 108 ++---
 fs/f2fs/recovery.c      | 117 ++---
 fs/f2fs/segment.c       |  59 ++-
 fs/f2fs/segment.h       |  20 -
 fs/f2fs/shrinker.c      |   3 +-
 fs/f2fs/super.c         |  56 +--
 fs/f2fs/xattr.c         | 123 +++---
 fs/f2fs/xattr.h         |  12 +-
 include/linux/f2fs_fs.h |   1 -
 26 files changed, 1420 insertions(+), 1503 deletions(-)
fs/f2fs/acl.c +13 -13
index d3253549173e..34c9aa279040 100644
@@ -181,7 +181,7 @@ static void *f2fs_acl_to_disk(struct f2fs_sb_info *sbi,
 }
 
 static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type,
-                                               struct folio *dfolio)
+                                               struct f2fs_cached_block *entry)
 {
        int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT;
        void *value = NULL;
@@ -191,13 +191,13 @@ static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type,
        if (type == ACL_TYPE_ACCESS)
                name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
 
-       retval = f2fs_getxattr(inode, name_index, "", NULL, 0, dfolio);
+       retval = f2fs_getxattr(inode, name_index, "", NULL, 0, entry);
        if (retval > 0) {
                value = f2fs_kmalloc(F2FS_I_SB(inode), retval, GFP_F2FS_ZERO);
                if (!value)
                        return ERR_PTR(-ENOMEM);
                retval = f2fs_getxattr(inode, name_index, "", value,
-                                                       retval, dfolio);
+                                                       retval, entry);
        }
 
        if (retval > 0)
@@ -242,7 +242,7 @@ static int f2fs_acl_update_mode(struct mnt_idmap *idmap,
 
 static int __f2fs_set_acl(struct mnt_idmap *idmap,
                        struct inode *inode, int type,
-                       struct posix_acl *acl, struct folio *ifolio)
+                       struct posix_acl *acl, struct f2fs_cached_block *ientry)
 {
        int name_index;
        void *value = NULL;
@@ -253,7 +253,7 @@ static int __f2fs_set_acl(struct mnt_idmap *idmap,
        switch (type) {
        case ACL_TYPE_ACCESS:
                name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
-               if (acl && !ifolio) {
+               if (acl && !ientry) {
                        error = f2fs_acl_update_mode(idmap, inode, &mode, &acl);
                        if (error)
                                return error;
@@ -279,7 +279,7 @@ static int __f2fs_set_acl(struct mnt_idmap *idmap,
                }
        }
 
-       error = f2fs_setxattr(inode, name_index, "", value, size, ifolio, 0);
+       error = f2fs_setxattr(inode, name_index, "", value, size, ientry, 0);
 
        kfree(value);
        if (!error)
@@ -374,7 +374,7 @@ static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
 
 static int f2fs_acl_create(struct inode *dir, umode_t *mode,
                struct posix_acl **default_acl, struct posix_acl **acl,
-               struct folio *dfolio)
+               struct f2fs_cached_block *entry)
 {
        struct posix_acl *p;
        struct posix_acl *clone;
@@ -386,7 +386,7 @@ static int f2fs_acl_create(struct inode *dir, umode_t *mode,
        if (S_ISLNK(*mode) || !IS_POSIXACL(dir))
                return 0;
 
-       p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, dfolio);
+       p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, entry);
        if (!p || p == ERR_PTR(-EOPNOTSUPP)) {
                *mode &= ~current_umask();
                return 0;
@@ -423,13 +423,13 @@ static int f2fs_acl_create(struct inode *dir, umode_t *mode,
        return ret;
 }
 
-int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
-                                                       struct folio *dfolio)
+int f2fs_init_acl(struct inode *inode, struct inode *dir, struct f2fs_cached_block *ientry,
+                                                       struct f2fs_cached_block *dentry)
 {
        struct posix_acl *default_acl = NULL, *acl = NULL;
        int error;
 
-       error = f2fs_acl_create(dir, &inode->i_mode, &default_acl, &acl, dfolio);
+       error = f2fs_acl_create(dir, &inode->i_mode, &default_acl, &acl, dentry);
        if (error)
                return error;
 
@@ -437,7 +437,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
 
        if (default_acl) {
                error = __f2fs_set_acl(NULL, inode, ACL_TYPE_DEFAULT,
-                               default_acl, ifolio);
+                               default_acl, ientry);
                posix_acl_release(default_acl);
        } else {
                inode->i_default_acl = NULL;
@@ -445,7 +445,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
        if (acl) {
                if (!error)
                        error = __f2fs_set_acl(NULL, inode, ACL_TYPE_ACCESS,
-                                       acl, ifolio);
+                                       acl, ientry);
                posix_acl_release(acl);
        } else {
                inode->i_acl = NULL;
fs/f2fs/acl.h +5 -3
index 20e87e63c089..0f639367a0ab 100644
@@ -36,14 +36,16 @@ struct f2fs_acl_header {
 struct posix_acl *f2fs_get_acl(struct inode *, int, bool);
 int f2fs_set_acl(struct mnt_idmap *, struct dentry *,
                        struct posix_acl *, int);
-int f2fs_init_acl(struct inode *, struct inode *, struct folio *ifolio,
-               struct folio *dfolio);
+int f2fs_init_acl(struct inode *inode, struct inode *dir,
+                       struct f2fs_cached_block *ientry,
+                       struct f2fs_cached_block *dentry);
 #else
 #define f2fs_get_acl   NULL
 #define f2fs_set_acl   NULL
 
 static inline int f2fs_init_acl(struct inode *inode, struct inode *dir,
-                               struct folio *ifolio, struct folio *dfolio)
+                               struct f2fs_cached_block *ientry,
+                               struct f2fs_cached_block *dentry)
 {
        return 0;
 }
fs/f2fs/cache.c +4 -3
index 8ab5e0e46b4e..3abd469dc011 100644
@@ -28,7 +28,7 @@ void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
                return;
 
        /* submit cached bio */
-       f2fs_submit_merged_write_cache(entry, type);
+       f2fs_submit_merged_write_cache(entry->cache->sbi, entry, 0, type);
 
        wait_on_bit_io(&entry->state, F2FS_BLOCK_WRITEBACK,
                                        TASK_UNINTERRUPTIBLE);
@@ -65,8 +65,8 @@ bool f2fs_mark_cache_dirty(struct f2fs_cached_block *entry)
        f2fs_cache_set_uptodate(entry);
 
 #ifdef CONFIG_F2FS_CHECK_FS
-       if (cache->type == F2FS_NODE_CACHE && IS_INODE(cache->sbi, cache_folio(entry)))
-               f2fs_inode_chksum_set(cache->sbi, cache_folio(entry));
+       if (f2fs_is_node_cache(entry) && IS_INODE(cache->sbi, entry))
+               f2fs_inode_chksum_set(cache->sbi, entry);
 #endif
 
        if (!f2fs_cache_test_and_set_dirty(entry)) {
@@ -665,6 +665,7 @@ static int f2fs_cache_writeback_kthread(void *data)
                        continue;
 
                f2fs_write_meta_caches(sbi);
+               f2fs_write_node_caches(sbi);
 
                sb_end_write(sbi->sb);
        }
fs/f2fs/cache.h +2 -1
index 1eabd787b4b7..a36ee57adb1a 100644
@@ -48,6 +48,7 @@ struct f2fs_cached_block_list {
 };
 
 #define IS_META_CACHE(cache) ((cache)->type == F2FS_META_CACHE)
+#define IS_NODE_CACHE(cache) ((cache)->type == F2FS_NODE_CACHE)
 
 /* Flags for f2fs_cached_block state */
 enum f2fs_cached_state {
@@ -207,7 +208,7 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
        f2fs_grab_cache(NODE_CACHE(sbi), blkaddr,       \
        F2FS_CACHE_LOCK_CREATE)
 #define f2fs_find_node_cache(sbi, blkaddr)             \
-       f2fs_find_cache(NODE_CACHE(sbi), blkaddr)
+       f2fs_find_cache(NODE_CACHE(sbi), blkaddr, F2FS_CACHE_ACCESS)
 #define f2fs_invalidate_node_cache(sbi, blkaddr)       \
        f2fs_drop_cache_range(NODE_CACHE(sbi), blkaddr, 1, false)
 #define f2fs_truncate_node_caches(sbi, start, len)     \
fs/f2fs/checkpoint.c +7 -10
index 8e524d9860a2..fe7e8bab644b 100644
@@ -927,7 +927,7 @@ void f2fs_add_orphan_inode(struct inode *inode)
 {
        /* add new orphan ino entry into list */
        f2fs_add_ino_entry(F2FS_I_SB(inode), inode->i_ino, ORPHAN_INO);
-       f2fs_update_inode_page(inode);
+       f2fs_update_inode_cache(inode);
 }
 
 void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
@@ -1428,7 +1428,7 @@ static int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
 
                        /* it's on eviction */
                        if (is_inode_flag_set(inode, FI_DIRTY_INODE))
-                               f2fs_update_inode_page(inode);
+                               f2fs_update_inode_cache(inode);
                        iput(inode);
                } else {
                        cond_resched();
@@ -1483,14 +1483,10 @@ static bool __need_flush_quota(struct f2fs_sb_info *sbi)
  */
 static int block_operations(struct f2fs_sb_info *sbi)
 {
-       struct writeback_control wbc = {
-               .sync_mode = WB_SYNC_ALL,
-               .nr_to_write = LONG_MAX,
-       };
        int err = 0, cnt = 0;
 
        /*
-        * Let's flush inline_data in dirty node pages.
+        * Let's flush inline_data in dirty node caches.
         */
        f2fs_flush_inline_data(sbi);
 
@@ -1529,7 +1525,7 @@ static int block_operations(struct f2fs_sb_info *sbi)
        }
 
        /*
-        * POR: we should ensure that there are no dirty node pages
+        * POR: we should ensure that there are no dirty node caches
         * until finishing nat/sit flush. inode->i_blocks can be updated.
         */
        f2fs_down_write(&sbi->node_change);
@@ -1550,7 +1546,8 @@ static int block_operations(struct f2fs_sb_info *sbi)
        if (get_pages(sbi, F2FS_DIRTY_NODES)) {
                f2fs_up_write(&sbi->node_write);
                atomic_inc(&sbi->wb_sync_req[NODE]);
-               err = f2fs_sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO);
+               err = f2fs_writeback_node_caches(sbi, LONG_MAX,
+                       true, false, FS_CP_NODE_IO);
                atomic_dec(&sbi->wb_sync_req[NODE]);
                if (err) {
                        f2fs_up_write(&sbi->node_change);
@@ -1900,7 +1897,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        __set_cp_next_pack(sbi);
 
        /*
-        * redirty superblock if metadata like node page or inode cache is
+        * redirty superblock if metadata like node caches or inode cache is
         * updated during writing checkpoint.
         */
        if (get_pages(sbi, F2FS_DIRTY_NODES) ||
fs/f2fs/compress.c +9 -9
index f85bbadde53f..d7f7c35e710f 100644
@@ -909,7 +909,7 @@ bool f2fs_sanity_check_cluster(struct dnode_of_data *dn)
        }
 
        for (i = 1, count = 1; i < cluster_size; i++, count++) {
-               block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                        dn->ofs_in_node + i);
 
                /* [COMPR_ADDR, ..., COMPR_ADDR] */
@@ -950,7 +950,7 @@ static int __f2fs_get_cluster_blocks(struct inode *inode,
        int count, i;
 
        for (i = 0, count = 0; i < cluster_size; i++) {
-               block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                        dn->ofs_in_node + i);
 
                if (__is_valid_data_blkaddr(blkaddr))
@@ -1146,7 +1146,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
                        goto release_and_retry;
                }
 
-               f2fs_folio_wait_writeback(folio, DATA, true, true);
+               f2fs_folio_wait_writeback(folio, true, true);
                f2fs_compress_ctx_add_page(cc, folio);
 
                if (!folio_test_uptodate(folio)) {
@@ -1322,7 +1322,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
                goto out_unlock_op;
 
        for (i = 0; i < cc->cluster_size; i++) {
-               if (data_blkaddr(dn.inode, dn.node_folio,
+               if (data_blkaddr(dn.inode, dn.node_entry,
                                        dn.ofs_in_node + i) == NULL_ADDR)
                        goto out_put_dnode;
        }
@@ -1354,7 +1354,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
                                page_folio(cc->rpages[i + 1])->index, cic);
                fio.compressed_page = cc->cpages[i];
 
-               fio.old_blkaddr = data_blkaddr(dn.inode, dn.node_folio,
+               fio.old_blkaddr = data_blkaddr(dn.inode, dn.node_entry,
                                                dn.ofs_in_node + i + 1);
 
                /* wait for GCed page writeback via generic cache */
@@ -1542,7 +1542,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
                if (folio_test_writeback(folio)) {
                        if (wbc->sync_mode == WB_SYNC_NONE)
                                goto continue_unlock;
-                       f2fs_folio_wait_writeback(folio, DATA, true, true);
+                       f2fs_folio_wait_writeback(folio, true, true);
                }
 
                if (!folio_clear_dirty_for_io(folio))
@@ -1874,14 +1874,14 @@ void f2fs_put_folio_dic(struct folio *folio, bool in_task)
 unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn,
                                                unsigned int ofs_in_node)
 {
-       bool compressed = data_blkaddr(dn->inode, dn->node_folio,
+       bool compressed = data_blkaddr(dn->inode, dn->node_entry,
                                        ofs_in_node) == COMPRESS_ADDR;
        int i = compressed ? 1 : 0;
-       block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+       block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                        ofs_in_node + i);
 
        for (i += 1; i < F2FS_I(dn->inode)->i_cluster_size; i++) {
-               block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                        ofs_in_node + i);
 
                if (!__is_valid_data_blkaddr(blkaddr))
fs/f2fs/data.c +19 -39
index 674d1b8e33d8..9a1d31df5f4f 100644
@@ -58,13 +58,10 @@ bool f2fs_is_cp_guaranteed(const struct folio *folio)
 {
        struct address_space *mapping = folio->mapping;
        struct inode *inode;
-       struct f2fs_sb_info *sbi;
 
        inode = mapping->host;
-       sbi = F2FS_I_SB(inode);
 
-       if (inode->i_ino == F2FS_NODE_INO(sbi) ||
-                       S_ISDIR(inode->i_mode))
+       if (S_ISDIR(inode->i_mode))
                return true;
 
        if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) ||
@@ -73,20 +70,6 @@ bool f2fs_is_cp_guaranteed(const struct folio *folio)
        return false;
 }
 
-static enum count_type __read_io_type(struct folio *folio)
-{
-       struct address_space *mapping = folio->mapping;
-
-       if (mapping) {
-               struct inode *inode = mapping->host;
-               struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-
-               if (inode->i_ino == F2FS_NODE_INO(sbi))
-                       return F2FS_RD_NODE;
-       }
-       return F2FS_RD_DATA;
-}
-
 /* postprocessing steps for read bios */
 enum bio_post_read_step {
 #ifdef CONFIG_F2FS_FS_COMPRESSION
@@ -160,14 +143,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
                }
 
                while (nr_pages--)
-                       dec_page_count(F2FS_F_SB(folio), __read_io_type(folio));
-
-               if (bio->bi_status == BLK_STS_OK &&
-                       F2FS_F_SB(folio)->node_inode &&
-                       is_node_folio(F2FS_F_SB(folio), folio) &&
-                       f2fs_sanity_check_node_footer(F2FS_F_SB(folio),
-                               folio, folio->index, NODE_TYPE_REGULAR, true))
-                       bio->bi_status = BLK_STS_IOERR;
+                       dec_page_count(F2FS_F_SB(folio), F2FS_RD_DATA);
 
                if (finished)
                        folio_end_read(folio, bio->bi_status == BLK_STS_OK);
@@ -351,14 +327,6 @@ static void f2fs_write_end_bio(struct bio *bio)
                        }
                }
 
-               if (is_node_folio(sbi, folio)) {
-                       f2fs_sanity_check_node_footer(sbi, folio,
-                               folio->index, NODE_TYPE_REGULAR, true);
-                       f2fs_bug_on(sbi, folio->index != nid_of_node(sbi, folio));
-               }
-               if (f2fs_in_warm_node_list(sbi, folio))
-                       f2fs_del_fsync_node_entry(sbi, folio);
-
                dec_page_count(sbi, type);
 
                /*
@@ -419,6 +387,12 @@ static void f2fs_cache_read_end_io(struct bio *bio)
                next = entry->next_entry;
                entry->next_entry = NULL;
 
+               if (bio->bi_status == BLK_STS_OK &&
+                       f2fs_is_node_cache(entry) &&
+                       f2fs_sanity_check_node_footer(sbi, entry,
+                               entry->index, NODE_TYPE_REGULAR, true))
+                       bio->bi_status = BLK_STS_IOERR;
+
                if (bio->bi_status == BLK_STS_OK)
                        f2fs_cache_set_uptodate(entry);
 
@@ -449,6 +423,14 @@ static void f2fs_cache_write_end_io(struct bio *bio)
                next = entry->next_entry;
                entry->next_entry = NULL;
 
+               if (f2fs_is_node_cache(entry)) {
+                       f2fs_sanity_check_node_footer(sbi, entry,
+                               entry->index, NODE_TYPE_REGULAR, true);
+                       f2fs_bug_on(sbi, entry->index != nid_of_node(sbi, entry));
+               }
+               if (f2fs_in_warm_node_list(sbi, entry))
+                       f2fs_del_fsync_node_entry(sbi, entry);
+
                dec_page_count(sbi, F2FS_WB_CP_DATA);
 
                if (!get_pages(sbi, F2FS_WB_CP_DATA) &&
@@ -655,15 +637,15 @@ static void __submit_merged_bio(struct f2fs_bio_info *io)
        io->bio = NULL;
 }
 
-static bool __has_merged_page(struct f2fs_sb_info *sbi, struct bio *bio,
-                       struct inode *inode, struct folio *folio, nid_t ino)
+static bool __has_merged_page(struct bio *bio, struct inode *inode,
+                                               struct folio *folio)
 {
        struct folio_iter fi;
 
        if (!bio)
                return false;
 
-       if (!inode && !folio && !ino)
+       if (!inode && !folio)
                return true;
 
        if (f2fs_is_cache_bio(bio))
@@ -682,8 +664,6 @@ static bool __has_merged_page(struct f2fs_sb_info *sbi, struct bio *bio,
                        return true;
                if (folio && folio == target)
                        return true;
-               if (ino && ino == ino_of_node(sbi, target))
-                       return true;
        }
 
        return false;

fs/f2fs/data.c static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi, · line 735

Quoted 5 lines
fs/f2fs/data.c +1 -1
@@ -752,24 +732,23 @@ static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi,
 
 static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
                                struct inode *inode, struct folio *folio,
-                               nid_t ino, enum page_type type, bool writeback)
+                               bool writeback)

Hi Chao,
seems this function just only handle DATA type now, so can we rename it xxx_data_xxx for easy reading?
others LGTM.

thanks!

Quoted 6,717 lines
fs/f2fs/data.c +97 -92
 {
        enum temp_type temp;
        bool ret = true;
-       bool force = !inode && !folio && !ino;
+       bool force = !inode && !folio;
 
        for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
-               if (!force)     {
-                       enum page_type btype = PAGE_TYPE_OF_BIO(type);
-                       struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
+               if (!force) {
+                       struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
                        struct f2fs_lock_context lc;
 
                        f2fs_down_read_trace(&io->io_rwsem, &lc);
-                       ret = __has_merged_page(io->sbi, io->bio, inode, folio, ino);
+                       ret = __has_merged_page(io->bio, inode, folio);
                        f2fs_up_read_trace(&io->io_rwsem, &lc);
                }
                if (ret) {
-                       __f2fs_submit_merged_write(sbi, type, temp);
+                       __f2fs_submit_merged_write(sbi, DATA, temp);
                        /*
                         * For waitting writebck case, if the bio owned by the
                         * folio is already submitted, we do not need to submit
@@ -778,33 +757,23 @@ static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
                        if (writeback)
                                break;
                }
-
-               /* TODO: use HOT temp only for meta pages now. */
-               if (type >= META)
-                       break;
        }
 }
 
-void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type)
-{
-       __submit_merged_write_cond(sbi, NULL, NULL, 0, type, false);
-}
-
 void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
-                               struct inode *inode, struct folio *folio,
-                               nid_t ino, enum page_type type)
+                               struct inode *inode, struct folio *folio)
 {
-       __submit_merged_write_cond(sbi, inode, folio, ino, type, false);
+       __submit_merged_write_cond(sbi, inode, folio, false);
 }
 
 void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
-                               struct folio *folio, enum page_type type)
+                               struct folio *folio)
 {
-       __submit_merged_write_cond(sbi, NULL, folio, 0, type, true);
+       __submit_merged_write_cond(sbi, NULL, folio, true);
 }
 
-static bool __has_merged_cache(struct bio *bio,
-               struct f2fs_cached_block *target)
+static bool __has_merged_cache(struct f2fs_sb_info *sbi, struct bio *bio,
+               struct f2fs_cached_block *target, nid_t ino)
 {
        struct f2fs_cached_block *entry;
 
@@ -816,27 +785,39 @@ static bool __has_merged_cache(struct bio *bio,
        while (entry) {
                if (target && entry == target)
                        return true;
+
+               if (ino) {
+                       if (likely(f2fs_is_node_cache(entry))) {
+                               if (ino_of_node(sbi, entry) == ino)
+                                       return true;
+                       } else {
+                               WARN_ON_ONCE(1);
+                       }
+               }
                entry = entry->next_entry;
        }
        return false;
 }
 
-bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
-                               enum page_type type)
+bool f2fs_submit_merged_write_cache(struct f2fs_sb_info *sbi,
+                               struct f2fs_cached_block *entry,
+                               nid_t ino, enum page_type type)
 {
-       struct f2fs_sb_info *sbi = entry->cache->sbi;
        enum temp_type temp;
        bool ret = false;
+       bool force = !entry && !ino;
 
        for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
                enum page_type btype = PAGE_TYPE_OF_BIO(type);
                struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
                struct f2fs_lock_context lc;
-               bool merged;
+               bool merged = true;
 
-               f2fs_down_read_trace(&io->io_rwsem, &lc);
-               merged = __has_merged_cache(io->bio, entry);
-               f2fs_up_read_trace(&io->io_rwsem, &lc);
+               if (!force) {
+                       f2fs_down_read_trace(&io->io_rwsem, &lc);
+                       merged = __has_merged_cache(sbi, io->bio, entry, ino);
+                       f2fs_up_read_trace(&io->io_rwsem, &lc);
+               }
 
                if (merged) {
                        __f2fs_submit_merged_write(sbi, type, temp);
@@ -850,6 +831,14 @@ bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
        return ret;
 }
 
+void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type)
+{
+       if (type == DATA)
+               __submit_merged_write_cond(sbi, NULL, NULL, false);
+       else
+               f2fs_submit_merged_write_cache(sbi, NULL, 0, type);
+}
+
 void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi)
 {
        f2fs_submit_merged_write(sbi, DATA);
@@ -886,7 +875,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
                wbc_account_cgroup_owner(fio->io_wbc, fio_folio, PAGE_SIZE);
 
        inc_page_count(fio->sbi, is_read_io(fio->op) ?
-                       __read_io_type(data_folio) : WB_DATA_TYPE(fio->folio, false));
+                       F2FS_RD_DATA : WB_DATA_TYPE(fio->folio, false));
 
        if (is_read_io(bio_op(bio)))
                f2fs_submit_read_bio(fio->sbi, bio, fio->type);
@@ -1022,8 +1011,8 @@ void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
                        if (target)
                                found = (target == be->bio);
                        else
-                               found = __has_merged_page(sbi, be->bio, NULL,
-                                                       folio, 0);
+                               found = __has_merged_page(be->bio,
+                                                       NULL, folio);
                        if (found)
                                break;
                }
@@ -1039,8 +1028,8 @@ void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
                        if (target)
                                found = (target == be->bio);
                        else
-                               found = __has_merged_page(sbi, be->bio, NULL,
-                                                       folio, 0);
+                               found = __has_merged_page(be->bio,
+                                                       NULL, folio);
                        if (found) {
                                target = be->bio;
                                del_bio_entry(be);
@@ -1427,7 +1416,7 @@ static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,
 
 static void __set_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
 {
-       __le32 *addr = get_dnode_addr(dn->inode, dn->node_folio);
+       __le32 *addr = get_dnode_addr(dn->inode, dn->node_entry);
 
        dn->data_blkaddr = blkaddr;
        addr[dn->ofs_in_node] = cpu_to_le32(dn->data_blkaddr);
@@ -1441,9 +1430,9 @@ static void __set_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
  */
 void f2fs_set_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
 {
-       f2fs_folio_wait_writeback(dn->node_folio, NODE, true, true);
+       f2fs_cache_wait_writeback(dn->node_entry);
        __set_data_blkaddr(dn, blkaddr);
-       if (folio_mark_dirty(dn->node_folio))
+       if (f2fs_mark_cache_dirty(dn->node_entry))
                dn->node_changed = true;
 }
 
@@ -1471,7 +1460,7 @@ int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)
        trace_f2fs_reserve_new_blocks(dn->inode, dn->nid,
                                                dn->ofs_in_node, count);
 
-       f2fs_folio_wait_writeback(dn->node_folio, NODE, true, true);
+       f2fs_cache_wait_writeback(dn->node_entry);
 
        for (; count > 0; dn->ofs_in_node++) {
                block_t blkaddr = f2fs_data_blkaddr(dn);
@@ -1482,7 +1471,7 @@ int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)
                }
        }
 
-       if (folio_mark_dirty(dn->node_folio))
+       if (f2fs_mark_cache_dirty(dn->node_entry))
                dn->node_changed = true;
        return 0;
 }
@@ -1500,7 +1489,7 @@ int f2fs_reserve_new_block(struct dnode_of_data *dn)
 
 int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)
 {
-       bool need_put = dn->inode_folio ? false : true;
+       bool need_put = dn->inode_entry ? false : true;
        int err;
 
        err = f2fs_get_dnode_of_data(dn, index, ALLOC_NODE);
@@ -1666,11 +1655,11 @@ struct folio *f2fs_get_lock_data_folio(struct inode *inode, pgoff_t index,
  *
  * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and
  * f2fs_unlock_op().
- * Note that, ifolio is set only by make_empty_dir, and if any error occur,
- * ifolio should be released by this function.
+ * Note that, ientry is set only by make_empty_dir, and if any error occur,
+ * ientry should be released by this function.
  */
 struct folio *f2fs_get_new_data_folio(struct inode *inode,
-               struct folio *ifolio, pgoff_t index, bool new_i_size)
+               struct f2fs_cached_block *ientry, pgoff_t index, bool new_i_size)
 {
        struct address_space *mapping = inode->i_mapping;
        struct folio *folio;
@@ -1680,20 +1669,20 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
        folio = f2fs_grab_cache_folio(mapping, index, true);
        if (IS_ERR(folio)) {
                /*
-                * before exiting, we should make sure ifolio will be released
+                * before exiting, we should make sure ientry will be released
                 * if any error occur.
                 */
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return ERR_PTR(-ENOMEM);
        }
 
-       set_new_dnode(&dn, inode, ifolio, NULL, 0);
+       set_new_dnode(&dn, inode, ientry, NULL, 0);
        err = f2fs_reserve_block(&dn, index);
        if (err) {
                f2fs_folio_put(folio, true);
                return ERR_PTR(err);
        }
-       if (!ifolio)
+       if (!ientry)
                f2fs_put_dnode(&dn);
 
        if (folio_test_uptodate(folio))
@@ -1706,8 +1695,8 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
        } else {
                f2fs_folio_put(folio, true);
 
-               /* if ifolio exists, blkaddr should be NEW_ADDR */
-               f2fs_bug_on(F2FS_I_SB(inode), ifolio);
+               /* if ientry exists, blkaddr should be NEW_ADDR */
+               f2fs_bug_on(F2FS_I_SB(inode), ientry);
                folio = f2fs_get_lock_data_folio(inode, index, true);
                if (IS_ERR(folio))
                        return folio;
@@ -1744,7 +1733,7 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
 
        set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
        old_blkaddr = dn->data_blkaddr;
-       err = f2fs_allocate_data_block(sbi, NULL, old_blkaddr,
+       err = f2fs_allocate_data_block(sbi, old_blkaddr,
                                &dn->data_blkaddr, &sum, seg_type, NULL);
        if (err) {
                if (old_blkaddr == NULL_ADDR)
@@ -1956,7 +1945,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
        start_pgofs = pgofs;
        prealloc = 0;
        last_ofs_in_node = ofs_in_node = dn.ofs_in_node;
-       end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+       end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
 
 next_block:
        blkaddr = f2fs_data_blkaddr(&dn);
@@ -2207,15 +2196,15 @@ static int f2fs_xattr_fiemap(struct inode *inode,
 
        if (f2fs_has_inline_xattr(inode)) {
                int offset;
-               struct folio *folio = f2fs_grab_cache_folio(NODE_MAPPING(sbi),
-                               inode->i_ino, false);
+               struct f2fs_cached_block *entry =
+                               f2fs_grab_node_cache(sbi, inode->i_ino);
 
-               if (IS_ERR(folio))
-                       return PTR_ERR(folio);
+               if (IS_ERR(entry))
+                       return PTR_ERR(entry);
 
                err = f2fs_get_node_info(sbi, inode->i_ino, &ni, false);
                if (err) {
-                       f2fs_folio_put(folio, true);
+                       f2fs_put_cache(entry, true);
                        return err;
                }
 
@@ -2227,7 +2216,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,
                phys += offset;
                len = inline_xattr_size(inode);
 
-               f2fs_folio_put(folio, true);
+               f2fs_put_cache(entry, true);
 
                flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED;
 
@@ -2241,22 +2230,22 @@ static int f2fs_xattr_fiemap(struct inode *inode,
        }
 
        if (xnid) {
-               struct folio *folio = f2fs_grab_cache_folio(NODE_MAPPING(sbi),
-                               xnid, false);
+               struct f2fs_cached_block *entry =
+                               f2fs_grab_node_cache(sbi, xnid);
 
-               if (IS_ERR(folio))
-                       return PTR_ERR(folio);
+               if (IS_ERR(entry))
+                       return PTR_ERR(entry);
 
                err = f2fs_get_node_info(sbi, xnid, &ni, false);
                if (err) {
-                       f2fs_folio_put(folio, true);
+                       f2fs_put_cache(entry, true);
                        return err;
                }
 
                phys = F2FS_BLK_TO_BYTES(sbi, ni.blk_addr);
                len = inode->i_sb->s_blocksize;
 
-               f2fs_folio_put(folio, true);
+               f2fs_put_cache(entry, true);
 
                flags = FIEMAP_EXTENT_LAST;
        }
@@ -2619,7 +2608,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
        for (i = 1; i < cc->cluster_size; i++) {
                block_t blkaddr;
 
-               blkaddr = from_dnode ? data_blkaddr(dn.inode, dn.node_folio,
+               blkaddr = from_dnode ? data_blkaddr(dn.inode, dn.node_entry,
                                        dn.ofs_in_node + i) :
                                        ei.blk + i - 1;
 
@@ -2653,7 +2642,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
                block_t blkaddr;
                struct bio_post_read_ctx *ctx;
 
-               blkaddr = from_dnode ? data_blkaddr(dn.inode, dn.node_folio,
+               blkaddr = from_dnode ? data_blkaddr(dn.inode, dn.node_entry,
                                        dn.ofs_in_node + i + 1) :
                                        ei.blk + i;
 
@@ -3646,7 +3635,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
                        if (folio_test_writeback(folio)) {
                                if (wbc->sync_mode == WB_SYNC_NONE)
                                        goto continue_unlock;
-                               f2fs_folio_wait_writeback(folio, DATA, true, true);
+                               f2fs_folio_wait_writeback(folio, true, true);
                        }
 
                        if (!folio_clear_dirty_for_io(folio))
@@ -3728,8 +3717,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
                mapping->writeback_index = done_index;
 
        if (nwritten)
-               f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host,
-                                                               NULL, 0, DATA);
+               f2fs_submit_merged_write_cond(F2FS_M_SB(mapping),
+                                       mapping->host, NULL);
        /* submit cached bio of IPU write */
        if (bio)
                f2fs_submit_merged_ipu_write(sbi, &bio, NULL);
@@ -3907,7 +3896,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
        pgoff_t index = folio->index;
        struct dnode_of_data dn;
        struct f2fs_lock_context lc;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        bool locked = false;
        int flag = F2FS_GET_BLOCK_PRE_AIO;
        int err = 0;
@@ -3938,20 +3927,20 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
 
 restart:
        /* check inline_data */
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto unlock_out;
        }
 
-       set_new_dnode(&dn, inode, ifolio, ifolio, 0);
+       set_new_dnode(&dn, inode, ientry, ientry, 0);
 
        if (f2fs_has_inline_data(inode)) {
                if (pos + len <= MAX_INLINE_DATA(inode)) {
-                       f2fs_do_read_inline_data(folio, ifolio);
+                       f2fs_do_read_inline_data(folio, ientry);
                        set_inode_flag(inode, FI_DATA_EXIST);
                        if (inode->i_nlink)
-                               folio_set_f2fs_inline(ifolio);
+                               f2fs_cache_set_inline(ientry);
                        goto out;
                }
                err = f2fs_convert_inline_folio(&dn, folio);
@@ -3998,14 +3987,14 @@ static int __find_data_block(struct inode *inode, pgoff_t index,
                                block_t *blk_addr)
 {
        struct dnode_of_data dn;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        int err = 0;
 
-       ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
-       set_new_dnode(&dn, inode, ifolio, ifolio, 0);
+       set_new_dnode(&dn, inode, ientry, ientry, 0);
 
        if (!f2fs_lookup_read_extent_cache_block(inode, index,
                                                 &dn.data_blkaddr)) {
@@ -4027,17 +4016,17 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct dnode_of_data dn;
        struct f2fs_lock_context lc;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        int err = 0;
 
        f2fs_map_lock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
 
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto unlock_out;
        }
-       set_new_dnode(&dn, inode, ifolio, ifolio, 0);
+       set_new_dnode(&dn, inode, ientry, ientry, 0);
 
        if (!f2fs_lookup_read_extent_cache_block(dn.inode, index,
                                                &dn.data_blkaddr))
@@ -4193,7 +4182,7 @@ static int f2fs_write_begin(const struct kiocb *iocb,
                }
        }
 
-       f2fs_folio_wait_writeback(folio, DATA, false, true);
+       f2fs_folio_wait_writeback(folio, false, true);
 
        if (len == folio_size(folio) || folio_test_uptodate(folio))
                return 0;
@@ -4310,12 +4299,8 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
                return;
 
        if (folio_test_dirty(folio)) {
-               if (inode->i_ino == F2FS_NODE_INO(sbi)) {
-                       dec_page_count(sbi, F2FS_DIRTY_NODES);
-               } else {
-                       inode_dec_dirty_pages(inode);
-                       f2fs_remove_dirty_inode(inode);
-               }
+               inode_dec_dirty_pages(inode);
+               f2fs_remove_dirty_inode(inode);
        }
 
        if (offset || length != folio_size(folio))
fs/f2fs/debug.c +4 -8
index 24819d4c0d55..c09c5f700c89 100644
@@ -222,8 +222,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
        si->free_secs = free_sections(sbi);
        si->prefree_count = prefree_segments(sbi);
        si->dirty_count = dirty_segments(sbi);
-       if (sbi->node_inode)
-               si->node_pages = NODE_MAPPING(sbi)->nrpages;
+       si->node_caches = NODE_CACHE(sbi)->num_entries;
        si->meta_caches = META_CACHE(sbi)->num_entries;
 #ifdef CONFIG_F2FS_FS_COMPRESSION
        if (sbi->compress_inode) {
@@ -382,13 +381,10 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
        }
 
        si->page_mem = 0;
-       if (sbi->node_inode) {
-               unsigned long npages = NODE_MAPPING(sbi)->nrpages;
-
-               si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
-       }
        si->page_mem += (unsigned long long)META_CACHE(sbi)->num_entries << PAGE_SHIFT;
        si->cache_mem += META_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
+       si->page_mem += (unsigned long long)NODE_CACHE(sbi)->num_entries << PAGE_SHIFT;
+       si->cache_mem += NODE_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
 #ifdef CONFIG_F2FS_FS_COMPRESSION
        if (sbi->compress_inode) {
                unsigned long npages = COMPRESS_MAPPING(sbi)->nrpages;
@@ -696,7 +692,7 @@ static int stat_show(struct seq_file *s, void *v)
                           si->aw_cnt, si->max_aw_cnt);
                seq_printf(s, "  - compress: %4d, hit:%8d\n", si->compress_pages, si->compress_page_hit);
                seq_printf(s, "  - nodes: %4d in %4d\n",
-                          si->ndirty_node, si->node_pages);
+                          si->ndirty_node, si->node_caches);
                seq_printf(s, "  - dents: %4d in dirs:%4d (%4d)\n",
                           si->ndirty_dent, si->ndirty_dirs, si->ndirty_all);
                seq_printf(s, "  - data: %4d in files:%4d\n",
fs/f2fs/dir.c +93 -77
index 75ff36a13f60..97f7fef6b068 100644
@@ -282,7 +282,7 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d,
 static struct f2fs_dir_entry *find_in_level(struct inode *dir,
                                        unsigned int level,
                                        const struct f2fs_filename *fname,
-                                       struct folio **res_folio,
+                                       void **dentry_block,
                                        bool use_hash)
 {
        int s = GET_DENTRY_SLOTS(fname->disk_name.len);
@@ -313,7 +313,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
                                bidx = next_pgofs;
                                continue;
                        } else {
-                               *res_folio = dentry_folio;
+                               *dentry_block = dentry_folio;
                                break;
                        }
                }
@@ -321,11 +321,11 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
                de = find_in_block(dir, dentry_folio, fname, &max_slots, use_hash);
                if (IS_ERR(de)) {
                        f2fs_folio_put(dentry_folio, false);
-                       *res_folio = ERR_CAST(de);
+                       *dentry_block = ERR_CAST(de);
                        de = NULL;
                        break;
                } else if (de) {
-                       *res_folio = dentry_folio;
+                       *dentry_block = dentry_folio;
                        break;
                }
 
@@ -352,7 +352,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
 
 struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
                                         const struct f2fs_filename *fname,
-                                        struct folio **res_folio)
+                                        void **dentry_block)
 {
        unsigned long npages = dir_blocks(dir);
        struct f2fs_dir_entry *de = NULL;
@@ -360,13 +360,13 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
        unsigned int level;
        bool use_hash = true;
 
-       *res_folio = NULL;
+       *dentry_block = NULL;
 
 #if IS_ENABLED(CONFIG_UNICODE)
 start_find_entry:
 #endif
        if (f2fs_has_inline_dentry(dir)) {
-               de = f2fs_find_in_inline_dir(dir, fname, res_folio, use_hash);
+               de = f2fs_find_in_inline_dir(dir, fname, dentry_block, use_hash);
                goto out;
        }
 
@@ -382,8 +382,8 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
        }
 
        for (level = 0; level < max_depth; level++) {
-               de = find_in_level(dir, level, fname, res_folio, use_hash);
-               if (de || IS_ERR(*res_folio))
+               de = find_in_level(dir, level, fname, dentry_block, use_hash);
+               if (de || IS_ERR(*dentry_block))
                        break;
        }
 
@@ -408,7 +408,7 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
  * Entry is guaranteed to be valid.
  */
 struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
-                       const struct qstr *child, struct folio **res_folio)
+                       const struct qstr *child, void **dentry_block)
 {
        struct f2fs_dir_entry *de = NULL;
        struct f2fs_filename fname;
@@ -417,67 +417,78 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
        err = f2fs_setup_filename(dir, child, 1, &fname);
        if (err) {
                if (err == -ENOENT)
-                       *res_folio = NULL;
+                       *dentry_block = NULL;
                else
-                       *res_folio = ERR_PTR(err);
+                       *dentry_block = ERR_PTR(err);
                return NULL;
        }
 
-       de = __f2fs_find_entry(dir, &fname, res_folio);
+       de = __f2fs_find_entry(dir, &fname, dentry_block);
 
        f2fs_free_filename(&fname);
        return de;
 }
 
-struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct folio **f)
+struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, void **dentry_block)
 {
-       return f2fs_find_entry(dir, &dotdot_name, f);
+       return f2fs_find_entry(dir, &dotdot_name, dentry_block);
 }
 
 ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
-                                                       struct folio **folio)
+                                                       void **dentry_block)
 {
        ino_t res = 0;
        struct f2fs_dir_entry *de;
 
-       de = f2fs_find_entry(dir, qstr, folio);
+       de = f2fs_find_entry(dir, qstr, dentry_block);
        if (de) {
                res = le32_to_cpu(de->ino);
-               f2fs_folio_put(*folio, false);
+               f2fs_put_dentry_block(*dentry_block, false);
        }
 
        return res;
 }
 
 void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
-               struct folio *folio, struct inode *inode)
+               void *dentry_block, struct inode *inode)
 {
-       enum page_type type = f2fs_has_inline_dentry(dir) ? NODE : DATA;
+       if (f2fs_dentry_is_cache(dentry_block)) {
+               struct f2fs_cached_block *entry =
+                               f2fs_dentry_cache(dentry_block);
+
+               f2fs_lock_cache(entry);
+               f2fs_cache_wait_writeback(entry);
+               de->ino = cpu_to_le32(inode->i_ino);
+               de->file_type = fs_umode_to_ftype(inode->i_mode);
+               f2fs_mark_cache_dirty(entry);
+       } else {
+               struct folio *folio = f2fs_dentry_folio(dentry_block);
 
-       folio_lock(folio);
-       f2fs_folio_wait_writeback(folio, type, true, true);
-       de->ino = cpu_to_le32(inode->i_ino);
-       de->file_type = fs_umode_to_ftype(inode->i_mode);
-       folio_mark_dirty(folio);
+               folio_lock(folio);
+               f2fs_folio_wait_writeback(folio, true, true);
+               de->ino = cpu_to_le32(inode->i_ino);
+               de->file_type = fs_umode_to_ftype(inode->i_mode);
+               folio_mark_dirty(folio);
+       }
 
        inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
        f2fs_mark_inode_dirty_sync(dir, true);
-       f2fs_folio_put(folio, true);
+       f2fs_put_dentry_block(dentry_block, true);
 }
 
 static void init_dent_inode(struct inode *dir, struct inode *inode,
                            const struct f2fs_filename *fname,
-                           struct folio *ifolio)
+                           struct f2fs_cached_block *ientry)
 {
        struct f2fs_inode *ri;
 
        if (!fname) /* tmpfile case? */
                return;
 
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       f2fs_cache_wait_writeback(ientry);
 
        /* copy name info. to this inode folio */
-       ri = F2FS_INODE(ifolio);
+       ri = F2FS_INODE(ientry);
        ri->i_namelen = cpu_to_le32(fname->disk_name.len);
        memcpy(ri->i_name, fname->disk_name.name, fname->disk_name.len);
        if (IS_ENCRYPTED(dir)) {
@@ -498,7 +509,7 @@ static void init_dent_inode(struct inode *dir, struct inode *inode,
                                file_lost_pino(inode);
                }
        }
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 }
 
 void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
@@ -515,16 +526,16 @@ void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
 }
 
 static int make_empty_dir(struct inode *inode,
-               struct inode *parent, struct folio *folio)
+               struct inode *parent, struct f2fs_cached_block *ientry)
 {
        struct folio *dentry_folio;
        void *dentry_blk;
        struct f2fs_dentry_ptr d;
 
        if (f2fs_has_inline_dentry(inode))
-               return f2fs_make_empty_inline_dir(inode, parent, folio);
+               return f2fs_make_empty_inline_dir(inode, parent, ientry);
 
-       dentry_folio = f2fs_get_new_data_folio(inode, folio, 0, true);
+       dentry_folio = f2fs_get_new_data_folio(inode, ientry, 0, true);
        if (IS_ERR(dentry_folio))
                return PTR_ERR(dentry_folio);
 
@@ -538,50 +549,50 @@ static int make_empty_dir(struct inode *inode,
        return 0;
 }
 
-struct folio *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
-               const struct f2fs_filename *fname, struct folio *dfolio)
+struct f2fs_cached_block *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
+               const struct f2fs_filename *fname, struct f2fs_cached_block *dentry)
 {
-       struct folio *folio;
+       struct f2fs_cached_block *ientry;
        int err;
 
        if (is_inode_flag_set(inode, FI_NEW_INODE)) {
-               folio = f2fs_new_inode_folio(inode);
-               if (IS_ERR(folio))
-                       return folio;
+               ientry = f2fs_new_inode_cache(inode);
+               if (IS_ERR(ientry))
+                       return ientry;
 
                if (S_ISDIR(inode->i_mode)) {
                        /* in order to handle error case */
-                       folio_get(folio);
-                       err = make_empty_dir(inode, dir, folio);
+                       f2fs_cache_get(ientry);
+                       err = make_empty_dir(inode, dir, ientry);
                        if (err) {
-                               folio_lock(folio);
+                               f2fs_lock_cache(ientry);
                                goto put_error;
                        }
-                       folio_put(folio);
+                       f2fs_put_cache(ientry, false);
                }
 
-               err = f2fs_init_acl(inode, dir, folio, dfolio);
+               err = f2fs_init_acl(inode, dir, ientry, dentry);
                if (err)
                        goto put_error;
 
                err = f2fs_init_security(inode, dir,
                                         fname ? fname->usr_fname : NULL,
-                                        folio);
+                                        ientry);
                if (err)
                        goto put_error;
 
                if (IS_ENCRYPTED(inode)) {
-                       err = fscrypt_set_context(inode, folio);
+                       err = fscrypt_set_context(inode, ientry);
                        if (err)
                                goto put_error;
                }
        } else {
-               folio = f2fs_get_inode_folio(F2FS_I_SB(dir), inode->i_ino);
-               if (IS_ERR(folio))
-                       return folio;
+               ientry = f2fs_get_inode_cache(F2FS_I_SB(dir), inode->i_ino);
+               if (IS_ERR(ientry))
+                       return ientry;
        }
 
-       init_dent_inode(dir, inode, fname, folio);
+       init_dent_inode(dir, inode, fname, ientry);
 
        /*
         * This file should be checkpointed during fsync.
@@ -598,12 +609,12 @@ struct folio *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
                        f2fs_remove_orphan_inode(F2FS_I_SB(dir), inode->i_ino);
                f2fs_i_links_write(inode, true);
        }
-       return folio;
+       return ientry;
 
 put_error:
        clear_nlink(inode);
-       f2fs_update_inode(inode, folio);
-       f2fs_folio_put(folio, true);
+       f2fs_update_inode(inode, ientry);
+       f2fs_put_cache(ientry, true);
        return ERR_PTR(err);
 }
 
@@ -645,14 +656,14 @@ int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots)
        goto next;
 }
 
-bool f2fs_has_enough_room(struct inode *dir, struct folio *ifolio,
+bool f2fs_has_enough_room(struct inode *dir, struct f2fs_cached_block *ientry,
                          const struct f2fs_filename *fname)
 {
        struct f2fs_dentry_ptr d;
        unsigned int bit_pos;
        int slots = GET_DENTRY_SLOTS(fname->disk_name.len);
 
-       make_dentry_ptr_inline(dir, &d, inline_data_addr(dir, ifolio));
+       make_dentry_ptr_inline(dir, &d, inline_data_addr(dir, ientry));
 
        bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
 
@@ -692,7 +703,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,
        struct folio *dentry_folio = NULL;
        void *dentry_blk = NULL;
        struct f2fs_dentry_ptr d;
-       struct folio *folio = NULL;
+       struct f2fs_cached_block *entry = NULL;
        int slots, err = 0;
 
        level = 0;
@@ -739,13 +750,13 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,
        ++level;
        goto start;
 add_dentry:
-       f2fs_folio_wait_writeback(dentry_folio, DATA, true, true);
+       f2fs_folio_wait_writeback(dentry_folio, true, true);
 
        if (inode) {
                f2fs_down_write(&F2FS_I(inode)->i_sem);
-               folio = f2fs_init_inode_metadata(inode, dir, fname, NULL);
-               if (IS_ERR(folio)) {
-                       err = PTR_ERR(folio);
+               entry = f2fs_init_inode_metadata(inode, dir, fname, NULL);
+               if (IS_ERR(entry)) {
+                       err = PTR_ERR(entry);
                        goto fail;
                }
        }
@@ -760,9 +771,9 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,
 
                /* synchronize inode page's data from inode cache */
                if (is_inode_flag_set(inode, FI_NEW_INODE))
-                       f2fs_update_inode(inode, folio);
+                       f2fs_update_inode(inode, entry);
 
-               f2fs_folio_put(folio, true);
+               f2fs_put_cache(entry, true);
        }
 
        f2fs_update_parent_metadata(dir, inode, current_depth);
@@ -804,7 +815,7 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
                                struct inode *inode, nid_t ino, umode_t mode)
 {
        struct f2fs_filename fname;
-       struct folio *folio = NULL;
+       void *dentry_blk = NULL;
        struct f2fs_dir_entry *de = NULL;
        int err;
 
@@ -820,14 +831,14 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
         * consistency more.
         */
        if (current != F2FS_I(dir)->task) {
-               de = __f2fs_find_entry(dir, &fname, &folio);
+               de = __f2fs_find_entry(dir, &fname, &dentry_blk);
                F2FS_I(dir)->task = NULL;
        }
        if (de) {
-               f2fs_folio_put(folio, false);
+               f2fs_put_dentry_block(dentry_blk, false);
                err = -EEXIST;
-       } else if (IS_ERR(folio)) {
-               err = PTR_ERR(folio);
+       } else if (IS_ERR(dentry_blk)) {
+               err = PTR_ERR(dentry_blk);
        } else {
                err = f2fs_add_dentry(dir, &fname, inode, ino, mode);
        }
@@ -838,16 +849,16 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
 int f2fs_do_tmpfile(struct inode *inode, struct inode *dir,
                                        struct f2fs_filename *fname)
 {
-       struct folio *folio;
+       struct f2fs_cached_block *ientry;
        int err = 0;
 
        f2fs_down_write(&F2FS_I(inode)->i_sem);
-       folio = f2fs_init_inode_metadata(inode, dir, fname, NULL);
-       if (IS_ERR(folio)) {
-               err = PTR_ERR(folio);
+       ientry = f2fs_init_inode_metadata(inode, dir, fname, NULL);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto fail;
        }
-       f2fs_folio_put(folio, true);
+       f2fs_put_cache(ientry, true);
 
        clear_inode_flag(inode, FI_NEW_INODE);
        f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
@@ -883,14 +894,15 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *inode)
  * It only removes the dentry from the dentry page, corresponding name
  * entry in name page does not need to be touched during deletion.
  */
-void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio,
+void f2fs_delete_entry(struct f2fs_dir_entry *dentry, void *dentry_block,
                                        struct inode *dir, struct inode *inode)
 {
        void *dentry_blk;
        struct f2fs_dentry_ptr d;
+       struct folio *folio;
        unsigned int bit_pos;
        int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
-       pgoff_t index = folio->index;
+       pgoff_t index;
        int i;
 
        f2fs_update_time(F2FS_I_SB(dir), REQ_TIME);
@@ -899,10 +911,14 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio,
                f2fs_add_ino_entry(F2FS_I_SB(dir), dir->i_ino, TRANS_DIR_INO);
 
        if (f2fs_has_inline_dentry(dir))
-               return f2fs_delete_inline_entry(dentry, folio, dir, inode);
+               return f2fs_delete_inline_entry(dentry,
+                               f2fs_dentry_cache(dentry_block), dir, inode);
+
+       folio = f2fs_dentry_folio(dentry_block);
+       index = folio->index;
 
        folio_lock(folio);
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
 
        dentry_blk = folio_address(folio);
        make_dentry_ptr_block(dir, &d, dentry_blk);
@@ -1050,7 +1066,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
                }
 
                if (readdir_ra)
-                       f2fs_ra_node_page(sbi, le32_to_cpu(de->ino));
+                       f2fs_ra_node_cache(sbi, le32_to_cpu(de->ino));
 
                ctx->pos = start_pos + bit_pos;
                found_valid_dirent = true;
fs/f2fs/extent_cache.c +7 -7
index 40cd87940961..5a944428aca0 100644
@@ -20,10 +20,10 @@
 #include "segment.h"
 #include <trace/events/f2fs.h>
 
-bool sanity_check_extent_cache(struct inode *inode, struct folio *ifolio)
+bool sanity_check_extent_cache(struct inode *inode, struct f2fs_cached_block *ientry)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-       struct f2fs_extent *i_ext = &F2FS_INODE(ifolio)->i_ext;
+       struct f2fs_extent *i_ext = &F2FS_INODE(ientry)->i_ext;
        struct extent_info ei;
        int devi;
 
@@ -416,11 +416,11 @@ static void __drop_largest_extent(struct extent_tree *et,
        }
 }
 
-void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
+void f2fs_init_read_extent_tree(struct inode *inode, struct f2fs_cached_block *ientry)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct extent_tree_info *eti = &sbi->extent_tree[EX_READ];
-       struct f2fs_extent *i_ext = &F2FS_INODE(ifolio)->i_ext;
+       struct f2fs_extent *i_ext = &F2FS_INODE(ientry)->i_ext;
        struct extent_tree *et;
        struct extent_node *en;
        struct extent_info ei = {0};
@@ -428,9 +428,9 @@ void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
        if (!__may_extent_tree(inode, EX_READ)) {
                /* drop largest read extent */
                if (i_ext->len) {
-                       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+                       f2fs_cache_wait_writeback(ientry);
                        i_ext->len = 0;
-                       folio_mark_dirty(ifolio);
+                       f2fs_mark_cache_dirty(ientry);
                }
                set_inode_flag(inode, FI_NO_EXTENT);
                return;
@@ -958,7 +958,7 @@ static void __update_extent_cache(struct dnode_of_data *dn, enum extent_type typ
                return;
 
        ei.fofs = f2fs_start_bidx_of_node(ofs_of_node(F2FS_I_SB(dn->inode),
-                               dn->node_folio), dn->inode) + dn->ofs_in_node;
+                               dn->node_entry), dn->inode) + dn->ofs_in_node;
        ei.len = 1;
 
        if (type == EX_READ) {
fs/f2fs/f2fs.h +142 -117
index 51c191c514bc..d6681276708e 100644
@@ -418,7 +418,7 @@ struct inode_entry {
 
 struct fsync_node_entry {
        struct list_head list;  /* list head */
-       struct folio *folio;    /* warm node folio pointer */
+       struct f2fs_cached_block *entry; /* warm node cache entry pointer */
        unsigned int seq_id;    /* sequence id */
 };
 
@@ -1116,11 +1116,11 @@ struct f2fs_nm_info {
  */
 struct dnode_of_data {
        struct inode *inode;            /* vfs inode pointer */
-       struct folio *inode_folio;      /* its inode folio, NULL is possible */
-       struct folio *node_folio;       /* cached direct node folio */
+       struct f2fs_cached_block *inode_entry; /* generic cache inode entry */
+       struct f2fs_cached_block *node_entry;  /* generic cache node entry */
        nid_t nid;                      /* node id of the direct node block */
        unsigned int ofs_in_node;       /* data offset in the node page */
-       bool inode_folio_locked;        /* inode folio is locked or not */
+       bool inode_entry_locked;        /* inode entry is locked or not */
        bool node_changed;              /* is node block changed */
        char cur_level;                 /* level of hole node page */
        char max_level;                 /* level of current page located */
@@ -1128,12 +1128,12 @@ struct dnode_of_data {
 };
 
 static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
-               struct folio *ifolio, struct folio *nfolio, nid_t nid)
+               struct f2fs_cached_block *ientry, struct f2fs_cached_block *nentry, nid_t nid)
 {
        memset(dn, 0, sizeof(*dn));
        dn->inode = inode;
-       dn->inode_folio = ifolio;
-       dn->node_folio = nfolio;
+       dn->inode_entry = ientry;
+       dn->node_entry = nentry;
        dn->nid = nid;
 }
 
@@ -1614,10 +1614,9 @@ static inline void f2fs_clear_bit(unsigned int nr, char *addr);
  * | bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... |
  * bit 0       PAGE_PRIVATE_NOT_POINTER
  * bit 1       PAGE_PRIVATE_ONGOING_MIGRATION
- * bit 2       PAGE_PRIVATE_INLINE_INODE
- * bit 3       PAGE_PRIVATE_REF_RESOURCE
- * bit 4       PAGE_PRIVATE_ATOMIC_WRITE
- * bit 5-      f2fs private data
+ * bit 2       PAGE_PRIVATE_REF_RESOURCE
+ * bit 3       PAGE_PRIVATE_ATOMIC_WRITE
+ * bit 4-      f2fs private data
  *
  * Layout B: lowest bit should be 0
  * page.private is a wrapped pointer.
@@ -1625,7 +1624,6 @@ static inline void f2fs_clear_bit(unsigned int nr, char *addr);
 enum {
        PAGE_PRIVATE_NOT_POINTER,               /* private contains non-pointer data */
        PAGE_PRIVATE_ONGOING_MIGRATION,         /* data page which is on-going migrating */
-       PAGE_PRIVATE_INLINE_INODE,              /* inode page contains inline data */
        PAGE_PRIVATE_REF_RESOURCE,              /* dirty page has referenced resources */
        PAGE_PRIVATE_ATOMIC_WRITE,              /* data page from atomic write path */
        PAGE_PRIVATE_MAX
@@ -1802,7 +1800,6 @@ struct f2fs_sb_info {
 
        /* for node-related operations */
        struct f2fs_nm_info *nm_info;           /* node manager */
-       struct inode *node_inode;               /* cache node blocks */
 
        /* for segment-related operations */
        struct f2fs_sm_info *sm_info;           /* segment manager */
@@ -2327,28 +2324,29 @@ static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
 }
 
 static inline struct node_footer *F2FS_NODE_FOOTER(struct f2fs_sb_info *sbi,
-                                               const struct folio *folio)
+                                               const struct f2fs_cached_block *entry)
 {
-       return folio_address(folio) + F2FS_BLKSIZE(sbi) -
-               sizeof(struct node_footer);
+       return (struct node_footer *)(cache_address(entry) +
+               F2FS_BLKSIZE(sbi) - sizeof(struct node_footer));
 }
 
-static inline struct f2fs_node *F2FS_NODE(const struct folio *folio)
+static inline struct f2fs_node *F2FS_NODE(const struct f2fs_cached_block *entry)
 {
-       return (struct f2fs_node *)folio_address(folio);
+       return (struct f2fs_node *)CACHED_NODE(entry);
 }
 
-static inline struct f2fs_inode *F2FS_INODE(const struct folio *folio)
+static inline struct f2fs_inode *F2FS_INODE(const struct f2fs_cached_block *entry)
 {
-       return &((struct f2fs_node *)folio_address(folio))->i;
+       return &CACHED_NODE(entry)->i;
 }
 
 static inline __le32 *F2FS_INODE_NIDS(struct f2fs_sb_info *sbi,
-                                               const struct folio *folio)
+                                               const struct f2fs_cached_block *entry)
 {
-       return folio_address(folio) + F2FS_BLKSIZE(sbi) -
+       return (__le32 *)(cache_address(entry) +
+               F2FS_BLKSIZE(sbi) -
                sizeof(struct node_footer) -
-               SIZE_OF_I_NID;
+               SIZE_OF_I_NID);
 }
 
 static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
@@ -2381,14 +2379,9 @@ static inline bool f2fs_is_meta_cache(struct f2fs_cached_block *entry)
        return entry->cache && entry->cache == META_CACHE(entry->cache->sbi);
 }
 
-static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
+static inline bool f2fs_is_node_cache(struct f2fs_cached_block *entry)
 {
-       return sbi->node_inode->i_mapping;
-}
-
-static inline bool is_node_folio(struct f2fs_sb_info *sbi, struct folio *folio)
-{
-       return folio->mapping == NODE_MAPPING(sbi);
+       return entry->cache && entry->cache == NODE_CACHE(entry->cache->sbi);
 }
 
 static inline struct f2fs_bio *F2FS_BIO(struct bio *bio)
@@ -2812,17 +2805,14 @@ static inline void clear_page_private_##name(struct page *page) \
 }
 
 PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER);
-PAGE_PRIVATE_GET_FUNC(inline, INLINE_INODE);
 PAGE_PRIVATE_GET_FUNC(gcing, ONGOING_MIGRATION);
 PAGE_PRIVATE_GET_FUNC(atomic, ATOMIC_WRITE);
 
 PAGE_PRIVATE_SET_FUNC(reference, REF_RESOURCE);
-PAGE_PRIVATE_SET_FUNC(inline, INLINE_INODE);
 PAGE_PRIVATE_SET_FUNC(gcing, ONGOING_MIGRATION);
 PAGE_PRIVATE_SET_FUNC(atomic, ATOMIC_WRITE);
 
 PAGE_PRIVATE_CLEAR_FUNC(reference, REF_RESOURCE);
-PAGE_PRIVATE_CLEAR_FUNC(inline, INLINE_INODE);
 PAGE_PRIVATE_CLEAR_FUNC(gcing, ONGOING_MIGRATION);
 PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE);
 
@@ -3231,14 +3221,51 @@ static inline void f2fs_put_page(struct page *page, bool unlock)
        f2fs_folio_put(page_folio(page), unlock);
 }
 
+#define F2FS_DENTRY_TAG_CACHE  1UL
+#define F2FS_DENTRY_TAG_MASK   1UL
+
+static inline void *f2fs_cache_make_dentry_block(struct f2fs_cached_block *entry)
+{
+       if (IS_ERR_OR_NULL(entry))
+               return entry;
+       return (void *)((unsigned long)entry | F2FS_DENTRY_TAG_CACHE);
+}
+
+static inline bool f2fs_dentry_is_cache(void *dentry_block)
+{
+       return ((unsigned long)dentry_block & F2FS_DENTRY_TAG_MASK) ==
+                                               F2FS_DENTRY_TAG_CACHE;
+}
+
+static inline struct f2fs_cached_block *f2fs_dentry_cache(void *dentry_block)
+{
+       return (struct f2fs_cached_block *)
+               ((unsigned long)dentry_block & ~F2FS_DENTRY_TAG_MASK);
+}
+
+static inline struct folio *f2fs_dentry_folio(void *dentry_block)
+{
+       return (struct folio *)dentry_block;
+}
+
+static inline void f2fs_put_dentry_block(void *dentry_block, bool unlock)
+{
+       if (IS_ERR_OR_NULL(dentry_block))
+               return;
+       if (f2fs_dentry_is_cache(dentry_block))
+               f2fs_put_cache(f2fs_dentry_cache(dentry_block), unlock);
+       else
+               f2fs_folio_put(f2fs_dentry_folio(dentry_block), unlock);
+}
+
 static inline void f2fs_put_dnode(struct dnode_of_data *dn)
 {
-       if (dn->node_folio)
-               f2fs_folio_put(dn->node_folio, true);
-       if (dn->inode_folio && dn->node_folio != dn->inode_folio)
-               f2fs_folio_put(dn->inode_folio, false);
-       dn->node_folio = NULL;
-       dn->inode_folio = NULL;
+       if (dn->node_entry)
+               f2fs_put_cache(dn->node_entry, true);
+       if (dn->inode_entry && dn->node_entry != dn->inode_entry)
+               f2fs_put_cache(dn->inode_entry, false);
+       dn->node_entry = NULL;
+       dn->inode_entry = NULL;
 }
 
 static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
@@ -3327,9 +3354,9 @@ static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
                cond_resched();
 }
 
-static inline bool IS_INODE(struct f2fs_sb_info *sbi, const struct folio *folio)
+static inline bool IS_INODE(struct f2fs_sb_info *sbi, const struct f2fs_cached_block *entry)
 {
-       struct node_footer *footer = F2FS_NODE_FOOTER(sbi, folio);
+       struct node_footer *footer = F2FS_NODE_FOOTER(sbi, entry);
 
        return footer->nid == footer->ino;
 }
@@ -3341,46 +3368,44 @@ static inline int offset_in_addr(struct f2fs_inode *i)
 }
 
 static inline __le32 *blkaddr_in_node(struct f2fs_sb_info *sbi,
-                                               const struct folio *folio)
+                                               const struct f2fs_cached_block *entry)
 {
-       struct f2fs_node *node = F2FS_NODE(folio);
+       struct f2fs_node *node = F2FS_NODE(entry);
 
-       return IS_INODE(sbi, folio) ? node->i.i_addr : node->dn.addr;
+       return IS_INODE(sbi, entry) ? node->i.i_addr : node->dn.addr;
 }
 
 static inline int f2fs_has_extra_attr(struct inode *inode);
+
 static inline unsigned int get_dnode_base(struct inode *inode,
-                                       struct folio *node_folio)
+                                       const struct f2fs_cached_block *entry)
 {
-       struct f2fs_sb_info *sbi = inode ? F2FS_I_SB(inode) :
-                                       F2FS_F_SB(node_folio);
-
-       if (!IS_INODE(sbi, node_folio))
+       if (!IS_INODE(inode ? F2FS_I_SB(inode) : entry->cache->sbi, entry))
                return 0;
 
        return inode ? get_extra_isize(inode) :
-                       offset_in_addr(&F2FS_NODE(node_folio)->i);
+                       offset_in_addr(&CACHED_NODE(entry)->i);
 }
 
 static inline __le32 *get_dnode_addr(struct inode *inode,
-                                       struct folio *node_folio)
+                                       const struct f2fs_cached_block *entry)
 {
-       struct f2fs_sb_info *sbi = inode ? F2FS_I_SB(inode) :
-                                       F2FS_F_SB(node_folio);
+       struct f2fs_sb_info *sbi = inode ? F2FS_I_SB(inode) : entry->cache->sbi;
 
-       return blkaddr_in_node(sbi, node_folio) +
-                       get_dnode_base(inode, node_folio);
+       return blkaddr_in_node(sbi, entry) +
+                       get_dnode_base(inode, entry);
 }
 
 static inline block_t data_blkaddr(struct inode *inode,
-                       struct folio *node_folio, unsigned int offset)
+                       const struct f2fs_cached_block *entry,
+                       unsigned int offset)
 {
-       return le32_to_cpu(*(get_dnode_addr(inode, node_folio) + offset));
+       return le32_to_cpu(*(get_dnode_addr(inode, entry) + offset));
 }
 
 static inline block_t f2fs_data_blkaddr(struct dnode_of_data *dn)
 {
-       return data_blkaddr(dn->inode, dn->node_folio, dn->ofs_in_node);
+       return data_blkaddr(dn->inode, dn->node_entry, dn->ofs_in_node);
 }
 
 static inline int f2fs_test_bit(unsigned int nr, char *addr)
@@ -3697,10 +3722,10 @@ static inline unsigned int cur_addrs_per_inode(struct inode *inode)
        return DEF_ADDRS_PER_INODE(F2FS_I_SB(inode)) - get_extra_isize(inode);
 }
 
-static inline
-void *inline_xattr_addr(struct inode *inode, const struct folio *folio)
+static inline void *inline_xattr_addr(struct inode *inode,
+                               const struct f2fs_cached_block *entry)
 {
-       struct f2fs_inode *ri = F2FS_INODE(folio);
+       struct f2fs_inode *ri = F2FS_INODE(entry);
 
        return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE(F2FS_I_SB(inode)) -
                                        get_inline_xattr_addrs(inode)]);
@@ -3747,9 +3772,10 @@ static inline bool f2fs_is_cow_file(struct inode *inode)
        return is_inode_flag_set(inode, FI_COW_FILE);
 }
 
-static inline void *inline_data_addr(struct inode *inode, struct folio *folio)
+static inline void *inline_data_addr(struct inode *inode,
+                       const struct f2fs_cached_block *entry)
 {
-       __le32 *addr = get_dnode_addr(inode, folio);
+       __le32 *addr = get_dnode_addr(inode, entry);
 
        return (void *)(addr + DEF_INLINE_RESERVED_SIZE);
 }
@@ -3959,13 +3985,13 @@ int f2fs_pin_file_control(struct inode *inode, bool inc);
  * inode.c
  */
 void f2fs_set_inode_flags(struct inode *inode);
-bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct folio *folio);
-void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct folio *folio);
+bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
+void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-void f2fs_update_inode(struct inode *inode, struct folio *node_folio);
-void f2fs_update_inode_page(struct inode *inode);
+void f2fs_update_inode(struct inode *inode, struct f2fs_cached_block *entry);
+void f2fs_update_inode_cache(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);
@@ -4014,22 +4040,22 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
                        unsigned int start_pos, struct fscrypt_str *fstr);
 void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
                        struct f2fs_dentry_ptr *d);
-struct folio *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
-               const struct f2fs_filename *fname, struct folio *dfolio);
+struct f2fs_cached_block *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
+               const struct f2fs_filename *fname, struct f2fs_cached_block *dentry);
 void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode,
                        unsigned int current_depth);
 int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots);
 void f2fs_drop_nlink(struct inode *dir, struct inode *inode);
 struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
-               const struct f2fs_filename *fname, struct folio **res_folio);
+               const struct f2fs_filename *fname, void **dentry_block);
 struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
-                       const struct qstr *child, struct folio **res_folio);
-struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct folio **f);
+                       const struct qstr *child, void **dentry_block);
+struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, void **dentry_block);
 ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
-                       struct folio **folio);
+                       void **dentry_block);
 void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
-                       struct folio *folio, struct inode *inode);
-bool f2fs_has_enough_room(struct inode *dir, struct folio *ifolio,
+                       void *dentry_blk, struct inode *inode);
+bool f2fs_has_enough_room(struct inode *dir, struct f2fs_cached_block *ientry,
                          const struct f2fs_filename *fname);
 void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
                        const struct fscrypt_str *name, f2fs_hash_t name_hash,
@@ -4040,7 +4066,7 @@ int f2fs_add_dentry(struct inode *dir, const struct f2fs_filename *fname,
                        struct inode *inode, nid_t ino, umode_t mode);
 int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
                        struct inode *inode, nid_t ino, umode_t mode);
-void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio,
+void f2fs_delete_entry(struct f2fs_dir_entry *dentry, void *dentry_blk,
                        struct inode *dir, struct inode *inode);
 int f2fs_do_tmpfile(struct inode *inode, struct inode *dir,
                                        struct f2fs_filename *fname);
@@ -4083,9 +4109,9 @@ enum node_type;
 
 int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid);
 bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type);
-bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct folio *folio);
+bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
 void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi);
-void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct folio *folio);
+void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
 void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi);
 bool f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
 bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
@@ -4096,29 +4122,28 @@ pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
 int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
 int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from);
 int f2fs_truncate_xattr_node(struct inode *inode);
-int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi,
+int f2fs_wait_on_node_caches_writeback(struct f2fs_sb_info *sbi,
                                        unsigned int seq_id);
-int f2fs_remove_inode_page(struct inode *inode);
-struct folio *f2fs_new_inode_folio(struct inode *inode);
-struct folio *f2fs_new_node_folio(struct dnode_of_data *dn, unsigned int ofs);
-void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
-struct folio *f2fs_get_node_folio(struct f2fs_sb_info *sbi, pgoff_t nid,
+int f2fs_write_node_caches(struct f2fs_sb_info *sbi);
+int f2fs_remove_inode_cache(struct inode *inode);
+struct f2fs_cached_block *f2fs_new_inode_cache(struct inode *inode);
+struct f2fs_cached_block *f2fs_new_node_cache(struct dnode_of_data *dn, unsigned int ofs);
+void f2fs_ra_node_cache(struct f2fs_sb_info *sbi, nid_t nid);
+struct f2fs_cached_block *f2fs_get_node_cache(struct f2fs_sb_info *sbi, pgoff_t nid,
                                                enum node_type node_type);
 int f2fs_sanity_check_node_footer(struct f2fs_sb_info *sbi,
-                                       struct folio *folio, pgoff_t nid,
+                                       struct f2fs_cached_block *entry, pgoff_t nid,
                                        enum node_type ntype, bool in_irq);
-struct folio *f2fs_get_inode_folio(struct f2fs_sb_info *sbi, pgoff_t ino);
-struct folio *f2fs_get_xnode_folio(struct f2fs_sb_info *sbi, pgoff_t xnid);
-int f2fs_write_single_node_folio(struct folio *node_folio, int sync_mode,
+struct f2fs_cached_block *f2fs_get_inode_cache(struct f2fs_sb_info *sbi, pgoff_t ino);
+struct f2fs_cached_block *f2fs_get_xnode_cache(struct f2fs_sb_info *sbi, pgoff_t xnid);
+int f2fs_write_node_cache(struct f2fs_cached_block *entry, int sync_mode,
                        bool mark_dirty, enum iostat_type io_type);
-int f2fs_move_node_folio(struct folio *node_folio, int gc_type);
+int f2fs_move_node_cache(struct f2fs_cached_block *entry, int gc_type);
 void f2fs_flush_inline_data(struct f2fs_sb_info *sbi);
-int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
-                       struct writeback_control *wbc, bool atomic,
-                       unsigned int *seq_id);
-int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
-                       struct writeback_control *wbc,
-                       bool do_balance, enum iostat_type io_type);
+int f2fs_fsync_node_caches(struct f2fs_sb_info *sbi, struct inode *inode,
+                                       bool atomic, unsigned int *seq_id);
+int f2fs_writeback_node_caches(struct f2fs_sb_info *sbi, long nr_to_write,
+                       bool sync, bool do_balance, enum iostat_type io_type);
 int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
 bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
 void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
@@ -4126,7 +4151,8 @@ void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
 int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
 int f2fs_recover_inline_xattr(struct inode *inode, struct f2fs_cached_block *entry);
 int f2fs_recover_xattr_data(struct inode *inode, struct f2fs_cached_block *entry);
-int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
+int f2fs_recover_inode_cache(struct f2fs_sb_info *sbi,
+                       struct f2fs_cached_block *entry);
 int f2fs_restore_node_summary(struct f2fs_sb_info *sbi,
                        unsigned int segno, struct f2fs_summary_block *sum);
 int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
@@ -4185,7 +4211,7 @@ void f2fs_update_meta_block(struct f2fs_sb_info *sbi, void *src,
 void f2fs_do_write_meta_cache(struct f2fs_sb_info *sbi,
                        struct f2fs_cached_block *entry,
                        enum iostat_type io_type);
-void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio);
+void f2fs_do_write_node_cache(unsigned int nid, struct f2fs_io_info *fio);
 void f2fs_outplace_write_data(struct dnode_of_data *dn,
                        struct f2fs_io_info *fio);
 int f2fs_inplace_write_data(struct f2fs_io_info *fio);
@@ -4199,14 +4225,13 @@ void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
                        bool recover_newaddr);
 enum temp_type f2fs_get_segment_temp(struct f2fs_sb_info *sbi,
                                                enum log_type seg_type);
-int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct folio *folio,
+int f2fs_allocate_data_block(struct f2fs_sb_info *sbi,
                        block_t old_blkaddr, block_t *new_blkaddr,
                        struct f2fs_summary *sum, int type,
                        struct f2fs_io_info *fio);
 void f2fs_update_device_state(struct f2fs_sb_info *sbi, nid_t ino,
                                        block_t blkaddr, unsigned int blkcnt);
-void f2fs_folio_wait_writeback(struct folio *folio, enum page_type type,
-               bool ordered, bool locked);
+void f2fs_folio_wait_writeback(struct folio *folio, bool ordered, bool locked);
 void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr);
 void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr,
                                                                block_t len);
@@ -4327,14 +4352,14 @@ void f2fs_destroy_bio_entry_cache(void);
 void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio,
                          enum page_type type);
 int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi);
-void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
 void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
-                               struct inode *inode, struct folio *folio,
-                               nid_t ino, enum page_type type);
+                               struct inode *inode, struct folio *folio);
 void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
-                               struct folio *folio, enum page_type type);
-bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
-                               enum page_type type);
+                               struct folio *folio);
+bool f2fs_submit_merged_write_cache(struct f2fs_sb_info *sbi,
+                               struct f2fs_cached_block *entry,
+                               nid_t ino, enum page_type type);
+void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
 void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
                                        struct bio **bio, struct folio *folio);
 void f2fs_submit_all_merged_ipu_writes(struct f2fs_sb_info *sbi);
@@ -4360,7 +4385,7 @@ struct folio *f2fs_find_data_folio(struct inode *inode, pgoff_t index,
 struct folio *f2fs_get_lock_data_folio(struct inode *inode, pgoff_t index,
                        bool for_write);
 struct folio *f2fs_get_new_data_folio(struct inode *inode,
-                       struct folio *ifolio, pgoff_t index, bool new_i_size);
+                       struct f2fs_cached_block *ientry, pgoff_t index, bool new_i_size);
 int f2fs_do_write_data_page(struct f2fs_io_info *fio);
 int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag);
 int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
@@ -4472,7 +4497,7 @@ struct f2fs_stat_info {
        unsigned int bimodal, avg_vblocks;
        int util_free, util_valid, util_invalid;
        int rsvd_segs, overp_segs;
-       int dirty_count, node_pages, meta_caches, compress_pages;
+       int dirty_count, node_caches, meta_caches, compress_pages;
        int compress_page_hit;
        int prefree_count, free_segs, free_secs;
        int cp_call_count[MAX_CALL_TYPE], cp_count;
@@ -4673,7 +4698,6 @@ extern const struct file_operations f2fs_dir_operations;
 extern const struct file_operations f2fs_file_operations;
 extern const struct inode_operations f2fs_file_inode_operations;
 extern const struct address_space_operations f2fs_dblock_aops;
-extern const struct address_space_operations f2fs_node_aops;
 extern const struct inode_operations f2fs_dir_inode_operations;
 extern const struct inode_operations f2fs_symlink_inode_operations;
 extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
@@ -4684,10 +4708,10 @@ extern struct kmem_cache *f2fs_inode_entry_slab;
  * inline.c
  */
 bool f2fs_may_inline_data(struct inode *inode);
-bool f2fs_sanity_check_inline_data(struct inode *inode, struct folio *ifolio);
+bool f2fs_sanity_check_inline_data(struct inode *inode, struct f2fs_cached_block *ientry);
 bool f2fs_may_inline_dentry(struct inode *inode);
-void f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio);
-void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio,
+void f2fs_do_read_inline_data(struct folio *folio, struct f2fs_cached_block *ientry);
+void f2fs_truncate_inline_inode(struct inode *inode, struct f2fs_cached_block *ientry,
                u64 from);
 int f2fs_read_inline_data(struct inode *inode, struct folio *folio);
 int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio);
@@ -4696,14 +4720,15 @@ int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry);
 int f2fs_write_inline_data(struct inode *inode, struct folio *folio);
 int f2fs_recover_inline_data(struct inode *inode, struct f2fs_cached_block *entry);
 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
-               const struct f2fs_filename *fname, struct folio **res_folio,
+               const struct f2fs_filename *fname, void **dentry_block,
                bool use_hash);
 int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
-                       struct folio *ifolio);
+                       struct f2fs_cached_block *ientry);
 int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
                        struct inode *inode, nid_t ino, umode_t mode);
 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
-               struct folio *folio, struct inode *dir, struct inode *inode);
+               struct f2fs_cached_block *ientry, struct inode *dir,
+               struct inode *inode);
 bool f2fs_empty_inline_dir(struct inode *dir);
 int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
                        struct fscrypt_str *fstr);
@@ -4726,7 +4751,7 @@ void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
 /*
  * extent_cache.c
  */
-bool sanity_check_extent_cache(struct inode *inode, struct folio *ifolio);
+bool sanity_check_extent_cache(struct inode *inode, struct f2fs_cached_block *ientry);
 void f2fs_init_extent_tree(struct inode *inode);
 void f2fs_drop_extent_tree(struct inode *inode);
 void f2fs_destroy_extent_node(struct inode *inode);
@@ -4736,7 +4761,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 folio *ifolio);
+void f2fs_init_read_extent_tree(struct inode *inode, struct f2fs_cached_block *ientry);
 bool f2fs_lookup_read_extent_cache(struct inode *inode, pgoff_t pgofs,
                        struct extent_info *ei);
 bool f2fs_lookup_read_extent_cache_block(struct inode *inode, pgoff_t index,
fs/f2fs/file.c +37 -41
index 7c2bfa0e63d2..6f4287fe180d 100644
@@ -213,7 +213,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
                goto out_sem;
        }
 
-       f2fs_folio_wait_writeback(folio, DATA, false, true);
+       f2fs_folio_wait_writeback(folio, false, true);
 
        /* wait for GCed page writeback via generic cache */
        f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
@@ -308,13 +308,13 @@ static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)
 
 static bool need_inode_page_update(struct f2fs_sb_info *sbi, nid_t ino)
 {
-       struct folio *i = filemap_get_folio(NODE_MAPPING(sbi), ino);
+       struct f2fs_cached_block *entry = f2fs_find_node_cache(sbi, ino);
        bool ret = false;
        /* But we need to avoid that there are some inode updates */
-       if ((!IS_ERR(i) && folio_test_dirty(i)) ||
+       if ((!IS_ERR(entry) && f2fs_cache_test_dirty(entry)) ||
            f2fs_need_inode_block_update(sbi, ino))
                ret = true;
-       f2fs_folio_put(i, false);
+       f2fs_put_cache(entry, false);
        return ret;
 }
 
@@ -340,10 +340,6 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
        nid_t ino = inode->i_ino;
        int ret = 0;
        enum cp_reason_type cp_reason = 0;
-       struct writeback_control wbc = {
-               .sync_mode = WB_SYNC_ALL,
-               .nr_to_write = LONG_MAX,
-       };
        unsigned int seq_id = 0;
 
        if (unlikely(f2fs_readonly(inode->i_sb)))
@@ -422,7 +418,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
        }
 sync_nodes:
        atomic_inc(&sbi->wb_sync_req[NODE]);
-       ret = f2fs_fsync_node_pages(sbi, inode, &wbc, atomic, &seq_id);
+       ret = f2fs_fsync_node_caches(sbi, inode, atomic, &seq_id);
        atomic_dec(&sbi->wb_sync_req[NODE]);
        if (ret)
                goto out;
@@ -448,7 +444,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
         * given fsync mark.
         */
        if (!atomic) {
-               ret = f2fs_wait_on_node_pages_writeback(sbi, seq_id);
+               ret = f2fs_wait_on_node_caches_writeback(sbi, seq_id);
                if (ret)
                        goto out;
        }
@@ -485,7 +481,7 @@ static bool __found_offset(struct address_space *mapping,
        bool compressed_cluster = false;
 
        if (f2fs_compressed_file(inode)) {
-               block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                    ALIGN_DOWN(dn->ofs_in_node, F2FS_I(inode)->i_cluster_size));
 
                compressed_cluster = first_blkaddr == COMPRESS_ADDR;
@@ -557,7 +553,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
                        }
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
 
                /* find data/hole in dnode block */
                for (; dn.ofs_in_node < end_offset;
@@ -720,7 +716,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
        block_t blkstart;
        int blklen = 0;
 
-       addr = get_dnode_addr(dn->inode, dn->node_folio) + ofs;
+       addr = get_dnode_addr(dn->inode, dn->node_entry) + ofs;
        blkstart = le32_to_cpu(*addr);
 
        /* Assumption: truncation starts with cluster */
@@ -784,7 +780,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
                 * once we invalidate valid blkaddr in range [ofs, ofs + count],
                 * we will invalidate all blkaddr in the whole range.
                 */
-               fofs = f2fs_start_bidx_of_node(ofs_of_node(sbi, dn->node_folio),
+               fofs = f2fs_start_bidx_of_node(ofs_of_node(sbi, dn->node_entry),
                                                        dn->inode) + ofs;
                f2fs_update_read_extent_cache_range(dn, fofs, 0, len);
                f2fs_update_age_extent_cache_range(dn, fofs, len);
@@ -822,7 +818,7 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,
        if (IS_ERR(folio))
                return PTR_ERR(folio) == -ENOENT ? 0 : PTR_ERR(folio);
 truncate_out:
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
        folio_zero_segment(folio, offset, folio_size(folio));
 
        /* An encrypted inode should have a key and truncate the last page. */
@@ -840,7 +836,7 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
        struct f2fs_lock_context lc;
        pgoff_t free_from;
        int count = 0, err = 0;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        bool truncate_page = false;
 
        trace_f2fs_truncate_blocks_enter(inode, from);
@@ -858,9 +854,9 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
        if (lock)
                f2fs_lock_op(sbi, &lc);
 
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto out;
        }
 
@@ -879,18 +875,18 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
 
                f2fs_drop_extent_tree(inode);
 
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                goto out;
        }
 
        if (f2fs_has_inline_data(inode)) {
-               f2fs_truncate_inline_inode(inode, ifolio, from);
-               f2fs_folio_put(ifolio, true);
+               f2fs_truncate_inline_inode(inode, ientry, from);
+               f2fs_put_cache(ientry, true);
                truncate_page = true;
                goto out;
        }
 
-       set_new_dnode(&dn, inode, ifolio, NULL, 0);
+       set_new_dnode(&dn, inode, ientry, NULL, 0);
        err = f2fs_get_dnode_of_data(&dn, free_from, LOOKUP_NODE_RA);
        if (err) {
                if (err == -ENOENT)
@@ -898,12 +894,12 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
                goto out;
        }
 
-       count = ADDRS_PER_PAGE(dn.node_folio, inode);
+       count = ADDRS_PER_PAGE(dn.node_entry, inode);
 
        count -= dn.ofs_in_node;
        f2fs_bug_on(sbi, count < 0);
 
-       if (dn.ofs_in_node || IS_INODE(sbi, dn.node_folio)) {
+       if (dn.ofs_in_node || IS_INODE(sbi, dn.node_entry)) {
                f2fs_truncate_data_blocks_range(&dn, count);
                free_from += count;
        }
@@ -1309,7 +1305,7 @@ static int fill_zero(struct inode *inode, pgoff_t index,
        if (IS_ERR(folio))
                return PTR_ERR(folio);
 
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
        folio_zero_range(folio, start, len);
        folio_mark_dirty(folio);
        f2fs_folio_put(folio, true);
@@ -1335,7 +1331,7 @@ int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end)
                        return err;
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                count = min(end_offset - dn.ofs_in_node, pg_end - pg_start);
 
                f2fs_bug_on(F2FS_I_SB(inode), count == 0 || count > end_offset);
@@ -1435,7 +1431,7 @@ static int __read_out_blkaddrs(struct inode *inode, block_t *blkaddr,
                goto next;
        }
 
-       done = min((pgoff_t)ADDRS_PER_PAGE(dn.node_folio, inode) -
+       done = min((pgoff_t)ADDRS_PER_PAGE(dn.node_entry, inode) -
                                                        dn.ofs_in_node, len);
        for (i = 0; i < done; i++, blkaddr++, do_replace++, dn.ofs_in_node++) {
                *blkaddr = f2fs_data_blkaddr(&dn);
@@ -1524,7 +1520,7 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
                        }
 
                        ilen = min((pgoff_t)
-                               ADDRS_PER_PAGE(dn.node_folio, dst_inode) -
+                               ADDRS_PER_PAGE(dn.node_entry, dst_inode) -
                                                dn.ofs_in_node, len - i);
                        do {
                                dn.data_blkaddr = f2fs_data_blkaddr(&dn);
@@ -1562,7 +1558,7 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
                                return PTR_ERR(fdst);
                        }
 
-                       f2fs_folio_wait_writeback(fdst, DATA, true, true);
+                       f2fs_folio_wait_writeback(fdst, true, true);
 
                        memcpy_folio(fdst, 0, fsrc, 0, PAGE_SIZE);
                        folio_mark_dirty(fdst);
@@ -1832,7 +1828,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
                                goto out;
                        }
 
-                       end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+                       end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                        end = min(pg_end, end_offset - dn.ofs_in_node + index);
 
                        ret = f2fs_do_zero_range(&dn, index, end);
@@ -3133,7 +3129,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
                                goto clear_out;
                        }
 
-                       f2fs_folio_wait_writeback(folio, DATA, true, true);
+                       f2fs_folio_wait_writeback(folio, true, true);
 
                        folio_mark_dirty(folio);
                        folio_set_f2fs_gcing(folio);
@@ -3856,7 +3852,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *filp)
        f2fs_reserve_device_alias(sbi, ei.blk, ei.len);
 
        i_size_write(inode, (loff_t)ei.len << sbi->log_blocksize);
-       f2fs_update_inode_page(inode);
+       f2fs_update_inode_cache(inode);
 
        spin_lock(&FREE_I(sbi)->segmap_lock);
        FDEV(f2fs_target_device_index(sbi, ei.blk)).is_reserving = false;
@@ -3950,7 +3946,7 @@ static int f2fs_ioc_release_dev_alias(struct file *filp)
                goto out_inode_unlock;
        }
 
-       f2fs_update_inode_page(inode);
+       f2fs_update_inode_cache(inode);
 
        f2fs_unlock_op(sbi, &lc);
        f2fs_up_write_trace(&sbi->gc_lock, &glc);
@@ -4169,7 +4165,7 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count)
        int i;
 
        for (i = 0; i < count; i++) {
-               blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                dn->ofs_in_node + i);
 
                if (!__is_valid_data_blkaddr(blkaddr))
@@ -4288,7 +4284,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
                        break;
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                count = min(end_offset - dn.ofs_in_node, last_idx - page_idx);
                count = round_up(count, fi->i_cluster_size);
 
@@ -4339,7 +4335,7 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count,
        int i;
 
        for (i = 0; i < count; i++) {
-               blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                dn->ofs_in_node + i);
 
                if (!__is_valid_data_blkaddr(blkaddr))
@@ -4356,7 +4352,7 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count,
                int ret;
 
                for (i = 0; i < cluster_size; i++) {
-                       blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+                       blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                dn->ofs_in_node + i);
 
                        if (i == 0) {
@@ -4467,7 +4463,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
                        break;
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                count = min(end_offset - dn.ofs_in_node, last_idx - page_idx);
                count = round_up(count, fi->i_cluster_size);
 
@@ -4633,7 +4629,7 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
                        goto out;
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                count = min(end_offset - dn.ofs_in_node, pg_end - index);
                for (i = 0; i < count; i++, index++, dn.ofs_in_node++) {
                        struct block_device *cur_bdev;
@@ -4829,7 +4825,7 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
                /* It will never fail, when folio has pinned above */
                f2fs_bug_on(F2FS_I_SB(inode), IS_ERR(folio));
 
-               f2fs_folio_wait_writeback(folio, DATA, true, true);
+               f2fs_folio_wait_writeback(folio, true, true);
 
                folio_mark_dirty(folio);
                folio_set_f2fs_gcing(folio);
fs/f2fs/gc.c +25 -25
index bed9056d6b6e..a35d15b97d5b 100644
@@ -1054,7 +1054,7 @@ static int gc_node_segment(struct f2fs_sb_info *sbi,
 
        for (off = 0; off < usable_blks_in_seg; off++, entry++) {
                nid_t nid = le32_to_cpu(entry->nid);
-               struct folio *node_folio;
+               struct f2fs_cached_block *node_entry;
                struct node_info ni;
                int err;
 
@@ -1072,32 +1072,32 @@ static int gc_node_segment(struct f2fs_sb_info *sbi,
                }
 
                if (phase == 1) {
-                       f2fs_ra_node_page(sbi, nid);
+                       f2fs_ra_node_cache(sbi, nid);
                        continue;
                }
 
                /* phase == 2 */
-               node_folio = f2fs_get_node_folio(sbi, nid, NODE_TYPE_REGULAR);
-               if (IS_ERR(node_folio))
+               node_entry = f2fs_get_node_cache(sbi, nid, NODE_TYPE_REGULAR);
+               if (IS_ERR(node_entry))
                        continue;
 
                /* block may become invalid during f2fs_get_node_folio */
                if (check_valid_map(sbi, segno, off) == 0) {
-                       f2fs_folio_put(node_folio, true);
+                       f2fs_put_cache(node_entry, true);
                        continue;
                }
 
                if (f2fs_get_node_info(sbi, nid, &ni, false)) {
-                       f2fs_folio_put(node_folio, true);
+                       f2fs_put_cache(node_entry, true);
                        continue;
                }
 
                if (ni.blk_addr != start_addr + off) {
-                       f2fs_folio_put(node_folio, true);
+                       f2fs_put_cache(node_entry, true);
                        continue;
                }
 
-               err = f2fs_move_node_folio(node_folio, gc_type);
+               err = f2fs_move_node_cache(node_entry, gc_type);
                if (!err && gc_type == FG_GC)
                        submitted++;
                stat_inc_node_blk_count(sbi, 1, gc_type);
@@ -1148,7 +1148,7 @@ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode)
 static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
                struct node_info *dni, block_t blkaddr, unsigned int *nofs)
 {
-       struct folio *node_folio;
+       struct f2fs_cached_block *node_entry;
        nid_t nid;
        unsigned int ofs_in_node, max_addrs, base;
        block_t source_blkaddr;
@@ -1156,12 +1156,12 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
        nid = le32_to_cpu(sum->nid);
        ofs_in_node = le16_to_cpu(sum->ofs_in_node);
 
-       node_folio = f2fs_get_node_folio(sbi, nid, NODE_TYPE_REGULAR);
-       if (IS_ERR(node_folio))
+       node_entry = f2fs_get_node_cache(sbi, nid, NODE_TYPE_REGULAR);
+       if (IS_ERR(node_entry))
                return false;
 
        if (f2fs_get_node_info(sbi, nid, dni, false)) {
-               f2fs_folio_put(node_folio, true);
+               f2fs_put_cache(node_entry, true);
                return false;
        }
 
@@ -1172,12 +1172,12 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
        }
 
        if (f2fs_check_nid_range(sbi, dni->ino)) {
-               f2fs_folio_put(node_folio, true);
+               f2fs_put_cache(node_entry, true);
                return false;
        }
 
-       if (IS_INODE(sbi, node_folio)) {
-               base = offset_in_addr(F2FS_INODE(node_folio));
+       if (IS_INODE(sbi, node_entry)) {
+               base = offset_in_addr(F2FS_INODE(node_entry));
                max_addrs = DEF_ADDRS_PER_INODE(sbi);
        } else {
                base = 0;
@@ -1187,13 +1187,13 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
        if (base + ofs_in_node >= max_addrs) {
                f2fs_err(sbi, "Inconsistent blkaddr offset: base:%u, ofs_in_node:%u, max:%u, ino:%u, nid:%u",
                        base, ofs_in_node, max_addrs, dni->ino, dni->nid);
-               f2fs_folio_put(node_folio, true);
+               f2fs_put_cache(node_entry, true);
                return false;
        }
 
-       *nofs = ofs_of_node(sbi, node_folio);
-       source_blkaddr = data_blkaddr(NULL, node_folio, ofs_in_node);
-       f2fs_folio_put(node_folio, true);
+       *nofs = ofs_of_node(sbi, node_entry);
+       source_blkaddr = data_blkaddr(NULL, node_entry, ofs_in_node);
+       f2fs_put_cache(node_entry, true);
 
        if (source_blkaddr != blkaddr) {
 #ifdef CONFIG_F2FS_CHECK_FS
@@ -1285,7 +1285,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
         * don't cache encrypted data into meta inode until previous dirty
         * data were writebacked to avoid racing between GC and flush.
         */
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
 
        f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
 
@@ -1396,7 +1396,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
         * don't cache encrypted data into meta inode until previous dirty
         * data were writebacked to avoid racing between GC and flush.
         */
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
 
        f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
 
@@ -1445,7 +1445,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
        set_summary(&sum, dn.nid, dn.ofs_in_node, ni.version);
 
        /* allocate block address */
-       err = f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr,
+       err = f2fs_allocate_data_block(fio.sbi, fio.old_blkaddr, &newaddr,
                                &sum, type, NULL);
        if (err) {
                f2fs_put_cache(sentry, true);
@@ -1549,7 +1549,7 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
                bool is_dirty = folio_test_dirty(folio);
 
 retry:
-               f2fs_folio_wait_writeback(folio, DATA, true, true);
+               f2fs_folio_wait_writeback(folio, true, true);
 
                folio_mark_dirty(folio);
                if (folio_clear_dirty_for_io(folio)) {
@@ -1626,7 +1626,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
                }
 
                if (phase == 1) {
-                       f2fs_ra_node_page(sbi, nid);
+                       f2fs_ra_node_cache(sbi, nid);
                        continue;
                }
 
@@ -1635,7 +1635,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
                        continue;
 
                if (phase == 2) {
-                       f2fs_ra_node_page(sbi, dni.ino);
+                       f2fs_ra_node_cache(sbi, dni.ino);
                        continue;
                }
 
fs/f2fs/inline.c +141 -138
index d10acb5042e3..273b6428c9f9 100644
@@ -34,7 +34,7 @@ bool f2fs_may_inline_data(struct inode *inode)
        return !f2fs_post_read_required(inode);
 }
 
-static bool inode_has_blocks(struct inode *inode, struct folio *ifolio)
+static bool inode_has_blocks(struct inode *inode, struct f2fs_cached_block *ientry)
 {
        int i;
 
@@ -42,18 +42,18 @@ static bool inode_has_blocks(struct inode *inode, struct folio *ifolio)
                return true;
 
        for (i = 0; i < DEF_NIDS_PER_INODE; i++) {
-               if (F2FS_INODE_NIDS(F2FS_I_SB(inode), ifolio)[i])
+               if (F2FS_INODE_NIDS(F2FS_I_SB(inode), ientry)[i])
                        return true;
        }
        return false;
 }
 
-bool f2fs_sanity_check_inline_data(struct inode *inode, struct folio *ifolio)
+bool f2fs_sanity_check_inline_data(struct inode *inode, struct f2fs_cached_block *ientry)
 {
        if (!f2fs_has_inline_data(inode))
                return false;
 
-       if (inode_has_blocks(inode, ifolio))
+       if (inode_has_blocks(inode, ientry))
                return false;
 
        if (!support_inline_data(inode))
@@ -79,7 +79,7 @@ bool f2fs_may_inline_dentry(struct inode *inode)
        return true;
 }
 
-void f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio)
+void f2fs_do_read_inline_data(struct folio *folio, struct f2fs_cached_block *ientry)
 {
        struct inode *inode = folio->mapping->host;
 
@@ -91,13 +91,13 @@ void f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio)
        folio_zero_segment(folio, MAX_INLINE_DATA(inode), folio_size(folio));
 
        /* Copy the whole inline data block */
-       memcpy_to_folio(folio, 0, inline_data_addr(inode, ifolio),
+       memcpy_to_folio(folio, 0, inline_data_addr(inode, ientry),
                       MAX_INLINE_DATA(inode));
        if (!folio_test_uptodate(folio))
                folio_mark_uptodate(folio);
 }
 
-void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio,
+void f2fs_truncate_inline_inode(struct inode *inode, struct f2fs_cached_block *ientry,
                u64 from)
 {
        void *addr;
@@ -105,11 +105,11 @@ void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio,
        if (from >= MAX_INLINE_DATA(inode))
                return;
 
-       addr = inline_data_addr(inode, ifolio);
+       addr = inline_data_addr(inode, ientry);
 
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       f2fs_cache_wait_writeback(ientry);
        memset(addr + from, 0, MAX_INLINE_DATA(inode) - from);
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 
        if (from == 0)
                clear_inode_flag(inode, FI_DATA_EXIST);
@@ -117,27 +117,27 @@ void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio,
 
 int f2fs_read_inline_data(struct inode *inode, struct folio *folio)
 {
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
 
-       ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-       if (IS_ERR(ifolio)) {
+       ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+       if (IS_ERR(ientry)) {
                folio_unlock(folio);
-               return PTR_ERR(ifolio);
+               return PTR_ERR(ientry);
        }
 
        if (!f2fs_has_inline_data(inode)) {
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return -EAGAIN;
        }
 
        if (folio->index)
                folio_zero_segment(folio, 0, folio_size(folio));
        else
-               f2fs_do_read_inline_data(folio, ifolio);
+               f2fs_do_read_inline_data(folio, ientry);
 
        if (!folio_test_uptodate(folio))
                folio_mark_uptodate(folio);
-       f2fs_folio_put(ifolio, true);
+       f2fs_put_cache(ientry, true);
        folio_unlock(folio);
        return 0;
 }
@@ -185,7 +185,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
 
        f2fs_bug_on(F2FS_F_SB(folio), folio_test_writeback(folio));
 
-       f2fs_do_read_inline_data(folio, dn->inode_folio);
+       f2fs_do_read_inline_data(folio, dn->inode_entry);
        folio_mark_dirty(folio);
 
        /* clear dirty state */
@@ -196,7 +196,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
        fio.old_blkaddr = dn->data_blkaddr;
        set_inode_flag(dn->inode, FI_HOT_DATA);
        f2fs_outplace_write_data(dn, &fio);
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
        if (dirty) {
                inode_dec_dirty_pages(dn->inode);
                f2fs_remove_dirty_inode(dn->inode);
@@ -206,8 +206,8 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
        set_inode_flag(dn->inode, FI_APPEND_WRITE);
 
        /* clear inline data and flag after data writeback */
-       f2fs_truncate_inline_inode(dn->inode, dn->inode_folio, 0);
-       folio_clear_f2fs_inline(dn->inode_folio);
+       f2fs_truncate_inline_inode(dn->inode, dn->inode_entry, 0);
+       f2fs_cache_clear_inline(dn->inode_entry);
 clear_out:
        stat_dec_inline_inode(dn->inode);
        clear_inode_flag(dn->inode, FI_INLINE_DATA);
@@ -220,7 +220,8 @@ int f2fs_convert_inline_inode(struct inode *inode)
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct dnode_of_data dn;
        struct f2fs_lock_context lc;
-       struct folio *ifolio, *folio;
+       struct f2fs_cached_block *ientry;
+       struct folio *folio;
        int err = 0;
 
        if (f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb))
@@ -239,13 +240,13 @@ int f2fs_convert_inline_inode(struct inode *inode)
 
        f2fs_lock_op(sbi, &lc);
 
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto out;
        }
 
-       set_new_dnode(&dn, inode, ifolio, ifolio, 0);
+       set_new_dnode(&dn, inode, ientry, ientry, 0);
 
        if (f2fs_has_inline_data(inode))
                err = f2fs_convert_inline_folio(&dn, folio);
@@ -265,31 +266,31 @@ int f2fs_convert_inline_inode(struct inode *inode)
 int f2fs_write_inline_data(struct inode *inode, struct folio *folio)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
 
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
        if (!f2fs_has_inline_data(inode)) {
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return -EAGAIN;
        }
 
        f2fs_bug_on(F2FS_I_SB(inode), folio->index);
 
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
-       memcpy_from_folio(inline_data_addr(inode, ifolio),
+       f2fs_cache_wait_writeback(ientry);
+       memcpy_from_folio(inline_data_addr(inode, ientry),
                         folio, 0, MAX_INLINE_DATA(inode));
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 
        f2fs_clear_page_cache_dirty_tag(folio);
 
        set_inode_flag(inode, FI_APPEND_WRITE);
        set_inode_flag(inode, FI_DATA_EXIST);
 
-       folio_clear_f2fs_inline(ifolio);
-       f2fs_folio_put(ifolio, true);
+       f2fs_cache_clear_inline(ientry);
+       f2fs_put_cache(ientry, true);
        return 0;
 }
 
@@ -307,40 +308,41 @@ int f2fs_recover_inline_data(struct inode *inode, struct f2fs_cached_block *entr
         *    x       o  -> remove data blocks, and then recover inline_data
         *    x       x  -> recover data blocks
         */
-       if (IS_INODE(sbi, cache_folio(entry)))
+       if (IS_INODE(F2FS_I_SB(inode), entry))
                ri = &CACHED_NODE(entry)->i;
 
        if (f2fs_has_inline_data(inode) &&
                        ri && (ri->i_inline & F2FS_INLINE_DATA)) {
-               struct folio *ifolio;
+               struct f2fs_cached_block *ientry;
 
 process_inline:
-               ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-               if (IS_ERR(ifolio))
-                       return PTR_ERR(ifolio);
+               ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+               if (IS_ERR(ientry))
+                       return PTR_ERR(ientry);
 
-               f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+               f2fs_cache_wait_writeback(ientry);
 
-               src_addr = inline_data_addr(inode, cache_folio(entry));
-               dst_addr = inline_data_addr(inode, ifolio);
+               src_addr = inline_data_addr(inode, entry);
+               dst_addr = inline_data_addr(inode, ientry);
                memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
 
                set_inode_flag(inode, FI_INLINE_DATA);
                set_inode_flag(inode, FI_DATA_EXIST);
 
-               folio_mark_dirty(ifolio);
-               f2fs_folio_put(ifolio, true);
+               f2fs_mark_cache_dirty(ientry);
+               f2fs_put_cache(ientry, true);
                return 1;
        }
 
        if (f2fs_has_inline_data(inode)) {
-               struct folio *ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-               if (IS_ERR(ifolio))
-                       return PTR_ERR(ifolio);
-               f2fs_truncate_inline_inode(inode, ifolio, 0);
+               struct f2fs_cached_block *ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+
+               if (IS_ERR(ientry))
+                       return PTR_ERR(ientry);
+               f2fs_truncate_inline_inode(inode, ientry, 0);
                stat_dec_inline_inode(inode);
                clear_inode_flag(inode, FI_INLINE_DATA);
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
        } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
                int ret;
 
@@ -355,50 +357,50 @@ int f2fs_recover_inline_data(struct inode *inode, struct f2fs_cached_block *entr
 
 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
                                        const struct f2fs_filename *fname,
-                                       struct folio **res_folio,
+                                       void **dentry_block,
                                        bool use_hash)
 {
        struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
        struct f2fs_dir_entry *de;
        struct f2fs_dentry_ptr d;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        void *inline_dentry;
 
-       ifolio = f2fs_get_inode_folio(sbi, dir->i_ino);
-       if (IS_ERR(ifolio)) {
-               *res_folio = ifolio;
+       ientry = f2fs_get_inode_cache(sbi, dir->i_ino);
+       if (IS_ERR(ientry)) {
+               *dentry_block = ientry;
                return NULL;
        }
 
-       inline_dentry = inline_data_addr(dir, ifolio);
+       inline_dentry = inline_data_addr(dir, ientry);
 
        make_dentry_ptr_inline(dir, &d, inline_dentry);
        de = f2fs_find_target_dentry(&d, fname, NULL, use_hash);
-       folio_unlock(ifolio);
+       f2fs_unlock_cache(ientry);
        if (IS_ERR(de)) {
-               *res_folio = ERR_CAST(de);
+               *dentry_block = ERR_CAST(de);
                de = NULL;
        }
        if (de)
-               *res_folio = ifolio;
+               *dentry_block = f2fs_cache_make_dentry_block(ientry);
        else
-               f2fs_folio_put(ifolio, false);
+               f2fs_put_cache(ientry, false);
 
        return de;
 }
 
 int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
-                                                       struct folio *ifolio)
+                                       struct f2fs_cached_block *ientry)
 {
        struct f2fs_dentry_ptr d;
        void *inline_dentry;
 
-       inline_dentry = inline_data_addr(inode, ifolio);
+       inline_dentry = inline_data_addr(inode, ientry);
 
        make_dentry_ptr_inline(inode, &d, inline_dentry);
        f2fs_do_make_empty_dir(inode, parent, &d);
 
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 
        /* update i_size to MAX_INLINE_DATA */
        if (i_size_read(inode) < MAX_INLINE_DATA(inode))
@@ -410,8 +412,9 @@ int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
  * NOTE: ipage is grabbed by caller, but if any error occurs, we should
  * release ipage in this function.
  */
-static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
-                                                       void *inline_dentry)
+static int f2fs_move_inline_dirents(struct inode *dir,
+                       struct f2fs_cached_block *ientry,
+                       void *inline_dentry)
 {
        struct folio *folio;
        struct dnode_of_data dn;
@@ -421,11 +424,11 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
 
        folio = f2fs_grab_cache_folio(dir->i_mapping, 0, true);
        if (IS_ERR(folio)) {
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return PTR_ERR(folio);
        }
 
-       set_new_dnode(&dn, dir, ifolio, NULL, 0);
+       set_new_dnode(&dn, dir, ientry, NULL, 0);
        err = f2fs_reserve_block(&dn, 0);
        if (err)
                goto out;
@@ -441,7 +444,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
                goto out;
        }
 
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
 
        dentry_blk = folio_address(folio);
 
@@ -464,7 +467,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
        folio_mark_dirty(folio);
 
        /* clear inline dir and flag after data writeback */
-       f2fs_truncate_inline_inode(dir, ifolio, 0);
+       f2fs_truncate_inline_inode(dir, ientry, 0);
 
        stat_dec_inline_dir(dir);
        clear_inode_flag(dir, FI_INLINE_DENTRY);
@@ -544,8 +547,8 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
        return err;
 }
 
-static int f2fs_move_rehashed_dirents(struct inode *dir, struct folio *ifolio,
-                                                       void *inline_dentry)
+static int f2fs_move_rehashed_dirents(struct inode *dir,
+               struct f2fs_cached_block *ientry, void *inline_dentry)
 {
        void *backup_dentry;
        int err;
@@ -553,20 +556,20 @@ static int f2fs_move_rehashed_dirents(struct inode *dir, struct folio *ifolio,
        backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
                                MAX_INLINE_DATA(dir), GFP_F2FS_ZERO);
        if (!backup_dentry) {
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return -ENOMEM;
        }
 
        memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir));
-       f2fs_truncate_inline_inode(dir, ifolio, 0);
+       f2fs_truncate_inline_inode(dir, ientry, 0);
 
-       folio_unlock(ifolio);
+       f2fs_unlock_cache(ientry);
 
        err = f2fs_add_inline_entries(dir, backup_dentry);
        if (err)
                goto recover;
 
-       folio_lock(ifolio);
+       f2fs_lock_cache(ientry);
 
        stat_dec_inline_dir(dir);
        clear_inode_flag(dir, FI_INLINE_DENTRY);
@@ -582,31 +585,31 @@ static int f2fs_move_rehashed_dirents(struct inode *dir, struct folio *ifolio,
        kfree(backup_dentry);
        return 0;
 recover:
-       folio_lock(ifolio);
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       f2fs_lock_cache(ientry);
+       f2fs_cache_wait_writeback(ientry);
        memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir));
        f2fs_i_depth_write(dir, 0);
        f2fs_i_size_write(dir, MAX_INLINE_DATA(dir));
-       folio_mark_dirty(ifolio);
-       f2fs_folio_put(ifolio, true);
+       f2fs_mark_cache_dirty(ientry);
+       f2fs_put_cache(ientry, true);
 
        kfree(backup_dentry);
        return err;
 }
 
-static int do_convert_inline_dir(struct inode *dir, struct folio *ifolio,
-                                                       void *inline_dentry)
+static int do_convert_inline_dir(struct inode *dir,
+               struct f2fs_cached_block *ientry, void *inline_dentry)
 {
        if (!F2FS_I(dir)->i_dir_level)
-               return f2fs_move_inline_dirents(dir, ifolio, inline_dentry);
+               return f2fs_move_inline_dirents(dir, ientry, inline_dentry);
        else
-               return f2fs_move_rehashed_dirents(dir, ifolio, inline_dentry);
+               return f2fs_move_rehashed_dirents(dir, ientry, inline_dentry);
 }
 
 int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        struct f2fs_filename fname;
        struct f2fs_lock_context lc;
        void *inline_dentry = NULL;
@@ -621,22 +624,22 @@ int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry)
        if (err)
                goto out;
 
-       ifolio = f2fs_get_inode_folio(sbi, dir->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, dir->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto out_fname;
        }
 
-       if (f2fs_has_enough_room(dir, ifolio, &fname)) {
-               f2fs_folio_put(ifolio, true);
+       if (f2fs_has_enough_room(dir, ientry, &fname)) {
+               f2fs_put_cache(ientry, true);
                goto out_fname;
        }
 
-       inline_dentry = inline_data_addr(dir, ifolio);
+       inline_dentry = inline_data_addr(dir, ientry);
 
-       err = do_convert_inline_dir(dir, ifolio, inline_dentry);
+       err = do_convert_inline_dir(dir, ientry, inline_dentry);
        if (!err)
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
 out_fname:
        f2fs_free_filename(&fname);
 out:
@@ -648,24 +651,24 @@ int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
                          struct inode *inode, nid_t ino, umode_t mode)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        unsigned int bit_pos;
        void *inline_dentry = NULL;
        struct f2fs_dentry_ptr d;
        int slots = GET_DENTRY_SLOTS(fname->disk_name.len);
-       struct folio *folio = NULL;
+       struct f2fs_cached_block *nentry = NULL;
        int err = 0;
 
-       ifolio = f2fs_get_inode_folio(sbi, dir->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, dir->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
-       inline_dentry = inline_data_addr(dir, ifolio);
+       inline_dentry = inline_data_addr(dir, ientry);
        make_dentry_ptr_inline(dir, &d, inline_dentry);
 
        bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
        if (bit_pos >= d.max) {
-               err = do_convert_inline_dir(dir, ifolio, inline_dentry);
+               err = do_convert_inline_dir(dir, ientry, inline_dentry);
                if (err)
                        return err;
                err = -EAGAIN;
@@ -675,19 +678,19 @@ int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
        if (inode) {
                f2fs_down_write_nested(&F2FS_I(inode)->i_sem,
                                                SINGLE_DEPTH_NESTING);
-               folio = f2fs_init_inode_metadata(inode, dir, fname, ifolio);
-               if (IS_ERR(folio)) {
-                       err = PTR_ERR(folio);
+               nentry = f2fs_init_inode_metadata(inode, dir, fname, ientry);
+               if (IS_ERR(nentry)) {
+                       err = PTR_ERR(nentry);
                        goto fail;
                }
        }
 
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       f2fs_cache_wait_writeback(ientry);
 
        f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash,
                           bit_pos);
 
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 
        /* we don't need to mark_inode_dirty now */
        if (inode) {
@@ -695,9 +698,9 @@ int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
 
                /* synchronize inode page's data from inode cache */
                if (is_inode_flag_set(inode, FI_NEW_INODE))
-                       f2fs_update_inode(inode, folio);
+                       f2fs_update_inode(inode, nentry);
 
-               f2fs_folio_put(folio, true);
+               f2fs_put_cache(nentry, true);
        }
 
        f2fs_update_parent_metadata(dir, inode, 0);
@@ -705,12 +708,12 @@ int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
        if (inode)
                f2fs_up_write(&F2FS_I(inode)->i_sem);
 out:
-       f2fs_folio_put(ifolio, true);
+       f2fs_put_cache(ientry, true);
        return err;
 }
 
 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
-               struct folio *folio, struct inode *dir, struct inode *inode)
+               struct f2fs_cached_block *ientry, struct inode *dir, struct inode *inode)
 {
        struct f2fs_dentry_ptr d;
        void *inline_dentry;
@@ -718,18 +721,18 @@ void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
        unsigned int bit_pos;
        int i;
 
-       folio_lock(folio);
-       f2fs_folio_wait_writeback(folio, NODE, true, true);
+       f2fs_lock_cache(ientry);
+       f2fs_cache_wait_writeback(ientry);
 
-       inline_dentry = inline_data_addr(dir, folio);
+       inline_dentry = inline_data_addr(dir, ientry);
        make_dentry_ptr_inline(dir, &d, inline_dentry);
 
        bit_pos = dentry - d.dentry;
        for (i = 0; i < slots; i++)
                __clear_bit_le(bit_pos + i, d.bitmap);
 
-       folio_mark_dirty(folio);
-       f2fs_folio_put(folio, true);
+       f2fs_mark_cache_dirty(ientry);
+       f2fs_put_cache(ientry, true);
 
        inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
        f2fs_mark_inode_dirty_sync(dir, true);
@@ -741,21 +744,21 @@ void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
 bool f2fs_empty_inline_dir(struct inode *dir)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        unsigned int bit_pos = 2;
        void *inline_dentry;
        struct f2fs_dentry_ptr d;
 
-       ifolio = f2fs_get_inode_folio(sbi, dir->i_ino);
-       if (IS_ERR(ifolio))
+       ientry = f2fs_get_inode_cache(sbi, dir->i_ino);
+       if (IS_ERR(ientry))
                return false;
 
-       inline_dentry = inline_data_addr(dir, ifolio);
+       inline_dentry = inline_data_addr(dir, ientry);
        make_dentry_ptr_inline(dir, &d, inline_dentry);
 
        bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos);
 
-       f2fs_folio_put(ifolio, true);
+       f2fs_put_cache(ientry, true);
 
        if (bit_pos < d.max)
                return false;
@@ -767,7 +770,7 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
                                struct fscrypt_str *fstr)
 {
        struct inode *inode = file_inode(file);
-       struct folio *ifolio = NULL;
+       struct f2fs_cached_block *ientry = NULL;
        struct f2fs_dentry_ptr d;
        void *inline_dentry = NULL;
        int err;
@@ -777,17 +780,17 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
        if (ctx->pos == d.max)
                return 0;
 
-       ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
        /*
         * f2fs_readdir was protected by inode.i_rwsem, it is safe to access
         * ipage without page's lock held.
         */
-       folio_unlock(ifolio);
+       f2fs_unlock_cache(ientry);
 
-       inline_dentry = inline_data_addr(inode, ifolio);
+       inline_dentry = inline_data_addr(inode, ientry);
 
        make_dentry_ptr_inline(inode, &d, inline_dentry);
 
@@ -795,7 +798,7 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
        if (!err)
                ctx->pos = d.max;
 
-       f2fs_folio_put(ifolio, false);
+       f2fs_put_cache(ientry, false);
        return err < 0 ? err : 0;
 }
 
@@ -806,12 +809,12 @@ int f2fs_inline_data_fiemap(struct inode *inode,
        __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
                FIEMAP_EXTENT_LAST;
        struct node_info ni;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        int err = 0;
 
-       ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
        if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
                                !f2fs_has_inline_data(inode)) {
@@ -825,13 +828,13 @@ int f2fs_inline_data_fiemap(struct inode *inode,
        }
 
        if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC) {
-               err = f2fs_write_single_node_folio(ifolio, true, false, FS_NODE_IO);
+               err = f2fs_write_node_cache(ientry, true, false, FS_NODE_IO);
                if (err)
                        return err;
-               ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-               if (IS_ERR(ifolio))
-                       return PTR_ERR(ifolio);
-               f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+               ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+               if (IS_ERR(ientry))
+                       return PTR_ERR(ientry);
+               f2fs_cache_wait_writeback(ientry);
        }
        ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
        if (start >= ilen)
@@ -846,8 +849,8 @@ int f2fs_inline_data_fiemap(struct inode *inode,
 
        if (__is_valid_data_blkaddr(ni.blk_addr)) {
                byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
-               byteaddr += (char *)inline_data_addr(inode, ifolio) -
-                                               (char *)F2FS_INODE(ifolio);
+               byteaddr += (char *)inline_data_addr(inode, ientry) -
+                                               (char *)F2FS_INODE(ientry);
        } else {
                f2fs_bug_on(F2FS_I_SB(inode), ni.blk_addr != NEW_ADDR);
                flags |= FIEMAP_EXTENT_DELALLOC | FIEMAP_EXTENT_UNKNOWN;
@@ -855,6 +858,6 @@ int f2fs_inline_data_fiemap(struct inode *inode,
        err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
        trace_f2fs_fiemap(inode, start, byteaddr, ilen, flags, err);
 out:
-       f2fs_folio_put(ifolio, true);
+       f2fs_put_cache(ientry, true);
        return err;
 }
fs/f2fs/inode.c +78 -89
index f2e1d8b50f8c..c822ca2dce20 100644
@@ -82,9 +82,9 @@ void f2fs_set_inode_flags(struct inode *inode)
                        S_ENCRYPTED|S_VERITY|S_CASEFOLD);
 }
 
-static void __get_inode_rdev(struct inode *inode, struct folio *node_folio)
+static void __get_inode_rdev(struct inode *inode, struct f2fs_cached_block *ientry)
 {
-       __le32 *addr = get_dnode_addr(inode, node_folio);
+       __le32 *addr = get_dnode_addr(inode, ientry);
 
        if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
                        S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
@@ -95,9 +95,9 @@ static void __get_inode_rdev(struct inode *inode, struct folio *node_folio)
        }
 }
 
-static void __set_inode_rdev(struct inode *inode, struct folio *node_folio)
+static void __set_inode_rdev(struct inode *inode, struct f2fs_cached_block *ientry)
 {
-       __le32 *addr = get_dnode_addr(inode, node_folio);
+       __le32 *addr = get_dnode_addr(inode, ientry);
 
        if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
                if (old_valid_dev(inode->i_rdev)) {
@@ -111,34 +111,33 @@ static void __set_inode_rdev(struct inode *inode, struct folio *node_folio)
        }
 }
 
-static void __recover_inline_status(struct inode *inode, struct folio *ifolio)
+static void __recover_inline_status(struct inode *inode, struct f2fs_cached_block *ientry)
 {
-       void *inline_data = inline_data_addr(inode, ifolio);
+       void *inline_data = inline_data_addr(inode, ientry);
        __le32 *start = inline_data;
        __le32 *end = start + MAX_INLINE_DATA(inode) / sizeof(__le32);
 
        while (start < end) {
                if (*start++) {
-                       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+                       f2fs_cache_wait_writeback(ientry);
 
                        set_inode_flag(inode, FI_DATA_EXIST);
-                       set_raw_inline(inode, F2FS_INODE(ifolio));
-                       folio_mark_dirty(ifolio);
+                       set_raw_inline(inode, F2FS_INODE(ientry));
+                       f2fs_mark_cache_dirty(ientry);
                        return;
                }
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

fs/f2fs/namei.c +59 -55
index ff86ee07290d..38fcea8b72bf 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/node.c +446 -507
index 197ce2f5149a..1af118858fd1 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/node.h +56 -52
index e37fb0d63120..c8d66ca54e94 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/recovery.c +59 -58
index 93564e532f2f..54b5246609de 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/segment.c +35 -24
index 9d08e762b131..87e24d0306e8 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/segment.h +0 -20
index 3083069c9092..b11461acc520 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/shrinker.c +2 -1
index baa09bc63585..499717cd693c 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/super.c +12 -44
index fa19152cd4da..bf42fbffa348 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/xattr.c +61 -62
index 98059e583b09..4328c9d9de45 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/xattr.h +6 -6
index 75beab2d1ee3..870524b667ed 100644

Lines of this file are not shown. View the raw message.

include/linux/f2fs_fs.h +0 -2
index c325904f461e..ac87446cc086 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

2.49.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Part of the diff is not shown here. View the raw message.

maintainer
#14 lore raw

Re: [f2fs-dev] [PATCH v8 07/12] f2fs: cache: use node cache

Quoted 499 lines · Zhiguo Niu

Chao Yu via Linux-f2fs-devel <[email protected]>

Quoted 497 lines · 于2026年9月16日周三 09:57写道:

From: Chao Yu <[email protected]>

This patch migrates F2FS node block caching from the fake VFS inode page cache (sbi->node_inode) to node cache (sbi->node_blocks).

It updates node related helpers to use node cache APIs and reference to struct f2fs_cached_block, and removes sbi->node_inode, especially, unifies inline and regular dentry block handling via struct f2fs_dentry_block_ref.

---
 fs/f2fs/acl.c           |  26 +-
 fs/f2fs/acl.h           |   8 +-
 fs/f2fs/cache.c         |   7 +-
 fs/f2fs/cache.h         |   3 +-
 fs/f2fs/checkpoint.c    |  17 +-
 fs/f2fs/compress.c      |  18 +-
 fs/f2fs/data.c          | 249 +++++------
 fs/f2fs/debug.c         |  12 +-
 fs/f2fs/dir.c           | 170 +++----
 fs/f2fs/extent_cache.c  |  14 +-
 fs/f2fs/f2fs.h          | 259 ++++++-----
 fs/f2fs/file.c          |  78 ++--
 fs/f2fs/gc.c            |  50 +--
 fs/f2fs/inline.c        | 279 ++++++------
 fs/f2fs/inode.c         | 167 ++++---
 fs/f2fs/namei.c         | 114 ++---
 fs/f2fs/node.c          | 953 +++++++++++++++++++---------------------
 fs/f2fs/node.h          | 108 ++---
 fs/f2fs/recovery.c      | 117 ++---
 fs/f2fs/segment.c       |  59 ++-
 fs/f2fs/segment.h       |  20 -
 fs/f2fs/shrinker.c      |   3 +-
 fs/f2fs/super.c         |  56 +--
 fs/f2fs/xattr.c         | 123 +++---
 fs/f2fs/xattr.h         |  12 +-
 include/linux/f2fs_fs.h |   1 -
 26 files changed, 1420 insertions(+), 1503 deletions(-)
fs/f2fs/acl.c +13 -13
index d3253549173e..34c9aa279040 100644
@@ -181,7 +181,7 @@ static void *f2fs_acl_to_disk(struct f2fs_sb_info *sbi,
 }
 
 static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type,
-                                               struct folio *dfolio)
+                                               struct f2fs_cached_block *entry)
 {
        int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT;
        void *value = NULL;
@@ -191,13 +191,13 @@ static struct posix_acl *__f2fs_get_acl(struct inode *inode, int type,
        if (type == ACL_TYPE_ACCESS)
                name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
 
-       retval = f2fs_getxattr(inode, name_index, "", NULL, 0, dfolio);
+       retval = f2fs_getxattr(inode, name_index, "", NULL, 0, entry);
        if (retval > 0) {
                value = f2fs_kmalloc(F2FS_I_SB(inode), retval, GFP_F2FS_ZERO);
                if (!value)
                        return ERR_PTR(-ENOMEM);
                retval = f2fs_getxattr(inode, name_index, "", value,
-                                                       retval, dfolio);
+                                                       retval, entry);
        }
 
        if (retval > 0)
@@ -242,7 +242,7 @@ static int f2fs_acl_update_mode(struct mnt_idmap *idmap,
 
 static int __f2fs_set_acl(struct mnt_idmap *idmap,
                        struct inode *inode, int type,
-                       struct posix_acl *acl, struct folio *ifolio)
+                       struct posix_acl *acl, struct f2fs_cached_block *ientry)
 {
        int name_index;
        void *value = NULL;
@@ -253,7 +253,7 @@ static int __f2fs_set_acl(struct mnt_idmap *idmap,
        switch (type) {
        case ACL_TYPE_ACCESS:
                name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
-               if (acl && !ifolio) {
+               if (acl && !ientry) {
                        error = f2fs_acl_update_mode(idmap, inode, &mode, &acl);
                        if (error)
                                return error;
@@ -279,7 +279,7 @@ static int __f2fs_set_acl(struct mnt_idmap *idmap,
                }
        }
 
-       error = f2fs_setxattr(inode, name_index, "", value, size, ifolio, 0);
+       error = f2fs_setxattr(inode, name_index, "", value, size, ientry, 0);
 
        kfree(value);
        if (!error)
@@ -374,7 +374,7 @@ static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
 
 static int f2fs_acl_create(struct inode *dir, umode_t *mode,
                struct posix_acl **default_acl, struct posix_acl **acl,
-               struct folio *dfolio)
+               struct f2fs_cached_block *entry)
 {
        struct posix_acl *p;
        struct posix_acl *clone;
@@ -386,7 +386,7 @@ static int f2fs_acl_create(struct inode *dir, umode_t *mode,
        if (S_ISLNK(*mode) || !IS_POSIXACL(dir))
                return 0;
 
-       p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, dfolio);
+       p = __f2fs_get_acl(dir, ACL_TYPE_DEFAULT, entry);
        if (!p || p == ERR_PTR(-EOPNOTSUPP)) {
                *mode &= ~current_umask();
                return 0;
@@ -423,13 +423,13 @@ static int f2fs_acl_create(struct inode *dir, umode_t *mode,
        return ret;
 }
 
-int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
-                                                       struct folio *dfolio)
+int f2fs_init_acl(struct inode *inode, struct inode *dir, struct f2fs_cached_block *ientry,
+                                                       struct f2fs_cached_block *dentry)
 {
        struct posix_acl *default_acl = NULL, *acl = NULL;
        int error;
 
-       error = f2fs_acl_create(dir, &inode->i_mode, &default_acl, &acl, dfolio);
+       error = f2fs_acl_create(dir, &inode->i_mode, &default_acl, &acl, dentry);
        if (error)
                return error;
 
@@ -437,7 +437,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
 
        if (default_acl) {
                error = __f2fs_set_acl(NULL, inode, ACL_TYPE_DEFAULT,
-                               default_acl, ifolio);
+                               default_acl, ientry);
                posix_acl_release(default_acl);
        } else {
                inode->i_default_acl = NULL;
@@ -445,7 +445,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, struct folio *ifolio,
        if (acl) {
                if (!error)
                        error = __f2fs_set_acl(NULL, inode, ACL_TYPE_ACCESS,
-                                       acl, ifolio);
+                                       acl, ientry);
                posix_acl_release(acl);
        } else {
                inode->i_acl = NULL;
fs/f2fs/acl.h +5 -3
index 20e87e63c089..0f639367a0ab 100644
@@ -36,14 +36,16 @@ struct f2fs_acl_header {
 struct posix_acl *f2fs_get_acl(struct inode *, int, bool);
 int f2fs_set_acl(struct mnt_idmap *, struct dentry *,
                        struct posix_acl *, int);
-int f2fs_init_acl(struct inode *, struct inode *, struct folio *ifolio,
-               struct folio *dfolio);
+int f2fs_init_acl(struct inode *inode, struct inode *dir,
+                       struct f2fs_cached_block *ientry,
+                       struct f2fs_cached_block *dentry);
 #else
 #define f2fs_get_acl   NULL
 #define f2fs_set_acl   NULL
 
 static inline int f2fs_init_acl(struct inode *inode, struct inode *dir,
-                               struct folio *ifolio, struct folio *dfolio)
+                               struct f2fs_cached_block *ientry,
+                               struct f2fs_cached_block *dentry)
 {
        return 0;
 }
fs/f2fs/cache.c +4 -3
index 8ab5e0e46b4e..3abd469dc011 100644
@@ -28,7 +28,7 @@ void f2fs_cache_wait_writeback_cond(struct f2fs_cached_block *entry,
                return;
 
        /* submit cached bio */
-       f2fs_submit_merged_write_cache(entry, type);
+       f2fs_submit_merged_write_cache(entry->cache->sbi, entry, 0, type);
 
        wait_on_bit_io(&entry->state, F2FS_BLOCK_WRITEBACK,
                                        TASK_UNINTERRUPTIBLE);
@@ -65,8 +65,8 @@ bool f2fs_mark_cache_dirty(struct f2fs_cached_block *entry)
        f2fs_cache_set_uptodate(entry);
 
 #ifdef CONFIG_F2FS_CHECK_FS
-       if (cache->type == F2FS_NODE_CACHE && IS_INODE(cache->sbi, cache_folio(entry)))
-               f2fs_inode_chksum_set(cache->sbi, cache_folio(entry));
+       if (f2fs_is_node_cache(entry) && IS_INODE(cache->sbi, entry))
+               f2fs_inode_chksum_set(cache->sbi, entry);
 #endif
 
        if (!f2fs_cache_test_and_set_dirty(entry)) {
@@ -665,6 +665,7 @@ static int f2fs_cache_writeback_kthread(void *data)
                        continue;
 
                f2fs_write_meta_caches(sbi);
+               f2fs_write_node_caches(sbi);
 
                sb_end_write(sbi->sb);
        }
fs/f2fs/cache.h +2 -1
index 1eabd787b4b7..a36ee57adb1a 100644
@@ -48,6 +48,7 @@ struct f2fs_cached_block_list {
 };
 
 #define IS_META_CACHE(cache) ((cache)->type == F2FS_META_CACHE)
+#define IS_NODE_CACHE(cache) ((cache)->type == F2FS_NODE_CACHE)
 
 /* Flags for f2fs_cached_block state */
 enum f2fs_cached_state {
@@ -207,7 +208,7 @@ void f2fs_drop_cache_range(struct f2fs_cached_block_list *cache,
        f2fs_grab_cache(NODE_CACHE(sbi), blkaddr,       \
        F2FS_CACHE_LOCK_CREATE)
 #define f2fs_find_node_cache(sbi, blkaddr)             \
-       f2fs_find_cache(NODE_CACHE(sbi), blkaddr)
+       f2fs_find_cache(NODE_CACHE(sbi), blkaddr, F2FS_CACHE_ACCESS)
 #define f2fs_invalidate_node_cache(sbi, blkaddr)       \
        f2fs_drop_cache_range(NODE_CACHE(sbi), blkaddr, 1, false)
 #define f2fs_truncate_node_caches(sbi, start, len)     \
fs/f2fs/checkpoint.c +7 -10
index 8e524d9860a2..fe7e8bab644b 100644
@@ -927,7 +927,7 @@ void f2fs_add_orphan_inode(struct inode *inode)
 {
        /* add new orphan ino entry into list */
        f2fs_add_ino_entry(F2FS_I_SB(inode), inode->i_ino, ORPHAN_INO);
-       f2fs_update_inode_page(inode);
+       f2fs_update_inode_cache(inode);
 }
 
 void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
@@ -1428,7 +1428,7 @@ static int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
 
                        /* it's on eviction */
                        if (is_inode_flag_set(inode, FI_DIRTY_INODE))
-                               f2fs_update_inode_page(inode);
+                               f2fs_update_inode_cache(inode);
                        iput(inode);
                } else {
                        cond_resched();
@@ -1483,14 +1483,10 @@ static bool __need_flush_quota(struct f2fs_sb_info *sbi)
  */
 static int block_operations(struct f2fs_sb_info *sbi)
 {
-       struct writeback_control wbc = {
-               .sync_mode = WB_SYNC_ALL,
-               .nr_to_write = LONG_MAX,
-       };
        int err = 0, cnt = 0;
 
        /*
-        * Let's flush inline_data in dirty node pages.
+        * Let's flush inline_data in dirty node caches.
         */
        f2fs_flush_inline_data(sbi);
 
@@ -1529,7 +1525,7 @@ static int block_operations(struct f2fs_sb_info *sbi)
        }
 
        /*
-        * POR: we should ensure that there are no dirty node pages
+        * POR: we should ensure that there are no dirty node caches
         * until finishing nat/sit flush. inode->i_blocks can be updated.
         */
        f2fs_down_write(&sbi->node_change);
@@ -1550,7 +1546,8 @@ static int block_operations(struct f2fs_sb_info *sbi)
        if (get_pages(sbi, F2FS_DIRTY_NODES)) {
                f2fs_up_write(&sbi->node_write);
                atomic_inc(&sbi->wb_sync_req[NODE]);
-               err = f2fs_sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO);
+               err = f2fs_writeback_node_caches(sbi, LONG_MAX,
+                       true, false, FS_CP_NODE_IO);
                atomic_dec(&sbi->wb_sync_req[NODE]);
                if (err) {
                        f2fs_up_write(&sbi->node_change);
@@ -1900,7 +1897,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        __set_cp_next_pack(sbi);
 
        /*
-        * redirty superblock if metadata like node page or inode cache is
+        * redirty superblock if metadata like node caches or inode cache is
         * updated during writing checkpoint.
         */
        if (get_pages(sbi, F2FS_DIRTY_NODES) ||
fs/f2fs/compress.c +9 -9
index f85bbadde53f..d7f7c35e710f 100644
@@ -909,7 +909,7 @@ bool f2fs_sanity_check_cluster(struct dnode_of_data *dn)
        }
 
        for (i = 1, count = 1; i < cluster_size; i++, count++) {
-               block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                        dn->ofs_in_node + i);
 
                /* [COMPR_ADDR, ..., COMPR_ADDR] */
@@ -950,7 +950,7 @@ static int __f2fs_get_cluster_blocks(struct inode *inode,
        int count, i;
 
        for (i = 0, count = 0; i < cluster_size; i++) {
-               block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                        dn->ofs_in_node + i);
 
                if (__is_valid_data_blkaddr(blkaddr))
@@ -1146,7 +1146,7 @@ static int prepare_compress_overwrite(struct compress_ctx *cc,
                        goto release_and_retry;
                }
 
-               f2fs_folio_wait_writeback(folio, DATA, true, true);
+               f2fs_folio_wait_writeback(folio, true, true);
                f2fs_compress_ctx_add_page(cc, folio);
 
                if (!folio_test_uptodate(folio)) {
@@ -1322,7 +1322,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
                goto out_unlock_op;
 
        for (i = 0; i < cc->cluster_size; i++) {
-               if (data_blkaddr(dn.inode, dn.node_folio,
+               if (data_blkaddr(dn.inode, dn.node_entry,
                                        dn.ofs_in_node + i) == NULL_ADDR)
                        goto out_put_dnode;
        }
@@ -1354,7 +1354,7 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
                                page_folio(cc->rpages[i + 1])->index, cic);
                fio.compressed_page = cc->cpages[i];
 
-               fio.old_blkaddr = data_blkaddr(dn.inode, dn.node_folio,
+               fio.old_blkaddr = data_blkaddr(dn.inode, dn.node_entry,
                                                dn.ofs_in_node + i + 1);
 
                /* wait for GCed page writeback via generic cache */
@@ -1542,7 +1542,7 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
                if (folio_test_writeback(folio)) {
                        if (wbc->sync_mode == WB_SYNC_NONE)
                                goto continue_unlock;
-                       f2fs_folio_wait_writeback(folio, DATA, true, true);
+                       f2fs_folio_wait_writeback(folio, true, true);
                }
 
                if (!folio_clear_dirty_for_io(folio))
@@ -1874,14 +1874,14 @@ void f2fs_put_folio_dic(struct folio *folio, bool in_task)
 unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn,
                                                unsigned int ofs_in_node)
 {
-       bool compressed = data_blkaddr(dn->inode, dn->node_folio,
+       bool compressed = data_blkaddr(dn->inode, dn->node_entry,
                                        ofs_in_node) == COMPRESS_ADDR;
        int i = compressed ? 1 : 0;
-       block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+       block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                        ofs_in_node + i);
 
        for (i += 1; i < F2FS_I(dn->inode)->i_cluster_size; i++) {
-               block_t blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               block_t blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                        ofs_in_node + i);
 
                if (!__is_valid_data_blkaddr(blkaddr))
fs/f2fs/data.c +19 -39
index 674d1b8e33d8..9a1d31df5f4f 100644
@@ -58,13 +58,10 @@ bool f2fs_is_cp_guaranteed(const struct folio *folio)
 {
        struct address_space *mapping = folio->mapping;
        struct inode *inode;
-       struct f2fs_sb_info *sbi;
 
        inode = mapping->host;
-       sbi = F2FS_I_SB(inode);
 
-       if (inode->i_ino == F2FS_NODE_INO(sbi) ||
-                       S_ISDIR(inode->i_mode))
+       if (S_ISDIR(inode->i_mode))
                return true;
 
        if ((S_ISREG(inode->i_mode) && IS_NOQUOTA(inode)) ||
@@ -73,20 +70,6 @@ bool f2fs_is_cp_guaranteed(const struct folio *folio)
        return false;
 }
 
-static enum count_type __read_io_type(struct folio *folio)
-{
-       struct address_space *mapping = folio->mapping;
-
-       if (mapping) {
-               struct inode *inode = mapping->host;
-               struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-
-               if (inode->i_ino == F2FS_NODE_INO(sbi))
-                       return F2FS_RD_NODE;
-       }
-       return F2FS_RD_DATA;
-}
-
 /* postprocessing steps for read bios */
 enum bio_post_read_step {
 #ifdef CONFIG_F2FS_FS_COMPRESSION
@@ -160,14 +143,7 @@ static void f2fs_finish_read_bio(struct bio *bio, bool in_task)
                }
 
                while (nr_pages--)
-                       dec_page_count(F2FS_F_SB(folio), __read_io_type(folio));
-
-               if (bio->bi_status == BLK_STS_OK &&
-                       F2FS_F_SB(folio)->node_inode &&
-                       is_node_folio(F2FS_F_SB(folio), folio) &&
-                       f2fs_sanity_check_node_footer(F2FS_F_SB(folio),
-                               folio, folio->index, NODE_TYPE_REGULAR, true))
-                       bio->bi_status = BLK_STS_IOERR;
+                       dec_page_count(F2FS_F_SB(folio), F2FS_RD_DATA);
 
                if (finished)
                        folio_end_read(folio, bio->bi_status == BLK_STS_OK);
@@ -351,14 +327,6 @@ static void f2fs_write_end_bio(struct bio *bio)
                        }
                }
 
-               if (is_node_folio(sbi, folio)) {
-                       f2fs_sanity_check_node_footer(sbi, folio,
-                               folio->index, NODE_TYPE_REGULAR, true);
-                       f2fs_bug_on(sbi, folio->index != nid_of_node(sbi, folio));
-               }
-               if (f2fs_in_warm_node_list(sbi, folio))
-                       f2fs_del_fsync_node_entry(sbi, folio);
-
                dec_page_count(sbi, type);
 
                /*
@@ -419,6 +387,12 @@ static void f2fs_cache_read_end_io(struct bio *bio)
                next = entry->next_entry;
                entry->next_entry = NULL;
 
+               if (bio->bi_status == BLK_STS_OK &&
+                       f2fs_is_node_cache(entry) &&
+                       f2fs_sanity_check_node_footer(sbi, entry,
+                               entry->index, NODE_TYPE_REGULAR, true))
+                       bio->bi_status = BLK_STS_IOERR;
+
                if (bio->bi_status == BLK_STS_OK)
                        f2fs_cache_set_uptodate(entry);
 
@@ -449,6 +423,14 @@ static void f2fs_cache_write_end_io(struct bio *bio)
                next = entry->next_entry;
                entry->next_entry = NULL;
 
+               if (f2fs_is_node_cache(entry)) {
+                       f2fs_sanity_check_node_footer(sbi, entry,
+                               entry->index, NODE_TYPE_REGULAR, true);
+                       f2fs_bug_on(sbi, entry->index != nid_of_node(sbi, entry));
+               }
+               if (f2fs_in_warm_node_list(sbi, entry))
+                       f2fs_del_fsync_node_entry(sbi, entry);
+
                dec_page_count(sbi, F2FS_WB_CP_DATA);
 
                if (!get_pages(sbi, F2FS_WB_CP_DATA) &&
@@ -655,15 +637,15 @@ static void __submit_merged_bio(struct f2fs_bio_info *io)
        io->bio = NULL;
 }
 
-static bool __has_merged_page(struct f2fs_sb_info *sbi, struct bio *bio,
-                       struct inode *inode, struct folio *folio, nid_t ino)
+static bool __has_merged_page(struct bio *bio, struct inode *inode,
+                                               struct folio *folio)
 {
        struct folio_iter fi;
 
        if (!bio)
                return false;
 
-       if (!inode && !folio && !ino)
+       if (!inode && !folio)
                return true;
 
        if (f2fs_is_cache_bio(bio))
@@ -682,8 +664,6 @@ static bool __has_merged_page(struct f2fs_sb_info *sbi, struct bio *bio,
                        return true;
                if (folio && folio == target)
                        return true;
-               if (ino && ino == ino_of_node(sbi, target))
-                       return true;
        }
 
        return false;
@@ -752,24 +732,23 @@ static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi,
 
Quoted 7 lines

fs/f2fs/data.c static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi, · line 735

Quoted 4 lines
fs/f2fs/data.c +1 -1
 static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
                                struct inode *inode, struct folio *folio,
-                               nid_t ino, enum page_type type, bool writeback)
+                               bool writeback)

Hi Chao,
seems this function just only handle DATA type now, so can we rename it xxx_data_xxx for easy reading?

Can we get v9? :)

Quoted 6,726 lines

others LGTM.

thanks!

Quoted 6,713 lines
fs/f2fs/data.c +97 -92
 {
        enum temp_type temp;
        bool ret = true;
-       bool force = !inode && !folio && !ino;
+       bool force = !inode && !folio;
 
        for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
-               if (!force)     {
-                       enum page_type btype = PAGE_TYPE_OF_BIO(type);
-                       struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
+               if (!force) {
+                       struct f2fs_bio_info *io = sbi->write_io[DATA] + temp;
                        struct f2fs_lock_context lc;
 
                        f2fs_down_read_trace(&io->io_rwsem, &lc);
-                       ret = __has_merged_page(io->sbi, io->bio, inode, folio, ino);
+                       ret = __has_merged_page(io->bio, inode, folio);
                        f2fs_up_read_trace(&io->io_rwsem, &lc);
                }
                if (ret) {
-                       __f2fs_submit_merged_write(sbi, type, temp);
+                       __f2fs_submit_merged_write(sbi, DATA, temp);
                        /*
                         * For waitting writebck case, if the bio owned by the
                         * folio is already submitted, we do not need to submit
@@ -778,33 +757,23 @@ static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
                        if (writeback)
                                break;
                }
-
-               /* TODO: use HOT temp only for meta pages now. */
-               if (type >= META)
-                       break;
        }
 }
 
-void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type)
-{
-       __submit_merged_write_cond(sbi, NULL, NULL, 0, type, false);
-}
-
 void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
-                               struct inode *inode, struct folio *folio,
-                               nid_t ino, enum page_type type)
+                               struct inode *inode, struct folio *folio)
 {
-       __submit_merged_write_cond(sbi, inode, folio, ino, type, false);
+       __submit_merged_write_cond(sbi, inode, folio, false);
 }
 
 void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
-                               struct folio *folio, enum page_type type)
+                               struct folio *folio)
 {
-       __submit_merged_write_cond(sbi, NULL, folio, 0, type, true);
+       __submit_merged_write_cond(sbi, NULL, folio, true);
 }
 
-static bool __has_merged_cache(struct bio *bio,
-               struct f2fs_cached_block *target)
+static bool __has_merged_cache(struct f2fs_sb_info *sbi, struct bio *bio,
+               struct f2fs_cached_block *target, nid_t ino)
 {
        struct f2fs_cached_block *entry;
 
@@ -816,27 +785,39 @@ static bool __has_merged_cache(struct bio *bio,
        while (entry) {
                if (target && entry == target)
                        return true;
+
+               if (ino) {
+                       if (likely(f2fs_is_node_cache(entry))) {
+                               if (ino_of_node(sbi, entry) == ino)
+                                       return true;
+                       } else {
+                               WARN_ON_ONCE(1);
+                       }
+               }
                entry = entry->next_entry;
        }
        return false;
 }
 
-bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
-                               enum page_type type)
+bool f2fs_submit_merged_write_cache(struct f2fs_sb_info *sbi,
+                               struct f2fs_cached_block *entry,
+                               nid_t ino, enum page_type type)
 {
-       struct f2fs_sb_info *sbi = entry->cache->sbi;
        enum temp_type temp;
        bool ret = false;
+       bool force = !entry && !ino;
 
        for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
                enum page_type btype = PAGE_TYPE_OF_BIO(type);
                struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
                struct f2fs_lock_context lc;
-               bool merged;
+               bool merged = true;
 
-               f2fs_down_read_trace(&io->io_rwsem, &lc);
-               merged = __has_merged_cache(io->bio, entry);
-               f2fs_up_read_trace(&io->io_rwsem, &lc);
+               if (!force) {
+                       f2fs_down_read_trace(&io->io_rwsem, &lc);
+                       merged = __has_merged_cache(sbi, io->bio, entry, ino);
+                       f2fs_up_read_trace(&io->io_rwsem, &lc);
+               }
 
                if (merged) {
                        __f2fs_submit_merged_write(sbi, type, temp);
@@ -850,6 +831,14 @@ bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
        return ret;
 }
 
+void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type)
+{
+       if (type == DATA)
+               __submit_merged_write_cond(sbi, NULL, NULL, false);
+       else
+               f2fs_submit_merged_write_cache(sbi, NULL, 0, type);
+}
+
 void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi)
 {
        f2fs_submit_merged_write(sbi, DATA);
@@ -886,7 +875,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
                wbc_account_cgroup_owner(fio->io_wbc, fio_folio, PAGE_SIZE);
 
        inc_page_count(fio->sbi, is_read_io(fio->op) ?
-                       __read_io_type(data_folio) : WB_DATA_TYPE(fio->folio, false));
+                       F2FS_RD_DATA : WB_DATA_TYPE(fio->folio, false));
 
        if (is_read_io(bio_op(bio)))
                f2fs_submit_read_bio(fio->sbi, bio, fio->type);
@@ -1022,8 +1011,8 @@ void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
                        if (target)
                                found = (target == be->bio);
                        else
-                               found = __has_merged_page(sbi, be->bio, NULL,
-                                                       folio, 0);
+                               found = __has_merged_page(be->bio,
+                                                       NULL, folio);
                        if (found)
                                break;
                }
@@ -1039,8 +1028,8 @@ void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
                        if (target)
                                found = (target == be->bio);
                        else
-                               found = __has_merged_page(sbi, be->bio, NULL,
-                                                       folio, 0);
+                               found = __has_merged_page(be->bio,
+                                                       NULL, folio);
                        if (found) {
                                target = be->bio;
                                del_bio_entry(be);
@@ -1427,7 +1416,7 @@ static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi,
 
 static void __set_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
 {
-       __le32 *addr = get_dnode_addr(dn->inode, dn->node_folio);
+       __le32 *addr = get_dnode_addr(dn->inode, dn->node_entry);
 
        dn->data_blkaddr = blkaddr;
        addr[dn->ofs_in_node] = cpu_to_le32(dn->data_blkaddr);
@@ -1441,9 +1430,9 @@ static void __set_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
  */
 void f2fs_set_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
 {
-       f2fs_folio_wait_writeback(dn->node_folio, NODE, true, true);
+       f2fs_cache_wait_writeback(dn->node_entry);
        __set_data_blkaddr(dn, blkaddr);
-       if (folio_mark_dirty(dn->node_folio))
+       if (f2fs_mark_cache_dirty(dn->node_entry))
                dn->node_changed = true;
 }
 
@@ -1471,7 +1460,7 @@ int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)
        trace_f2fs_reserve_new_blocks(dn->inode, dn->nid,
                                                dn->ofs_in_node, count);
 
-       f2fs_folio_wait_writeback(dn->node_folio, NODE, true, true);
+       f2fs_cache_wait_writeback(dn->node_entry);
 
        for (; count > 0; dn->ofs_in_node++) {
                block_t blkaddr = f2fs_data_blkaddr(dn);
@@ -1482,7 +1471,7 @@ int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)
                }
        }
 
-       if (folio_mark_dirty(dn->node_folio))
+       if (f2fs_mark_cache_dirty(dn->node_entry))
                dn->node_changed = true;
        return 0;
 }
@@ -1500,7 +1489,7 @@ int f2fs_reserve_new_block(struct dnode_of_data *dn)
 
 int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)
 {
-       bool need_put = dn->inode_folio ? false : true;
+       bool need_put = dn->inode_entry ? false : true;
        int err;
 
        err = f2fs_get_dnode_of_data(dn, index, ALLOC_NODE);
@@ -1666,11 +1655,11 @@ struct folio *f2fs_get_lock_data_folio(struct inode *inode, pgoff_t index,
  *
  * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and
  * f2fs_unlock_op().
- * Note that, ifolio is set only by make_empty_dir, and if any error occur,
- * ifolio should be released by this function.
+ * Note that, ientry is set only by make_empty_dir, and if any error occur,
+ * ientry should be released by this function.
  */
 struct folio *f2fs_get_new_data_folio(struct inode *inode,
-               struct folio *ifolio, pgoff_t index, bool new_i_size)
+               struct f2fs_cached_block *ientry, pgoff_t index, bool new_i_size)
 {
        struct address_space *mapping = inode->i_mapping;
        struct folio *folio;
@@ -1680,20 +1669,20 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
        folio = f2fs_grab_cache_folio(mapping, index, true);
        if (IS_ERR(folio)) {
                /*
-                * before exiting, we should make sure ifolio will be released
+                * before exiting, we should make sure ientry will be released
                 * if any error occur.
                 */
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return ERR_PTR(-ENOMEM);
        }
 
-       set_new_dnode(&dn, inode, ifolio, NULL, 0);
+       set_new_dnode(&dn, inode, ientry, NULL, 0);
        err = f2fs_reserve_block(&dn, index);
        if (err) {
                f2fs_folio_put(folio, true);
                return ERR_PTR(err);
        }
-       if (!ifolio)
+       if (!ientry)
                f2fs_put_dnode(&dn);
 
        if (folio_test_uptodate(folio))
@@ -1706,8 +1695,8 @@ struct folio *f2fs_get_new_data_folio(struct inode *inode,
        } else {
                f2fs_folio_put(folio, true);
 
-               /* if ifolio exists, blkaddr should be NEW_ADDR */
-               f2fs_bug_on(F2FS_I_SB(inode), ifolio);
+               /* if ientry exists, blkaddr should be NEW_ADDR */
+               f2fs_bug_on(F2FS_I_SB(inode), ientry);
                folio = f2fs_get_lock_data_folio(inode, index, true);
                if (IS_ERR(folio))
                        return folio;
@@ -1744,7 +1733,7 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type)
 
        set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
        old_blkaddr = dn->data_blkaddr;
-       err = f2fs_allocate_data_block(sbi, NULL, old_blkaddr,
+       err = f2fs_allocate_data_block(sbi, old_blkaddr,
                                &dn->data_blkaddr, &sum, seg_type, NULL);
        if (err) {
                if (old_blkaddr == NULL_ADDR)
@@ -1956,7 +1945,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
        start_pgofs = pgofs;
        prealloc = 0;
        last_ofs_in_node = ofs_in_node = dn.ofs_in_node;
-       end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+       end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
 
 next_block:
        blkaddr = f2fs_data_blkaddr(&dn);
@@ -2207,15 +2196,15 @@ static int f2fs_xattr_fiemap(struct inode *inode,
 
        if (f2fs_has_inline_xattr(inode)) {
                int offset;
-               struct folio *folio = f2fs_grab_cache_folio(NODE_MAPPING(sbi),
-                               inode->i_ino, false);
+               struct f2fs_cached_block *entry =
+                               f2fs_grab_node_cache(sbi, inode->i_ino);
 
-               if (IS_ERR(folio))
-                       return PTR_ERR(folio);
+               if (IS_ERR(entry))
+                       return PTR_ERR(entry);
 
                err = f2fs_get_node_info(sbi, inode->i_ino, &ni, false);
                if (err) {
-                       f2fs_folio_put(folio, true);
+                       f2fs_put_cache(entry, true);
                        return err;
                }
 
@@ -2227,7 +2216,7 @@ static int f2fs_xattr_fiemap(struct inode *inode,
                phys += offset;
                len = inline_xattr_size(inode);
 
-               f2fs_folio_put(folio, true);
+               f2fs_put_cache(entry, true);
 
                flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED;
 
@@ -2241,22 +2230,22 @@ static int f2fs_xattr_fiemap(struct inode *inode,
        }
 
        if (xnid) {
-               struct folio *folio = f2fs_grab_cache_folio(NODE_MAPPING(sbi),
-                               xnid, false);
+               struct f2fs_cached_block *entry =
+                               f2fs_grab_node_cache(sbi, xnid);
 
-               if (IS_ERR(folio))
-                       return PTR_ERR(folio);
+               if (IS_ERR(entry))
+                       return PTR_ERR(entry);
 
                err = f2fs_get_node_info(sbi, xnid, &ni, false);
                if (err) {
-                       f2fs_folio_put(folio, true);
+                       f2fs_put_cache(entry, true);
                        return err;
                }
 
                phys = F2FS_BLK_TO_BYTES(sbi, ni.blk_addr);
                len = inode->i_sb->s_blocksize;
 
-               f2fs_folio_put(folio, true);
+               f2fs_put_cache(entry, true);
 
                flags = FIEMAP_EXTENT_LAST;
        }
@@ -2619,7 +2608,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
        for (i = 1; i < cc->cluster_size; i++) {
                block_t blkaddr;
 
-               blkaddr = from_dnode ? data_blkaddr(dn.inode, dn.node_folio,
+               blkaddr = from_dnode ? data_blkaddr(dn.inode, dn.node_entry,
                                        dn.ofs_in_node + i) :
                                        ei.blk + i - 1;
 
@@ -2653,7 +2642,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
                block_t blkaddr;
                struct bio_post_read_ctx *ctx;
 
-               blkaddr = from_dnode ? data_blkaddr(dn.inode, dn.node_folio,
+               blkaddr = from_dnode ? data_blkaddr(dn.inode, dn.node_entry,
                                        dn.ofs_in_node + i + 1) :
                                        ei.blk + i;
 
@@ -3646,7 +3635,7 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
                        if (folio_test_writeback(folio)) {
                                if (wbc->sync_mode == WB_SYNC_NONE)
                                        goto continue_unlock;
-                               f2fs_folio_wait_writeback(folio, DATA, true, true);
+                               f2fs_folio_wait_writeback(folio, true, true);
                        }
 
                        if (!folio_clear_dirty_for_io(folio))
@@ -3728,8 +3717,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
                mapping->writeback_index = done_index;
 
        if (nwritten)
-               f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host,
-                                                               NULL, 0, DATA);
+               f2fs_submit_merged_write_cond(F2FS_M_SB(mapping),
+                                       mapping->host, NULL);
        /* submit cached bio of IPU write */
        if (bio)
                f2fs_submit_merged_ipu_write(sbi, &bio, NULL);
@@ -3907,7 +3896,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
        pgoff_t index = folio->index;
        struct dnode_of_data dn;
        struct f2fs_lock_context lc;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        bool locked = false;
        int flag = F2FS_GET_BLOCK_PRE_AIO;
        int err = 0;
@@ -3938,20 +3927,20 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,
 
 restart:
        /* check inline_data */
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto unlock_out;
        }
 
-       set_new_dnode(&dn, inode, ifolio, ifolio, 0);
+       set_new_dnode(&dn, inode, ientry, ientry, 0);
 
        if (f2fs_has_inline_data(inode)) {
                if (pos + len <= MAX_INLINE_DATA(inode)) {
-                       f2fs_do_read_inline_data(folio, ifolio);
+                       f2fs_do_read_inline_data(folio, ientry);
                        set_inode_flag(inode, FI_DATA_EXIST);
                        if (inode->i_nlink)
-                               folio_set_f2fs_inline(ifolio);
+                               f2fs_cache_set_inline(ientry);
                        goto out;
                }
                err = f2fs_convert_inline_folio(&dn, folio);
@@ -3998,14 +3987,14 @@ static int __find_data_block(struct inode *inode, pgoff_t index,
                                block_t *blk_addr)
 {
        struct dnode_of_data dn;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        int err = 0;
 
-       ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
-       set_new_dnode(&dn, inode, ifolio, ifolio, 0);
+       set_new_dnode(&dn, inode, ientry, ientry, 0);
 
        if (!f2fs_lookup_read_extent_cache_block(inode, index,
                                                 &dn.data_blkaddr)) {
@@ -4027,17 +4016,17 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct dnode_of_data dn;
        struct f2fs_lock_context lc;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        int err = 0;
 
        f2fs_map_lock(sbi, &lc, F2FS_GET_BLOCK_PRE_AIO);
 
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto unlock_out;
        }
-       set_new_dnode(&dn, inode, ifolio, ifolio, 0);
+       set_new_dnode(&dn, inode, ientry, ientry, 0);
 
        if (!f2fs_lookup_read_extent_cache_block(dn.inode, index,
                                                &dn.data_blkaddr))
@@ -4193,7 +4182,7 @@ static int f2fs_write_begin(const struct kiocb *iocb,
                }
        }
 
-       f2fs_folio_wait_writeback(folio, DATA, false, true);
+       f2fs_folio_wait_writeback(folio, false, true);
 
        if (len == folio_size(folio) || folio_test_uptodate(folio))
                return 0;
@@ -4310,12 +4299,8 @@ void f2fs_invalidate_folio(struct folio *folio, size_t offset, size_t length)
                return;
 
        if (folio_test_dirty(folio)) {
-               if (inode->i_ino == F2FS_NODE_INO(sbi)) {
-                       dec_page_count(sbi, F2FS_DIRTY_NODES);
-               } else {
-                       inode_dec_dirty_pages(inode);
-                       f2fs_remove_dirty_inode(inode);
-               }
+               inode_dec_dirty_pages(inode);
+               f2fs_remove_dirty_inode(inode);
        }
 
        if (offset || length != folio_size(folio))
fs/f2fs/debug.c +4 -8
index 24819d4c0d55..c09c5f700c89 100644
@@ -222,8 +222,7 @@ static void update_general_status(struct f2fs_sb_info *sbi)
        si->free_secs = free_sections(sbi);
        si->prefree_count = prefree_segments(sbi);
        si->dirty_count = dirty_segments(sbi);
-       if (sbi->node_inode)
-               si->node_pages = NODE_MAPPING(sbi)->nrpages;
+       si->node_caches = NODE_CACHE(sbi)->num_entries;
        si->meta_caches = META_CACHE(sbi)->num_entries;
 #ifdef CONFIG_F2FS_FS_COMPRESSION
        if (sbi->compress_inode) {
@@ -382,13 +381,10 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
        }
 
        si->page_mem = 0;
-       if (sbi->node_inode) {
-               unsigned long npages = NODE_MAPPING(sbi)->nrpages;
-
-               si->page_mem += (unsigned long long)npages << PAGE_SHIFT;
-       }
        si->page_mem += (unsigned long long)META_CACHE(sbi)->num_entries << PAGE_SHIFT;
        si->cache_mem += META_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
+       si->page_mem += (unsigned long long)NODE_CACHE(sbi)->num_entries << PAGE_SHIFT;
+       si->cache_mem += NODE_CACHE(sbi)->num_entries * sizeof(struct f2fs_cached_block);
 #ifdef CONFIG_F2FS_FS_COMPRESSION
        if (sbi->compress_inode) {
                unsigned long npages = COMPRESS_MAPPING(sbi)->nrpages;
@@ -696,7 +692,7 @@ static int stat_show(struct seq_file *s, void *v)
                           si->aw_cnt, si->max_aw_cnt);
                seq_printf(s, "  - compress: %4d, hit:%8d\n", si->compress_pages, si->compress_page_hit);
                seq_printf(s, "  - nodes: %4d in %4d\n",
-                          si->ndirty_node, si->node_pages);
+                          si->ndirty_node, si->node_caches);
                seq_printf(s, "  - dents: %4d in dirs:%4d (%4d)\n",
                           si->ndirty_dent, si->ndirty_dirs, si->ndirty_all);
                seq_printf(s, "  - data: %4d in files:%4d\n",
fs/f2fs/dir.c +93 -77
index 75ff36a13f60..97f7fef6b068 100644
@@ -282,7 +282,7 @@ struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d,
 static struct f2fs_dir_entry *find_in_level(struct inode *dir,
                                        unsigned int level,
                                        const struct f2fs_filename *fname,
-                                       struct folio **res_folio,
+                                       void **dentry_block,
                                        bool use_hash)
 {
        int s = GET_DENTRY_SLOTS(fname->disk_name.len);
@@ -313,7 +313,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
                                bidx = next_pgofs;
                                continue;
                        } else {
-                               *res_folio = dentry_folio;
+                               *dentry_block = dentry_folio;
                                break;
                        }
                }
@@ -321,11 +321,11 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
                de = find_in_block(dir, dentry_folio, fname, &max_slots, use_hash);
                if (IS_ERR(de)) {
                        f2fs_folio_put(dentry_folio, false);
-                       *res_folio = ERR_CAST(de);
+                       *dentry_block = ERR_CAST(de);
                        de = NULL;
                        break;
                } else if (de) {
-                       *res_folio = dentry_folio;
+                       *dentry_block = dentry_folio;
                        break;
                }
 
@@ -352,7 +352,7 @@ static struct f2fs_dir_entry *find_in_level(struct inode *dir,
 
 struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
                                         const struct f2fs_filename *fname,
-                                        struct folio **res_folio)
+                                        void **dentry_block)
 {
        unsigned long npages = dir_blocks(dir);
        struct f2fs_dir_entry *de = NULL;
@@ -360,13 +360,13 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
        unsigned int level;
        bool use_hash = true;
 
-       *res_folio = NULL;
+       *dentry_block = NULL;
 
 #if IS_ENABLED(CONFIG_UNICODE)
 start_find_entry:
 #endif
        if (f2fs_has_inline_dentry(dir)) {
-               de = f2fs_find_in_inline_dir(dir, fname, res_folio, use_hash);
+               de = f2fs_find_in_inline_dir(dir, fname, dentry_block, use_hash);
                goto out;
        }
 
@@ -382,8 +382,8 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
        }
 
        for (level = 0; level < max_depth; level++) {
-               de = find_in_level(dir, level, fname, res_folio, use_hash);
-               if (de || IS_ERR(*res_folio))
+               de = find_in_level(dir, level, fname, dentry_block, use_hash);
+               if (de || IS_ERR(*dentry_block))
                        break;
        }
 
@@ -408,7 +408,7 @@ struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
  * Entry is guaranteed to be valid.
  */
 struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
-                       const struct qstr *child, struct folio **res_folio)
+                       const struct qstr *child, void **dentry_block)
 {
        struct f2fs_dir_entry *de = NULL;
        struct f2fs_filename fname;
@@ -417,67 +417,78 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
        err = f2fs_setup_filename(dir, child, 1, &fname);
        if (err) {
                if (err == -ENOENT)
-                       *res_folio = NULL;
+                       *dentry_block = NULL;
                else
-                       *res_folio = ERR_PTR(err);
+                       *dentry_block = ERR_PTR(err);
                return NULL;
        }
 
-       de = __f2fs_find_entry(dir, &fname, res_folio);
+       de = __f2fs_find_entry(dir, &fname, dentry_block);
 
        f2fs_free_filename(&fname);
        return de;
 }
 
-struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct folio **f)
+struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, void **dentry_block)
 {
-       return f2fs_find_entry(dir, &dotdot_name, f);
+       return f2fs_find_entry(dir, &dotdot_name, dentry_block);
 }
 
 ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
-                                                       struct folio **folio)
+                                                       void **dentry_block)
 {
        ino_t res = 0;
        struct f2fs_dir_entry *de;
 
-       de = f2fs_find_entry(dir, qstr, folio);
+       de = f2fs_find_entry(dir, qstr, dentry_block);
        if (de) {
                res = le32_to_cpu(de->ino);
-               f2fs_folio_put(*folio, false);
+               f2fs_put_dentry_block(*dentry_block, false);
        }
 
        return res;
 }
 
 void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
-               struct folio *folio, struct inode *inode)
+               void *dentry_block, struct inode *inode)
 {
-       enum page_type type = f2fs_has_inline_dentry(dir) ? NODE : DATA;
+       if (f2fs_dentry_is_cache(dentry_block)) {
+               struct f2fs_cached_block *entry =
+                               f2fs_dentry_cache(dentry_block);
+
+               f2fs_lock_cache(entry);
+               f2fs_cache_wait_writeback(entry);
+               de->ino = cpu_to_le32(inode->i_ino);
+               de->file_type = fs_umode_to_ftype(inode->i_mode);
+               f2fs_mark_cache_dirty(entry);
+       } else {
+               struct folio *folio = f2fs_dentry_folio(dentry_block);
 
-       folio_lock(folio);
-       f2fs_folio_wait_writeback(folio, type, true, true);
-       de->ino = cpu_to_le32(inode->i_ino);
-       de->file_type = fs_umode_to_ftype(inode->i_mode);
-       folio_mark_dirty(folio);
+               folio_lock(folio);
+               f2fs_folio_wait_writeback(folio, true, true);
+               de->ino = cpu_to_le32(inode->i_ino);
+               de->file_type = fs_umode_to_ftype(inode->i_mode);
+               folio_mark_dirty(folio);
+       }
 
        inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
        f2fs_mark_inode_dirty_sync(dir, true);
-       f2fs_folio_put(folio, true);
+       f2fs_put_dentry_block(dentry_block, true);
 }
 
 static void init_dent_inode(struct inode *dir, struct inode *inode,
                            const struct f2fs_filename *fname,
-                           struct folio *ifolio)
+                           struct f2fs_cached_block *ientry)
 {
        struct f2fs_inode *ri;
 
        if (!fname) /* tmpfile case? */
                return;
 
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       f2fs_cache_wait_writeback(ientry);
 
        /* copy name info. to this inode folio */
-       ri = F2FS_INODE(ifolio);
+       ri = F2FS_INODE(ientry);
        ri->i_namelen = cpu_to_le32(fname->disk_name.len);
        memcpy(ri->i_name, fname->disk_name.name, fname->disk_name.len);
        if (IS_ENCRYPTED(dir)) {
@@ -498,7 +509,7 @@ static void init_dent_inode(struct inode *dir, struct inode *inode,
                                file_lost_pino(inode);
                }
        }
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 }
 
 void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
@@ -515,16 +526,16 @@ void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
 }
 
 static int make_empty_dir(struct inode *inode,
-               struct inode *parent, struct folio *folio)
+               struct inode *parent, struct f2fs_cached_block *ientry)
 {
        struct folio *dentry_folio;
        void *dentry_blk;
        struct f2fs_dentry_ptr d;
 
        if (f2fs_has_inline_dentry(inode))
-               return f2fs_make_empty_inline_dir(inode, parent, folio);
+               return f2fs_make_empty_inline_dir(inode, parent, ientry);
 
-       dentry_folio = f2fs_get_new_data_folio(inode, folio, 0, true);
+       dentry_folio = f2fs_get_new_data_folio(inode, ientry, 0, true);
        if (IS_ERR(dentry_folio))
                return PTR_ERR(dentry_folio);
 
@@ -538,50 +549,50 @@ static int make_empty_dir(struct inode *inode,
        return 0;
 }
 
-struct folio *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
-               const struct f2fs_filename *fname, struct folio *dfolio)
+struct f2fs_cached_block *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
+               const struct f2fs_filename *fname, struct f2fs_cached_block *dentry)
 {
-       struct folio *folio;
+       struct f2fs_cached_block *ientry;
        int err;
 
        if (is_inode_flag_set(inode, FI_NEW_INODE)) {
-               folio = f2fs_new_inode_folio(inode);
-               if (IS_ERR(folio))
-                       return folio;
+               ientry = f2fs_new_inode_cache(inode);
+               if (IS_ERR(ientry))
+                       return ientry;
 
                if (S_ISDIR(inode->i_mode)) {
                        /* in order to handle error case */
-                       folio_get(folio);
-                       err = make_empty_dir(inode, dir, folio);
+                       f2fs_cache_get(ientry);
+                       err = make_empty_dir(inode, dir, ientry);
                        if (err) {
-                               folio_lock(folio);
+                               f2fs_lock_cache(ientry);
                                goto put_error;
                        }
-                       folio_put(folio);
+                       f2fs_put_cache(ientry, false);
                }
 
-               err = f2fs_init_acl(inode, dir, folio, dfolio);
+               err = f2fs_init_acl(inode, dir, ientry, dentry);
                if (err)
                        goto put_error;
 
                err = f2fs_init_security(inode, dir,
                                         fname ? fname->usr_fname : NULL,
-                                        folio);
+                                        ientry);
                if (err)
                        goto put_error;
 
                if (IS_ENCRYPTED(inode)) {
-                       err = fscrypt_set_context(inode, folio);
+                       err = fscrypt_set_context(inode, ientry);
                        if (err)
                                goto put_error;
                }
        } else {
-               folio = f2fs_get_inode_folio(F2FS_I_SB(dir), inode->i_ino);
-               if (IS_ERR(folio))
-                       return folio;
+               ientry = f2fs_get_inode_cache(F2FS_I_SB(dir), inode->i_ino);
+               if (IS_ERR(ientry))
+                       return ientry;
        }
 
-       init_dent_inode(dir, inode, fname, folio);
+       init_dent_inode(dir, inode, fname, ientry);
 
        /*
         * This file should be checkpointed during fsync.
@@ -598,12 +609,12 @@ struct folio *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
                        f2fs_remove_orphan_inode(F2FS_I_SB(dir), inode->i_ino);
                f2fs_i_links_write(inode, true);
        }
-       return folio;
+       return ientry;
 
 put_error:
        clear_nlink(inode);
-       f2fs_update_inode(inode, folio);
-       f2fs_folio_put(folio, true);
+       f2fs_update_inode(inode, ientry);
+       f2fs_put_cache(ientry, true);
        return ERR_PTR(err);
 }
 
@@ -645,14 +656,14 @@ int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots)
        goto next;
 }
 
-bool f2fs_has_enough_room(struct inode *dir, struct folio *ifolio,
+bool f2fs_has_enough_room(struct inode *dir, struct f2fs_cached_block *ientry,
                          const struct f2fs_filename *fname)
 {
        struct f2fs_dentry_ptr d;
        unsigned int bit_pos;
        int slots = GET_DENTRY_SLOTS(fname->disk_name.len);
 
-       make_dentry_ptr_inline(dir, &d, inline_data_addr(dir, ifolio));
+       make_dentry_ptr_inline(dir, &d, inline_data_addr(dir, ientry));
 
        bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
 
@@ -692,7 +703,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,
        struct folio *dentry_folio = NULL;
        void *dentry_blk = NULL;
        struct f2fs_dentry_ptr d;
-       struct folio *folio = NULL;
+       struct f2fs_cached_block *entry = NULL;
        int slots, err = 0;
 
        level = 0;
@@ -739,13 +750,13 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,
        ++level;
        goto start;
 add_dentry:
-       f2fs_folio_wait_writeback(dentry_folio, DATA, true, true);
+       f2fs_folio_wait_writeback(dentry_folio, true, true);
 
        if (inode) {
                f2fs_down_write(&F2FS_I(inode)->i_sem);
-               folio = f2fs_init_inode_metadata(inode, dir, fname, NULL);
-               if (IS_ERR(folio)) {
-                       err = PTR_ERR(folio);
+               entry = f2fs_init_inode_metadata(inode, dir, fname, NULL);
+               if (IS_ERR(entry)) {
+                       err = PTR_ERR(entry);
                        goto fail;
                }
        }
@@ -760,9 +771,9 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,
 
                /* synchronize inode page's data from inode cache */
                if (is_inode_flag_set(inode, FI_NEW_INODE))
-                       f2fs_update_inode(inode, folio);
+                       f2fs_update_inode(inode, entry);
 
-               f2fs_folio_put(folio, true);
+               f2fs_put_cache(entry, true);
        }
 
        f2fs_update_parent_metadata(dir, inode, current_depth);
@@ -804,7 +815,7 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
                                struct inode *inode, nid_t ino, umode_t mode)
 {
        struct f2fs_filename fname;
-       struct folio *folio = NULL;
+       void *dentry_blk = NULL;
        struct f2fs_dir_entry *de = NULL;
        int err;
 
@@ -820,14 +831,14 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
         * consistency more.
         */
        if (current != F2FS_I(dir)->task) {
-               de = __f2fs_find_entry(dir, &fname, &folio);
+               de = __f2fs_find_entry(dir, &fname, &dentry_blk);
                F2FS_I(dir)->task = NULL;
        }
        if (de) {
-               f2fs_folio_put(folio, false);
+               f2fs_put_dentry_block(dentry_blk, false);
                err = -EEXIST;
-       } else if (IS_ERR(folio)) {
-               err = PTR_ERR(folio);
+       } else if (IS_ERR(dentry_blk)) {
+               err = PTR_ERR(dentry_blk);
        } else {
                err = f2fs_add_dentry(dir, &fname, inode, ino, mode);
        }
@@ -838,16 +849,16 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
 int f2fs_do_tmpfile(struct inode *inode, struct inode *dir,
                                        struct f2fs_filename *fname)
 {
-       struct folio *folio;
+       struct f2fs_cached_block *ientry;
        int err = 0;
 
        f2fs_down_write(&F2FS_I(inode)->i_sem);
-       folio = f2fs_init_inode_metadata(inode, dir, fname, NULL);
-       if (IS_ERR(folio)) {
-               err = PTR_ERR(folio);
+       ientry = f2fs_init_inode_metadata(inode, dir, fname, NULL);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto fail;
        }
-       f2fs_folio_put(folio, true);
+       f2fs_put_cache(ientry, true);
 
        clear_inode_flag(inode, FI_NEW_INODE);
        f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
@@ -883,14 +894,15 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *inode)
  * It only removes the dentry from the dentry page, corresponding name
  * entry in name page does not need to be touched during deletion.
  */
-void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio,
+void f2fs_delete_entry(struct f2fs_dir_entry *dentry, void *dentry_block,
                                        struct inode *dir, struct inode *inode)
 {
        void *dentry_blk;
        struct f2fs_dentry_ptr d;
+       struct folio *folio;
        unsigned int bit_pos;
        int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
-       pgoff_t index = folio->index;
+       pgoff_t index;
        int i;
 
        f2fs_update_time(F2FS_I_SB(dir), REQ_TIME);
@@ -899,10 +911,14 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio,
                f2fs_add_ino_entry(F2FS_I_SB(dir), dir->i_ino, TRANS_DIR_INO);
 
        if (f2fs_has_inline_dentry(dir))
-               return f2fs_delete_inline_entry(dentry, folio, dir, inode);
+               return f2fs_delete_inline_entry(dentry,
+                               f2fs_dentry_cache(dentry_block), dir, inode);
+
+       folio = f2fs_dentry_folio(dentry_block);
+       index = folio->index;
 
        folio_lock(folio);
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
 
        dentry_blk = folio_address(folio);
        make_dentry_ptr_block(dir, &d, dentry_blk);
@@ -1050,7 +1066,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
                }
 
                if (readdir_ra)
-                       f2fs_ra_node_page(sbi, le32_to_cpu(de->ino));
+                       f2fs_ra_node_cache(sbi, le32_to_cpu(de->ino));
 
                ctx->pos = start_pos + bit_pos;
                found_valid_dirent = true;
fs/f2fs/extent_cache.c +7 -7
index 40cd87940961..5a944428aca0 100644
@@ -20,10 +20,10 @@
 #include "segment.h"
 #include <trace/events/f2fs.h>
 
-bool sanity_check_extent_cache(struct inode *inode, struct folio *ifolio)
+bool sanity_check_extent_cache(struct inode *inode, struct f2fs_cached_block *ientry)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-       struct f2fs_extent *i_ext = &F2FS_INODE(ifolio)->i_ext;
+       struct f2fs_extent *i_ext = &F2FS_INODE(ientry)->i_ext;
        struct extent_info ei;
        int devi;
 
@@ -416,11 +416,11 @@ static void __drop_largest_extent(struct extent_tree *et,
        }
 }
 
-void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
+void f2fs_init_read_extent_tree(struct inode *inode, struct f2fs_cached_block *ientry)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct extent_tree_info *eti = &sbi->extent_tree[EX_READ];
-       struct f2fs_extent *i_ext = &F2FS_INODE(ifolio)->i_ext;
+       struct f2fs_extent *i_ext = &F2FS_INODE(ientry)->i_ext;
        struct extent_tree *et;
        struct extent_node *en;
        struct extent_info ei = {0};
@@ -428,9 +428,9 @@ void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
        if (!__may_extent_tree(inode, EX_READ)) {
                /* drop largest read extent */
                if (i_ext->len) {
-                       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+                       f2fs_cache_wait_writeback(ientry);
                        i_ext->len = 0;
-                       folio_mark_dirty(ifolio);
+                       f2fs_mark_cache_dirty(ientry);
                }
                set_inode_flag(inode, FI_NO_EXTENT);
                return;
@@ -958,7 +958,7 @@ static void __update_extent_cache(struct dnode_of_data *dn, enum extent_type typ
                return;
 
        ei.fofs = f2fs_start_bidx_of_node(ofs_of_node(F2FS_I_SB(dn->inode),
-                               dn->node_folio), dn->inode) + dn->ofs_in_node;
+                               dn->node_entry), dn->inode) + dn->ofs_in_node;
        ei.len = 1;
 
        if (type == EX_READ) {
fs/f2fs/f2fs.h +142 -117
index 51c191c514bc..d6681276708e 100644
@@ -418,7 +418,7 @@ struct inode_entry {
 
 struct fsync_node_entry {
        struct list_head list;  /* list head */
-       struct folio *folio;    /* warm node folio pointer */
+       struct f2fs_cached_block *entry; /* warm node cache entry pointer */
        unsigned int seq_id;    /* sequence id */
 };
 
@@ -1116,11 +1116,11 @@ struct f2fs_nm_info {
  */
 struct dnode_of_data {
        struct inode *inode;            /* vfs inode pointer */
-       struct folio *inode_folio;      /* its inode folio, NULL is possible */
-       struct folio *node_folio;       /* cached direct node folio */
+       struct f2fs_cached_block *inode_entry; /* generic cache inode entry */
+       struct f2fs_cached_block *node_entry;  /* generic cache node entry */
        nid_t nid;                      /* node id of the direct node block */
        unsigned int ofs_in_node;       /* data offset in the node page */
-       bool inode_folio_locked;        /* inode folio is locked or not */
+       bool inode_entry_locked;        /* inode entry is locked or not */
        bool node_changed;              /* is node block changed */
        char cur_level;                 /* level of hole node page */
        char max_level;                 /* level of current page located */
@@ -1128,12 +1128,12 @@ struct dnode_of_data {
 };
 
 static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
-               struct folio *ifolio, struct folio *nfolio, nid_t nid)
+               struct f2fs_cached_block *ientry, struct f2fs_cached_block *nentry, nid_t nid)
 {
        memset(dn, 0, sizeof(*dn));
        dn->inode = inode;
-       dn->inode_folio = ifolio;
-       dn->node_folio = nfolio;
+       dn->inode_entry = ientry;
+       dn->node_entry = nentry;
        dn->nid = nid;
 }
 
@@ -1614,10 +1614,9 @@ static inline void f2fs_clear_bit(unsigned int nr, char *addr);
  * | bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... |
  * bit 0       PAGE_PRIVATE_NOT_POINTER
  * bit 1       PAGE_PRIVATE_ONGOING_MIGRATION
- * bit 2       PAGE_PRIVATE_INLINE_INODE
- * bit 3       PAGE_PRIVATE_REF_RESOURCE
- * bit 4       PAGE_PRIVATE_ATOMIC_WRITE
- * bit 5-      f2fs private data
+ * bit 2       PAGE_PRIVATE_REF_RESOURCE
+ * bit 3       PAGE_PRIVATE_ATOMIC_WRITE
+ * bit 4-      f2fs private data
  *
  * Layout B: lowest bit should be 0
  * page.private is a wrapped pointer.
@@ -1625,7 +1624,6 @@ static inline void f2fs_clear_bit(unsigned int nr, char *addr);
 enum {
        PAGE_PRIVATE_NOT_POINTER,               /* private contains non-pointer data */
        PAGE_PRIVATE_ONGOING_MIGRATION,         /* data page which is on-going migrating */
-       PAGE_PRIVATE_INLINE_INODE,              /* inode page contains inline data */
        PAGE_PRIVATE_REF_RESOURCE,              /* dirty page has referenced resources */
        PAGE_PRIVATE_ATOMIC_WRITE,              /* data page from atomic write path */
        PAGE_PRIVATE_MAX
@@ -1802,7 +1800,6 @@ struct f2fs_sb_info {
 
        /* for node-related operations */
        struct f2fs_nm_info *nm_info;           /* node manager */
-       struct inode *node_inode;               /* cache node blocks */
 
        /* for segment-related operations */
        struct f2fs_sm_info *sm_info;           /* segment manager */
@@ -2327,28 +2324,29 @@ static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
 }
 
 static inline struct node_footer *F2FS_NODE_FOOTER(struct f2fs_sb_info *sbi,
-                                               const struct folio *folio)
+                                               const struct f2fs_cached_block *entry)
 {
-       return folio_address(folio) + F2FS_BLKSIZE(sbi) -
-               sizeof(struct node_footer);
+       return (struct node_footer *)(cache_address(entry) +
+               F2FS_BLKSIZE(sbi) - sizeof(struct node_footer));
 }
 
-static inline struct f2fs_node *F2FS_NODE(const struct folio *folio)
+static inline struct f2fs_node *F2FS_NODE(const struct f2fs_cached_block *entry)
 {
-       return (struct f2fs_node *)folio_address(folio);
+       return (struct f2fs_node *)CACHED_NODE(entry);
 }
 
-static inline struct f2fs_inode *F2FS_INODE(const struct folio *folio)
+static inline struct f2fs_inode *F2FS_INODE(const struct f2fs_cached_block *entry)
 {
-       return &((struct f2fs_node *)folio_address(folio))->i;
+       return &CACHED_NODE(entry)->i;
 }
 
 static inline __le32 *F2FS_INODE_NIDS(struct f2fs_sb_info *sbi,
-                                               const struct folio *folio)
+                                               const struct f2fs_cached_block *entry)
 {
-       return folio_address(folio) + F2FS_BLKSIZE(sbi) -
+       return (__le32 *)(cache_address(entry) +
+               F2FS_BLKSIZE(sbi) -
                sizeof(struct node_footer) -
-               SIZE_OF_I_NID;
+               SIZE_OF_I_NID);
 }
 
 static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
@@ -2381,14 +2379,9 @@ static inline bool f2fs_is_meta_cache(struct f2fs_cached_block *entry)
        return entry->cache && entry->cache == META_CACHE(entry->cache->sbi);
 }
 
-static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
+static inline bool f2fs_is_node_cache(struct f2fs_cached_block *entry)
 {
-       return sbi->node_inode->i_mapping;
-}
-
-static inline bool is_node_folio(struct f2fs_sb_info *sbi, struct folio *folio)
-{
-       return folio->mapping == NODE_MAPPING(sbi);
+       return entry->cache && entry->cache == NODE_CACHE(entry->cache->sbi);
 }
 
 static inline struct f2fs_bio *F2FS_BIO(struct bio *bio)
@@ -2812,17 +2805,14 @@ static inline void clear_page_private_##name(struct page *page) \
 }
 
 PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER);
-PAGE_PRIVATE_GET_FUNC(inline, INLINE_INODE);
 PAGE_PRIVATE_GET_FUNC(gcing, ONGOING_MIGRATION);
 PAGE_PRIVATE_GET_FUNC(atomic, ATOMIC_WRITE);
 
 PAGE_PRIVATE_SET_FUNC(reference, REF_RESOURCE);
-PAGE_PRIVATE_SET_FUNC(inline, INLINE_INODE);
 PAGE_PRIVATE_SET_FUNC(gcing, ONGOING_MIGRATION);
 PAGE_PRIVATE_SET_FUNC(atomic, ATOMIC_WRITE);
 
 PAGE_PRIVATE_CLEAR_FUNC(reference, REF_RESOURCE);
-PAGE_PRIVATE_CLEAR_FUNC(inline, INLINE_INODE);
 PAGE_PRIVATE_CLEAR_FUNC(gcing, ONGOING_MIGRATION);
 PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE);
 
@@ -3231,14 +3221,51 @@ static inline void f2fs_put_page(struct page *page, bool unlock)
        f2fs_folio_put(page_folio(page), unlock);
 }
 
+#define F2FS_DENTRY_TAG_CACHE  1UL
+#define F2FS_DENTRY_TAG_MASK   1UL
+
+static inline void *f2fs_cache_make_dentry_block(struct f2fs_cached_block *entry)
+{
+       if (IS_ERR_OR_NULL(entry))
+               return entry;
+       return (void *)((unsigned long)entry | F2FS_DENTRY_TAG_CACHE);
+}
+
+static inline bool f2fs_dentry_is_cache(void *dentry_block)
+{
+       return ((unsigned long)dentry_block & F2FS_DENTRY_TAG_MASK) ==
+                                               F2FS_DENTRY_TAG_CACHE;
+}
+
+static inline struct f2fs_cached_block *f2fs_dentry_cache(void *dentry_block)
+{
+       return (struct f2fs_cached_block *)
+               ((unsigned long)dentry_block & ~F2FS_DENTRY_TAG_MASK);
+}
+
+static inline struct folio *f2fs_dentry_folio(void *dentry_block)
+{
+       return (struct folio *)dentry_block;
+}
+
+static inline void f2fs_put_dentry_block(void *dentry_block, bool unlock)
+{
+       if (IS_ERR_OR_NULL(dentry_block))
+               return;
+       if (f2fs_dentry_is_cache(dentry_block))
+               f2fs_put_cache(f2fs_dentry_cache(dentry_block), unlock);
+       else
+               f2fs_folio_put(f2fs_dentry_folio(dentry_block), unlock);
+}
+
 static inline void f2fs_put_dnode(struct dnode_of_data *dn)
 {
-       if (dn->node_folio)
-               f2fs_folio_put(dn->node_folio, true);
-       if (dn->inode_folio && dn->node_folio != dn->inode_folio)
-               f2fs_folio_put(dn->inode_folio, false);
-       dn->node_folio = NULL;
-       dn->inode_folio = NULL;
+       if (dn->node_entry)
+               f2fs_put_cache(dn->node_entry, true);
+       if (dn->inode_entry && dn->node_entry != dn->inode_entry)
+               f2fs_put_cache(dn->inode_entry, false);
+       dn->node_entry = NULL;
+       dn->inode_entry = NULL;
 }
 
 static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
@@ -3327,9 +3354,9 @@ static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
                cond_resched();
 }
 
-static inline bool IS_INODE(struct f2fs_sb_info *sbi, const struct folio *folio)
+static inline bool IS_INODE(struct f2fs_sb_info *sbi, const struct f2fs_cached_block *entry)
 {
-       struct node_footer *footer = F2FS_NODE_FOOTER(sbi, folio);
+       struct node_footer *footer = F2FS_NODE_FOOTER(sbi, entry);
 
        return footer->nid == footer->ino;
 }
@@ -3341,46 +3368,44 @@ static inline int offset_in_addr(struct f2fs_inode *i)
 }
 
 static inline __le32 *blkaddr_in_node(struct f2fs_sb_info *sbi,
-                                               const struct folio *folio)
+                                               const struct f2fs_cached_block *entry)
 {
-       struct f2fs_node *node = F2FS_NODE(folio);
+       struct f2fs_node *node = F2FS_NODE(entry);
 
-       return IS_INODE(sbi, folio) ? node->i.i_addr : node->dn.addr;
+       return IS_INODE(sbi, entry) ? node->i.i_addr : node->dn.addr;
 }
 
 static inline int f2fs_has_extra_attr(struct inode *inode);
+
 static inline unsigned int get_dnode_base(struct inode *inode,
-                                       struct folio *node_folio)
+                                       const struct f2fs_cached_block *entry)
 {
-       struct f2fs_sb_info *sbi = inode ? F2FS_I_SB(inode) :
-                                       F2FS_F_SB(node_folio);
-
-       if (!IS_INODE(sbi, node_folio))
+       if (!IS_INODE(inode ? F2FS_I_SB(inode) : entry->cache->sbi, entry))
                return 0;
 
        return inode ? get_extra_isize(inode) :
-                       offset_in_addr(&F2FS_NODE(node_folio)->i);
+                       offset_in_addr(&CACHED_NODE(entry)->i);
 }
 
 static inline __le32 *get_dnode_addr(struct inode *inode,
-                                       struct folio *node_folio)
+                                       const struct f2fs_cached_block *entry)
 {
-       struct f2fs_sb_info *sbi = inode ? F2FS_I_SB(inode) :
-                                       F2FS_F_SB(node_folio);
+       struct f2fs_sb_info *sbi = inode ? F2FS_I_SB(inode) : entry->cache->sbi;
 
-       return blkaddr_in_node(sbi, node_folio) +
-                       get_dnode_base(inode, node_folio);
+       return blkaddr_in_node(sbi, entry) +
+                       get_dnode_base(inode, entry);
 }
 
 static inline block_t data_blkaddr(struct inode *inode,
-                       struct folio *node_folio, unsigned int offset)
+                       const struct f2fs_cached_block *entry,
+                       unsigned int offset)
 {
-       return le32_to_cpu(*(get_dnode_addr(inode, node_folio) + offset));
+       return le32_to_cpu(*(get_dnode_addr(inode, entry) + offset));
 }
 
 static inline block_t f2fs_data_blkaddr(struct dnode_of_data *dn)
 {
-       return data_blkaddr(dn->inode, dn->node_folio, dn->ofs_in_node);
+       return data_blkaddr(dn->inode, dn->node_entry, dn->ofs_in_node);
 }
 
 static inline int f2fs_test_bit(unsigned int nr, char *addr)
@@ -3697,10 +3722,10 @@ static inline unsigned int cur_addrs_per_inode(struct inode *inode)
        return DEF_ADDRS_PER_INODE(F2FS_I_SB(inode)) - get_extra_isize(inode);
 }
 
-static inline
-void *inline_xattr_addr(struct inode *inode, const struct folio *folio)
+static inline void *inline_xattr_addr(struct inode *inode,
+                               const struct f2fs_cached_block *entry)
 {
-       struct f2fs_inode *ri = F2FS_INODE(folio);
+       struct f2fs_inode *ri = F2FS_INODE(entry);
 
        return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE(F2FS_I_SB(inode)) -
                                        get_inline_xattr_addrs(inode)]);
@@ -3747,9 +3772,10 @@ static inline bool f2fs_is_cow_file(struct inode *inode)
        return is_inode_flag_set(inode, FI_COW_FILE);
 }
 
-static inline void *inline_data_addr(struct inode *inode, struct folio *folio)
+static inline void *inline_data_addr(struct inode *inode,
+                       const struct f2fs_cached_block *entry)
 {
-       __le32 *addr = get_dnode_addr(inode, folio);
+       __le32 *addr = get_dnode_addr(inode, entry);
 
        return (void *)(addr + DEF_INLINE_RESERVED_SIZE);
 }
@@ -3959,13 +3985,13 @@ int f2fs_pin_file_control(struct inode *inode, bool inc);
  * inode.c
  */
 void f2fs_set_inode_flags(struct inode *inode);
-bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct folio *folio);
-void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct folio *folio);
+bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
+void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-void f2fs_update_inode(struct inode *inode, struct folio *node_folio);
-void f2fs_update_inode_page(struct inode *inode);
+void f2fs_update_inode(struct inode *inode, struct f2fs_cached_block *entry);
+void f2fs_update_inode_cache(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);
@@ -4014,22 +4040,22 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
                        unsigned int start_pos, struct fscrypt_str *fstr);
 void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
                        struct f2fs_dentry_ptr *d);
-struct folio *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
-               const struct f2fs_filename *fname, struct folio *dfolio);
+struct f2fs_cached_block *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
+               const struct f2fs_filename *fname, struct f2fs_cached_block *dentry);
 void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode,
                        unsigned int current_depth);
 int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots);
 void f2fs_drop_nlink(struct inode *dir, struct inode *inode);
 struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
-               const struct f2fs_filename *fname, struct folio **res_folio);
+               const struct f2fs_filename *fname, void **dentry_block);
 struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
-                       const struct qstr *child, struct folio **res_folio);
-struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct folio **f);
+                       const struct qstr *child, void **dentry_block);
+struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, void **dentry_block);
 ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
-                       struct folio **folio);
+                       void **dentry_block);
 void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
-                       struct folio *folio, struct inode *inode);
-bool f2fs_has_enough_room(struct inode *dir, struct folio *ifolio,
+                       void *dentry_blk, struct inode *inode);
+bool f2fs_has_enough_room(struct inode *dir, struct f2fs_cached_block *ientry,
                          const struct f2fs_filename *fname);
 void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
                        const struct fscrypt_str *name, f2fs_hash_t name_hash,
@@ -4040,7 +4066,7 @@ int f2fs_add_dentry(struct inode *dir, const struct f2fs_filename *fname,
                        struct inode *inode, nid_t ino, umode_t mode);
 int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
                        struct inode *inode, nid_t ino, umode_t mode);
-void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio,
+void f2fs_delete_entry(struct f2fs_dir_entry *dentry, void *dentry_blk,
                        struct inode *dir, struct inode *inode);
 int f2fs_do_tmpfile(struct inode *inode, struct inode *dir,
                                        struct f2fs_filename *fname);
@@ -4083,9 +4109,9 @@ enum node_type;
 
 int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid);
 bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type);
-bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct folio *folio);
+bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
 void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi);
-void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct folio *folio);
+void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
 void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi);
 bool f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
 bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
@@ -4096,29 +4122,28 @@ pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
 int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
 int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from);
 int f2fs_truncate_xattr_node(struct inode *inode);
-int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi,
+int f2fs_wait_on_node_caches_writeback(struct f2fs_sb_info *sbi,
                                        unsigned int seq_id);
-int f2fs_remove_inode_page(struct inode *inode);
-struct folio *f2fs_new_inode_folio(struct inode *inode);
-struct folio *f2fs_new_node_folio(struct dnode_of_data *dn, unsigned int ofs);
-void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
-struct folio *f2fs_get_node_folio(struct f2fs_sb_info *sbi, pgoff_t nid,
+int f2fs_write_node_caches(struct f2fs_sb_info *sbi);
+int f2fs_remove_inode_cache(struct inode *inode);
+struct f2fs_cached_block *f2fs_new_inode_cache(struct inode *inode);
+struct f2fs_cached_block *f2fs_new_node_cache(struct dnode_of_data *dn, unsigned int ofs);
+void f2fs_ra_node_cache(struct f2fs_sb_info *sbi, nid_t nid);
+struct f2fs_cached_block *f2fs_get_node_cache(struct f2fs_sb_info *sbi, pgoff_t nid,
                                                enum node_type node_type);
 int f2fs_sanity_check_node_footer(struct f2fs_sb_info *sbi,
-                                       struct folio *folio, pgoff_t nid,
+                                       struct f2fs_cached_block *entry, pgoff_t nid,
                                        enum node_type ntype, bool in_irq);
-struct folio *f2fs_get_inode_folio(struct f2fs_sb_info *sbi, pgoff_t ino);
-struct folio *f2fs_get_xnode_folio(struct f2fs_sb_info *sbi, pgoff_t xnid);
-int f2fs_write_single_node_folio(struct folio *node_folio, int sync_mode,
+struct f2fs_cached_block *f2fs_get_inode_cache(struct f2fs_sb_info *sbi, pgoff_t ino);
+struct f2fs_cached_block *f2fs_get_xnode_cache(struct f2fs_sb_info *sbi, pgoff_t xnid);
+int f2fs_write_node_cache(struct f2fs_cached_block *entry, int sync_mode,
                        bool mark_dirty, enum iostat_type io_type);
-int f2fs_move_node_folio(struct folio *node_folio, int gc_type);
+int f2fs_move_node_cache(struct f2fs_cached_block *entry, int gc_type);
 void f2fs_flush_inline_data(struct f2fs_sb_info *sbi);
-int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
-                       struct writeback_control *wbc, bool atomic,
-                       unsigned int *seq_id);
-int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
-                       struct writeback_control *wbc,
-                       bool do_balance, enum iostat_type io_type);
+int f2fs_fsync_node_caches(struct f2fs_sb_info *sbi, struct inode *inode,
+                                       bool atomic, unsigned int *seq_id);
+int f2fs_writeback_node_caches(struct f2fs_sb_info *sbi, long nr_to_write,
+                       bool sync, bool do_balance, enum iostat_type io_type);
 int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
 bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
 void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
@@ -4126,7 +4151,8 @@ void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
 int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
 int f2fs_recover_inline_xattr(struct inode *inode, struct f2fs_cached_block *entry);
 int f2fs_recover_xattr_data(struct inode *inode, struct f2fs_cached_block *entry);
-int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct f2fs_cached_block *entry);
+int f2fs_recover_inode_cache(struct f2fs_sb_info *sbi,
+                       struct f2fs_cached_block *entry);
 int f2fs_restore_node_summary(struct f2fs_sb_info *sbi,
                        unsigned int segno, struct f2fs_summary_block *sum);
 int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
@@ -4185,7 +4211,7 @@ void f2fs_update_meta_block(struct f2fs_sb_info *sbi, void *src,
 void f2fs_do_write_meta_cache(struct f2fs_sb_info *sbi,
                        struct f2fs_cached_block *entry,
                        enum iostat_type io_type);
-void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio);
+void f2fs_do_write_node_cache(unsigned int nid, struct f2fs_io_info *fio);
 void f2fs_outplace_write_data(struct dnode_of_data *dn,
                        struct f2fs_io_info *fio);
 int f2fs_inplace_write_data(struct f2fs_io_info *fio);
@@ -4199,14 +4225,13 @@ void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
                        bool recover_newaddr);
 enum temp_type f2fs_get_segment_temp(struct f2fs_sb_info *sbi,
                                                enum log_type seg_type);
-int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct folio *folio,
+int f2fs_allocate_data_block(struct f2fs_sb_info *sbi,
                        block_t old_blkaddr, block_t *new_blkaddr,
                        struct f2fs_summary *sum, int type,
                        struct f2fs_io_info *fio);
 void f2fs_update_device_state(struct f2fs_sb_info *sbi, nid_t ino,
                                        block_t blkaddr, unsigned int blkcnt);
-void f2fs_folio_wait_writeback(struct folio *folio, enum page_type type,
-               bool ordered, bool locked);
+void f2fs_folio_wait_writeback(struct folio *folio, bool ordered, bool locked);
 void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr);
 void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr,
                                                                block_t len);
@@ -4327,14 +4352,14 @@ void f2fs_destroy_bio_entry_cache(void);
 void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio,
                          enum page_type type);
 int f2fs_init_write_merge_io(struct f2fs_sb_info *sbi);
-void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
 void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
-                               struct inode *inode, struct folio *folio,
-                               nid_t ino, enum page_type type);
+                               struct inode *inode, struct folio *folio);
 void f2fs_submit_merged_write_folio(struct f2fs_sb_info *sbi,
-                               struct folio *folio, enum page_type type);
-bool f2fs_submit_merged_write_cache(struct f2fs_cached_block *entry,
-                               enum page_type type);
+                               struct folio *folio);
+bool f2fs_submit_merged_write_cache(struct f2fs_sb_info *sbi,
+                               struct f2fs_cached_block *entry,
+                               nid_t ino, enum page_type type);
+void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
 void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
                                        struct bio **bio, struct folio *folio);
 void f2fs_submit_all_merged_ipu_writes(struct f2fs_sb_info *sbi);
@@ -4360,7 +4385,7 @@ struct folio *f2fs_find_data_folio(struct inode *inode, pgoff_t index,
 struct folio *f2fs_get_lock_data_folio(struct inode *inode, pgoff_t index,
                        bool for_write);
 struct folio *f2fs_get_new_data_folio(struct inode *inode,
-                       struct folio *ifolio, pgoff_t index, bool new_i_size);
+                       struct f2fs_cached_block *ientry, pgoff_t index, bool new_i_size);
 int f2fs_do_write_data_page(struct f2fs_io_info *fio);
 int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag);
 int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
@@ -4472,7 +4497,7 @@ struct f2fs_stat_info {
        unsigned int bimodal, avg_vblocks;
        int util_free, util_valid, util_invalid;
        int rsvd_segs, overp_segs;
-       int dirty_count, node_pages, meta_caches, compress_pages;
+       int dirty_count, node_caches, meta_caches, compress_pages;
        int compress_page_hit;
        int prefree_count, free_segs, free_secs;
        int cp_call_count[MAX_CALL_TYPE], cp_count;
@@ -4673,7 +4698,6 @@ extern const struct file_operations f2fs_dir_operations;
 extern const struct file_operations f2fs_file_operations;
 extern const struct inode_operations f2fs_file_inode_operations;
 extern const struct address_space_operations f2fs_dblock_aops;
-extern const struct address_space_operations f2fs_node_aops;
 extern const struct inode_operations f2fs_dir_inode_operations;
 extern const struct inode_operations f2fs_symlink_inode_operations;
 extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
@@ -4684,10 +4708,10 @@ extern struct kmem_cache *f2fs_inode_entry_slab;
  * inline.c
  */
 bool f2fs_may_inline_data(struct inode *inode);
-bool f2fs_sanity_check_inline_data(struct inode *inode, struct folio *ifolio);
+bool f2fs_sanity_check_inline_data(struct inode *inode, struct f2fs_cached_block *ientry);
 bool f2fs_may_inline_dentry(struct inode *inode);
-void f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio);
-void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio,
+void f2fs_do_read_inline_data(struct folio *folio, struct f2fs_cached_block *ientry);
+void f2fs_truncate_inline_inode(struct inode *inode, struct f2fs_cached_block *ientry,
                u64 from);
 int f2fs_read_inline_data(struct inode *inode, struct folio *folio);
 int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio);
@@ -4696,14 +4720,15 @@ int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry);
 int f2fs_write_inline_data(struct inode *inode, struct folio *folio);
 int f2fs_recover_inline_data(struct inode *inode, struct f2fs_cached_block *entry);
 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
-               const struct f2fs_filename *fname, struct folio **res_folio,
+               const struct f2fs_filename *fname, void **dentry_block,
                bool use_hash);
 int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
-                       struct folio *ifolio);
+                       struct f2fs_cached_block *ientry);
 int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
                        struct inode *inode, nid_t ino, umode_t mode);
 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
-               struct folio *folio, struct inode *dir, struct inode *inode);
+               struct f2fs_cached_block *ientry, struct inode *dir,
+               struct inode *inode);
 bool f2fs_empty_inline_dir(struct inode *dir);
 int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
                        struct fscrypt_str *fstr);
@@ -4726,7 +4751,7 @@ void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
 /*
  * extent_cache.c
  */
-bool sanity_check_extent_cache(struct inode *inode, struct folio *ifolio);
+bool sanity_check_extent_cache(struct inode *inode, struct f2fs_cached_block *ientry);
 void f2fs_init_extent_tree(struct inode *inode);
 void f2fs_drop_extent_tree(struct inode *inode);
 void f2fs_destroy_extent_node(struct inode *inode);
@@ -4736,7 +4761,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 folio *ifolio);
+void f2fs_init_read_extent_tree(struct inode *inode, struct f2fs_cached_block *ientry);
 bool f2fs_lookup_read_extent_cache(struct inode *inode, pgoff_t pgofs,
                        struct extent_info *ei);
 bool f2fs_lookup_read_extent_cache_block(struct inode *inode, pgoff_t index,
fs/f2fs/file.c +37 -41
index 7c2bfa0e63d2..6f4287fe180d 100644
@@ -213,7 +213,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
                goto out_sem;
        }
 
-       f2fs_folio_wait_writeback(folio, DATA, false, true);
+       f2fs_folio_wait_writeback(folio, false, true);
 
        /* wait for GCed page writeback via generic cache */
        f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
@@ -308,13 +308,13 @@ static inline enum cp_reason_type need_do_checkpoint(struct inode *inode)
 
 static bool need_inode_page_update(struct f2fs_sb_info *sbi, nid_t ino)
 {
-       struct folio *i = filemap_get_folio(NODE_MAPPING(sbi), ino);
+       struct f2fs_cached_block *entry = f2fs_find_node_cache(sbi, ino);
        bool ret = false;
        /* But we need to avoid that there are some inode updates */
-       if ((!IS_ERR(i) && folio_test_dirty(i)) ||
+       if ((!IS_ERR(entry) && f2fs_cache_test_dirty(entry)) ||
            f2fs_need_inode_block_update(sbi, ino))
                ret = true;
-       f2fs_folio_put(i, false);
+       f2fs_put_cache(entry, false);
        return ret;
 }
 
@@ -340,10 +340,6 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
        nid_t ino = inode->i_ino;
        int ret = 0;
        enum cp_reason_type cp_reason = 0;
-       struct writeback_control wbc = {
-               .sync_mode = WB_SYNC_ALL,
-               .nr_to_write = LONG_MAX,
-       };
        unsigned int seq_id = 0;
 
        if (unlikely(f2fs_readonly(inode->i_sb)))
@@ -422,7 +418,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
        }
 sync_nodes:
        atomic_inc(&sbi->wb_sync_req[NODE]);
-       ret = f2fs_fsync_node_pages(sbi, inode, &wbc, atomic, &seq_id);
+       ret = f2fs_fsync_node_caches(sbi, inode, atomic, &seq_id);
        atomic_dec(&sbi->wb_sync_req[NODE]);
        if (ret)
                goto out;
@@ -448,7 +444,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
         * given fsync mark.
         */
        if (!atomic) {
-               ret = f2fs_wait_on_node_pages_writeback(sbi, seq_id);
+               ret = f2fs_wait_on_node_caches_writeback(sbi, seq_id);
                if (ret)
                        goto out;
        }
@@ -485,7 +481,7 @@ static bool __found_offset(struct address_space *mapping,
        bool compressed_cluster = false;
 
        if (f2fs_compressed_file(inode)) {
-               block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                    ALIGN_DOWN(dn->ofs_in_node, F2FS_I(inode)->i_cluster_size));
 
                compressed_cluster = first_blkaddr == COMPRESS_ADDR;
@@ -557,7 +553,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
                        }
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
 
                /* find data/hole in dnode block */
                for (; dn.ofs_in_node < end_offset;
@@ -720,7 +716,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
        block_t blkstart;
        int blklen = 0;
 
-       addr = get_dnode_addr(dn->inode, dn->node_folio) + ofs;
+       addr = get_dnode_addr(dn->inode, dn->node_entry) + ofs;
        blkstart = le32_to_cpu(*addr);
 
        /* Assumption: truncation starts with cluster */
@@ -784,7 +780,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count)
                 * once we invalidate valid blkaddr in range [ofs, ofs + count],
                 * we will invalidate all blkaddr in the whole range.
                 */
-               fofs = f2fs_start_bidx_of_node(ofs_of_node(sbi, dn->node_folio),
+               fofs = f2fs_start_bidx_of_node(ofs_of_node(sbi, dn->node_entry),
                                                        dn->inode) + ofs;
                f2fs_update_read_extent_cache_range(dn, fofs, 0, len);
                f2fs_update_age_extent_cache_range(dn, fofs, len);
@@ -822,7 +818,7 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,
        if (IS_ERR(folio))
                return PTR_ERR(folio) == -ENOENT ? 0 : PTR_ERR(folio);
 truncate_out:
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
        folio_zero_segment(folio, offset, folio_size(folio));
 
        /* An encrypted inode should have a key and truncate the last page. */
@@ -840,7 +836,7 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
        struct f2fs_lock_context lc;
        pgoff_t free_from;
        int count = 0, err = 0;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        bool truncate_page = false;
 
        trace_f2fs_truncate_blocks_enter(inode, from);
@@ -858,9 +854,9 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
        if (lock)
                f2fs_lock_op(sbi, &lc);
 
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto out;
        }
 
@@ -879,18 +875,18 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
 
                f2fs_drop_extent_tree(inode);
 
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                goto out;
        }
 
        if (f2fs_has_inline_data(inode)) {
-               f2fs_truncate_inline_inode(inode, ifolio, from);
-               f2fs_folio_put(ifolio, true);
+               f2fs_truncate_inline_inode(inode, ientry, from);
+               f2fs_put_cache(ientry, true);
                truncate_page = true;
                goto out;
        }
 
-       set_new_dnode(&dn, inode, ifolio, NULL, 0);
+       set_new_dnode(&dn, inode, ientry, NULL, 0);
        err = f2fs_get_dnode_of_data(&dn, free_from, LOOKUP_NODE_RA);
        if (err) {
                if (err == -ENOENT)
@@ -898,12 +894,12 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock)
                goto out;
        }
 
-       count = ADDRS_PER_PAGE(dn.node_folio, inode);
+       count = ADDRS_PER_PAGE(dn.node_entry, inode);
 
        count -= dn.ofs_in_node;
        f2fs_bug_on(sbi, count < 0);
 
-       if (dn.ofs_in_node || IS_INODE(sbi, dn.node_folio)) {
+       if (dn.ofs_in_node || IS_INODE(sbi, dn.node_entry)) {
                f2fs_truncate_data_blocks_range(&dn, count);
                free_from += count;
        }
@@ -1309,7 +1305,7 @@ static int fill_zero(struct inode *inode, pgoff_t index,
        if (IS_ERR(folio))
                return PTR_ERR(folio);
 
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
        folio_zero_range(folio, start, len);
        folio_mark_dirty(folio);
        f2fs_folio_put(folio, true);
@@ -1335,7 +1331,7 @@ int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end)
                        return err;
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                count = min(end_offset - dn.ofs_in_node, pg_end - pg_start);
 
                f2fs_bug_on(F2FS_I_SB(inode), count == 0 || count > end_offset);
@@ -1435,7 +1431,7 @@ static int __read_out_blkaddrs(struct inode *inode, block_t *blkaddr,
                goto next;
        }
 
-       done = min((pgoff_t)ADDRS_PER_PAGE(dn.node_folio, inode) -
+       done = min((pgoff_t)ADDRS_PER_PAGE(dn.node_entry, inode) -
                                                        dn.ofs_in_node, len);
        for (i = 0; i < done; i++, blkaddr++, do_replace++, dn.ofs_in_node++) {
                *blkaddr = f2fs_data_blkaddr(&dn);
@@ -1524,7 +1520,7 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
                        }
 
                        ilen = min((pgoff_t)
-                               ADDRS_PER_PAGE(dn.node_folio, dst_inode) -
+                               ADDRS_PER_PAGE(dn.node_entry, dst_inode) -
                                                dn.ofs_in_node, len - i);
                        do {
                                dn.data_blkaddr = f2fs_data_blkaddr(&dn);
@@ -1562,7 +1558,7 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
                                return PTR_ERR(fdst);
                        }
 
-                       f2fs_folio_wait_writeback(fdst, DATA, true, true);
+                       f2fs_folio_wait_writeback(fdst, true, true);
 
                        memcpy_folio(fdst, 0, fsrc, 0, PAGE_SIZE);
                        folio_mark_dirty(fdst);
@@ -1832,7 +1828,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
                                goto out;
                        }
 
-                       end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+                       end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                        end = min(pg_end, end_offset - dn.ofs_in_node + index);
 
                        ret = f2fs_do_zero_range(&dn, index, end);
@@ -3133,7 +3129,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
                                goto clear_out;
                        }
 
-                       f2fs_folio_wait_writeback(folio, DATA, true, true);
+                       f2fs_folio_wait_writeback(folio, true, true);
 
                        folio_mark_dirty(folio);
                        folio_set_f2fs_gcing(folio);
@@ -3856,7 +3852,7 @@ static int f2fs_ioc_reserve_dev_alias(struct file *filp)
        f2fs_reserve_device_alias(sbi, ei.blk, ei.len);
 
        i_size_write(inode, (loff_t)ei.len << sbi->log_blocksize);
-       f2fs_update_inode_page(inode);
+       f2fs_update_inode_cache(inode);
 
        spin_lock(&FREE_I(sbi)->segmap_lock);
        FDEV(f2fs_target_device_index(sbi, ei.blk)).is_reserving = false;
@@ -3950,7 +3946,7 @@ static int f2fs_ioc_release_dev_alias(struct file *filp)
                goto out_inode_unlock;
        }
 
-       f2fs_update_inode_page(inode);
+       f2fs_update_inode_cache(inode);
 
        f2fs_unlock_op(sbi, &lc);
        f2fs_up_write_trace(&sbi->gc_lock, &glc);
@@ -4169,7 +4165,7 @@ static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count)
        int i;
 
        for (i = 0; i < count; i++) {
-               blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                dn->ofs_in_node + i);
 
                if (!__is_valid_data_blkaddr(blkaddr))
@@ -4288,7 +4284,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg)
                        break;
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                count = min(end_offset - dn.ofs_in_node, last_idx - page_idx);
                count = round_up(count, fi->i_cluster_size);
 
@@ -4339,7 +4335,7 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count,
        int i;
 
        for (i = 0; i < count; i++) {
-               blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+               blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                dn->ofs_in_node + i);
 
                if (!__is_valid_data_blkaddr(blkaddr))
@@ -4356,7 +4352,7 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count,
                int ret;
 
                for (i = 0; i < cluster_size; i++) {
-                       blkaddr = data_blkaddr(dn->inode, dn->node_folio,
+                       blkaddr = data_blkaddr(dn->inode, dn->node_entry,
                                                dn->ofs_in_node + i);
 
                        if (i == 0) {
@@ -4467,7 +4463,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
                        break;
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                count = min(end_offset - dn.ofs_in_node, last_idx - page_idx);
                count = round_up(count, fi->i_cluster_size);
 
@@ -4633,7 +4629,7 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg)
                        goto out;
                }
 
-               end_offset = ADDRS_PER_PAGE(dn.node_folio, inode);
+               end_offset = ADDRS_PER_PAGE(dn.node_entry, inode);
                count = min(end_offset - dn.ofs_in_node, pg_end - index);
                for (i = 0; i < count; i++, index++, dn.ofs_in_node++) {
                        struct block_device *cur_bdev;
@@ -4829,7 +4825,7 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len)
                /* It will never fail, when folio has pinned above */
                f2fs_bug_on(F2FS_I_SB(inode), IS_ERR(folio));
 
-               f2fs_folio_wait_writeback(folio, DATA, true, true);
+               f2fs_folio_wait_writeback(folio, true, true);
 
                folio_mark_dirty(folio);
                folio_set_f2fs_gcing(folio);
fs/f2fs/gc.c +25 -25
index bed9056d6b6e..a35d15b97d5b 100644
@@ -1054,7 +1054,7 @@ static int gc_node_segment(struct f2fs_sb_info *sbi,
 
        for (off = 0; off < usable_blks_in_seg; off++, entry++) {
                nid_t nid = le32_to_cpu(entry->nid);
-               struct folio *node_folio;
+               struct f2fs_cached_block *node_entry;
                struct node_info ni;
                int err;
 
@@ -1072,32 +1072,32 @@ static int gc_node_segment(struct f2fs_sb_info *sbi,
                }
 
                if (phase == 1) {
-                       f2fs_ra_node_page(sbi, nid);
+                       f2fs_ra_node_cache(sbi, nid);
                        continue;
                }
 
                /* phase == 2 */
-               node_folio = f2fs_get_node_folio(sbi, nid, NODE_TYPE_REGULAR);
-               if (IS_ERR(node_folio))
+               node_entry = f2fs_get_node_cache(sbi, nid, NODE_TYPE_REGULAR);
+               if (IS_ERR(node_entry))
                        continue;
 
                /* block may become invalid during f2fs_get_node_folio */
                if (check_valid_map(sbi, segno, off) == 0) {
-                       f2fs_folio_put(node_folio, true);
+                       f2fs_put_cache(node_entry, true);
                        continue;
                }
 
                if (f2fs_get_node_info(sbi, nid, &ni, false)) {
-                       f2fs_folio_put(node_folio, true);
+                       f2fs_put_cache(node_entry, true);
                        continue;
                }
 
                if (ni.blk_addr != start_addr + off) {
-                       f2fs_folio_put(node_folio, true);
+                       f2fs_put_cache(node_entry, true);
                        continue;
                }
 
-               err = f2fs_move_node_folio(node_folio, gc_type);
+               err = f2fs_move_node_cache(node_entry, gc_type);
                if (!err && gc_type == FG_GC)
                        submitted++;
                stat_inc_node_blk_count(sbi, 1, gc_type);
@@ -1148,7 +1148,7 @@ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode)
 static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
                struct node_info *dni, block_t blkaddr, unsigned int *nofs)
 {
-       struct folio *node_folio;
+       struct f2fs_cached_block *node_entry;
        nid_t nid;
        unsigned int ofs_in_node, max_addrs, base;
        block_t source_blkaddr;
@@ -1156,12 +1156,12 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
        nid = le32_to_cpu(sum->nid);
        ofs_in_node = le16_to_cpu(sum->ofs_in_node);
 
-       node_folio = f2fs_get_node_folio(sbi, nid, NODE_TYPE_REGULAR);
-       if (IS_ERR(node_folio))
+       node_entry = f2fs_get_node_cache(sbi, nid, NODE_TYPE_REGULAR);
+       if (IS_ERR(node_entry))
                return false;
 
        if (f2fs_get_node_info(sbi, nid, dni, false)) {
-               f2fs_folio_put(node_folio, true);
+               f2fs_put_cache(node_entry, true);
                return false;
        }
 
@@ -1172,12 +1172,12 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
        }
 
        if (f2fs_check_nid_range(sbi, dni->ino)) {
-               f2fs_folio_put(node_folio, true);
+               f2fs_put_cache(node_entry, true);
                return false;
        }
 
-       if (IS_INODE(sbi, node_folio)) {
-               base = offset_in_addr(F2FS_INODE(node_folio));
+       if (IS_INODE(sbi, node_entry)) {
+               base = offset_in_addr(F2FS_INODE(node_entry));
                max_addrs = DEF_ADDRS_PER_INODE(sbi);
        } else {
                base = 0;
@@ -1187,13 +1187,13 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
        if (base + ofs_in_node >= max_addrs) {
                f2fs_err(sbi, "Inconsistent blkaddr offset: base:%u, ofs_in_node:%u, max:%u, ino:%u, nid:%u",
                        base, ofs_in_node, max_addrs, dni->ino, dni->nid);
-               f2fs_folio_put(node_folio, true);
+               f2fs_put_cache(node_entry, true);
                return false;
        }
 
-       *nofs = ofs_of_node(sbi, node_folio);
-       source_blkaddr = data_blkaddr(NULL, node_folio, ofs_in_node);
-       f2fs_folio_put(node_folio, true);
+       *nofs = ofs_of_node(sbi, node_entry);
+       source_blkaddr = data_blkaddr(NULL, node_entry, ofs_in_node);
+       f2fs_put_cache(node_entry, true);
 
        if (source_blkaddr != blkaddr) {
 #ifdef CONFIG_F2FS_CHECK_FS
@@ -1285,7 +1285,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
         * don't cache encrypted data into meta inode until previous dirty
         * data were writebacked to avoid racing between GC and flush.
         */
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
 
        f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
 
@@ -1396,7 +1396,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
         * don't cache encrypted data into meta inode until previous dirty
         * data were writebacked to avoid racing between GC and flush.
         */
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
 
        f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);
 
@@ -1445,7 +1445,7 @@ static int move_data_block(struct inode *inode, block_t bidx,
        set_summary(&sum, dn.nid, dn.ofs_in_node, ni.version);
 
        /* allocate block address */
-       err = f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr,
+       err = f2fs_allocate_data_block(fio.sbi, fio.old_blkaddr, &newaddr,
                                &sum, type, NULL);
        if (err) {
                f2fs_put_cache(sentry, true);
@@ -1549,7 +1549,7 @@ static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
                bool is_dirty = folio_test_dirty(folio);
 
 retry:
-               f2fs_folio_wait_writeback(folio, DATA, true, true);
+               f2fs_folio_wait_writeback(folio, true, true);
 
                folio_mark_dirty(folio);
                if (folio_clear_dirty_for_io(folio)) {
@@ -1626,7 +1626,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
                }
 
                if (phase == 1) {
-                       f2fs_ra_node_page(sbi, nid);
+                       f2fs_ra_node_cache(sbi, nid);
                        continue;
                }
 
@@ -1635,7 +1635,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
                        continue;
 
                if (phase == 2) {
-                       f2fs_ra_node_page(sbi, dni.ino);
+                       f2fs_ra_node_cache(sbi, dni.ino);
                        continue;
                }
 
fs/f2fs/inline.c +141 -138
index d10acb5042e3..273b6428c9f9 100644
@@ -34,7 +34,7 @@ bool f2fs_may_inline_data(struct inode *inode)
        return !f2fs_post_read_required(inode);
 }
 
-static bool inode_has_blocks(struct inode *inode, struct folio *ifolio)
+static bool inode_has_blocks(struct inode *inode, struct f2fs_cached_block *ientry)
 {
        int i;
 
@@ -42,18 +42,18 @@ static bool inode_has_blocks(struct inode *inode, struct folio *ifolio)
                return true;
 
        for (i = 0; i < DEF_NIDS_PER_INODE; i++) {
-               if (F2FS_INODE_NIDS(F2FS_I_SB(inode), ifolio)[i])
+               if (F2FS_INODE_NIDS(F2FS_I_SB(inode), ientry)[i])
                        return true;
        }
        return false;
 }
 
-bool f2fs_sanity_check_inline_data(struct inode *inode, struct folio *ifolio)
+bool f2fs_sanity_check_inline_data(struct inode *inode, struct f2fs_cached_block *ientry)
 {
        if (!f2fs_has_inline_data(inode))
                return false;
 
-       if (inode_has_blocks(inode, ifolio))
+       if (inode_has_blocks(inode, ientry))
                return false;
 
        if (!support_inline_data(inode))
@@ -79,7 +79,7 @@ bool f2fs_may_inline_dentry(struct inode *inode)
        return true;
 }
 
-void f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio)
+void f2fs_do_read_inline_data(struct folio *folio, struct f2fs_cached_block *ientry)
 {
        struct inode *inode = folio->mapping->host;
 
@@ -91,13 +91,13 @@ void f2fs_do_read_inline_data(struct folio *folio, struct folio *ifolio)
        folio_zero_segment(folio, MAX_INLINE_DATA(inode), folio_size(folio));
 
        /* Copy the whole inline data block */
-       memcpy_to_folio(folio, 0, inline_data_addr(inode, ifolio),
+       memcpy_to_folio(folio, 0, inline_data_addr(inode, ientry),
                       MAX_INLINE_DATA(inode));
        if (!folio_test_uptodate(folio))
                folio_mark_uptodate(folio);
 }
 
-void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio,
+void f2fs_truncate_inline_inode(struct inode *inode, struct f2fs_cached_block *ientry,
                u64 from)
 {
        void *addr;
@@ -105,11 +105,11 @@ void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio,
        if (from >= MAX_INLINE_DATA(inode))
                return;
 
-       addr = inline_data_addr(inode, ifolio);
+       addr = inline_data_addr(inode, ientry);
 
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       f2fs_cache_wait_writeback(ientry);
        memset(addr + from, 0, MAX_INLINE_DATA(inode) - from);
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 
        if (from == 0)
                clear_inode_flag(inode, FI_DATA_EXIST);
@@ -117,27 +117,27 @@ void f2fs_truncate_inline_inode(struct inode *inode, struct folio *ifolio,
 
 int f2fs_read_inline_data(struct inode *inode, struct folio *folio)
 {
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
 
-       ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-       if (IS_ERR(ifolio)) {
+       ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+       if (IS_ERR(ientry)) {
                folio_unlock(folio);
-               return PTR_ERR(ifolio);
+               return PTR_ERR(ientry);
        }
 
        if (!f2fs_has_inline_data(inode)) {
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return -EAGAIN;
        }
 
        if (folio->index)
                folio_zero_segment(folio, 0, folio_size(folio));
        else
-               f2fs_do_read_inline_data(folio, ifolio);
+               f2fs_do_read_inline_data(folio, ientry);
 
        if (!folio_test_uptodate(folio))
                folio_mark_uptodate(folio);
-       f2fs_folio_put(ifolio, true);
+       f2fs_put_cache(ientry, true);
        folio_unlock(folio);
        return 0;
 }
@@ -185,7 +185,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
 
        f2fs_bug_on(F2FS_F_SB(folio), folio_test_writeback(folio));
 
-       f2fs_do_read_inline_data(folio, dn->inode_folio);
+       f2fs_do_read_inline_data(folio, dn->inode_entry);
        folio_mark_dirty(folio);
 
        /* clear dirty state */
@@ -196,7 +196,7 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
        fio.old_blkaddr = dn->data_blkaddr;
        set_inode_flag(dn->inode, FI_HOT_DATA);
        f2fs_outplace_write_data(dn, &fio);
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
        if (dirty) {
                inode_dec_dirty_pages(dn->inode);
                f2fs_remove_dirty_inode(dn->inode);
@@ -206,8 +206,8 @@ int f2fs_convert_inline_folio(struct dnode_of_data *dn, struct folio *folio)
        set_inode_flag(dn->inode, FI_APPEND_WRITE);
 
        /* clear inline data and flag after data writeback */
-       f2fs_truncate_inline_inode(dn->inode, dn->inode_folio, 0);
-       folio_clear_f2fs_inline(dn->inode_folio);
+       f2fs_truncate_inline_inode(dn->inode, dn->inode_entry, 0);
+       f2fs_cache_clear_inline(dn->inode_entry);
 clear_out:
        stat_dec_inline_inode(dn->inode);
        clear_inode_flag(dn->inode, FI_INLINE_DATA);
@@ -220,7 +220,8 @@ int f2fs_convert_inline_inode(struct inode *inode)
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
        struct dnode_of_data dn;
        struct f2fs_lock_context lc;
-       struct folio *ifolio, *folio;
+       struct f2fs_cached_block *ientry;
+       struct folio *folio;
        int err = 0;
 
        if (f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb))
@@ -239,13 +240,13 @@ int f2fs_convert_inline_inode(struct inode *inode)
 
        f2fs_lock_op(sbi, &lc);
 
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto out;
        }
 
-       set_new_dnode(&dn, inode, ifolio, ifolio, 0);
+       set_new_dnode(&dn, inode, ientry, ientry, 0);
 
        if (f2fs_has_inline_data(inode))
                err = f2fs_convert_inline_folio(&dn, folio);
@@ -265,31 +266,31 @@ int f2fs_convert_inline_inode(struct inode *inode)
 int f2fs_write_inline_data(struct inode *inode, struct folio *folio)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
 
-       ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
        if (!f2fs_has_inline_data(inode)) {
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return -EAGAIN;
        }
 
        f2fs_bug_on(F2FS_I_SB(inode), folio->index);
 
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
-       memcpy_from_folio(inline_data_addr(inode, ifolio),
+       f2fs_cache_wait_writeback(ientry);
+       memcpy_from_folio(inline_data_addr(inode, ientry),
                         folio, 0, MAX_INLINE_DATA(inode));
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 
        f2fs_clear_page_cache_dirty_tag(folio);
 
        set_inode_flag(inode, FI_APPEND_WRITE);
        set_inode_flag(inode, FI_DATA_EXIST);
 
-       folio_clear_f2fs_inline(ifolio);
-       f2fs_folio_put(ifolio, true);
+       f2fs_cache_clear_inline(ientry);
+       f2fs_put_cache(ientry, true);
        return 0;
 }
 
@@ -307,40 +308,41 @@ int f2fs_recover_inline_data(struct inode *inode, struct f2fs_cached_block *entr
         *    x       o  -> remove data blocks, and then recover inline_data
         *    x       x  -> recover data blocks
         */
-       if (IS_INODE(sbi, cache_folio(entry)))
+       if (IS_INODE(F2FS_I_SB(inode), entry))
                ri = &CACHED_NODE(entry)->i;
 
        if (f2fs_has_inline_data(inode) &&
                        ri && (ri->i_inline & F2FS_INLINE_DATA)) {
-               struct folio *ifolio;
+               struct f2fs_cached_block *ientry;
 
 process_inline:
-               ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-               if (IS_ERR(ifolio))
-                       return PTR_ERR(ifolio);
+               ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+               if (IS_ERR(ientry))
+                       return PTR_ERR(ientry);
 
-               f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+               f2fs_cache_wait_writeback(ientry);
 
-               src_addr = inline_data_addr(inode, cache_folio(entry));
-               dst_addr = inline_data_addr(inode, ifolio);
+               src_addr = inline_data_addr(inode, entry);
+               dst_addr = inline_data_addr(inode, ientry);
                memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
 
                set_inode_flag(inode, FI_INLINE_DATA);
                set_inode_flag(inode, FI_DATA_EXIST);
 
-               folio_mark_dirty(ifolio);
-               f2fs_folio_put(ifolio, true);
+               f2fs_mark_cache_dirty(ientry);
+               f2fs_put_cache(ientry, true);
                return 1;
        }
 
        if (f2fs_has_inline_data(inode)) {
-               struct folio *ifolio = f2fs_get_inode_folio(sbi, inode->i_ino);
-               if (IS_ERR(ifolio))
-                       return PTR_ERR(ifolio);
-               f2fs_truncate_inline_inode(inode, ifolio, 0);
+               struct f2fs_cached_block *ientry = f2fs_get_inode_cache(sbi, inode->i_ino);
+
+               if (IS_ERR(ientry))
+                       return PTR_ERR(ientry);
+               f2fs_truncate_inline_inode(inode, ientry, 0);
                stat_dec_inline_inode(inode);
                clear_inode_flag(inode, FI_INLINE_DATA);
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
        } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) {
                int ret;
 
@@ -355,50 +357,50 @@ int f2fs_recover_inline_data(struct inode *inode, struct f2fs_cached_block *entr
 
 struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
                                        const struct f2fs_filename *fname,
-                                       struct folio **res_folio,
+                                       void **dentry_block,
                                        bool use_hash)
 {
        struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
        struct f2fs_dir_entry *de;
        struct f2fs_dentry_ptr d;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        void *inline_dentry;
 
-       ifolio = f2fs_get_inode_folio(sbi, dir->i_ino);
-       if (IS_ERR(ifolio)) {
-               *res_folio = ifolio;
+       ientry = f2fs_get_inode_cache(sbi, dir->i_ino);
+       if (IS_ERR(ientry)) {
+               *dentry_block = ientry;
                return NULL;
        }
 
-       inline_dentry = inline_data_addr(dir, ifolio);
+       inline_dentry = inline_data_addr(dir, ientry);
 
        make_dentry_ptr_inline(dir, &d, inline_dentry);
        de = f2fs_find_target_dentry(&d, fname, NULL, use_hash);
-       folio_unlock(ifolio);
+       f2fs_unlock_cache(ientry);
        if (IS_ERR(de)) {
-               *res_folio = ERR_CAST(de);
+               *dentry_block = ERR_CAST(de);
                de = NULL;
        }
        if (de)
-               *res_folio = ifolio;
+               *dentry_block = f2fs_cache_make_dentry_block(ientry);
        else
-               f2fs_folio_put(ifolio, false);
+               f2fs_put_cache(ientry, false);
 
        return de;
 }
 
 int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
-                                                       struct folio *ifolio)
+                                       struct f2fs_cached_block *ientry)
 {
        struct f2fs_dentry_ptr d;
        void *inline_dentry;
 
-       inline_dentry = inline_data_addr(inode, ifolio);
+       inline_dentry = inline_data_addr(inode, ientry);
 
        make_dentry_ptr_inline(inode, &d, inline_dentry);
        f2fs_do_make_empty_dir(inode, parent, &d);
 
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 
        /* update i_size to MAX_INLINE_DATA */
        if (i_size_read(inode) < MAX_INLINE_DATA(inode))
@@ -410,8 +412,9 @@ int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
  * NOTE: ipage is grabbed by caller, but if any error occurs, we should
  * release ipage in this function.
  */
-static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
-                                                       void *inline_dentry)
+static int f2fs_move_inline_dirents(struct inode *dir,
+                       struct f2fs_cached_block *ientry,
+                       void *inline_dentry)
 {
        struct folio *folio;
        struct dnode_of_data dn;
@@ -421,11 +424,11 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
 
        folio = f2fs_grab_cache_folio(dir->i_mapping, 0, true);
        if (IS_ERR(folio)) {
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return PTR_ERR(folio);
        }
 
-       set_new_dnode(&dn, dir, ifolio, NULL, 0);
+       set_new_dnode(&dn, dir, ientry, NULL, 0);
        err = f2fs_reserve_block(&dn, 0);
        if (err)
                goto out;
@@ -441,7 +444,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
                goto out;
        }
 
-       f2fs_folio_wait_writeback(folio, DATA, true, true);
+       f2fs_folio_wait_writeback(folio, true, true);
 
        dentry_blk = folio_address(folio);
 
@@ -464,7 +467,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio,
        folio_mark_dirty(folio);
 
        /* clear inline dir and flag after data writeback */
-       f2fs_truncate_inline_inode(dir, ifolio, 0);
+       f2fs_truncate_inline_inode(dir, ientry, 0);
 
        stat_dec_inline_dir(dir);
        clear_inode_flag(dir, FI_INLINE_DENTRY);
@@ -544,8 +547,8 @@ static int f2fs_add_inline_entries(struct inode *dir, void *inline_dentry)
        return err;
 }
 
-static int f2fs_move_rehashed_dirents(struct inode *dir, struct folio *ifolio,
-                                                       void *inline_dentry)
+static int f2fs_move_rehashed_dirents(struct inode *dir,
+               struct f2fs_cached_block *ientry, void *inline_dentry)
 {
        void *backup_dentry;
        int err;
@@ -553,20 +556,20 @@ static int f2fs_move_rehashed_dirents(struct inode *dir, struct folio *ifolio,
        backup_dentry = f2fs_kmalloc(F2FS_I_SB(dir),
                                MAX_INLINE_DATA(dir), GFP_F2FS_ZERO);
        if (!backup_dentry) {
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
                return -ENOMEM;
        }
 
        memcpy(backup_dentry, inline_dentry, MAX_INLINE_DATA(dir));
-       f2fs_truncate_inline_inode(dir, ifolio, 0);
+       f2fs_truncate_inline_inode(dir, ientry, 0);
 
-       folio_unlock(ifolio);
+       f2fs_unlock_cache(ientry);
 
        err = f2fs_add_inline_entries(dir, backup_dentry);
        if (err)
                goto recover;
 
-       folio_lock(ifolio);
+       f2fs_lock_cache(ientry);
 
        stat_dec_inline_dir(dir);
        clear_inode_flag(dir, FI_INLINE_DENTRY);
@@ -582,31 +585,31 @@ static int f2fs_move_rehashed_dirents(struct inode *dir, struct folio *ifolio,
        kfree(backup_dentry);
        return 0;
 recover:
-       folio_lock(ifolio);
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       f2fs_lock_cache(ientry);
+       f2fs_cache_wait_writeback(ientry);
        memcpy(inline_dentry, backup_dentry, MAX_INLINE_DATA(dir));
        f2fs_i_depth_write(dir, 0);
        f2fs_i_size_write(dir, MAX_INLINE_DATA(dir));
-       folio_mark_dirty(ifolio);
-       f2fs_folio_put(ifolio, true);
+       f2fs_mark_cache_dirty(ientry);
+       f2fs_put_cache(ientry, true);
 
        kfree(backup_dentry);
        return err;
 }
 
-static int do_convert_inline_dir(struct inode *dir, struct folio *ifolio,
-                                                       void *inline_dentry)
+static int do_convert_inline_dir(struct inode *dir,
+               struct f2fs_cached_block *ientry, void *inline_dentry)
 {
        if (!F2FS_I(dir)->i_dir_level)
-               return f2fs_move_inline_dirents(dir, ifolio, inline_dentry);
+               return f2fs_move_inline_dirents(dir, ientry, inline_dentry);
        else
-               return f2fs_move_rehashed_dirents(dir, ifolio, inline_dentry);
+               return f2fs_move_rehashed_dirents(dir, ientry, inline_dentry);
 }
 
 int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        struct f2fs_filename fname;
        struct f2fs_lock_context lc;
        void *inline_dentry = NULL;
@@ -621,22 +624,22 @@ int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry)
        if (err)
                goto out;
 
-       ifolio = f2fs_get_inode_folio(sbi, dir->i_ino);
-       if (IS_ERR(ifolio)) {
-               err = PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, dir->i_ino);
+       if (IS_ERR(ientry)) {
+               err = PTR_ERR(ientry);
                goto out_fname;
        }
 
-       if (f2fs_has_enough_room(dir, ifolio, &fname)) {
-               f2fs_folio_put(ifolio, true);
+       if (f2fs_has_enough_room(dir, ientry, &fname)) {
+               f2fs_put_cache(ientry, true);
                goto out_fname;
        }
 
-       inline_dentry = inline_data_addr(dir, ifolio);
+       inline_dentry = inline_data_addr(dir, ientry);
 
-       err = do_convert_inline_dir(dir, ifolio, inline_dentry);
+       err = do_convert_inline_dir(dir, ientry, inline_dentry);
        if (!err)
-               f2fs_folio_put(ifolio, true);
+               f2fs_put_cache(ientry, true);
 out_fname:
        f2fs_free_filename(&fname);
 out:
@@ -648,24 +651,24 @@ int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
                          struct inode *inode, nid_t ino, umode_t mode)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        unsigned int bit_pos;
        void *inline_dentry = NULL;
        struct f2fs_dentry_ptr d;
        int slots = GET_DENTRY_SLOTS(fname->disk_name.len);
-       struct folio *folio = NULL;
+       struct f2fs_cached_block *nentry = NULL;
        int err = 0;
 
-       ifolio = f2fs_get_inode_folio(sbi, dir->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(sbi, dir->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
-       inline_dentry = inline_data_addr(dir, ifolio);
+       inline_dentry = inline_data_addr(dir, ientry);
        make_dentry_ptr_inline(dir, &d, inline_dentry);
 
        bit_pos = f2fs_room_for_filename(d.bitmap, slots, d.max);
        if (bit_pos >= d.max) {
-               err = do_convert_inline_dir(dir, ifolio, inline_dentry);
+               err = do_convert_inline_dir(dir, ientry, inline_dentry);
                if (err)
                        return err;
                err = -EAGAIN;
@@ -675,19 +678,19 @@ int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
        if (inode) {
                f2fs_down_write_nested(&F2FS_I(inode)->i_sem,
                                                SINGLE_DEPTH_NESTING);
-               folio = f2fs_init_inode_metadata(inode, dir, fname, ifolio);
-               if (IS_ERR(folio)) {
-                       err = PTR_ERR(folio);
+               nentry = f2fs_init_inode_metadata(inode, dir, fname, ientry);
+               if (IS_ERR(nentry)) {
+                       err = PTR_ERR(nentry);
                        goto fail;
                }
        }
 
-       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+       f2fs_cache_wait_writeback(ientry);
 
        f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash,
                           bit_pos);
 
-       folio_mark_dirty(ifolio);
+       f2fs_mark_cache_dirty(ientry);
 
        /* we don't need to mark_inode_dirty now */
        if (inode) {
@@ -695,9 +698,9 @@ int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
 
                /* synchronize inode page's data from inode cache */
                if (is_inode_flag_set(inode, FI_NEW_INODE))
-                       f2fs_update_inode(inode, folio);
+                       f2fs_update_inode(inode, nentry);
 
-               f2fs_folio_put(folio, true);
+               f2fs_put_cache(nentry, true);
        }
 
        f2fs_update_parent_metadata(dir, inode, 0);
@@ -705,12 +708,12 @@ int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
        if (inode)
                f2fs_up_write(&F2FS_I(inode)->i_sem);
 out:
-       f2fs_folio_put(ifolio, true);
+       f2fs_put_cache(ientry, true);
        return err;
 }
 
 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
-               struct folio *folio, struct inode *dir, struct inode *inode)
+               struct f2fs_cached_block *ientry, struct inode *dir, struct inode *inode)
 {
        struct f2fs_dentry_ptr d;
        void *inline_dentry;
@@ -718,18 +721,18 @@ void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
        unsigned int bit_pos;
        int i;
 
-       folio_lock(folio);
-       f2fs_folio_wait_writeback(folio, NODE, true, true);
+       f2fs_lock_cache(ientry);
+       f2fs_cache_wait_writeback(ientry);
 
-       inline_dentry = inline_data_addr(dir, folio);
+       inline_dentry = inline_data_addr(dir, ientry);
        make_dentry_ptr_inline(dir, &d, inline_dentry);
 
        bit_pos = dentry - d.dentry;
        for (i = 0; i < slots; i++)
                __clear_bit_le(bit_pos + i, d.bitmap);
 
-       folio_mark_dirty(folio);
-       f2fs_folio_put(folio, true);
+       f2fs_mark_cache_dirty(ientry);
+       f2fs_put_cache(ientry, true);
 
        inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
        f2fs_mark_inode_dirty_sync(dir, true);
@@ -741,21 +744,21 @@ void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
 bool f2fs_empty_inline_dir(struct inode *dir)
 {
        struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        unsigned int bit_pos = 2;
        void *inline_dentry;
        struct f2fs_dentry_ptr d;
 
-       ifolio = f2fs_get_inode_folio(sbi, dir->i_ino);
-       if (IS_ERR(ifolio))
+       ientry = f2fs_get_inode_cache(sbi, dir->i_ino);
+       if (IS_ERR(ientry))
                return false;
 
-       inline_dentry = inline_data_addr(dir, ifolio);
+       inline_dentry = inline_data_addr(dir, ientry);
        make_dentry_ptr_inline(dir, &d, inline_dentry);
 
        bit_pos = find_next_bit_le(d.bitmap, d.max, bit_pos);
 
-       f2fs_folio_put(ifolio, true);
+       f2fs_put_cache(ientry, true);
 
        if (bit_pos < d.max)
                return false;
@@ -767,7 +770,7 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
                                struct fscrypt_str *fstr)
 {
        struct inode *inode = file_inode(file);
-       struct folio *ifolio = NULL;
+       struct f2fs_cached_block *ientry = NULL;
        struct f2fs_dentry_ptr d;
        void *inline_dentry = NULL;
        int err;
@@ -777,17 +780,17 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
        if (ctx->pos == d.max)
                return 0;
 
-       ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
        /*
         * f2fs_readdir was protected by inode.i_rwsem, it is safe to access
         * ipage without page's lock held.
         */
-       folio_unlock(ifolio);
+       f2fs_unlock_cache(ientry);
 
-       inline_dentry = inline_data_addr(inode, ifolio);
+       inline_dentry = inline_data_addr(inode, ientry);
 
        make_dentry_ptr_inline(inode, &d, inline_dentry);
 
@@ -795,7 +798,7 @@ int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
        if (!err)
                ctx->pos = d.max;
 
-       f2fs_folio_put(ifolio, false);
+       f2fs_put_cache(ientry, false);
        return err < 0 ? err : 0;
 }
 
@@ -806,12 +809,12 @@ int f2fs_inline_data_fiemap(struct inode *inode,
        __u32 flags = FIEMAP_EXTENT_DATA_INLINE | FIEMAP_EXTENT_NOT_ALIGNED |
                FIEMAP_EXTENT_LAST;
        struct node_info ni;
-       struct folio *ifolio;
+       struct f2fs_cached_block *ientry;
        int err = 0;
 
-       ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-       if (IS_ERR(ifolio))
-               return PTR_ERR(ifolio);
+       ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+       if (IS_ERR(ientry))
+               return PTR_ERR(ientry);
 
        if ((S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
                                !f2fs_has_inline_data(inode)) {
@@ -825,13 +828,13 @@ int f2fs_inline_data_fiemap(struct inode *inode,
        }
 
        if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC) {
-               err = f2fs_write_single_node_folio(ifolio, true, false, FS_NODE_IO);
+               err = f2fs_write_node_cache(ientry, true, false, FS_NODE_IO);
                if (err)
                        return err;
-               ifolio = f2fs_get_inode_folio(F2FS_I_SB(inode), inode->i_ino);
-               if (IS_ERR(ifolio))
-                       return PTR_ERR(ifolio);
-               f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+               ientry = f2fs_get_inode_cache(F2FS_I_SB(inode), inode->i_ino);
+               if (IS_ERR(ientry))
+                       return PTR_ERR(ientry);
+               f2fs_cache_wait_writeback(ientry);
        }
        ilen = min_t(size_t, MAX_INLINE_DATA(inode), i_size_read(inode));
        if (start >= ilen)
@@ -846,8 +849,8 @@ int f2fs_inline_data_fiemap(struct inode *inode,
 
        if (__is_valid_data_blkaddr(ni.blk_addr)) {
                byteaddr = (__u64)ni.blk_addr << inode->i_sb->s_blocksize_bits;
-               byteaddr += (char *)inline_data_addr(inode, ifolio) -
-                                               (char *)F2FS_INODE(ifolio);
+               byteaddr += (char *)inline_data_addr(inode, ientry) -
+                                               (char *)F2FS_INODE(ientry);
        } else {
                f2fs_bug_on(F2FS_I_SB(inode), ni.blk_addr != NEW_ADDR);
                flags |= FIEMAP_EXTENT_DELALLOC | FIEMAP_EXTENT_UNKNOWN;
@@ -855,6 +858,6 @@ int f2fs_inline_data_fiemap(struct inode *inode,
        err = fiemap_fill_next_extent(fieinfo, start, byteaddr, ilen, flags);
        trace_f2fs_fiemap(inode, start, byteaddr, ilen, flags, err);
 out:
-       f2fs_folio_put(ifolio, true);
+       f2fs_put_cache(ientry, true);
        return err;
 }
fs/f2fs/inode.c +78 -89
index f2e1d8b50f8c..c822ca2dce20 100644
@@ -82,9 +82,9 @@ void f2fs_set_inode_flags(struct inode *inode)
                        S_ENCRYPTED|S_VERITY|S_CASEFOLD);
 }
 
-static void __get_inode_rdev(struct inode *inode, struct folio *node_folio)
+static void __get_inode_rdev(struct inode *inode, struct f2fs_cached_block *ientry)
 {
-       __le32 *addr = get_dnode_addr(inode, node_folio);
+       __le32 *addr = get_dnode_addr(inode, ientry);
 
        if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
                        S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
@@ -95,9 +95,9 @@ static void __get_inode_rdev(struct inode *inode, struct folio *node_folio)
        }
 }
 
-static void __set_inode_rdev(struct inode *inode, struct folio *node_folio)
+static void __set_inode_rdev(struct inode *inode, struct f2fs_cached_block *ientry)
 {
-       __le32 *addr = get_dnode_addr(inode, node_folio);
+       __le32 *addr = get_dnode_addr(inode, ientry);
 
        if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
                if (old_valid_dev(inode->i_rdev)) {
@@ -111,34 +111,33 @@ static void __set_inode_rdev(struct inode *inode, struct folio *node_folio)
        }
 }
 
-static void __recover_inline_status(struct inode *inode, struct folio *ifolio)
+static void __recover_inline_status(struct inode *inode, struct f2fs_cached_block *ientry)
 {
-       void *inline_data = inline_data_addr(inode, ifolio);
+       void *inline_data = inline_data_addr(inode, ientry);
        __le32 *start = inline_data;
        __le32 *end = start + MAX_INLINE_DATA(inode) / sizeof(__le32);
 
        while (start < end) {
                if (*start++) {
-                       f2fs_folio_wait_writeback(ifolio, NODE, true, true);
+                       f2fs_cache_wait_writeback(ientry);
 
                        set_inode_flag(inode, FI_DATA_EXIST);
-                       set_raw_inline(inode, F2FS_INODE(ifolio));
-                       folio_mark_dirty(ifolio);
+                       set_raw_inline(inode, F2FS_INODE(ientry));
+                       f2fs_mark_cache_dirty(ientry);
                        return;
                }
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

fs/f2fs/namei.c +59 -55
index ff86ee07290d..38fcea8b72bf 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/node.c +446 -507
index 197ce2f5149a..1af118858fd1 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/node.h +56 -52
index e37fb0d63120..c8d66ca54e94 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/recovery.c +59 -58
index 93564e532f2f..54b5246609de 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/segment.c +35 -24
index 9d08e762b131..87e24d0306e8 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/segment.h +0 -20
index 3083069c9092..b11461acc520 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/shrinker.c +2 -1
index baa09bc63585..499717cd693c 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/super.c +12 -44
index fa19152cd4da..bf42fbffa348 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/xattr.c +61 -62
index 98059e583b09..4328c9d9de45 100644

Lines of this file are not shown. View the raw message.

fs/f2fs/xattr.h +6 -6
index 75beab2d1ee3..870524b667ed 100644

Lines of this file are not shown. View the raw message.

include/linux/f2fs_fs.h +0 -2
index c325904f461e..ac87446cc086 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

2.49.0

Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Part of the diff is not shown here. View the raw message.