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=RBgIIatveuCtdRS8cWzG0ikeMM7OjRvXGSzIfpo2AvgL8fGVJXXFXdQf4xprL5p4tuRm 6x3xn3hP2EEhOpBrRwpaBNvBYBxr1g7dueoF8z8F3DsDXWExDFjkep1Z16RtRVnbDVmm5 qQtJt5lBLCj3LxtYxc1lSDB+fveeq8dU6WELQAarZ2sq/U6V23EpofSrt0G0bqflUJofu IrbygVD0AjOoF/IncTMiC58gE8FunlSH+yLOl9Y1SbsvruhwT6ttx6nABfFpc0/+uTL2O LhU1G0bII+4QdwDAkeEZHn+UmTJl43QmrIQouf80EOQ88dXEYMQfgZiNnGMlYIGNSAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135737; h=DMARC-Filter:Received: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-Pre-Result: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=VqHNRpMmBb6Bj8xpyW6r4He0IHjzmwjAY09SSNXVEvQ=; b=HuaL0xR54tA29NfbQIaY7yRHUwARsHxqBRZpXmrtvcM0aShIcjxFV5mrxxLx17JekUyX NUAAcvUoF4M1eUkC3GEgI3OWHFQArbJnrfxuUJNH7YHaknCK4ZRfai7LQG/BvtGi9dHPF 4ZhKclS96zhNTpZlygt0Yzm8jQL86MviPxGO/stlZ2g7xOJlqX5b9y2HFbD7pU+nCAx6k cla9WVk4sgwofXZIP+LuMvC1mBKkh2mdS1jGyCL6eiz8oMhgwVM8ofEM6IE0cMaDiVXyz IfTOOwpZJC8YHjTvUN3Q7j+m1IcSuWROn0wYWPyam17R8Q4e9oljqrlMiqyrI9pVYmw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; 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 D2465606A31A for ; Tue, 1 Dec 2026 14:35:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D2465606A31A 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 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 4D9DC1F790; Tue, 1 Dec 2026 14:35:35 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none 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 1C7DE137C1; Tue, 1 Dec 2026 14:35:34 +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 rOleODXbDmsHVQAAD6G6ig (envelope-from ); Tue, 01 Dec 2026 14:35:34 +0000 Received: by quack.suse.cz (Postfix, from userid 1000) id 2EDE65154B; 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 8/8] ext4: Defer inode reclaim if it has preallocations Date: Tue, 1 Dec 2026 15:35:10 +0100 Message-ID: <20261201143522.483168-16-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=2241; i=jack@suse.cz; h=from:subject; bh=5d0bhwSlVwQ2moUUqSxh3fmdkgNHJa3u6plV1bhKRNk=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBrDtswxLIOrynhOetNAORZ//kv7Z/0JZmP5nrti l805u8MRcKJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCaw7bMAAKCRCcnaoHP2RA 2XuiCADqM1dFD4jvfGQEHEPTl7LHzQJuS7OIgSKeQSjIw2abnqZ8f/kO4CcWYKgqxBuR+B7yaj1 fr87J0dwmYFJrjCf6A9rZ0eopAGiGEu4FM0v0SPjJK92ZoeT5Mc1Jayh42iJ8xopDim8oRzdnBz CKzBgyW11RGVbtkdsIM79S5dLEJy88i7nFTmOhagvgP7+RQ3fbpEhzySPCC4ZwTkE3puiPuxnGq 7dq5Puk2e7JODH+QczCnc0e0iLj8lq3cyvfxu7zCUoJSaNLT4V2oQQB1b381NwJ//76wphTPPNg ZjBk0CgYOaeiIhwR3UpvShI8pyoL94qk72ip02yXKwbIkyIo X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated 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: 4D9DC1F790 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action When we have to free preallocations during inode eviction, we need to load block bitmaps and run transaction to modify them. This takes time and also requires GFP_NOFAIL allocations. Mark inodes with preallocated blocks as needing offloading of inode reclaim to a workqueue so that we don't block reclaim for long and potentially deadlock MM subsystem. We do the marking in ext4_mb_regular_allocator() to reliably catch all the cases adding preallocated blocks to the inode and additionally when adding delay allocated blocks (which will very likely result in preallocated blocks in the future) so that deferred reclaim throttling has a chance of throttling tasks generating the work. Signed-off-by: Jan Kara --- fs/ext4/inode.c | 9 ++++++++- fs/ext4/mballoc.c | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e3129353d4ed..efc2f8ebe7ba 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2113,8 +2113,15 @@ static int ext4_da_map_blocks(struct inode *inode, struct ext4_map_blocks *map) map->m_flags |= EXT4_MAP_DELAYED | EXT4_MAP_NEW; retval = ext4_insert_delayed_blocks(inode, map->m_lblk, map->m_len); - if (!retval) + if (!retval) { map->m_seq = READ_ONCE(EXT4_I(inode)->i_es_seq); + /* + * Inode will likely have preallocations which are hard to + * reclaim. Mark is for deferred reclaim early so that deferred + * reclaim throttling hits the task causing the work. + */ + mark_inode_reclaim_deferred(inode); + } up_write(&EXT4_I(inode)->i_data_sem); return retval; diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index a15285224cdf..d138c4b697b3 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3113,6 +3113,13 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac) if (ac->ac_prefetch_nr) ext4_mb_prefetch_fini(sb, ac->ac_prefetch_grp, ac->ac_prefetch_nr); + /* + * Freeing preallocations requires loading bitmaps and running + * transactions. Defer inode reclaim to a workqueue. + */ + if (!RB_EMPTY_ROOT(&EXT4_I(ac->ac_inode)->i_prealloc_node)) + mark_inode_reclaim_deferred(ac->ac_inode); + return err; } -- 2.53.0