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/cRsv42scnyPex1MyjXJiZHXTLZdTsL2aNv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o0sfZUB+28oL24ESFQPExHYdxIVTM6PjvSxE0ot1g2Tw8HVgIuhPKOxO9pwlIDCsp/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);