Linux EXT4 FS development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: tytso@mit.edu
Cc: miklos@szeredi.hu, neal@gompa.dev, linux-fsdevel@vger.kernel.org,
	linux-ext4@vger.kernel.org, John@groves.net, bernd@bsbernd.com,
	joannelkoong@gmail.com
Subject: [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses
Date: Mon, 15 Sep 2025 18:07:36 -0700	[thread overview]
Message-ID: <175798162906.391868.12371905303539413042.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <175798162827.391868.5088762964182041258.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

If a buffer is hot enough to survive more than 50 access without being
reclaimed, bump its priority to the next MRU so it sticks around longer.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 lib/support/cache.h   |    1 +
 lib/support/cache.c   |   16 ++++++++++++++++
 lib/support/iocache.c |    9 +++++++++
 3 files changed, 26 insertions(+)


diff --git a/lib/support/cache.h b/lib/support/cache.h
index f482948a3b6331..5a8e19f5d18e78 100644
--- a/lib/support/cache.h
+++ b/lib/support/cache.h
@@ -173,5 +173,6 @@ int cache_node_purge(struct cache *, cache_key_t, struct cache_node *);
 void cache_report(FILE *fp, const char *, struct cache *);
 int cache_overflowed(struct cache *);
 struct cache_node *cache_node_grab(struct cache *cache, struct cache_node *node);
+void cache_node_bump_priority(struct cache *cache, struct cache_node *node);
 
 #endif	/* __CACHE_H__ */
diff --git a/lib/support/cache.c b/lib/support/cache.c
index 7e1ddc3cc8788d..34df5cb51cd5e4 100644
--- a/lib/support/cache.c
+++ b/lib/support/cache.c
@@ -649,6 +649,22 @@ cache_node_put(
 		cache_shrink(cache);
 }
 
+/* Bump the priority of a cache node.  Caller must hold cn_mutex. */
+void
+cache_node_bump_priority(
+	struct cache		*cache,
+	struct cache_node	*node)
+{
+	int			*priop;
+
+	if (node->cn_priority == CACHE_DIRTY_PRIORITY)
+		priop = &node->cn_old_priority;
+	else
+		priop = &node->cn_priority;
+	if (*priop < CACHE_MAX_PRIORITY)
+		(*priop)++;
+}
+
 void
 cache_node_set_priority(
 	struct cache *		cache,
diff --git a/lib/support/iocache.c b/lib/support/iocache.c
index ab879e85d18f2a..92d88331bfa54d 100644
--- a/lib/support/iocache.c
+++ b/lib/support/iocache.c
@@ -56,6 +56,7 @@ struct iocache_buf {
 	blk64_t			block;
 	void			*buf;
 	errcode_t		write_error;
+	uint8_t			access;
 	unsigned int		uptodate:1;
 	unsigned int		dirty:1;
 };
@@ -552,6 +553,10 @@ static errcode_t iocache_read_blk64(io_channel channel,
 		}
 		if (ubuf->uptodate)
 			memcpy(buf, ubuf->buf, channel->block_size);
+		if (++ubuf->access > 50) {
+			cache_node_bump_priority(&data->cache, node);
+			ubuf->access = 0;
+		}
 		iocache_buf_unlock(ubuf);
 		cache_node_put(&data->cache, node);
 		if (retval)
@@ -613,6 +618,10 @@ static errcode_t iocache_write_blk64(io_channel channel,
 				     ubuf->uptodate ? CACHE_HIT : CACHE_MISS);
 		ubuf->dirty = 1;
 		ubuf->uptodate = 1;
+		if (++ubuf->access > 50) {
+			cache_node_bump_priority(&data->cache, node);
+			ubuf->access = 0;
+		}
 		iocache_buf_unlock(ubuf);
 		cache_node_put(&data->cache, node);
 	}


  parent reply	other threads:[~2025-09-16  1:07 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-16  0:07 [RFC v5] fuse: containerize ext4 for safer operation Darrick J. Wong
2025-09-16  0:21 ` [PATCHSET 1/9] fuse2fs: upgrade to libfuse 3.17 Darrick J. Wong
2025-09-16  0:49   ` [PATCH 1/4] fuse2fs: bump library version Darrick J. Wong
2025-09-16  0:50   ` [PATCH 2/4] fuse2fs: wrap the fuse_set_feature_flag helper for older libfuse Darrick J. Wong
2025-09-16  0:50   ` [PATCH 3/4] fuse2fs: disable nfs exports Darrick J. Wong
2025-09-16  0:50   ` [PATCH 4/4] fuse2fs: drop fuse 2.x support code Darrick J. Wong
2025-09-16  0:22 ` [PATCHSET RFC v5 2/9] fuse4fs: fork a low level fuse server Darrick J. Wong
2025-09-16  0:50   ` [PATCH 01/21] fuse2fs: separate libfuse3 and fuse2fs detection in configure Darrick J. Wong
2025-09-16  0:51   ` [PATCH 02/21] fuse2fs: start porting fuse2fs to lowlevel libfuse API Darrick J. Wong
2025-09-16  0:51   ` [PATCH 03/21] debian: create new package for fuse4fs Darrick J. Wong
2025-09-16  0:51   ` [PATCH 04/21] fuse4fs: namespace some helpers Darrick J. Wong
2025-09-16  0:51   ` [PATCH 05/21] fuse4fs: convert to low level API Darrick J. Wong
2025-09-16  0:52   ` [PATCH 06/21] libsupport: port the kernel list.h to libsupport Darrick J. Wong
2025-09-16  0:52   ` [PATCH 07/21] libsupport: add a cache Darrick J. Wong
2025-09-16  0:52   ` [PATCH 08/21] cache: disable debugging Darrick J. Wong
2025-09-16  0:53   ` [PATCH 09/21] cache: use modern list iterator macros Darrick J. Wong
2025-09-16  0:53   ` [PATCH 10/21] cache: embed struct cache in the owner Darrick J. Wong
2025-09-16  0:53   ` [PATCH 11/21] cache: pass cache pointer to callbacks Darrick J. Wong
2025-09-16  0:53   ` [PATCH 12/21] cache: pass a private data pointer through cache_walk Darrick J. Wong
2025-09-16  0:54   ` [PATCH 13/21] cache: add a helper to grab a new refcount for a cache_node Darrick J. Wong
2025-09-16  0:54   ` [PATCH 14/21] cache: return results of a cache flush Darrick J. Wong
2025-09-16  0:54   ` [PATCH 15/21] cache: add a "get only if incore" flag to cache_node_get Darrick J. Wong
2025-09-16  0:54   ` [PATCH 16/21] cache: support gradual expansion Darrick J. Wong
2025-09-16  0:55   ` [PATCH 17/21] cache: implement automatic shrinking Darrick J. Wong
2025-09-16  0:55   ` [PATCH 18/21] fuse4fs: add cache to track open files Darrick J. Wong
2025-09-16  0:55   ` [PATCH 19/21] fuse4fs: use the orphaned inode list Darrick J. Wong
2025-09-16  0:55   ` [PATCH 20/21] fuse4fs: implement FUSE_TMPFILE Darrick J. Wong
2025-09-16  0:56   ` [PATCH 21/21] fuse4fs: create incore reverse orphan list Darrick J. Wong
2025-09-16  0:22 ` [PATCHSET RFC v5 3/9] libext2fs: refactoring for fuse2fs iomap support Darrick J. Wong
2025-09-16  0:56   ` [PATCH 01/10] libext2fs: make it possible to extract the fd from an IO manager Darrick J. Wong
2025-09-16  0:56   ` [PATCH 02/10] libext2fs: always fsync the device when flushing the cache Darrick J. Wong
2025-09-16  0:56   ` [PATCH 03/10] libext2fs: always fsync the device when closing the unix IO manager Darrick J. Wong
2025-09-16  0:57   ` [PATCH 04/10] libext2fs: only fsync the unix fd if we wrote to the device Darrick J. Wong
2025-09-16  0:57   ` [PATCH 05/10] libext2fs: invalidate cached blocks when freeing them Darrick J. Wong
2025-09-16  0:57   ` [PATCH 06/10] libext2fs: only flush affected blocks in unix_write_byte Darrick J. Wong
2025-09-16  0:57   ` [PATCH 07/10] libext2fs: allow unix_write_byte when the write would be aligned Darrick J. Wong
2025-09-16  0:58   ` [PATCH 08/10] libext2fs: allow clients to ask to write full superblocks Darrick J. Wong
2025-09-16  0:58   ` [PATCH 09/10] libext2fs: allow callers to disallow I/O to file data blocks Darrick J. Wong
2025-09-16  0:58   ` [PATCH 10/10] libext2fs: add posix advisory locking to the unix IO manager Darrick J. Wong
2025-10-08 22:09     ` Darrick J. Wong
2025-09-16  0:22 ` [PATCHSET RFC v5 4/9] fuse2fs: use fuse iomap data paths for better file I/O performance Darrick J. Wong
2025-09-16  0:58   ` [PATCH 01/17] fuse2fs: implement bare minimum iomap for file mapping reporting Darrick J. Wong
2025-09-16  0:59   ` [PATCH 02/17] fuse2fs: add iomap= mount option Darrick J. Wong
2025-09-16  0:59   ` [PATCH 03/17] fuse2fs: implement iomap configuration Darrick J. Wong
2025-09-16  0:59   ` [PATCH 04/17] fuse2fs: register block devices for use with iomap Darrick J. Wong
2025-09-16  1:00   ` [PATCH 05/17] fuse2fs: implement directio file reads Darrick J. Wong
2025-09-16  1:00   ` [PATCH 06/17] fuse2fs: add extent dump function for debugging Darrick J. Wong
2025-09-16  1:00   ` [PATCH 07/17] fuse2fs: implement direct write support Darrick J. Wong
2025-09-16  1:00   ` [PATCH 08/17] fuse2fs: turn on iomap for pagecache IO Darrick J. Wong
2025-09-16  1:01   ` [PATCH 09/17] fuse2fs: don't zero bytes in punch hole Darrick J. Wong
2025-09-16  1:01   ` [PATCH 10/17] fuse2fs: don't do file data block IO when iomap is enabled Darrick J. Wong
2025-09-16  1:01   ` [PATCH 11/17] fuse2fs: avoid fuseblk mode if fuse-iomap support is likely Darrick J. Wong
2025-09-16  1:01   ` [PATCH 12/17] fuse2fs: enable file IO to inline data files Darrick J. Wong
2025-09-16  1:02   ` [PATCH 13/17] fuse2fs: set iomap-related inode flags Darrick J. Wong
2025-09-16  1:02   ` [PATCH 14/17] fuse2fs: configure block device block size Darrick J. Wong
2025-09-16  1:02   ` [PATCH 15/17] fuse4fs: separate invalidation Darrick J. Wong
2025-09-16  1:02   ` [PATCH 16/17] fuse2fs: implement statx Darrick J. Wong
2025-09-16  1:03   ` [PATCH 17/17] fuse2fs: enable atomic writes Darrick J. Wong
2025-09-16  0:22 ` [PATCHSET RFC v5 5/9] fuse4fs: specify the root node id Darrick J. Wong
2025-09-16  1:03   ` [PATCH 1/1] fuse4fs: don't use inode number translation when possible Darrick J. Wong
2025-09-16  0:23 ` [PATCHSET RFC v5 6/9] fuse2fs: handle timestamps and ACLs correctly when iomap is enabled Darrick J. Wong
2025-09-16  1:03   ` [PATCH 01/10] fuse2fs: add strictatime/lazytime mount options Darrick J. Wong
2025-09-16  1:03   ` [PATCH 02/10] fuse2fs: skip permission checking on utimens when iomap is enabled Darrick J. Wong
2025-09-16  1:04   ` [PATCH 03/10] fuse2fs: let the kernel tell us about acl/mode updates Darrick J. Wong
2025-09-16  1:04   ` [PATCH 04/10] fuse2fs: better debugging for file mode updates Darrick J. Wong
2025-09-16  1:04   ` [PATCH 05/10] fuse2fs: debug timestamp updates Darrick J. Wong
2025-09-16  1:05   ` [PATCH 06/10] fuse2fs: use coarse timestamps for iomap mode Darrick J. Wong
2025-09-16  1:05   ` [PATCH 07/10] fuse2fs: add tracing for retrieving timestamps Darrick J. Wong
2025-09-16  1:05   ` [PATCH 08/10] fuse2fs: enable syncfs Darrick J. Wong
2025-09-16  1:05   ` [PATCH 09/10] fuse2fs: skip the gdt write in op_destroy if syncfs is working Darrick J. Wong
2025-09-16  1:06   ` [PATCH 10/10] fuse2fs: set sync, immutable, and append at file load time Darrick J. Wong
2025-09-16  0:23 ` [PATCHSET RFC v5 7/9] fuse2fs: cache iomap mappings for even better file IO performance Darrick J. Wong
2025-09-16  1:06   ` [PATCH 1/3] fuse2fs: enable caching of iomaps Darrick J. Wong
2025-09-16  1:06   ` [PATCH 2/3] fuse2fs: be smarter about caching iomaps Darrick J. Wong
2025-09-16  1:06   ` [PATCH 3/3] fuse2fs: enable iomap Darrick J. Wong
2025-09-16  0:23 ` [PATCHSET RFC v5 8/9] fuse2fs: improve block and inode caching Darrick J. Wong
2025-09-16  1:07   ` [PATCH 1/6] libsupport: add caching IO manager Darrick J. Wong
2025-09-16  1:07   ` [PATCH 2/6] iocache: add the actual buffer cache Darrick J. Wong
2025-09-16  1:07   ` Darrick J. Wong [this message]
2025-09-16  1:07   ` [PATCH 4/6] fuse2fs: enable caching IO manager Darrick J. Wong
2025-09-16  1:08   ` [PATCH 5/6] fuse2fs: increase inode cache size Darrick J. Wong
2025-09-16  1:08   ` [PATCH 6/6] libext2fs: improve caching for inodes Darrick J. Wong
2025-09-16  0:24 ` [PATCHSET RFC v5 9/9] fuse4fs: run servers as a contained service Darrick J. Wong
2025-09-16  1:08   ` [PATCH 1/4] libext2fs: fix MMP code to work with unixfd IO manager Darrick J. Wong
2025-09-16  1:08   ` [PATCH 2/4] fuse4fs: enable safe service mode Darrick J. Wong
2025-09-16  1:09   ` [PATCH 3/4] fuse4fs: set proc title when in fuse " Darrick J. Wong
2025-09-16  1:09   ` [PATCH 4/4] fuse4fs: set iomap backing device blocksize Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2026-06-25 19:35 [PATCHSET v6 3/4] fuse2fs: improve block and inode caching Darrick J. Wong
2026-06-25 19:40 ` [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses Darrick J. Wong
2026-02-23 23:05 [PATCHSET v7 5/8] fuse2fs: improve block and inode caching Darrick J. Wong
2026-02-23 23:45 ` [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses Darrick J. Wong
2025-10-29  0:42 [PATCHSET v6 5/6] fuse2fs: improve block and inode caching Darrick J. Wong
2025-10-29  1:17 ` [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses Darrick J. Wong
2025-08-21  0:50 [PATCHSET RFC v4 6/6] fuse2fs: improve block and inode caching Darrick J. Wong
2025-08-21  1:24 ` [PATCH 3/6] iocache: bump buffer mru priority every 50 accesses Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=175798162906.391868.12371905303539413042.stgit@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=John@groves.net \
    --cc=bernd@bsbernd.com \
    --cc=joannelkoong@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=neal@gompa.dev \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox