Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796135737; b=Nx8H49EK61beDb19NLmzSjZapQ+ceX6NuX7AnVriCU2vHHbBMlhVSrsI+e+TW8xrN64D 9GITwe+Vl6RyNZh25nX6ZOcYblYvyChezhP2h39LRyFLOWnsCcHsqRL1/NKqxhNOuUhTI 0PCZQS9eN0tDqxNoks8/l5VtbGBWa3BEMtnU0fYmchANiMEPDyIgLZsw0hLOv7RwaD7LC 1y/5GWrdE15oqkhOm7oWulB20LFFZrU8vDupy82+Bay1a+a1KxfOddz26nq+Awn6RXKVb RLNof1uQyCbabAFgPUX6472K1SGAUqx9/RPj02JHIOuBh6v/cSk/IrlSJUqg5Q6q5wA== 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-Queue-Id: X-Rspamd-Pre-Result:X-Rspamd-Action:X-Rspamd-Server:X-Spam-Level: X-Spamd-Result:X-Spam-Flag:X-Spam-Score; bh=AuPY6JU7oib2B7eIBBihTTAwyyTcJ+CpBfm6TG62B7A=; b=E4YCsNt51/K1nji57saAVUClCRhxnMG7HsYt8IHv+v5d610Ox80rR76CyEpgE6qlSBag MDxG9CcjICnOVrIfCGBhCtggKMrM0EkJvLEPs+xNAXyvNOJzWZZeSLv/MSIjv6hzfToJr Lmbz//0V83xh1EyZ8aNm9Wy1UK4tMjnQEsxX2gp1b3WZecFPrKrsOt35ioW7EF57l8LQs TiwDCyprqboYf0Lm9PgX3KU38AHtwhXfo+bDa4A05eCSndJcF2HZJiexwYtZBo8TOzQxA ZUSKBfMKqfdRHAWLQ4MfL7gGRxJZfL0PMb6vv240m5LQm8JsmkCsyBFJsXxFDg+ex0Q== 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=KeS14ekI; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Zp0l+vZe; arc=none smtp.remote-ip=195.135.223.131 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 AD332606A333 for ; Tue, 1 Dec 2026 14:35:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AD332606A333 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=KeS14ekI; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Zp0l+vZe 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-out2.suse.de (Postfix) with ESMTPS id 0BD5A1F76B; Tue, 1 Dec 2026 14:35:34 +0000 (UTC) Authentication-Results: smtp-out2.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=AuPY6JU7oib2B7eIBBihTTAwyyTcJ+CpBfm6TG62B7A=; b=KeS14ekInsq6lASYn6/CMW3xwgfNP8u8qZxPNt/S8TxGuYarvOnKcahnOwnAeTCRUlrsfB faIkoQwQhgm1/8t5zHpiWUJRnLWtsFkJ5XN7n2m8kja6U9gJroOc1C8piEYYtIVz+W9w4W Tc8NKV8avAOwDh4jc/o5x1YRYvhlC/I= 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=AuPY6JU7oib2B7eIBBihTTAwyyTcJ+CpBfm6TG62B7A=; b=Zp0l+vZegRbgYZfsupYWWddTK/izc7LgpUjIyT0ASgAjmetn8dzTfWAQP7QH0IeAIQq5Mx aODh3yAwyWME3rBw== 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 ABD681352B; 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 p3knIjXbDmv2VAAAD6G6ig (envelope-from ); Tue, 01 Dec 2026 14:35:33 +0000 Received: by quack.suse.cz (Postfix, from userid 1000) id 0D2275153F; 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 2/8] fs: Fix inode writeback list placement for switched and redirtied inodes Date: Tue, 1 Dec 2026 15:35:04 +0100 Message-ID: <20261201143522.483168-10-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=3886; i=jack@suse.cz; h=from:subject; bh=gEDzytAMDuRNBUrlRluD2lHeySDhLvfQOL6NR/jSrH4=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBrDtsrSW9kHw3u+63iUjUMjkc18vT/ehBFPSicL ZuzrySs94aJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCaw7bKwAKCRCcnaoHP2RA 2UogCADAZ0SA4u683ZU7gr2nLrzutGQVAKtvPcZLaabW3pSihtbjo36PLm59WatVNScENhaMb4D abGJHBMWsMZbzWF7qJVTi8umhsY4QOhJBmcBkDEF6jinCQx0JJ/kmbcX65P6kCkvW0mmk24RT34 KMcd9/EQOtVb0SWnw8E+ig0gODBp1MfmH4m8KPD/2tuyYKWdor1IycoK/HxDzL+cn643staX5Do DG1vXz6eXlgcNqmbw23SRpbkqunYr5AqUB7XJZDe7UKOZySuSmOHB5USdX0mmqi1TPo7lg6wa0/ 04J+6grvZcGGWGksD9Y3/KbppzE+a/8qGQzHLl4JGFOZAOKG X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 0BD5A1F76B X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spam-Level: X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Flag: NO X-Spam-Score: -4.00 inode_switch_wbs() places dirty inodes to b_dirty list even if they have only dirty timestamps. This is somewhat inconsistent and furthermore when writeback runs, it queues such inodes, __writeback_single_inode() does nothing for them (timestamps have not expired yet so they are not synced to the inode) and so their dirtied_when is only clobbered again and now they end up in b_dirty_time list. Similarly redirty_tail_locked() may place inodes with only timestamps dirty to b_dirty list. Fix the code to place such inodes to b_dirty_time list in both cases. Signed-off-by: Jan Kara --- fs/fs-writeback.c | 50 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 65b1af2879e8..ec65ec6e48e7 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -416,6 +416,8 @@ static void bdi_up_write_wb_switch_rwsem(struct backing_dev_info *bdi) up_write(&bdi->wb_switch_rwsem); } +static void redirty_tail_locked(struct inode *inode, struct bdi_writeback *wb); + static bool inode_do_switch_wbs(struct inode *inode, struct bdi_writeback *old_wb, struct bdi_writeback *new_wb) @@ -481,15 +483,12 @@ static bool inode_do_switch_wbs(struct inode *inode, if (inode_state_read(inode) & I_DIRTY_ALL) { /* - * We need to keep b_dirty list sorted by + * We need to keep b_dirty[_time] list sorted by * dirtied_when. However properly sorting the * inode in the list gets too expensive when switching - * many inodes. So just attach inode at the end of the - * dirty list and clobber the dirtied_when. + * many inodes. So just use redirty_tail_locked(). */ - inode->dirtied_when = jiffies; - inode_io_list_move_locked(inode, new_wb, - &new_wb->b_dirty); + redirty_tail_locked(inode, new_wb); } else { inode_cgwb_move_to_attached(inode, new_wb); } @@ -1542,9 +1541,28 @@ void sb_clear_inode_writeback(struct inode *inode) } } +static void move_to_dirtytime_locked(struct inode *inode, + struct bdi_writeback *wb) +{ + /* If the inode is used, move it to the tail of b_dirty_time list */ + if (icount_read(inode)) { + inode->dirtied_when = jiffies; + inode_io_list_move_locked(inode, wb, &wb->b_dirty_time); + return; + } + + /* + * Inode is not used. Expedite writeback by moving it to the head + * of b_dirty_time list so that it can enter LRU and be evicted. + */ + inode_add_dirtytime_head(inode, wb); + wb_io_lists_depopulated(wb); +} + /* * Redirty an inode: set its when-it-was dirtied timestamp and move it to the - * furthest end of its superblock's dirty-inode list. + * furthest end of its wb's dirty list or dirty_time list if only timestamps + * are dirty. * * Before stamping the inode's ->dirtied_when, we check to see whether it is * already the most-recently-dirtied inode on the b_dirty list. If that is @@ -1566,14 +1584,20 @@ static void redirty_tail_locked(struct inode *inode, struct bdi_writeback *wb) wb_io_lists_depopulated(wb); return; } - if (!list_empty(&wb->b_dirty)) { - struct inode *tail; - tail = wb_inode(wb->b_dirty.next); - if (time_before(inode->dirtied_when, tail->dirtied_when)) - inode->dirtied_when = jiffies; + if (inode_state_read(inode) & I_DIRTY) { + if (!list_empty(&wb->b_dirty)) { + struct inode *tail; + + tail = wb_inode(wb->b_dirty.next); + if (time_before(inode->dirtied_when, + tail->dirtied_when)) + inode->dirtied_when = jiffies; + } + inode_io_list_move_locked(inode, wb, &wb->b_dirty); + } else { + move_to_dirtytime_locked(inode, wb); } - inode_io_list_move_locked(inode, wb, &wb->b_dirty); } static void redirty_tail(struct inode *inode, struct bdi_writeback *wb) -- 2.53.0