From patchwork Wed Dec 18 02:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13912925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C11B9E77184 for ; Wed, 18 Dec 2024 02:26:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DD1B6B0085; Tue, 17 Dec 2024 21:26:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 878E36B0088; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 732186B0085; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4A5976B0085 for ; Tue, 17 Dec 2024 21:26:34 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 03F5F1A0A9B for ; Wed, 18 Dec 2024 02:26:33 +0000 (UTC) X-FDA: 82906490394.05.11C2CC9 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id 8CEFB40010 for ; Wed, 18 Dec 2024 02:26:08 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="BkxYihM/"; spf=none (imf17.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734488763; a=rsa-sha256; cv=none; b=6HQBcmxF4cKnG0IJAMJzR7YZ+Reex7ADyjQgXV+Ecta4NzDs4HLpAIprPUvWVF23xiNVO/ 0Ax6xF72F4VudN197zmGk6VNBszDjqr6D/im9j4ZJiU91vSv0SV37YmstRjoIjQpDBjqt2 LQ//OUgmOVyqYdsu84ANZNglUxkElOg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="BkxYihM/"; spf=none (imf17.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734488763; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PAjepITga0a8Mt36xpxUX/NyoUbIA2AsDDdcgVOuJ40=; b=LKqvNjnrY5lE5RpFcdwbnTpyQ+J1UbkAPTGam7mjvmcWl6cTmccVSYYCKypNloRo1wEpmp wo1UGcd9V7rGirdAp3vbWsS6LrjqsMq2WBpvI4TKVLQGpXwk8cCnqtEDIoehgWLiuB+RvA Y2fJ99uwrg6e9PrmwgytQwEpu8pXT0s= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=PAjepITga0a8Mt36xpxUX/NyoUbIA2AsDDdcgVOuJ40=; b=BkxYihM/ixv1x+y1GBn61vuqpI 9uMGmUbRsMUgI7XBDYzqLUWkOar5BL6dzU9F1tUO4CIA4n0+LWX9pCweVDBnSQEWxMvpWm1n6JBKz /Dsn1uG4vzykfhqR7SvsS+CDSJHDeZ+bBrn3s4478DOW2HSvucEKQ5V8SD0zfoIKS0fwbT9gKHRj5 pLcksMtPjjUZFjz+Q9yHaEizn2AXP9Riv8BG6ZdIhs0Y3hhxRkhmGoPiQMmsLe+a7mNR9wk1km02m Itv1KGFNuxgryqijDbmFRyzjE6ia4ohMLRGuTSuLPwnpI0nR6n1/HkGfLKzBMvShiyHd2Jsw3hKxv phXnpcCg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tNjlc-0000000FOFS-0xNt; Wed, 18 Dec 2024 02:26:28 +0000 From: Luis Chamberlain To: hare@suse.de, willy@infradead.org, dave@stgolabs.net, david@fromorbit.com, djwong@kernel.org, kbusch@kernel.org Cc: john.g.garry@oracle.com, hch@lst.de, ritesh.list@gmail.com, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, da.gomez@samsung.com, kernel@pankajraghav.com, mcgrof@kernel.org Subject: [PATCH 1/5] fs/buffer: move async batch read code into a helper Date: Tue, 17 Dec 2024 18:26:22 -0800 Message-ID: <20241218022626.3668119-2-mcgrof@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218022626.3668119-1-mcgrof@kernel.org> References: <20241218022626.3668119-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8CEFB40010 X-Stat-Signature: 1oeqaodiakkooxi73agjwc76b7m5bfis X-Rspam-User: X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspamd-Server: rspam09 X-Rspam: Yes X-HE-Tag: 1734488768-393822 X-HE-Meta: U2FsdGVkX19WcEAgCyZRlIS+8PL4iqQ9IA2iDXJcPtPoDC5zlQ4RaNPmiEwCsxlu5zmEbo1e43x4gnC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QpyxGYXmxU9ZABseONuaMgpLqq0YYNrMtSJMdP7TOeBn2abeszZ7HaIv9uuOxbGiY3aedYwi879cx1qjAalmbky9TrCtF+moEzkODiFu6AdWYLScYvAGUGnodN1UrO1G/usyP+uZs85ZIaU5rhYkK5LReWfuPU3H8AO9NvHTRZDRfF2ecQNzEqMn1O+alKoJ10wlETTfBUrdW7fKO1XUan/OZrpa10Lpg3Af4MhB0+zo+vLEyz6uJmEz3C9nW8x/7J5Ukk7Tn0F7sj8E+7SWip6XQAM55YWOgwA9cI0b7V1BJn/EeSV3pjFWrnWNlvzkKAVEnVqlg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000057, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move the code from block_read_full_folio() which does a batch of async reads into a helper. No functional changes. Signed-off-by: Luis Chamberlain --- fs/buffer.c | 79 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index cc8452f60251..7c6aac0742a6 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2350,6 +2350,53 @@ bool block_is_partially_uptodate(struct folio *folio, size_t from, size_t count) } EXPORT_SYMBOL(block_is_partially_uptodate); +/* + * Stage one is to collect an array of buffer heads which we need a read for, + * you can then use this afterwards. On that effort you should also check + * to see if you really need a read, and if we are already fully mapped. + */ +static void bh_read_batch_async(struct folio *folio, + int nr, struct buffer_head *arr[], + bool fully_mapped, bool no_reads, + bool any_get_block_error) +{ + int i; + struct buffer_head *bh; + + if (fully_mapped) + folio_set_mappedtodisk(folio); + + if (no_reads) { + /* + * All buffers are uptodate or get_block() returned an + * error when trying to map them *all* buffers we can + * finish the read. + */ + folio_end_read(folio, !any_get_block_error); + return; + } + + /* Stage two: lock the buffers */ + for (i = 0; i < nr; i++) { + bh = arr[i]; + lock_buffer(bh); + mark_buffer_async_read(bh); + } + + /* + * Stage three: start the IO. Check for uptodateness + * inside the buffer lock in case another process reading + * the underlying blockdev brought it uptodate (the sct fix). + */ + for (i = 0; i < nr; i++) { + bh = arr[i]; + if (buffer_uptodate(bh)) + end_buffer_async_read(bh, 1); + else + submit_bh(REQ_OP_READ, bh); + } +} + /* * Generic "read_folio" function for block devices that have the normal * get_block functionality. This is most of the block device filesystems. @@ -2383,6 +2430,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) nr = 0; i = 0; + /* Stage one - collect buffer heads we need issue a read for */ do { if (buffer_uptodate(bh)) continue; @@ -2414,37 +2462,8 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) arr[nr++] = bh; } while (i++, iblock++, (bh = bh->b_this_page) != head); - if (fully_mapped) - folio_set_mappedtodisk(folio); - - if (!nr) { - /* - * All buffers are uptodate or get_block() returned an - * error when trying to map them - we can finish the read. - */ - folio_end_read(folio, !page_error); - return 0; - } - - /* Stage two: lock the buffers */ - for (i = 0; i < nr; i++) { - bh = arr[i]; - lock_buffer(bh); - mark_buffer_async_read(bh); - } + bh_read_batch_async(folio, nr, arr, fully_mapped, nr == 0, page_error); - /* - * Stage 3: start the IO. Check for uptodateness - * inside the buffer lock in case another process reading - * the underlying blockdev brought it uptodate (the sct fix). - */ - for (i = 0; i < nr; i++) { - bh = arr[i]; - if (buffer_uptodate(bh)) - end_buffer_async_read(bh, 1); - else - submit_bh(REQ_OP_READ, bh); - } return 0; } EXPORT_SYMBOL(block_read_full_folio); From patchwork Wed Dec 18 02:26:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13912924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE2EAE77187 for ; Wed, 18 Dec 2024 02:26:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34AF36B0082; Tue, 17 Dec 2024 21:26:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FAE46B0083; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C2A56B0085; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F293A6B0082 for ; Tue, 17 Dec 2024 21:26:33 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 94A67C0B17 for ; Wed, 18 Dec 2024 02:26:33 +0000 (UTC) X-FDA: 82906490142.24.4A63225 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf15.hostedemail.com (Postfix) with ESMTP id 976EEA0008 for ; Wed, 18 Dec 2024 02:25:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3qaC05k7; spf=none (imf15.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734488770; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KAcXP1LLN9RIr4LUuyxBmqGvK7FM1npzcMSwryY+7ME=; b=H7z0ZxOVAwDsMkAlP+4M5GwnhELRA31KkOxsDpRs7Ljiy7sek8VAaXmk9uWZAUJeFKVV/S H2qgQpUYHdNVz9WQrD18ZSETqeqm5U+53Sn+OA8n8cdY6qFemtxOJBefXyq944YKnfIu8R YY0FaMqN7Y6U6WPMxcflTRDYAXRBX6U= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=3qaC05k7; spf=none (imf15.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734488770; a=rsa-sha256; cv=none; b=hgRLqOLfNL+cjaUvwDVAKuFpa2lortR6x1DoFnCN3yuCn54x1mc64UZxhj2ZO9YbN6ypAW yFZ5Jl1VFxhzOVqx8e/G2QnANn+HhhmzNh9gejYT+clDWZ62y/6byW9IKBtJuJV+pmzaop HsI5DDRQZ1z++z0Y7JVTdRdswKn4L4Q= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=KAcXP1LLN9RIr4LUuyxBmqGvK7FM1npzcMSwryY+7ME=; b=3qaC05k7YgxBzQwXc9ZAOl7DAT k61pID00MJyziEMK2a/rV9rNOMTAiDPENc2QdtSsXU1PRi68fxGTFDy8dAn848eYwuVU4g6SzLUFN vwenXhO4VWLRUjJOHA3Z7Qyf6Yy6knyLtBAB/LupK9s0sdcSjpz8D53qvxjRTzgIcHp/10eV1u5jO lrh0jIW2l6IJq0zzB1AqB3idKyQzCI2cWnmBL4YFePKdAnGbpv/fMBW6odvahgNV7DTzfDcS2NF8b dghX2PPebP4c53s6nR+FcNy2avvEOLCpIjKRipbwyxpSMp2nQsdx43cWKgWU/lxo2IP9GVtm1W1/m BHnGwU/A==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tNjlc-0000000FOFU-168x; Wed, 18 Dec 2024 02:26:28 +0000 From: Luis Chamberlain To: hare@suse.de, willy@infradead.org, dave@stgolabs.net, david@fromorbit.com, djwong@kernel.org, kbusch@kernel.org Cc: john.g.garry@oracle.com, hch@lst.de, ritesh.list@gmail.com, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, da.gomez@samsung.com, kernel@pankajraghav.com, mcgrof@kernel.org Subject: [PATCH 2/5] fs/buffer: simplify block_read_full_folio() with bh_offset() Date: Tue, 17 Dec 2024 18:26:23 -0800 Message-ID: <20241218022626.3668119-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218022626.3668119-1-mcgrof@kernel.org> References: <20241218022626.3668119-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 976EEA0008 X-Stat-Signature: h6c1fqhkhubfww48gfjkrec3z4gjb7wp X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Rspam: Yes X-HE-Tag: 1734488746-523641 X-HE-Meta: U2FsdGVkX1/WK7zuCzucOuGyRd/pyUVE05qkEQiNDxii1gBsMRtCCBBshXLkX2hKts/F4iQz57F2CBhflzJhLIDLpdn9VJIFUa0PSD8gIb5kE45C5BvNLu4R66ox32/ypnhqv5I8JLzTBaNkuMnVX0c1EkAopzD8zTbTyan9WVfUgHK8N61zSuG6GroLs7aKjRfEHdodAr+TJRbcGajI1CaMB84CxTaVoJ5KxIc/Zxf9Bu2XfO8X28Gyo6kZo8MAqUcYPvOU7RHkWStU1WkoBGVYcw9C4owKWIRFPpWhmO1tyUK3t/4uqn9RslqiEGxBFTFzx1/dY+GYBg+hPNw+T49cvbatYbM6C/yCJRzC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aKs0+PjwASsBBVPzdJulqpjnMXrg8uabyjp5EkIR85wSpaZdDJJH9LXSasmn+zrZl6WkmPDk1UaIGE5vD5YsEUo5nsxxhKUxHAlJ8t72v154aVqsn0atlZ12+8V7saF4/NSodnz9BK0maxTNIhUxDfZkK8rul X-Bogosity: Ham, tests=bogofilter, spamicity=0.001249, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Remove the temporary variable i on the iteration of all buffer heads on a folio and just use bh_offset(bh) to simplify the loop. Suggested-by: Matthew Wilcox Signed-off-by: Luis Chamberlain --- fs/buffer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 7c6aac0742a6..8baf87db110d 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2410,7 +2410,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) sector_t iblock, lblock; struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE]; size_t blocksize; - int nr, i; + int nr; int fully_mapped = 1; bool page_error = false; loff_t limit = i_size_read(inode); @@ -2428,7 +2428,6 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) lblock = div_u64(limit + blocksize - 1, blocksize); bh = head; nr = 0; - i = 0; /* Stage one - collect buffer heads we need issue a read for */ do { @@ -2446,7 +2445,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) page_error = true; } if (!buffer_mapped(bh)) { - folio_zero_range(folio, i * blocksize, + folio_zero_range(folio, bh_offset(bh), blocksize); if (!err) set_buffer_uptodate(bh); @@ -2460,7 +2459,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) continue; } arr[nr++] = bh; - } while (i++, iblock++, (bh = bh->b_this_page) != head); + } while (iblock++, (bh = bh->b_this_page) != head); bh_read_batch_async(folio, nr, arr, fully_mapped, nr == 0, page_error); From patchwork Wed Dec 18 02:26:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13912926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1BE5E77187 for ; Wed, 18 Dec 2024 02:26:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DABB86B0088; Tue, 17 Dec 2024 21:26:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AC28B6B0083; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 835626B008A; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5F8B86B0083 for ; Tue, 17 Dec 2024 21:26:34 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 14564A04A1 for ; Wed, 18 Dec 2024 02:26:34 +0000 (UTC) X-FDA: 82906489596.03.2395274 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf09.hostedemail.com (Postfix) with ESMTP id 0FD7A140010 for ; Wed, 18 Dec 2024 02:26:10 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=YF8qki9A; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine); spf=none (imf09.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734488763; a=rsa-sha256; cv=none; b=sFI+mAY/nj7xVhdm1tvb3IvSnps/16o7bLr7XPobCXTe+4Yez/Kb/QXjzC6p3z4iSJoTBR HcwuHJDfnNi7hnfa0l5HsMYRM5yjFuFfo4KQtcnytnl0z/K8cGjKaWW55pNmVuQ8oS2/Tg XOd4pJR9LMeEQFVk/6SgnoRsDIH6pBA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=YF8qki9A; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine); spf=none (imf09.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734488763; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/TZr4nFjkp9nWadpjSdHplXgIdajpwwrN5XnPc56j5k=; b=y2Tpb5VHMYf53GglbKFV6nkomFNVJ7dzhx9EuPXbW0XxB0uMfp2flAYOu7/nsmzGeJs8TB mAvjEjnhMQsBJUNf/yjC/AF35kni1SIrPNtT6ZT2m+voTWbiHv6LFa5N+MZES3HuWbAvI6 2hoB4q7jhqXezrkmhXxhy+d7/WBkBgM= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=/TZr4nFjkp9nWadpjSdHplXgIdajpwwrN5XnPc56j5k=; b=YF8qki9ApWj9O9QPiw4UQveFJ3 NQfKB26z4bEkBtNfWRijXe1dUgTBw9CxUwpzJfYVsCd7Rq3m0PVX5FbT0zu4spnX3P2bTOWTbHIjs BBAKfLiuJkXTrFwI1eODbWULVvv7LXNdVU2+HPaC/SoEa6MMKjk6+1fI6cFnczLZBrKbdhlAH3uDF C9+9eaa4KZovy/GjDgqOnOaKmip06d+jjsyFjML7RHJ3Hdb+H55jjeq0uLDA47ZG/ZvAyfapr3C1p o6Hs0K+5NPo/jujeuy6EEI7JzJXKcEytrh6LDi/AUNYX0/j6taWl5O/Me4vjhI5OGY20dAqBWLowM qmN/oplQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tNjlc-0000000FOFW-1EJE; Wed, 18 Dec 2024 02:26:28 +0000 From: Luis Chamberlain To: hare@suse.de, willy@infradead.org, dave@stgolabs.net, david@fromorbit.com, djwong@kernel.org, kbusch@kernel.org Cc: john.g.garry@oracle.com, hch@lst.de, ritesh.list@gmail.com, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, da.gomez@samsung.com, kernel@pankajraghav.com, mcgrof@kernel.org Subject: [PATCH 3/5] fs/buffer: add a for_each_bh() for block_read_full_folio() Date: Tue, 17 Dec 2024 18:26:24 -0800 Message-ID: <20241218022626.3668119-4-mcgrof@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218022626.3668119-1-mcgrof@kernel.org> References: <20241218022626.3668119-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 4g6juz4ccodn13knmgz611feqbymeerc X-Rspam-User: X-Rspamd-Queue-Id: 0FD7A140010 X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspamd-Server: rspam08 X-Rspam: Yes X-HE-Tag: 1734488770-314338 X-HE-Meta: U2FsdGVkX1/h1oLDe6Z7diPvxiAiD+/Ukc7Ua85vvhr4rY7cM/cRsv42scnyPex1MyjXJiZHXTLZdTsL2aNvz6mPnLvQFCW9b/KlYqhDxZ1pxzrBHOtYv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ot1g2Tw8HVgIuhPKOxO9pwlIDCsp/5KfNhRU8qwDqIR5hFL5PySwA/ciZ/6RN9NjqbzZwsubwuWTQRN5Ioh/XQWc2LVILZ8hAECr5bqI5Uf0GTSuVavDgxGw6TIlbbBhLMbTtid/pI4cQzBTM3TLd2OtZW/aSOkHt8sAdRdyAWuiNhWbtskpcjmoGCRLRa4GduFHod8UZjeWnfeSZx0Q1aud3DyYTy6qrtCo8suQnZ4lTwKkKM7I713VJ7TfE8y7lix/crhqhIzVJuccJi3o7i+k1klXWvkR6rvrsKWOGyDibNId7K3TB3ibHp29cyxQnRAYPW6XAaH85M1GzO0hP0+AWoYsYTkX9A/g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000080, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We want to be able to work through all buffer heads on a folio for an async read, but in the future we want to support the option to stop before we've processed all linked buffer heads. To make code easier to read and follow adopt a for_each_bh(tmp, head) loop instead of using a do { ... } while () to make the code easier to read and later be expanded in subsequent patches. This introduces no functional changes. Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain --- fs/buffer.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 8baf87db110d..1aeef7dd2281 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2397,6 +2397,17 @@ static void bh_read_batch_async(struct folio *folio, } } +#define bh_is_last(__bh, __head) ((__bh)->b_this_page == (__head)) + +#define bh_next(__bh, __head) \ + (bh_is_last(__bh, __head) ? NULL : (__bh)->b_this_page) + +/* Starts from the provided head */ +#define for_each_bh(__tmp, __head) \ + for ((__tmp) = (__head); \ + (__tmp); \ + (__tmp) = bh_next(__tmp, __head)) + /* * Generic "read_folio" function for block devices that have the normal * get_block functionality. This is most of the block device filesystems. @@ -2426,13 +2437,14 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) iblock = div_u64(folio_pos(folio), blocksize); lblock = div_u64(limit + blocksize - 1, blocksize); - bh = head; nr = 0; /* Stage one - collect buffer heads we need issue a read for */ - do { - if (buffer_uptodate(bh)) + for_each_bh(bh, head) { + if (buffer_uptodate(bh)) { + iblock++; continue; + } if (!buffer_mapped(bh)) { int err = 0; @@ -2449,17 +2461,21 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) blocksize); if (!err) set_buffer_uptodate(bh); + iblock++; continue; } /* * get_block() might have updated the buffer * synchronously */ - if (buffer_uptodate(bh)) + if (buffer_uptodate(bh)) { + iblock++; continue; + } } arr[nr++] = bh; - } while (iblock++, (bh = bh->b_this_page) != head); + iblock++; + } bh_read_batch_async(folio, nr, arr, fully_mapped, nr == 0, page_error); From patchwork Wed Dec 18 02:26:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13912927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13920E77188 for ; Wed, 18 Dec 2024 02:26:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 063E26B0083; Tue, 17 Dec 2024 21:26:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C20D86B0093; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 957126B0092; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6D01B6B0089 for ; Tue, 17 Dec 2024 21:26:34 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1DDD5120AD2 for ; Wed, 18 Dec 2024 02:26:34 +0000 (UTC) X-FDA: 82906490100.30.C5C9A46 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP id ED83920003 for ; Wed, 18 Dec 2024 02:26:01 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UOyu5RHN; spf=none (imf13.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734488768; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2tu6vw3HnVklrsZdZBeEEpq3jVFl8xYfgifT0A/bbJA=; b=YO2MlJKVP72+J2JINcLYMY19rY5xAF4uCgk0lZm92uLEjeDPUED5GNTOiWwDKF3ilAX4Vw IVhhmg/sFvh4i54e6wbT8eO146arROH2vuwiPP9YCWYA4G3k8bgQ+zthcnfjCdmhQG13zO UjUC3vs8fIRf1UTZjFRCm37Ic/D4PCc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=UOyu5RHN; spf=none (imf13.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734488768; a=rsa-sha256; cv=none; b=c5bPHpmyS9opYPUAV9k3ym74NqrBccMtAIYws4t0SVHNtdG4iAcJcpcBjFbwp4+mmv71hE 9dk6UBl6pV/NR42PyuqftJwLusXXNatbFP2a1vP4JpBqf9xVn5Av/MMDLdNl4ZB5Ij3D5Z HM0FAkmiUc8nc6PnzrXxHSJPS0cgyew= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=2tu6vw3HnVklrsZdZBeEEpq3jVFl8xYfgifT0A/bbJA=; b=UOyu5RHNs1b1dIBIPJ3wXeM11K Qem2FStQNp12ErJNPvBxR8pD7ECxcshmwcWWQMoKlNNWXGc2UmQ17TtyzfCe62rNSP1oRjC+o5JJo vs5OeIciaTldFNmK4eHoM/ogSKq/h8jQGFaRs1bjS8wOQHdwl1/lxu28kqdPAcVDjtGDLnFDgmh3U xn5m+02QHyVvqS4WqbA0WIdEyGaai4Y5Io//FfGcKarijsMIoLsfLldTW9A1rttjzbwpg0+tGTjeP Lo2HtB1olSfaksGtbOY3dXGGsH/5C49xgoKFfzDxAdRm4d/8XVovi3sVIlX44mxqR+HpVwLDlmOgY N7Qza3aQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tNjlc-0000000FOFZ-1MBK; Wed, 18 Dec 2024 02:26:28 +0000 From: Luis Chamberlain To: hare@suse.de, willy@infradead.org, dave@stgolabs.net, david@fromorbit.com, djwong@kernel.org, kbusch@kernel.org Cc: john.g.garry@oracle.com, hch@lst.de, ritesh.list@gmail.com, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, da.gomez@samsung.com, kernel@pankajraghav.com, mcgrof@kernel.org Subject: [PATCH 4/5] fs/buffer: add iteration support for block_read_full_folio() Date: Tue, 17 Dec 2024 18:26:25 -0800 Message-ID: <20241218022626.3668119-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218022626.3668119-1-mcgrof@kernel.org> References: <20241218022626.3668119-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: ED83920003 X-Rspamd-Server: rspam12 X-Stat-Signature: 3qy3pgboh5xzsy596s7za6uim4fobw86 X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1734488761-161609 X-HE-Meta: U2FsdGVkX19u98fT/4ejmGcsbxR//WY4sfoxOlJjjlozq41z/1i02zXb6rnc9fNAEPFar2sqmShWL719/kmwO2dZU6V/b5HCjlRZLm31/o5rK3q9JG8+5sfDfRYEXtfgE7m85KNSBCTiHFlWZ5OWC9xbg6Agh5QsoFhrw/83rd2lwPNJLx10PiecCPNAfDbENDSfFb03MxbuwhaJj77l96CgQ8+SJKopXtT3q9jDZAOAWac4a8KaGpY7ZE7lXataljDeXfJZmeWEY7OeVjeu8QZQJ+JJjT/MHGVKLAWj1zJtS1l1XQtMVtbhTrZfusVxQJITlkRNuPalS9TYuiEeVF+P9Fa32J6KSECYuyD0Ufr9sLBjXOxRkiB56GOqntRwrUEqzgdUvakuCiMFEnrIswTCVglJesjFzgJqkCR8hwjMFSma/N/6/sAArfBPxlLGAZd2UA6vUziij1DvGGAffI3CINvqf06pNx3iEdsICiGVTK0Ozv6MQS/YhzAnqXvM5IYaWX2eTcVrfAxxcTfoTiEHEuQ0w9NWyP1/BAg8FU9Nh0VChv7NDl+HzP+19bUUXMB5EKUj19E+mkV92WXyO73D92Evq8I/8uCEwHhmRXVqu3WQDeW/NRoB3lCsFWsQ7EmiufQ4CWW9E3mKLA7bfm1ealZ2eCOsK0KSj1Enk0GeZsQXnhPYhZuB48JVUiB97rBGQdovw8OZmQN0HSy6i3XOnV4O8rowuhWYJGm2h0iC3Bryiprzn3kztlqMTN1CpjcRMx4itfCLe8tSlMyIC2AQVufvmfRvHLeFs5ILbJ/9BZxuUSiLgGAnUiREf/B59UqmcXPXgW/KV1XWAflC6cXOxXVSqXRMNXlXZcbw1qYoDfdXRG3idcRJzdfiLd8vfPhb7BT0wtVjF3pnA6+/Jja5WbQ91cxutBE8JE1KT59UxCuNZ0kZKXPQsOr3R/ouP/6TW7Wwqg29oi2XtLH Sz2BFblh 74y2UstFY3T6wvRpIO9SA7M3892v6ogZSW/12wGMG0Q8z3T8L2IaMY8HQDGlcWehU/v5qbc9+QCnuVbC4aImxl+H+5eNWWxzVjHcbecq8wFa1qlMfUl2YsCrrU63oJLfBq7Ix7RLCwyyoAwPfZstJ/esBua5CWcgmnSUCMDCRaPkjFwSQ0ruRi9lJXBcqqtjB37FYdqeB2DPN2bTAQhYcvfsV0gdpsLqz8isIr3ENG2OrDocSPmal/pVr8CiRRlzU+87uLGL9h05ktqtLhejoUts1aQcyhiX/Sz+6kPLud0RxtSiXGK4tRs7lFUMT6/HpnOB4GwUxPv/fUmd1z7Oh+vjbliwv6DwqHPWs80PrJISD/MKlaBw8gskx9/Yg+vERau0b/qvsmIcXaK/04B/VsrKJ4eRIvtQfYzcsjA/fv+bQKjd2IwLfiyOID65q6PUYszB62Vn+zDuQbpGs2rADKyEdF9UWt9xVxJ9USlvQVaBFh2abvbzYRJLdTe+wqapSQzjZNnvMH8EQNCAzEbaDHKdil6SJLhXAGyuVEHacSBKMlik= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Provide a helper to iterate on buffer heads on a folio. We do this as a preliminary step so to make the subsequent changes easier to read. Right now we use an array on stack to loop over all buffer heads in a folio of size MAX_BUF_PER_PAGE, however on CPUs where the system page size is quite larger like Hexagon with 256 KiB page size support this can mean the kernel can end up spewing spews stack growth warnings. To be able to break this down into smaller array chunks add support for processing smaller array chunks of buffer heads at a time. The used array size is not changed yet, that will be done in a subsequent patch, this just adds the iterator support and logic. While at it clarify the booleans used on bh_read_batch_async() and how they are only valid in consideration when we've processed all buffer-heads of a folio, that is when we're on the last buffer head in a folio: * bh_folio_reads * unmapped Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain --- fs/buffer.c | 134 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 97 insertions(+), 37 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 1aeef7dd2281..b8ba72f2f211 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2402,66 +2402,75 @@ static void bh_read_batch_async(struct folio *folio, #define bh_next(__bh, __head) \ (bh_is_last(__bh, __head) ? NULL : (__bh)->b_this_page) +/* Starts from a pivot which you initialize */ +#define for_each_bh_pivot(__pivot, __last, __head) \ + for ((__pivot) = __last = (__pivot); \ + (__pivot); \ + (__pivot) = bh_next(__pivot, __head), \ + (__last) = (__pivot) ? (__pivot) : (__last)) + /* Starts from the provided head */ #define for_each_bh(__tmp, __head) \ for ((__tmp) = (__head); \ (__tmp); \ (__tmp) = bh_next(__tmp, __head)) +struct bh_iter { + sector_t iblock; + get_block_t *get_block; + bool any_get_block_error; + int unmapped; + int bh_folio_reads; +}; + /* - * Generic "read_folio" function for block devices that have the normal - * get_block functionality. This is most of the block device filesystems. - * Reads the folio asynchronously --- the unlock_buffer() and - * set/clear_buffer_uptodate() functions propagate buffer state into the - * folio once IO has completed. + * Reads up to MAX_BUF_PER_PAGE buffer heads at a time on a folio on the given + * block range iblock to lblock and helps update the number of buffer-heads + * which were not uptodate or unmapped for which we issued an async read for + * on iter->bh_folio_reads for the full folio. Returns the last buffer-head we + * worked on. */ -int block_read_full_folio(struct folio *folio, get_block_t *get_block) -{ - struct inode *inode = folio->mapping->host; - sector_t iblock, lblock; - struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE]; - size_t blocksize; - int nr; - int fully_mapped = 1; - bool page_error = false; - loff_t limit = i_size_read(inode); - - /* This is needed for ext4. */ - if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) - limit = inode->i_sb->s_maxbytes; +static struct buffer_head *bh_read_iter(struct folio *folio, + struct buffer_head *pivot, + struct buffer_head *head, + struct inode *inode, + struct bh_iter *iter, sector_t lblock) +{ + struct buffer_head *arr[MAX_BUF_PER_PAGE]; + struct buffer_head *bh = pivot, *last; + int nr = 0, i = 0; + size_t blocksize = head->b_size; + bool no_reads = false; + bool fully_mapped = false; - VM_BUG_ON_FOLIO(folio_test_large(folio), folio); + /* Stage one - collect buffer heads we need issue a read for */ - head = folio_create_buffers(folio, inode, 0); - blocksize = head->b_size; + /* collect buffers not uptodate and not mapped yet */ + for_each_bh_pivot(bh, last, head) { + BUG_ON(nr >= MAX_BUF_PER_PAGE); - iblock = div_u64(folio_pos(folio), blocksize); - lblock = div_u64(limit + blocksize - 1, blocksize); - nr = 0; - - /* Stage one - collect buffer heads we need issue a read for */ - for_each_bh(bh, head) { if (buffer_uptodate(bh)) { - iblock++; + iter->iblock++; continue; } if (!buffer_mapped(bh)) { int err = 0; - fully_mapped = 0; - if (iblock < lblock) { + iter->unmapped++; + if (iter->iblock < lblock) { WARN_ON(bh->b_size != blocksize); - err = get_block(inode, iblock, bh, 0); + err = iter->get_block(inode, iter->iblock, + bh, 0); if (err) - page_error = true; + iter->any_get_block_error = true; } if (!buffer_mapped(bh)) { folio_zero_range(folio, bh_offset(bh), blocksize); if (!err) set_buffer_uptodate(bh); - iblock++; + iter->iblock++; continue; } /* @@ -2469,15 +2478,66 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) * synchronously */ if (buffer_uptodate(bh)) { - iblock++; + iter->iblock++; continue; } } arr[nr++] = bh; - iblock++; + iter->iblock++; + } + + iter->bh_folio_reads += nr; + + WARN_ON_ONCE(!bh_is_last(last, head)); + + if (bh_is_last(last, head)) { + if (!iter->bh_folio_reads) + no_reads = true; + if (!iter->unmapped) + fully_mapped = true; } - bh_read_batch_async(folio, nr, arr, fully_mapped, nr == 0, page_error); + bh_read_batch_async(folio, nr, arr, fully_mapped, no_reads, + iter->any_get_block_error); + + return last; +} + +/* + * Generic "read_folio" function for block devices that have the normal + * get_block functionality. This is most of the block device filesystems. + * Reads the folio asynchronously --- the unlock_buffer() and + * set/clear_buffer_uptodate() functions propagate buffer state into the + * folio once IO has completed. + */ +int block_read_full_folio(struct folio *folio, get_block_t *get_block) +{ + struct inode *inode = folio->mapping->host; + sector_t lblock; + size_t blocksize; + struct buffer_head *bh, *head; + struct bh_iter iter = { + .get_block = get_block, + .unmapped = 0, + .any_get_block_error = false, + .bh_folio_reads = 0, + }; + loff_t limit = i_size_read(inode); + + /* This is needed for ext4. */ + if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) + limit = inode->i_sb->s_maxbytes; + + VM_BUG_ON_FOLIO(folio_test_large(folio), folio); + + head = folio_create_buffers(folio, inode, 0); + blocksize = head->b_size; + + iter.iblock = div_u64(folio_pos(folio), blocksize); + lblock = div_u64(limit + blocksize - 1, blocksize); + + for_each_bh(bh, head) + bh = bh_read_iter(folio, bh, head, inode, &iter, lblock); return 0; } From patchwork Wed Dec 18 02:26:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13912928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C415AE77184 for ; Wed, 18 Dec 2024 02:26:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 395736B008A; Tue, 17 Dec 2024 21:26:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 047946B0095; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE4716B008A; Tue, 17 Dec 2024 21:26:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 956C56B008C for ; Tue, 17 Dec 2024 21:26:34 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3CB08C0B17 for ; Wed, 18 Dec 2024 02:26:34 +0000 (UTC) X-FDA: 82906490184.26.F74C678 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id DD59DC000A for ; Wed, 18 Dec 2024 02:26:18 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=rOCE0qvP; spf=none (imf10.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734488771; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZbUYX9Sq5KIho4Fukut+jcN4YUtrDSxc8GT+CZTyNJI=; b=AjLMNmu5UEZBl2JK2O4bdZswdzIPThTHzsmHOusFvscnZ+llaSRDQIaPRBOJvkrt9mPET9 HFpFHmxg0o8nQinz5srT07reA0g0JbWqJfz4RFQ/FKrg7pGBRclc/i5HJJxvq3vLizdhfF TgPG6h/b7mf1vdDgV3CoDp9wXZH0XGk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734488771; a=rsa-sha256; cv=none; b=rkkIiBYYm+a7aYOqMIWIKWbfGz87muB5gD5/uP526IENBdlyX7nzcC3zly3RnQiBD50Pxi Q7DfmhaCUT0az59RfwwHrsvrdZwHSkzKO2QxHJrAGxUxCj8h8sHR5lZXjVpcgkHVcytz// SQlUnr2uPBfBwAoABD8qkw0sjcLeVEE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=rOCE0qvP; spf=none (imf10.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=quarantine) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=ZbUYX9Sq5KIho4Fukut+jcN4YUtrDSxc8GT+CZTyNJI=; b=rOCE0qvP1bit6BhC2nOW+ZmD1C MjnSDQBMGg0LebsCOfpJZS5VU+y1MF9ftXASeJHmNQu668uZk62viyqP2nWwMFil83pO0XL6VaLcc 7ebXitKACjEMvt3i+W7gaNBm8ysthbep6l4kO2V96ZIJETU/OEl0ofk9QvN1ogbhPTg9gLYq3LVfy i3b8vLmSXM3vSiaWT0vzDdfIPVuI6xps08Qj8YCSppp+iiqyXLC7IjPxC+NEq3/4A7ICfNRpO6GM4 QYbvzZjEM7IFZaFXNlhwvIVOtZZTL9Kmwf2IQlX1GUowQNUkXADtFpVK9hUCgEOLpdmccNaGqUWra 0NvGIbdA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tNjlc-0000000FOFb-1UCn; Wed, 18 Dec 2024 02:26:28 +0000 From: Luis Chamberlain To: hare@suse.de, willy@infradead.org, dave@stgolabs.net, david@fromorbit.com, djwong@kernel.org, kbusch@kernel.org Cc: john.g.garry@oracle.com, hch@lst.de, ritesh.list@gmail.com, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, gost.dev@samsung.com, p.raghav@samsung.com, da.gomez@samsung.com, kernel@pankajraghav.com, mcgrof@kernel.org Subject: [PATCH 5/5] fs/buffer: reduce stack usage on bh_read_iter() Date: Tue, 17 Dec 2024 18:26:26 -0800 Message-ID: <20241218022626.3668119-6-mcgrof@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241218022626.3668119-1-mcgrof@kernel.org> References: <20241218022626.3668119-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: DD59DC000A X-Stat-Signature: gf4xwqufzz913mu5hn9jgr56nku9q34p X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1734488778-79959 X-HE-Meta: U2FsdGVkX18P7yNIrji66WlQ0jCZ97I2KymVuvBfhFbu/TCRhpDiOOq6xUx0HngOt0HL+81rXg+bpXR3sU6oqLG1+NbdIL46ijLEJ4kBvh9yKKchFUmrFRumDGfJelkDvIHXIimS/Mn2wV6JAX3UpHEzg4nleQMk/0poeaRpSWMs5e2hKrDh6sY600QUQvqB5NAsE3VlTcOv8vRFQyzm4/yqh1puCfSfwP66ElwbMTuDadTyIoZl88lul3kvN+w9FWehf2KE6CGyjeuZq8t8IUDgrfMcrn1TedZIilQ2MekqUh0fk9b9lC14lTeF4qzGNlp6PY/VS/BaWLJ7lkVQvstd6cQgIx8kU1IkgCNu+tvRltbY4rPA8b7I0/e52KqLKDSLiedSzefdLfM6khI4WPUaxP7Hy+X2xlBnWOvFXtBMD7jSThOtn15Sm+mnJ1ytGsdVw81V/geMmLi1Q795tn7blN6unYzyU3b3uPJcssPWCiru63V2aXUT2PROsnsvJiN3zXRWdKuu+2Rmh1YuUikLygv7dRF+KDlbFkuhmdBUZCNNsv+qC7EcISSiBA7Hiags/VTSzkDA5w2RqRCdZwxLf8luyXTZ9aMkaBRF32AgFI+9iB1R5cmsp11E05NZE2321F+Nem/61fHRZppIGaeZHKZgzq6mOztu7LqFFxZWXYTwWzW+u3UxTugr6dtMTTOuCgYTBPZKo/fyD5RLOJEkuw1yhjZIJHS9Ry7FA48HpAVKbBMk4/WCMa1FAiCW0B9Zbe6My2VDjlyHWRupTsH7UzUpM5RbVZNkZkuHNT1g7sgezMPdoDUVXVBE1Lmg7ldidw8gq3n1OY/b1w9BtGVsuZtA4cf+3odS8QXjx7oiuWgDNQYCk/lfrjbjUc2vW0/ZhBoFZrfoXm4XghSDNs6AuaQxDTOsy5aE4HA4SZeOCsw/U0HuBoiLWU2IBh2A52qqRsV2fG0c6ErMmKj v7gr3U8q HW2cqyM7CN5jg3nX3GJPE/GvlQNKoXE0qgqkBL8SBfLlbVLcSNUoCtOg5iuS55czFiE33/himrCJomPtz0o1F97LBEbpVgfmjcIr4ZOa+znhtizO7Yq5CBWzB6uotSmNBkQBvL6TvYP+Q2IftVYouFkKK4W+IzJLoCu0URgR/M7B4Lc8t3hq8i9KiPy0pygL7oDLKTc12D2t9KdCYGMkaqEW79F0Wcqjbh925NLOtWQMiK3vqSfQPtlpxCcRomWOlCDFjDr1uy/5038hON28gWTh5uF1KSe/WXBCW73k62sb8qQ1M2Y8BmI1J96ofIJQnppqyMgKvWj7XAObRCCHyniZv8/NaqXdVqtx2/gM+fDGCoLObKqPLqpEO3nnINy2etI6RgHDs88AgTPF2l6Y2SVQhTSe0DUj28+m0Obs3Yv9CAFCX7Ke4GjOyVZQVV6f35S0ZDdpVXUWLCkwRkKFWVAFgpsd0LvS+5wbZMc/T607kLM7NqTPxvS8PZlPLHJT2de7BhqO8hjzOXm01GTpFkl451WiKWKbtMh3+7svRy60bxR0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000021, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Now that we can read asynchronously buffer heads from a folio in chunks, we can chop up bh_read_iter() with a smaller array size. Use an array of 8 to avoid stack growth warnings on systems with huge base page sizes. Reviewed-by: Hannes Reinecke Signed-off-by: Luis Chamberlain --- fs/buffer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index b8ba72f2f211..bfa9c09b8597 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2415,7 +2415,10 @@ static void bh_read_batch_async(struct folio *folio, (__tmp); \ (__tmp) = bh_next(__tmp, __head)) +#define MAX_BUF_CHUNK 8 + struct bh_iter { + int chunk_number; sector_t iblock; get_block_t *get_block; bool any_get_block_error; @@ -2424,7 +2427,7 @@ struct bh_iter { }; /* - * Reads up to MAX_BUF_PER_PAGE buffer heads at a time on a folio on the given + * Reads up to MAX_BUF_CHUNK buffer heads at a time on a folio on the given * block range iblock to lblock and helps update the number of buffer-heads * which were not uptodate or unmapped for which we issued an async read for * on iter->bh_folio_reads for the full folio. Returns the last buffer-head we @@ -2436,10 +2439,11 @@ static struct buffer_head *bh_read_iter(struct folio *folio, struct inode *inode, struct bh_iter *iter, sector_t lblock) { - struct buffer_head *arr[MAX_BUF_PER_PAGE]; + struct buffer_head *arr[MAX_BUF_CHUNK]; struct buffer_head *bh = pivot, *last; int nr = 0, i = 0; size_t blocksize = head->b_size; + int chunk_idx = MAX_BUF_CHUNK * iter->chunk_number; bool no_reads = false; bool fully_mapped = false; @@ -2447,7 +2451,8 @@ static struct buffer_head *bh_read_iter(struct folio *folio, /* collect buffers not uptodate and not mapped yet */ for_each_bh_pivot(bh, last, head) { - BUG_ON(nr >= MAX_BUF_PER_PAGE); + if (nr >= MAX_BUF_CHUNK) + break; if (buffer_uptodate(bh)) { iter->iblock++; @@ -2487,8 +2492,7 @@ static struct buffer_head *bh_read_iter(struct folio *folio, } iter->bh_folio_reads += nr; - - WARN_ON_ONCE(!bh_is_last(last, head)); + iter->chunk_number++; if (bh_is_last(last, head)) { if (!iter->bh_folio_reads) @@ -2518,6 +2522,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) struct buffer_head *bh, *head; struct bh_iter iter = { .get_block = get_block, + .chunk_number = 0, .unmapped = 0, .any_get_block_error = false, .bh_folio_reads = 0,