From patchwork Sat Dec 14 03:10:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13908280 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 AB437E7716A for ; Sat, 14 Dec 2024 03:11:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 433276B0096; Fri, 13 Dec 2024 22:11:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EB0E6B009F; Fri, 13 Dec 2024 22:11:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE4C06B009E; Fri, 13 Dec 2024 22:11:02 -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 0A1CD6B0093 for ; Fri, 13 Dec 2024 22:11:02 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A534B141689 for ; Sat, 14 Dec 2024 03:11:01 +0000 (UTC) X-FDA: 82892087082.23.D3DEE4E Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id D274AC000B for ; Sat, 14 Dec 2024 03:10:29 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=y+Vot3PJ; spf=none (imf28.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=1734145840; 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=ly9Z0m8eTHU3wfdp35JFAoonrPj9YJ5xpu33d2EAXi4=; b=IkI5EWjrDdAxgauCRCzPJQXSrvAj2YpzYzYswq9FCD5GqOZx5Oq1lMS19g9jUuTuiSIVtN eF1n/CkT2utK/ZslJ2zxXY4+raiMGtFHadxR0xpbbBaY4F6lWt8DzHMhCSBMCpI7/IqwG4 su9hCu05ii/4iPjmgXJMLzNHdExPL/c= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=y+Vot3PJ; spf=none (imf28.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=1734145840; a=rsa-sha256; cv=none; b=CVuFrNGVvzXKJyvYAsp0AMjYwsrSFE8g2N01cXFmSxCe6JkyTp41JockMrhgWFJGV41zxR 1eHp27jxYxMqzhXbCoiyCVAv+3lBIKs0PgZQaWAiKq3t+401iCKnupgiY0LZNnqXpaB1Mh moEtfdOrMGyxHHcV9OtabockHhFnOdA= 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=ly9Z0m8eTHU3wfdp35JFAoonrPj9YJ5xpu33d2EAXi4=; b=y+Vot3PJozFxtHqZ7Fp9JDbo4c jsrflL/YvKop7QmnivqVS3/9cSOrtdNg1NZt87O4y3Fo0P3YmFEh9/6/z11Ef8JQPkW11UbAml0SX dB33hD26ixC0mXy6W9q36zaEDrc+EuP2Gay4kESD2wcM+A4tuvYvCRryQz1gZrGPfX6i8p2pffDWZ DouswSptmAW/mI1zWobDfnT0kYB+yzVgSHn87hRfSub8MYVWaJdRL+WpipyflNXZIoh8fl/YQ4MMU hxiYm95uqF/bNOR2mx96TdbdT1NVHq4GImAWGKf8IHWbdAstSa0ejAnvTpz9mLIlOtxuybuU1h404 JfGexPMg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tMIYN-00000005c3Z-3ONS; Sat, 14 Dec 2024 03:10:51 +0000 From: Luis Chamberlain To: willy@infradead.org, hch@lst.de, hare@suse.de, dave@stgolabs.net, david@fromorbit.com, djwong@kernel.org Cc: john.g.garry@oracle.com, ritesh.list@gmail.com, kbusch@kernel.org, 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: [RFC v2 02/11] fs/buffer: add a for_each_bh() for block_read_full_folio() Date: Fri, 13 Dec 2024 19:10:40 -0800 Message-ID: <20241214031050.1337920-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241214031050.1337920-1-mcgrof@kernel.org> References: <20241214031050.1337920-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: D274AC000B X-Rspamd-Server: rspam12 X-Stat-Signature: egc4jpzrudx3hcfzswknti6f1rg9uott X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1734145829-866680 X-HE-Meta: U2FsdGVkX1/CRE7YVDlsghunLDb1UJLhO0lGPT/O9zCPHLxMMA2jpY6f3l2d4W4PPAVWy+8zxluZOj0mnZ3qwxOsTg/izNV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RWU3FjK82UT+LIy0ZZxHtBsXOaqgmOUoz2tvPrv9pAMU+/bwB0JmF7CTD/8U2DjDj5pAO9TLLJL02/LS8sT8HKyjhIjxSdje8daeRJIwMQtbzOcZoKwvLWUzXQwlyPrgRQheBTyusuVhVd00HDgT1VBpYwqgb/N0NaeH5HZhFcsKIIE+X5XlUT79VI6ybVEoihKkufaSo94QZlN5OqdFI4AkGrCvouVjYydgGNJpQt4OjgL01VZdQ8NB1ypoEOn5DNVziYNy0gu5nBLgSKy0rGrv2DdbdLZh8HTXUr/+iXWaSNEiwNPPoWlmmmOFIm3N1R58/nZNP6I9c15V1GcMFfwh/yR/laHQVfKzGrQJewauxk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.002869, 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. Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke --- fs/buffer.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 580451337efa..108e1c36fc1a 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2392,6 +2392,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. @@ -2421,11 +2432,10 @@ 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; i = 0; - do { + for_each_bh(bh, head) { if (buffer_uptodate(bh)) continue; @@ -2454,7 +2464,9 @@ 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); + i++; + iblock++; + } bh_read_batch_async(folio, nr, arr, fully_mapped, nr == 0, page_error);