From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCFB33AE198; Fri, 4 Sep 2026 05:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788499167; cv=none; b=D9shyiF5eUHDPPSRNYMqIzXpBafPdnLDOXhOyrQ2rMScKkKvZSeRRPFQ9Z1lTulJ7NHZ0hd69d6EU3t349x0KNeu8G0nfPDkKlkIS3+Rsry12Ju4vvRcmm3Iw1ao5VY1pQmh3pCQhBLEkvk17pmg0ipXoLs8Ndo6Evsr2KEcfyE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788499167; c=relaxed/simple; bh=LdGb2TmMxishhcje2e5ejCHP9/1BQYdA35xdvfm4WNA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UfmO17TYgaJeRsLVkNmuvLJ6jt5Tchz1af95zWau1AMiLKjMkfAotw02LHrPFQpwx4ZG/xC26Pwn/YKX3U/CXKN2wrhRFeJIte4OsCpT6Pv0iG2wdRxEZBIFFcPZ5lLQU94GAluz2kD3mq0wHyivUrtSvzkGa1YOL+dp2GHJrZY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MJBy1N9b; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MJBy1N9b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 428501F00A3D; Fri, 4 Sep 2026 05:19:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788499165; bh=bY/kDyr7Q7jetyZM3bm3h+T+YHe1GR6MCsFLqL1FFmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MJBy1N9bWPIEW5gP0YX9hEcXv+rOKHvgFiZMzBhwhhjenGctAgZrR0+S6LkPk+n8T lxDXqgudTbnqCEAqSzH4tWCtb82VTfhi3ZGGCwyX7AlgpRVPdpAkFa3ui9+eo8JTP3 CitAbByznWWixHsR5Yr+fZ+ZvHToKGqwQP9b9Khw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Matthew Wilcox (Oracle)" , Jan Kara , Jia Zhu , Theodore Tso Subject: [PATCH 7.2 322/713] buffer: avoid tail commit walk for uptodate folios Date: Fri, 4 Sep 2026 06:54:50 +0200 Message-ID: <20260904045811.047388465@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045803.810145556@linuxfoundation.org> References: <20260904045803.810145556@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jia Zhu commit f10b9cc1eb20637351f4e33372bfb464f89de59b upstream. block_commit_write() always walks every buffer_head attached to the folio. That was cheap for order-0 folios, but large folios can contain hundreds of buffer_heads. For a small buffered overwrite of an already-uptodate large folio, the commit work is therefore proportional to the folio size rather than the copied range. This became visible with ext4 regular-file large folios, where cached small overwrites reach block_commit_write() through block_write_end(). Before ext4 enabled large folios for regular files, this path was only hit with order-0 folios for normal ext4 buffered writes, so the full walk was bounded. The ext4 large-folio commit is therefore the regression point for this generic helper cost. The full walk is still needed when the folio is not uptodate, because block_commit_write() uses per-buffer uptodate state to decide whether the whole folio can be marked uptodate. Keep those folios on the old full-buffer path. For a folio that was already uptodate on entry, the commit no longer needs tail buffers for folio-uptodate discovery. The copied range has already been processed once block_start reaches @to, so stop there and avoid the suffix walk. Fixes: 7ac67301e82f0 ("ext4: enable large folio for regular file") Suggested-by: Matthew Wilcox (Oracle) Cc: stable@vger.kernel.org # v6.16+ Reviewed-by: Jan Kara Signed-off-by: Jia Zhu Link: https://patch.msgid.link/20260609035202.90669-2-zhujia.zj@bytedance.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/buffer.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2177,6 +2177,7 @@ void block_commit_write(struct folio *fo { size_t block_start, block_end; bool partial = false; + bool uptodate = folio_test_uptodate(folio); unsigned blocksize; struct buffer_head *bh, *head; @@ -2199,6 +2200,8 @@ void block_commit_write(struct folio *fo clear_buffer_new(bh); block_start = block_end; + if (uptodate && block_start >= to) + break; bh = bh->b_this_page; } while (bh != head);