From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBC71606A31A for ; Wed, 2 Dec 2026 14:36:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V2m7zrgv Received: by kanga.kvack.org (Postfix) id DE8156B0640; Wed, 2 Dec 2026 09:36:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D987A6B0641; Wed, 2 Dec 2026 09:36:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CADBF6B0645; Wed, 2 Dec 2026 09:36:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 98F496B0640 for ; Wed, 2 Dec 2026 09:36:42 -0500 (EST) Received: from smtpin10.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 30436120376 for ; Wed, 2 Dec 2026 14:36:42 +0000 (UTC) X-FDA: 85499294244.10.90A9F76 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf28.hostedemail.com (Postfix) with ESMTP id 840EEC000F for ; Wed, 2 Dec 2026 14:36:40 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=V2m7zrgv; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796222200; b=wki+FAESgv1pSfnhkHmK6R9ZkixBGdR30Q3YZ85rjAKykJfV2WEav7upjO/mjy94WZ9LwI A0slO4wMO2awqAUHt2ykpReKrbiMZUpJujRaY6lun9UIL67r0+yFkpR/xDrH5ugwuaJ0XO o8YjkqI/2TZoA6aJDVVMNJOUqKl5vqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796222200; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iOtCHAk7Cvjw0LDNP0GwT7TqRxLrjGmkpZtuSz6l9Sw=; b=YEL7dh57+Lx535+Jw2AYlaWDAV0o4W36gCiqYrlogKmYzGR6tyh5cUkNK2Umlov/bYhrwT mLnC+WytNMsXnmvAiic8NCIbncODH2sL3OtGPKsNvkoJoq+C7qEVfxrzC12GaM5zvQO3sE d14vRiTgTXo5adFLFfv4gV2ihPna6vU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=V2m7zrgv; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 226FA628A1; Wed, 2 Dec 2026 14:36:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DEB71F00893; Wed, 2 Dec 2026 14:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796222199; bh=iOtCHAk7Cvjw0LDNP0GwT7TqRxLrjGmkpZtuSz6l9Sw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=V2m7zrgv3pVvo+y8/0C4tfBn4WqBT+iwR6GK+z/bAmagUnynyV3auZuZv/giWg1hl DYyeBZ5CqC7KLOSwoDyYf1Of3Lv+emVGxZgICHfTB4dKWv3+soO7Fl4Ne52GX68O56 UMABPB/F/c0r3vJwwV/HX3MUzRbik66VuXLIuscCo1Fxkt/1q1GZnR2dJ2fRsGPvCW 8c6q5v572A1PChWGc/LH8QlD+fu1t/c1h2tD3A5YoDeznKboT6AJgwW1XJ3gBKiYJP kmfYyIa8iUL2732TPb3IE9EC5qbK3zPN7dtj/peIyqRXwF0xUglrkt022mkDgpYhap 7aINBEDHw91oQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 3/8] fs: Avoid inode dirtying on last iput Reply-To: sashiko-reviews@lists.linux.dev To: "Jan Kara" , "Christian Brauner" Cc: "Christoph Hellwig" , linux-mm@kvack.org, "Mikhail Rudenko" , "Andreas Gruenbacher" In-Reply-To: <20261201143522.483168-11-jack@suse.cz> References: <20261201105733.18997-1-jack@suse.cz> <20261201143522.483168-11-jack@suse.cz> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 14:36:39 +0000 X-Stat-Signature: x4nf7891eo5b7ehnaiyyy5ewtaoudidc X-Rspamd-Queue-Id: 840EEC000F X-Rspamd-Server: rspam02 X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-HE-Tag: 1796222200-309135 X-HE-Meta: U2FsdGVkX1/09WlHP0OWfouDb+hWFGhLEivvVAFa+qwbjp9niHUxGSdFeXKllvjvNo2TupA74+R+LKVvIDCjudNGxGLTBxiZO80DJMIalJZp0GSxRsU8HfSpt4yYTlUTnAheyHvChbC8wWzGpjxUBZhKTHFdTmqXhPOorLcWCNnDaIlSiV887dia/t2+SEwZmMFHPY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/VAG08eAEHTtSqyPLp5ga5KjLdBf3o43ihl8eGmeJpsQj32f6xPJ71Tg1zs9d4GGvdXDe7bYBdvkRE3QYqwToju4JxyEk6In91xPyCMZKdhF1OZgky8eg6DDXUwNF6ql5S9+poH5cE1ldjgNpTNgPXcB5KPwwUchEnvoAL7bU8iLPU0gWMx2s/UTEiOiIUVE8Tb12Kv7xN69x2pU/O+99vMNHFj4QmN5b9M8jv4nbL8TFc0vnfDrq1F5ysGlkLzAMoPEBJ4bqH4DH2Vkb7LJpjvX68k7nYDFnm1e1jKFQA5AvlERmL7p2184ABa5NlVwa+EThMf/Rhoa/1ImbtqhnRmlhKHECrlZ3D6GcHurUaX80JBp+svgfFrb4ELE9+YDNQa3cpHvAyC/UxfkaHDoYIbLS+9gKhsFu8hyuc9hBZYxd9uh2lKS9YwITy/VNTdqIweDcvCrsPFuktTXd+huWaaqeyLINYpbmswi8zGSiqjwQAMRqUm9OeRzGR/H6CcR75VRnZYzK Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] writeback: missed delayed wakeup for unused inodes on b_dirty_time - [Medium] fs: queue_dirtytime_writeback() queues unhashed and evicted inodes - [Medium] writeback: redirty_tail_locked() puts unused inodes at b_dirty_time head - [Medium] writeback: clobbered dirtied_time_when persists across __mark_inode_dirty() - [Medium] fs: lost lazytime timestamps in iput_final() when drop_inode() returns 1 -- commit 84464a49204ee2cc47ba9c4cc55f3f3c862e495d Author: Jan Kara fs: Avoid inode dirtying on last iput This commit replaces the synchronous sync_lazytime() call in iput() with queue_dirtytime_writeback(), moving unused inodes with dirty timestamps to the head of wb->b_dirty_time with an expired dirtied_time_when timestamp so that periodic writeback flushes them. > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > index ec65ec6e48e7d..44f68a8c146f2 100644 > --- a/fs/fs-writeback.c > +++ b/fs/fs-writeback.c > @@ -1541,6 +1541,24 @@ void sb_clear_inode_writeback(struct inode *inode) > } > } > =20 > +static void inode_add_dirtytime_head(struct inode *inode, > + struct bdi_writeback *wb) > +{ > + unsigned long new_time; > + > + new_time =3D jiffies - dirtytime_expire_interval * HZ; > + if (!list_empty(&wb->b_dirty_time)) { > + struct inode *first =3D wb_inode(wb->b_dirty_time.prev); > + unsigned long first_time =3D READ_ONCE(first->dirtied_time_when); > + > + if (time_before(first_time, new_time)) > + new_time =3D first_time; > + } > + inode->dirtied_when =3D new_time; > + inode->dirtied_time_when =3D new_time; > + list_move_tail(&inode->i_io_list, &wb->b_dirty_time); > +} > + > static void move_to_dirtytime_locked(struct inode *inode, > struct bdi_writeback *wb) > { [Severity: Medium] When writeback skips an unused I_DIRTY_TIME inode and calls redirty_tail() or redirty_tail_locked() (for example when super_trylock_shared() fails in __writeback_inodes_wb() or when writeback_sb_inodes() filters for a different superblock), does calling move_to_dirtytime_locked() -> inode_add_dirtytime_head() put the skipped inode back at the oldest end of wb->b_dirty_time (wb->b_dirty_time.prev) with an expired dirtied_when? On the next iteration of wb_writeback(), queue_io() -> move_expired_inodes() will immediately see the skipped inode as expired and move it back onto wb->b_io, busy-retrying it instead of deferring it to the tail with dirtied_when =3D jiffies. [Severity: Medium] Can clobbering inode->dirtied_time_when to jiffies - dirtytime_expire_interval * HZ here (and in queue_dirtytime_writeback()) leave a permanently expired timestamp on the inode after I_DIRTY_TIME is cleared? Neither sync_lazytime() nor __mark_inode_dirty(inode, I_DIRTY_INODE) resets dirtied_time_when, and __mark_inode_dirty(inode, I_DIRTY_TIME) only updates dirtied_time_when when !was_dirty and !(i_state & I_SYNC_QUEUED): fs/fs-writeback.c:__mark_inode_dirty() { ... if (inode_state_read(inode) & I_SYNC_QUEUED) goto out_unlock; ... if (!was_dirty) { ... inode->dirtied_when =3D jiffies; if (dirtytime) inode->dirtied_time_when =3D jiffies; ... } If the cached inode is reused and has I_DIRTY_PAGES or I_SYNC_QUEUED set when its timestamps are dirtied again, dirtied_time_when retains the clobbered value from hours ago, causing __writeback_single_inode() to call sync_lazytime() immediately on the next data writeback pass. [ ... ] > @@ -2986,6 +3002,50 @@ void __mark_inode_dirty(struct inode *inode, int f= lags) > } > EXPORT_SYMBOL(__mark_inode_dirty); > =20 > +/* > + * If inode has dirty timestamps to write out, make sure flush worker wr= ites > + * them out during its next periodic writeback writeout. > + */ > +void queue_dirtytime_writeback(struct inode *inode) > +{ > + struct bdi_writeback *wb; > + unsigned int i_state; > + > + lockdep_assert_held(&inode->i_lock); > + > + wb =3D locked_inode_to_wb_and_lock_list(inode); > + spin_lock(&inode->i_lock); > + i_state =3D inode_state_read(inode); > + /* Written back while we dropped i_lock? */ > + if (!(i_state & I_DIRTY_TIME)) > + goto out_wb_lock; > + > + /* > + * If the inode is dirty, next writeback will come soon so we don't > + * need to do anything. If it is under writeback, we cannot touch dirty > + * lists now so we handle moving the inode after writeback is complete. > + */ > + if (i_state & (I_SYNC_QUEUED | I_SYNC | I_DIRTY)) { > + /* > + * Clobber dirtied_time_when so that timestamps get synced on > + * next inode writeback. > + */ > + inode->dirtied_time_when =3D jiffies - > + dirtytime_expire_interval * HZ; > + goto out_wb_lock; > + } > + > + /* > + * Move inode to the beginning of dirty queue so that it gets written > + * out during the next periodic writeback. > + */ > + inode_add_dirtytime_head(inode, wb); > + /* Wake up flush worker to ensure timely flush of the inode */ > + wb_wakeup_delayed(wb); > +out_wb_lock: > + spin_unlock(&wb->list_lock); > +} [Severity: Medium] Can an unused inode placed at the head of wb->b_dirty_time miss periodic writeback scheduling and stay off the LRU for up to dirtytime_expire_interval? If queue_dirtytime_writeback() hits the I_SYNC_QUEUED | I_SYNC | I_DIRTY branch while __writeback_single_inode() has already passed its dirtied_time_when check, writeback finishes with I_DIRTY_TIME still set and calls move_to_dirtytime_locked(). For icount_read(inode) =3D=3D 0, move_to_dirtytime_locked() calls inode_add_dirtytime_head() and wb_io_lists_depopulated() (which clears WB_has_dirty_io when b_dirty, b_io and b_more_io are empty) without calling wb_wakeup_delayed(wb). Similarly, even when queue_dirtytime_writeback() calls wb_wakeup_delayed(wb), b_dirty_time does not set WB_has_dirty_io. If wb_workfn() runs before wb->last_old_flush + msecs_to_jiffies(dirty_writeback_interval * 10), wb_check_old_data_flush() returns 0 and wb_workfn() only re-arms wb->dwork if wb_has_dirty_io(wb) is true, leaving wb->b_dirty_time unscheduled until wakeup_dirtytime_writeback= () runs hours later. [Severity: Medium] Can queue_dirtytime_writeback() place unhashed non-blockdev inodes onto wb->b_dirty_time or clobber timestamps on inodes that are still in use or about to be evicted? __mark_inode_dirty() sets I_DIRTY_TIME in i_state before skipping dirty-list insertion for (!S_ISBLK(inode->i_mode) && inode_unhashed(inode)). Because queue_dirtytime_writeback() does not check inode_unhashed(inode), and drops inode->i_lock in locked_inode_to_wb_and_lock_list() without rechecking icount_read(inode) =3D=3D 1 or inode->i_nlink after re-acquiring i_lock, it= will link unhashed inodes onto wb->b_dirty_time and clobber timestamps even if another thread grabbed a reference while i_lock was dropped. It also queues and wakes writeback for I_DONTCACHE or unhashed inodes that iput_final() immediately evicts. > diff --git a/fs/inode.c b/fs/inode.c > index f2003ae753745..4b13125f0678c 100644 > --- a/fs/inode.c > +++ b/fs/inode.c > @@ -2052,7 +2052,6 @@ void iput(struct inode *inode) > if (unlikely(!inode)) > return; > =20 > -retry: > lockdep_assert_not_held(&inode->i_lock); > VFS_BUG_ON_INODE(inode_state_read_once(inode) & (I_FREEING | I_CLEAR), = inode); > /* > @@ -2065,14 +2064,14 @@ void iput(struct inode *inode) > if (atomic_add_unless(&inode->i_count, -1, 1)) > return; > =20 > - if (inode->i_nlink && sync_lazytime(inode)) > - goto retry; > - > spin_lock(&inode->i_lock); > - if (unlikely((inode_state_read(inode) & I_DIRTY_TIME) && inode->i_nlink= )) { > - spin_unlock(&inode->i_lock); > - goto retry; > - } > + /* > + * If inode has timestamp updates pending, queue flushing them now as > + * otherwise the dirtiness could be preventing the inode from entering > + * LRU for hours. > + */ > + if (inode->i_nlink && inode_state_read(inode) & I_DIRTY_TIME) > + queue_dirtytime_writeback(inode); > =20 > if (!atomic_dec_and_test(&inode->i_count)) { > spin_unlock(&inode->i_lock); [Severity: Medium] Can this lose pending lazytime timestamp updates when ->drop_inode() returns 1 on a linked inode? Previously, iput() called sync_lazytime() before iput_final(), invoking ->dirty_inode(inode, I_DIRTY_SYNC | I_DIRTY_TIME). Now I_DIRTY_TIME is only queued on wb->b_dirty_time, and when op->drop_inode(inode) returns 1 in iput_final(), the drop branch skips write_inode_now(inode, 1) and evicts the inode directly: fs/inode.c:iput_final() { ... if (drop) { inode_state_set(inode, I_FREEING); } else { inode_state_set(inode, I_WILL_FREE); spin_unlock(&inode->i_lock); write_inode_now(inode, 1); ... } For example, during unmount of a lazytime gfs2 filesystem, gfs2_kill_sb() -> gfs2_evict_inodes() sets SDF_EVICTING so gfs2_drop_inode() returns 1 for all linked inodes before kill_block_super() runs, and evict_linked_inode() skips writing the inode because gfs2_dirty_inode() was never called to copy the timestamps and set GLF_DIRTY. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201105733.1899= 7-1-jack@suse.cz?part=3D3