From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.230.111 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796080001; b=qdTO3kinlXfMNNLYjCXmjFb0EOw/V7wjZhUSbnnTsbYN2qARqHWayEpK8MqlMAyg6dQ7 +Bsp9A9LUYyU1gq+SHL3DXrwUNQBoMhVlUDvlA118hwnxnlHWV6Xn3ri5mq4TFnc8/h4z lHFVBqpWs6PMYcgqYDfsFmz2sX9u0DjJiPvbJ7CzsbxjPkka2KTkJt4JdeOO7GksTS009 YKMpwiV+u5+StJ+LiyRgpz7a2wLju8H+f0J7xOSte9AxR8fhBfpZSIaWoQ9f1LY4dZC47 IyIrroqM3vVOO6SYJnhqwEzqOAO5yrCvrTrba09WZSFYvE+3xsAjMzZVTOE2tUocIgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796080001; h=DMARC-Filter:DKIM-Signature:From:Message-Id:Content-Type:To: In-Reply-To:X-Original-From:X-Lms-Return-Path:Subject:Mime-Version:Cc: Date:References:Content-Transfer-Encoding; bh=VvWRNz7HA2vMqDuIfd0TQJv8EJcWweifkJA2AGDhtRw=; b=R8CDo+DyjEFq2GfoS4eRV7lMrpTNA4+JhOg2NfcB1QWnnjzTG4pSiVzJCyAZjMYG57yr AkcNykQwiwYlGbuJlz6IKUY6Ql6MfXw6Xnh3gMNx63Tan5G87kHZY6Ckrb4kYn7v/k+yu C810CF2Kai8TQRpYomv1bwJUhQpfZYPoUNDobCQX+Y328u4ZPomCRvExzrNQW6kHXPNM6 TWLkzgY0Lp5+ji6EU3WRP0ltMdLNwFcUFOBU62ii6JfOom/udlbSHRf0Igcy8oXYMNc+H +UB9cMenTm+hKKXJGm2JNeRuUhVdTqpPKjVCFvPRubuUNJwNanbBcuvyMVZDZwNl9Ow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=FjCwybvc; arc=none smtp.remote-ip=209.127.230.111 Received: from va-1-111.ptr.blmpb.com (va-1-111.ptr.blmpb.com [209.127.230.111]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 183DB606A31A for ; Mon, 30 Nov 2026 23:06:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 183DB606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=2212171451 header.b=FjCwybvc DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1796079996; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=VvWRNz7HA2vMqDuIfd0TQJv8EJcWweifkJA2AGDhtRw=; b=FjCwybvcEd8NRsKQwmKB02R63keXiOmlUFaQdMM9svN9xNlleFsIJyD2Iugns0X5Zk7Uaw +GRxFeOKHFYpTFAOWCIswbt4+O7JG48IYUKPQd4OPlBR+IMO5NDIwJvgSzus/jLxy0O4Ac NNX7lNyWehI+VRv6LyZTpSvaOxxU/ja+8lR9SVjJ2XOkMJh+B/NI6ENxrZB1O30vkIYWXw A0EBNcDFoImYaob1y9sxCvlS8zIflPrGpGQW8RIylPucGtGBokwCA9WWnXAx7DKfdH/aZU cxIsDW4o2DRigmKv70vCkxqeEu6SuO1E0VmRqyJOlIckz5KxKlmR/Ey9srxBfQ== From: "Xing Ma" Message-Id: <20261201070558.4017023-3-maxing.lan@bytedance.com> Content-Type: text/plain; charset=UTF-8 To: In-Reply-To: <20261201070558.4017023-1-maxing.lan@bytedance.com> X-Original-From: Xing Ma X-Lms-Return-Path: Subject: [PATCH v3 2/2] ext4: track truncated block range in ext4_truncate() for fast commit X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Cc: "Theodore Ts'o" , "Andreas Dilger" , "Jan Kara" , "Baokun Li" , "Ojaswin Mujoo" , "Ritesh Harjani (IBM)" , "Zhang Yi" , "Harshad Shirwadkar" , Date: Tue, 01 Dec 2026 07:06:00 +0800 References: <20261201070558.4017023-1-maxing.lan@bytedance.com> Content-Transfer-Encoding: 7bit Truncation range tracking (ext4_fc_track_range()) is currently only called in ext4_truncate_down(), which misses three cases where ext4_truncate() frees extents: 1. Same-size ftruncate(fd, oldsize) dropping FALLOC_FL_KEEP_SIZE preallocated blocks beyond EOF jumps straight to ext4_truncate() without calling ext4_fc_track_range(). 2. If a commit occurs between ext4_truncate_down() stopping its handle and ext4_truncate() starting a new handle in transaction T+1, ext4_fc_track_inode() resets i_fc_lblk_len to 0 and freed extents are not tracked. 3. If ext4_ext_remove_space() or ext4_ind_truncate() restarts the journal handle onto a new transaction, earlier tracking belonged to the previous transaction. In all three cases, a subsequent fast commit omits EXT4_FC_TAG_DEL_RANGE and resurrects freed extents (or emits an indirect-mapped inode without falling back to a full commit) after crash recovery. Case 1 reproduces deterministically on -O fast_commit: xfs_io -f -c "pwrite -S 0xaa 0 4k" -c "falloc -k 4k 64k" mnt/foo sync xfs_io -c "truncate 4k" -c "fsync" mnt/foo # crash (dm-flakey drop_writes) and remount: # stat -c %b mnt/foo returns 136 instead of 8 Furthermore, unlike ext4_punch_hole(), ext4_ext_truncate() removes extent status entries for [last_block, EXT_MAX_BLOCKS - 1] without inserting an EXTENT_STATUS_HOLE entry. Tracking that range without populating the hole entry causes ext4_fc_snapshot_inode_data() to fail with EXT4_FC_SNAP_ERR_ES_MISS and fall back to a full commit (even on a no-op same-size ftruncate() + fsync()). In ext4_ext_truncate(), insert an EXTENT_STATUS_HOLE entry covering [last_block, EXT_MAX_BLOCKS - 1] after ext4_ext_remove_space() succeeds when JOURNAL_FAST_COMMIT is enabled and the inode is still linked. In ext4_truncate(), call ext4_fc_track_range() for [last_block, EXT_MAX_BLOCKS - 1] after checking err and !ext4_handle_is_aborted(). Extent-based inodes then emit EXT4_FC_TAG_DEL_RANGE cleanly via fast commit, while indirect-mapped inodes have no hole entry inserted and continue to fall back safely to a full commit. Fixes: aa75f4d3daae ("ext4: main fast-commit commit path") Cc: stable@vger.kernel.org Signed-off-by: Xing Ma --- fs/ext4/extents.c | 5 +++++ fs/ext4/inode.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index b65b0261ee5c3..a47b56e3cbe9c 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4608,6 +4608,11 @@ int ext4_ext_truncate(handle_t *handle, struct inode *inode) memalloc_retry_wait(GFP_ATOMIC); goto retry_remove_space; } + if (!err && inode->i_nlink && test_opt2(sb, JOURNAL_FAST_COMMIT) && + last_block < EXT_MAX_BLOCKS) + ext4_es_insert_extent(inode, last_block, + EXT_MAX_BLOCKS - last_block, ~0, + EXTENT_STATUS_HOLE, 0); return err; } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 07a62d8569d31..78823397d4245 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5608,6 +5608,16 @@ int ext4_truncate(struct inode *inode) if (err) goto out_stop; + if (!ext4_handle_is_aborted(handle)) { + ext4_lblk_t last_block; + + last_block = (inode->i_size + inode->i_sb->s_blocksize - 1) + >> inode->i_blkbits; + if (last_block < EXT_MAX_BLOCKS) + ext4_fc_track_range(handle, inode, last_block, + EXT_MAX_BLOCKS - 1); + } + if (IS_SYNC(inode)) ext4_handle_sync(handle); -- 2.39.5