linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Josef Bacik <josef@toxicpanda.com>
Cc: linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org,
	 kernel-team@fb.com, linux-ext4@vger.kernel.org,
	linux-xfs@vger.kernel.org,  viro@zeniv.linux.org.uk,
	amir73il@gmail.com
Subject: Re: [PATCH v2 52/54] fs: remove I_REFERENCED
Date: Thu, 28 Aug 2025 14:47:41 +0200	[thread overview]
Message-ID: <20250828-boomen-jagdrevier-885a71cd5080@brauner> (raw)
In-Reply-To: <6e9872dad14133dd05f1142da46d86e456815208.1756222465.git.josef@toxicpanda.com>

On Tue, Aug 26, 2025 at 11:39:52AM -0400, Josef Bacik wrote:
> Because we have referenced inodes on the LRU we've had to change the
> behavior to make sure we remove the inode from the LRU when we reference
> it.

All for this patch but I'm confused by this sentence. Maybe:

"Because inodes must hold a full refcount while on the LRU we've had to
change the behavior to make sure we remove the inode from the LRU when
someone takes another full refcount to it."?

Basically, I_REFERENCED was a way to sidestep the problem that if there
was another access to the inode and it was already on the LRU we had to
do something to acknowledge that.

This is now completely put on it's head by just taking them always off
in such cases and afaict we only do that when we take another full
reference (or I guess when it's actually evicted).

> 
> We do this to account for the fact that we may end up with an inode on
> the LRU list, and then unlink the inode. We want the last iput() in the
> unlink() to actually evict the inode ideally, so we don't want it to
> stick around on the LRU and be evicted that way.
> 
> With that behavior change we no longer need I_REFERENCED, as we're
> always removing the inode from the LRU list on a subsequent access if
> it's on the LRU.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/inode.c                       | 36 +++++++-------------------------
>  include/linux/fs.h               | 22 +++++++++----------
>  include/trace/events/writeback.h |  1 -
>  3 files changed, 17 insertions(+), 42 deletions(-)
> 
> diff --git a/fs/inode.c b/fs/inode.c
> index 8f61761ca021..4f77db7aca75 100644
> --- a/fs/inode.c
> +++ b/fs/inode.c
> @@ -591,7 +591,12 @@ static bool inode_del_cached_lru(struct inode *inode)
>  	return false;
>  }
>  
> -static void __inode_add_lru(struct inode *inode, bool rotate)
> +/*
> + * Add inode to LRU if needed (inode is unused and clean).
> + *
> + * Needs inode->i_lock held.
> + */
> +void inode_add_lru(struct inode *inode)
>  {
>  	bool need_ref = true;
>  
> @@ -614,8 +619,6 @@ static void __inode_add_lru(struct inode *inode, bool rotate)
>  		if (need_ref)
>  			__iget(inode);
>  		this_cpu_inc(nr_unused);
> -	} else if (rotate) {
> -		inode->i_state |= I_REFERENCED;
>  	}
>  }
>  
> @@ -630,16 +633,6 @@ struct wait_queue_head *inode_bit_waitqueue(struct wait_bit_queue_entry *wqe,
>  }
>  EXPORT_SYMBOL(inode_bit_waitqueue);
>  
> -/*
> - * Add inode to LRU if needed (inode is unused and clean).
> - *
> - * Needs inode->i_lock held.
> - */
> -void inode_add_lru(struct inode *inode)
> -{
> -	__inode_add_lru(inode, false);
> -}
> -
>  /*
>   * Caller must be holding it's own i_count reference on this inode in order to
>   * prevent this being the final iput.
> @@ -1001,14 +994,6 @@ EXPORT_SYMBOL_GPL(evict_inodes);
>  
>  /*
>   * Isolate the inode from the LRU in preparation for freeing it.
> - *
> - * If the inode has the I_REFERENCED flag set, then it means that it has been
> - * used recently - the flag is set in iput_final(). When we encounter such an
> - * inode, clear the flag and move it to the back of the LRU so it gets another
> - * pass through the LRU before it gets reclaimed. This is necessary because of
> - * the fact we are doing lazy LRU updates to minimise lock contention so the
> - * LRU does not have strict ordering. Hence we don't want to reclaim inodes
> - * with this flag set because they are the inodes that are out of order.
>   */
>  static enum lru_status inode_lru_isolate(struct list_head *item,
>  		struct list_lru_one *lru, void *arg)
> @@ -1039,13 +1024,6 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
>  		return LRU_REMOVED;
>  	}
>  
> -	/* Recently referenced inodes get one more pass */
> -	if (inode->i_state & I_REFERENCED) {
> -		inode->i_state &= ~I_REFERENCED;
> -		spin_unlock(&inode->i_lock);
> -		return LRU_ROTATE;
> -	}
> -
>  	/*
>  	 * On highmem systems, mapping_shrinkable() permits dropping
>  	 * page cache in order to free up struct inodes: lowmem might
> @@ -1995,7 +1973,7 @@ static bool maybe_add_lru(struct inode *inode, bool skip_lru)
>  	if (!(sb->s_flags & SB_ACTIVE))
>  		return drop;
>  
> -	__inode_add_lru(inode, true);
> +	inode_add_lru(inode);
>  	return drop;
>  }
>  
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 2a7e7fc96431..39cde53c1b3b 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -715,7 +715,6 @@ is_uncached_acl(struct posix_acl *acl)
>   *			address once it is done. The bit is also used to pin
>   *			the inode in memory for flusher thread.
>   *
> - * I_REFERENCED		Marks the inode as recently references on the LRU list.
>   *
>   * I_WB_SWITCH		Cgroup bdi_writeback switching in progress.  Used to
>   *			synchronize competing switching instances and to tell
> @@ -764,17 +763,16 @@ enum inode_state_flags_t {
>  	I_DIRTY_DATASYNC	= (1U << 4),
>  	I_DIRTY_PAGES		= (1U << 5),
>  	I_CLEAR			= (1U << 6),
> -	I_REFERENCED		= (1U << 7),
> -	I_LINKABLE		= (1U << 8),
> -	I_DIRTY_TIME		= (1U << 9),
> -	I_WB_SWITCH		= (1U << 10),
> -	I_OVL_INUSE		= (1U << 11),
> -	I_CREATING		= (1U << 12),
> -	I_DONTCACHE		= (1U << 13),
> -	I_SYNC_QUEUED		= (1U << 14),
> -	I_PINNING_NETFS_WB	= (1U << 15),
> -	I_LRU			= (1U << 16),
> -	I_CACHED_LRU		= (1U << 17)
> +	I_LINKABLE		= (1U << 7),
> +	I_DIRTY_TIME		= (1U << 8),
> +	I_WB_SWITCH		= (1U << 9),
> +	I_OVL_INUSE		= (1U << 10),
> +	I_CREATING		= (1U << 11),
> +	I_DONTCACHE		= (1U << 12),
> +	I_SYNC_QUEUED		= (1U << 13),
> +	I_PINNING_NETFS_WB	= (1U << 14),
> +	I_LRU			= (1U << 15),
> +	I_CACHED_LRU		= (1U << 16)
>  };
>  
>  #define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
> diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
> index 58ee61f3d91d..b419b8060dda 100644
> --- a/include/trace/events/writeback.h
> +++ b/include/trace/events/writeback.h
> @@ -18,7 +18,6 @@
>  		{I_CLEAR,		"I_CLEAR"},		\
>  		{I_SYNC,		"I_SYNC"},		\
>  		{I_DIRTY_TIME,		"I_DIRTY_TIME"},	\
> -		{I_REFERENCED,		"I_REFERENCED"},	\
>  		{I_LINKABLE,		"I_LINKABLE"},		\
>  		{I_WB_SWITCH,		"I_WB_SWITCH"},		\
>  		{I_OVL_INUSE,		"I_OVL_INUSE"},		\
> -- 
> 2.49.0
> 

  reply	other threads:[~2025-08-28 12:47 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-26 15:39 [PATCH v2 00/54] fs: rework inode reference counting Josef Bacik
2025-08-26 15:39 ` [PATCH v2 01/54] fs: make the i_state flags an enum Josef Bacik
2025-08-26 15:39 ` [PATCH v2 02/54] fs: add an icount_read helper Josef Bacik
2025-08-26 22:18   ` Mateusz Guzik
2025-08-27 11:25   ` (subset) " Christian Brauner
2025-08-26 15:39 ` [PATCH v2 03/54] fs: rework iput logic Josef Bacik
2025-08-27 12:58   ` Mateusz Guzik
2025-08-27 14:18     ` Mateusz Guzik
2025-08-27 14:54       ` Josef Bacik
2025-08-27 14:57       ` Christian Brauner
2025-08-27 16:24         ` [PATCH] fs: revamp iput() Mateusz Guzik
2025-08-30 15:54           ` Mateusz Guzik
2025-09-01  8:50             ` Jan Kara
2025-09-01 10:39               ` Christian Brauner
2025-09-01 10:41             ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 04/54] fs: add an i_obj_count refcount to the inode Josef Bacik
2025-08-26 15:39 ` [PATCH v2 05/54] fs: hold an i_obj_count reference in wait_sb_inodes Josef Bacik
2025-08-26 15:39 ` [PATCH v2 06/54] fs: hold an i_obj_count reference for the i_wb_list Josef Bacik
2025-08-26 15:39 ` [PATCH v2 07/54] fs: hold an i_obj_count reference for the i_io_list Josef Bacik
2025-08-26 15:39 ` [PATCH v2 08/54] fs: hold an i_obj_count reference in writeback_sb_inodes Josef Bacik
2025-08-26 15:39 ` [PATCH v2 09/54] fs: hold an i_obj_count reference while on the hashtable Josef Bacik
2025-08-26 15:39 ` [PATCH v2 10/54] fs: hold an i_obj_count reference while on the LRU list Josef Bacik
2025-08-26 15:39 ` [PATCH v2 11/54] fs: hold an i_obj_count reference while on the sb inode list Josef Bacik
2025-08-26 15:39 ` [PATCH v2 12/54] fs: stop accessing ->i_count directly in f2fs and gfs2 Josef Bacik
2025-08-26 15:39 ` [PATCH v2 13/54] fs: hold an i_obj_count when we have an i_count reference Josef Bacik
2025-08-26 15:39 ` [PATCH v2 14/54] fs: add an I_LRU flag to the inode Josef Bacik
2025-08-26 15:39 ` [PATCH v2 15/54] fs: maintain a list of pinned inodes Josef Bacik
2025-08-27 15:20   ` Christian Brauner
2025-08-27 16:07     ` Josef Bacik
2025-08-28  8:24       ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 16/54] fs: delete the inode from the LRU list on lookup Josef Bacik
2025-08-27 21:46   ` Dave Chinner
2025-08-28 11:42     ` Josef Bacik
2025-09-02  4:07       ` Dave Chinner
2025-08-26 15:39 ` [PATCH v2 17/54] fs: remove the inode from the LRU list on unlink/rmdir Josef Bacik
2025-08-27 12:32   ` Christian Brauner
2025-08-27 16:08     ` Josef Bacik
2025-08-27 22:01     ` Dave Chinner
2025-08-28 11:46       ` Josef Bacik
2025-09-02  1:48         ` Dave Chinner
2025-08-28  9:00   ` Christian Brauner
2025-08-28  9:06   ` Christian Brauner
2025-08-28 10:43     ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 18/54] fs: change evict_inodes to use iput instead of evict directly Josef Bacik
2025-08-28 10:18   ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 19/54] fs: hold a full ref while the inode is on a LRU Josef Bacik
2025-08-28 10:51   ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 20/54] fs: disallow 0 reference count inodes Josef Bacik
2025-08-28 11:02   ` Christian Brauner
2025-08-28 11:44     ` Josef Bacik
2025-08-26 15:39 ` [PATCH v2 21/54] fs: make evict_inodes add to the dispose list under the i_lock Josef Bacik
2025-08-26 15:39 ` [PATCH v2 22/54] fs: convert i_count to refcount_t Josef Bacik
2025-08-28 12:00   ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 23/54] fs: use refcount_inc_not_zero in igrab Josef Bacik
2025-08-28 22:08   ` Eric Biggers
2025-08-29 13:42     ` Josef Bacik
2025-08-26 15:39 ` [PATCH v2 24/54] fs: use inode_tryget in find_inode* Josef Bacik
2025-08-26 15:39 ` [PATCH v2 25/54] fs: update find_inode_*rcu to check the i_count count Josef Bacik
2025-08-26 15:39 ` [PATCH v2 26/54] fs: use igrab in insert_inode_locked Josef Bacik
2025-08-28 12:15   ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 27/54] fs: remove I_WILL_FREE|I_FREEING check from __inode_add_lru Josef Bacik
2025-08-26 15:39 ` [PATCH v2 28/54] fs: remove I_WILL_FREE|I_FREEING check in inode_pin_lru_isolating Josef Bacik
2025-08-26 15:39 ` [PATCH v2 29/54] fs: use inode_tryget in evict_inodes Josef Bacik
2025-08-26 15:39 ` [PATCH v2 30/54] fs: change evict_dentries_for_decrypted_inodes to use refcount Josef Bacik
2025-08-28 12:25   ` Christian Brauner
2025-08-28 22:26     ` Eric Biggers
2025-08-29  7:38       ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 31/54] block: use igrab in sync_bdevs Josef Bacik
2025-08-26 15:39 ` [PATCH v2 32/54] bcachefs: use the refcount instead of I_WILL_FREE|I_FREEING Josef Bacik
2025-08-26 15:39 ` [PATCH v2 33/54] btrfs: don't check I_WILL_FREE|I_FREEING Josef Bacik
2025-08-26 15:39 ` [PATCH v2 34/54] fs: use igrab in drop_pagecache_sb Josef Bacik
2025-08-26 15:39 ` [PATCH v2 35/54] fs: stop checking I_FREEING in d_find_alias_rcu Josef Bacik
2025-08-26 15:39 ` [PATCH v2 36/54] ext4: stop checking I_WILL_FREE|IFREEING in ext4_check_map_extents_env Josef Bacik
2025-08-26 15:39 ` [PATCH v2 37/54] fs: remove I_WILL_FREE|I_FREEING from fs-writeback.c Josef Bacik
2025-08-26 15:39 ` [PATCH v2 38/54] gfs2: remove I_WILL_FREE|I_FREEING usage Josef Bacik
2025-08-26 15:39 ` [PATCH v2 39/54] fs: remove I_WILL_FREE|I_FREEING check from dquot.c Josef Bacik
2025-08-28 12:35   ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 40/54] notify: remove I_WILL_FREE|I_FREEING checks in fsnotify_unmount_inodes Josef Bacik
2025-08-26 15:39 ` [PATCH v2 41/54] xfs: remove I_FREEING check Josef Bacik
2025-08-26 15:39 ` [PATCH v2 42/54] landlock: remove I_FREEING|I_WILL_FREE check Josef Bacik
2025-08-26 15:39 ` [PATCH v2 43/54] fs: change inode_is_dirtytime_only to use refcount Josef Bacik
2025-08-26 22:06   ` Mateusz Guzik
2025-08-28 12:38     ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 44/54] btrfs: remove references to I_FREEING Josef Bacik
2025-08-26 15:39 ` [PATCH v2 45/54] ext4: remove reference to I_FREEING in inode.c Josef Bacik
2025-08-26 15:39 ` [PATCH v2 46/54] ext4: remove reference to I_FREEING in orphan.c Josef Bacik
2025-08-26 15:39 ` [PATCH v2 47/54] pnfs: use i_count refcount to determine if the inode is going away Josef Bacik
2025-08-26 15:39 ` [PATCH v2 48/54] fs: remove some spurious I_FREEING references in inode.c Josef Bacik
2025-08-28 12:40   ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 49/54] xfs: remove reference to I_FREEING|I_WILL_FREE Josef Bacik
2025-08-26 15:39 ` [PATCH v2 50/54] ocfs2: do not set I_WILL_FREE Josef Bacik
2025-08-26 15:39 ` [PATCH v2 51/54] fs: remove I_FREEING|I_WILL_FREE Josef Bacik
2025-08-28 12:42   ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 52/54] fs: remove I_REFERENCED Josef Bacik
2025-08-28 12:47   ` Christian Brauner [this message]
2025-08-26 15:39 ` [PATCH v2 53/54] fs: remove I_LRU_ISOLATING flag Josef Bacik
2025-08-28  0:26   ` Dave Chinner
2025-08-28 10:35     ` Christian Brauner
2025-08-26 15:39 ` [PATCH v2 54/54] fs: add documentation explaining the reference count rules for inodes Josef Bacik
2025-08-27  8:03 ` [syzbot ci] Re: fs: rework inode reference counting syzbot ci
2025-08-27 11:14 ` (subset) [PATCH v2 00/54] " Christian Brauner
2025-08-28 12:51 ` Christian Brauner
2025-08-28 21:22   ` Josef Bacik
2025-09-02 10:06 ` Mateusz Guzik
2025-09-02 21:16   ` Josef Bacik

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=20250828-boomen-jagdrevier-885a71cd5080@brauner \
    --to=brauner@kernel.org \
    --cc=amir73il@gmail.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).