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);