From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379391; b=sL8tewQMtBfZTG785Cw7tBtBIkrGoymw2HMcKpWuY4ahMDLGddyXizcMwKByRBiKYao7 Wb0I1yUAvB9H1Ty/SaHj/CU0gRiPVmLhZonl2hk/lRu/kpLElrOuiBd+gCiGPrNZpX5x8 Q4/cb9TY4erEAfOQDeWzK0ZHUfUr/YdhZHUBfJFgPQanRBdsvyBI6+7c2kL8uRbSkQckI A1uVJgenXKtRv5zLI+TG5ZuCEuqAtgqu6zTPejMpDbAQFg4oGE3EIIGVWx0ytkx6J/bIP ra28/rEF3SdxFxsvbRp82wrOAg9ZdkzS6bf/puZDC3/DTcTxDrtsMMBj+/HQSSsRZ8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379391; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Yve9PPXupsp46O/r/237GmN3TSNUrf3HVWxHcrh3Dfk=; b=iydWRjskfhRVmEaoAQtGsE7Zq/xippLrXEOur0iKDP5siXg0VVauwnPq2bIzDEWaDy5m MtSA6y1mqE1E0fzdo7j/TO77TvPZBQ3ExeR/g9BIRdr301lPbw1o/IRGweO43NeW/blnZ yNMQLAAGFfdBOQ/ndFbcOX6yiNw3i20qtWa96fCHvXTcohvDb+pz5qGZVK42NyMY4a2B0 fCJwVe6Ct3bDC+JDKyL7DU9JUD+nV0tSkP0wFZ7xmQzc2e1eEWL077XhXq7YucwJnWDa/ 6lI251dHJJo899vtzjaiZwQ5rJu9dAOYttnw2mqbpy1e3ivi2lFgQllSguFsIdnc7fg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vidVOdGk; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B334606A322; Fri, 4 Dec 2026 10:16:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=vidVOdGk Received: by smtp.kernel.org (Postfix) with ESMTPSA id E66741F000CE; Fri, 4 Dec 2026 10:16:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379391; bh=Yve9PPXupsp46O/r/237GmN3TSNUrf3HVWxHcrh3Dfk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vidVOdGkb9Xx+5NVKFuBdy8SogBVszJ3qV5qkkNOJWqe2p4hvqRLwwWs7IOxRo9zk /iPu7jF1cO9OVPi/dj5cvD/kz5g8JY3Vi+nFfuRunyt0qQX8N9OD/Ebbunx5bNa7GE Z6QtJ9FQ1TRksXpndOgedWkO/5bHV/JOIbDPnP1Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 6.18 012/703] ext4: teach ext4_meta_trans_blocks() about number of allocated extents Date: Fri, 4 Dec 2026 18:58:31 +0900 Message-ID: <20261204100627.875275201@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara [ Upstream commit 25b2a7e8d420c49fc46f25b6f953603e4dae1dbf ] So far ext4_meta_trans_blocks() expects that each extent counted in @pextents will be allocated in the transaction we estimate credits for. This is correct for the use in ext4_chunk_trans_blocks() and ext4_chunk_trans_extent() however the use in atomic write path (ext4_convert_unwritten_extents_atomic() and ext4_iomap_alloc() for IOMAP_ATOMIC) unnecessarily overestimates the number of necessary credits as neither of them allocates any data. Add argument to ext4_meta_trans_blocks() for number of extents that are going to be allocated in the transaction. Signed-off-by: Jan Kara Link: https://patch.msgid.link/20260805153605.166545-4-jack@suse.cz Signed-off-by: Theodore Ts'o [ sashal: adjusted ext4.h prototype context for missing upstream declarations, and updated the move_extent.c caller to pass block_len_in_page as the new alloc_extents argument. ] Signed-off-by: Sasha Levin --- fs/ext4/ext4.h | 2 +- fs/ext4/extents.c | 2 +- fs/ext4/inode.c | 30 +++++++++++++++--------------- fs/ext4/move_extent.c | 1 + 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 9c67a2c28faf5..dc7232e8e8315 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3123,7 +3123,7 @@ extern int ext4_normal_submit_inode_data_buffers(struct jbd2_inode *jinode); extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks); extern int ext4_chunk_trans_extent(struct inode *inode, int nrblocks); extern int ext4_meta_trans_blocks(struct inode *inode, int lblocks, - int pextents); + int pextents, int alloc_extents); extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, loff_t lstart, loff_t lend); extern vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 80d41be515644..d789c7c2b5357 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4946,7 +4946,7 @@ int ext4_convert_unwritten_extents_atomic(handle_t *handle, struct inode *inode, * it can tell if the extent in the cache is a split extent. * But for now let's assume pextents as 2 always. */ - credits = ext4_meta_trans_blocks(inode, max_blocks, 2); + credits = ext4_meta_trans_blocks(inode, max_blocks, 2, 0); } if (credits) { diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d46d243d53c47..a8325b778355e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3731,8 +3731,8 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map, return ret; if (map->m_len < orig_mlen) { map->m_len = orig_mlen; - dio_credits = ext4_meta_trans_blocks(inode, orig_mlen, - map->m_len); + dio_credits = ext4_meta_trans_blocks(inode, map->m_len, + map->m_len, 0); } else { dio_credits = ext4_chunk_trans_blocks(inode, map->m_len); @@ -6271,17 +6271,17 @@ static int ext4_index_trans_blocks(struct inode *inode, int lblocks, } /* - * Account for index blocks, block groups bitmaps and block group - * descriptor blocks if modify datablocks and index blocks - * worse case, the indexs blocks spread over different block groups - * - * If datablocks are discontiguous, they are possible to spread over - * different block groups too. If they are contiguous, with flexbg, - * they could still across block group boundary. - * - * Also account for superblock, inode, quota and xattr blocks + * Calculate number of credits needed in a transaction to: + * * Allocate data blocks from @alloc_extents different groups - note that + * with flexbg a single physical extent can span multiple groups but + * single mballoc request only returns extent within one group. + * * Allocate metatadata (extent tree blocks, indirect blocks) to store + * pointers to @pextents data extents having @lblocks in total. + * * Modify extent tree / indirect block tree, inode, superblock, quota + * tracking, xattr blocks */ -int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents) +int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents, + int alloc_extents) { ext4_group_t groups, ngroups = ext4_get_groups_count(inode->i_sb); int gdpblocks; @@ -6298,7 +6298,7 @@ int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents) * Now let's see how many group bitmaps and group descriptors need * to account */ - groups = idxblocks + pextents; + groups = idxblocks + alloc_extents; gdpblocks = groups; if (groups > ngroups) groups = ngroups; @@ -6324,7 +6324,7 @@ int ext4_chunk_trans_extent(struct inode *inode, int nrblocks) { int ret; - ret = ext4_meta_trans_blocks(inode, nrblocks, 1); + ret = ext4_meta_trans_blocks(inode, nrblocks, 1, 1); /* Account for data blocks for journalled mode */ if (ext4_should_journal_data(inode)) ret += nrblocks; @@ -6342,7 +6342,7 @@ int ext4_chunk_trans_extent(struct inode *inode, int nrblocks) */ int ext4_chunk_trans_blocks(struct inode *inode, int nrblocks) { - return ext4_meta_trans_blocks(inode, nrblocks, 1); + return ext4_meta_trans_blocks(inode, nrblocks, 1, 1); } /* diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index e2705ea5e5c63..6a60d29e433bc 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -281,6 +281,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, again: *err = 0; jblocks = ext4_meta_trans_blocks(orig_inode, block_len_in_page, + block_len_in_page, block_len_in_page) * 2; handle = ext4_journal_start(orig_inode, EXT4_HT_MOVE_EXTENTS, jblocks); if (IS_ERR(handle)) { -- 2.53.0