Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796135737; b=24fQYFQNRW6N0WJbH8UhH2JPBtiB2zpRuqA8p4KqC5ly33TMVkwCzAMIeltJYBhG3I5F Ij8rPQtH88Yq6asJqzHifRl65D9+cq/e+dyOH2g1xJqfyXpMCNl+92DoZQaUTCZQPXgZo vB7vOAojnk3Uf5dWv9HCSLMKGrkCxJm8jQbfFE5cSgkGoW5xq/q4RusBo95M/Nlczrm/T XkOaYPQzcOwGH6FQmCuBY5Oa0up/hd9fCY5KsUkqAm2uJ1H3ChPwqfTd6SoQHDZFieJsZ Vhar7bGZa7zcMg0p+LPXuh5IwaVJOjHT4z/3N60URIp4I4bkdc+4Q6sknhSU7dAX1gg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135737; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:Received: Received:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:X-Developer-Signature: X-Developer-Key:Content-Transfer-Encoding:X-Rspamd-Server: X-Spamd-Result:X-Spam-Flag:X-Spam-Score:X-Spam-Level: X-Rspamd-Queue-Id:X-Rspamd-Pre-Result:X-Rspamd-Action; bh=W98QQqP7ASgnzwPsxKXTW4CZYNgtBKy4qUee8d8Hib4=; b=hb3tf7HpOQ5a5io0amX71LuR3tDiGIE7LLEqZTEcULJ0a8CJQ/v/LzSWrnvq2SmUrc8A seGErTxaiJbdQIwJq6tP3EgE06n9XF6deGcVo1kj5WhWPQdBn8S9IXaHXbs6Eq47MGItG Ti6Z1KloU55q1jGq+G2aYO8n34AunF9zNzf2b2rrR2X73ADGJu6BTdwf240pZqHJb5DJR ryc08UHhtHEms+aLYFJK5uKnZ4t7afGf03EgrmTyZ3aZoJhBOYIYcWijbI6G3Lbr/DKtw Be5qhY37h52BlEW4oMP8px0nrXNBPWpWnPC+cQwfHAzfEwdXnR7XaZRdw2hMI9rgTgQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=LrjROdq1; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3cGDdhqr; arc=none smtp.remote-ip=195.135.223.130 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B25E8606A339 for ; Tue, 1 Dec 2026 14:35:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B25E8606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=LrjROdq1; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=3cGDdhqr Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3FC27222AB; Tue, 1 Dec 2026 14:35:34 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1796135734; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W98QQqP7ASgnzwPsxKXTW4CZYNgtBKy4qUee8d8Hib4=; b=LrjROdq1BI9D/+RX3SLQHQrQUArqkiL7u6R40i0lngAXVT97YNR6EeV84HxJi5mEuVhsOz gVmooP9TO9X6faukPGS54vUrRUJ6n7CljpDs19acBXHf4ToR7A2Z/ABvsuxjV4zaj4jhRZ S+8tK0bySF4Xq17M/U5NaiOJmD2tVeA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1796135734; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W98QQqP7ASgnzwPsxKXTW4CZYNgtBKy4qUee8d8Hib4=; b=3cGDdhqrkknGXMj+okui4BWf/ABkZnMeYM9XpjWyMam2t9NzmRPX/AoNvmskSTBU/Acs4Y /jcnImTQD2JJflBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C1463136AF; Tue, 1 Dec 2026 14:35:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4C6gKDXbDmv4VAAAD6G6ig (envelope-from ); Tue, 01 Dec 2026 14:35:33 +0000 Received: by quack.suse.cz (Postfix, from userid 1000) id 12CE751541; Tue, 01 Dec 2026 15:35:33 +0100 (CET) From: Jan Kara To: Christian Brauner Cc: , Christoph Hellwig , , Mikhail Rudenko , Andreas Gruenbacher , Jan Kara Subject: [PATCH v5 3/8] fs: Avoid inode dirtying on last iput Date: Tue, 1 Dec 2026 15:35:05 +0100 Message-ID: <20261201143522.483168-11-jack@suse.cz> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201105733.18997-1-jack@suse.cz> References: <20261201105733.18997-1-jack@suse.cz> X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5938; i=jack@suse.cz; h=from:subject; bh=b5ATDAUL2DnMt4mVA79E341Vv9j2YUj4n5ZffHTQins=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBrDtss/+K6KpvxQIIVJ9qJc3qjyihZU1ib1Kx6t tEat+2JIOGJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCaw7bLAAKCRCcnaoHP2RA 2YW7B/43oFez1MrCviGjLgo+FVrpjLU3yz2EdbqojIMcNuSJLuCp1Bw7xFJDmmtFjr1M1Tc9pOO s7Jq/mqSQc7SvK5xWIAbS2ARsyrJnXTornbdFoWnAeUsnYHdnal8UsQzlbXuD5+ra31dPbU0Yqd hNpHSJk6FbWStxWHNcU8tacqJxwZa8rvgwkq0Vsv3LQH3+J7m09LNkxbMxNepZzJiHABkVYgKdx jMRcCVCJ22rT0cnIeQOLih+JHjdmhi2qge469hytOS18WUyYkikTVDODX31ujGOh8pvWgAaOWyV q4E19sOZvCgVU26URFictcvBpZ0yocoOuSI683LCFiTlaKVk X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 X-Spam-Level: X-Rspamd-Queue-Id: 3FC27222AB X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action When inode has dirtied timestamps, we currently call sync_lazytime() on last iput. This is done because inode with any dirty bit set is not inserted into LRU and dirty timestamps expire only after many (12 by default) hours so these inodes would be sitting outside of LRU aging for a really long time. However this can result in doing IO and consequently GFP_NOFAIL allocations from dentry reclaim making MM complain. Sample trace for ext4 is: prune_dcache_sb shrink_dentry_list __dentry_kill iput sync_lazytime __mark_inode_dirty ext4_dirty_inode __ext4_mark_inode_dirty ext4_reserve_inode_write ext4_get_inode_loc bdev_getblk __filemap_get_folio_mpol Avoid this dirtying on last iput by reshuffling unused inodes to the beginning of b_dirty_time list and clobbering dirtied_time_when instead so that they get written during next periodic writeback. Signed-off-by: Jan Kara --- fs/fs-writeback.c | 68 ++++++++++++++++++++++++++++++++++++++++++++--- fs/inode.c | 15 +++++------ fs/internal.h | 1 + 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index ec65ec6e48e7..44f68a8c146f 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1541,6 +1541,24 @@ void sb_clear_inode_writeback(struct inode *inode) } } +static void inode_add_dirtytime_head(struct inode *inode, + struct bdi_writeback *wb) +{ + unsigned long new_time; + + new_time = jiffies - dirtytime_expire_interval * HZ; + if (!list_empty(&wb->b_dirty_time)) { + struct inode *first = wb_inode(wb->b_dirty_time.prev); + unsigned long first_time = READ_ONCE(first->dirtied_time_when); + + if (time_before(first_time, new_time)) + new_time = first_time; + } + inode->dirtied_when = new_time; + inode->dirtied_time_when = 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) { @@ -1854,8 +1872,7 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb, */ redirty_tail_locked(inode, wb); } else if (inode_state_read(inode) & I_DIRTY_TIME) { - inode->dirtied_when = jiffies; - inode_io_list_move_locked(inode, wb, &wb->b_dirty_time); + move_to_dirtytime_locked(inode, wb); inode_state_clear(inode, I_SYNC_QUEUED); } else { /* The inode is clean. Remove from writeback lists. */ @@ -2096,8 +2113,7 @@ static int writeback_single_inode(struct inode *inode, inode_cgwb_move_to_attached(inode, wb); else if (!(istate & I_SYNC_QUEUED) && !(istate & I_DIRTY)) { WARN_ON_ONCE(!(istate & I_DIRTY_TIME)); - inode->dirtied_when = jiffies; - inode_io_list_move_locked(inode, wb, &wb->b_dirty_time); + move_to_dirtytime_locked(inode, wb); } } @@ -2986,6 +3002,50 @@ void __mark_inode_dirty(struct inode *inode, int flags) } EXPORT_SYMBOL(__mark_inode_dirty); +/* + * If inode has dirty timestamps to write out, make sure flush worker writes + * 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 = locked_inode_to_wb_and_lock_list(inode); + spin_lock(&inode->i_lock); + i_state = 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 = 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); +} + /* * The @s_sync_lock is used to serialise concurrent sync operations * to avoid lock contention problems with concurrent wait_sb_inodes() calls. diff --git a/fs/inode.c b/fs/inode.c index bf9403c32188..a9f757fba23b 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2051,7 +2051,6 @@ void iput(struct inode *inode) if (unlikely(!inode)) return; -retry: lockdep_assert_not_held(&inode->i_lock); VFS_BUG_ON_INODE(inode_state_read_once(inode) & (I_FREEING | I_CLEAR), inode); /* @@ -2064,14 +2063,14 @@ void iput(struct inode *inode) if (atomic_add_unless(&inode->i_count, -1, 1)) return; - 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); if (!atomic_dec_and_test(&inode->i_count)) { spin_unlock(&inode->i_lock); diff --git a/fs/internal.h b/fs/internal.h index 9580afef293e..855a80f4b879 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -222,6 +222,7 @@ bool in_group_or_capable(const struct mnt_idmap *idmap, */ long get_nr_dirty_inodes(void); bool sync_lazytime(struct inode *inode); +void queue_dirtytime_writeback(struct inode *inode); /* * dcache.c -- 2.53.0