From patchwork Sat Dec 14 03:10:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13908279 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 82CD0E77180 for ; Sat, 14 Dec 2024 03:11:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 157E66B0092; Fri, 13 Dec 2024 22:11:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1FBD6B0096; 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 99F896B0098; Fri, 13 Dec 2024 22:11:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0AD1A6B0096 for ; Fri, 13 Dec 2024 22:11:02 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A7E6F81525 for ; Sat, 14 Dec 2024 03:11:01 +0000 (UTC) X-FDA: 82892087166.22.D1FC7DF Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf19.hostedemail.com (Postfix) with ESMTP id 81F751A0016 for ; Sat, 14 Dec 2024 03:10:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DUwsEwV0; spf=none (imf19.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=1734145835; a=rsa-sha256; cv=none; b=fPn3yYZkyipR49ELQKz+8kwjtk0XuTPQOQNmwij6j36keMLHsA/zMbaqxwU752Ut6P0rSz dzVwSuTwCirBnIS9QsXJUV3jzBK9Y6PweCt0MuzMat7bDBUvBas5s0PHNYDgNvrWu+LRJX j0zSxxKvtEzWEEdVNHOg8HlenZUT2jc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=DUwsEwV0; spf=none (imf19.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=1734145835; 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=7VkY/OzBoZXEa2cuwiycPcKImztiWgLu3Zlcz14G1p4=; b=7REC52dKhYkghyS6qqCVDmch5uUaReUHjVsz/hO8TxPHIMbPfPA7cev7G1It4Gq7e3/X6Z W1AHS622E7/IMuQ+nZ6tiuR5qZdnvivUYENlduPqeU5g6eCJmlkaC3iA2OpXcbQs75VhfG gXGGgKRYML+euPItsSw/qxnRblkm4Wg= 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=7VkY/OzBoZXEa2cuwiycPcKImztiWgLu3Zlcz14G1p4=; b=DUwsEwV079VBpxwAvrs6U6I8Cu +yB5Af7X5dyJDHK+0BxH0M7EaxriNLYaJvIdNxNvPOrYxYSQH/jU6jB8GynWgvVdzNF+teFgMqOkz mjPRr02cXWTdhinHpXpBhT4dzbeSTZFB7pJuqYAnEpNKz8fKfY9zR9r1IIknCnCbVnL2MuibGND6h Zeje92OBV13LXKmVEQ6HFBf9qbrjM5QFgsqwfDPfPRBUdVSwCTMN+0mmrrEp5a7iPTJDQkb1vIBl1 IWJrME7NwGx/w9FAz1UoW5zrg8+kESNsILRCVqNAQZjRAt/wB6HzCQ9sloAPF0+rCThoEaLmed8nf eYOcYkpA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tMIYN-00000005c3d-3dl7; 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 04/11] fs/buffer: reduce stack usage on bh_read_iter() Date: Fri, 13 Dec 2024 19:10:42 -0800 Message-ID: <20241214031050.1337920-5-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-Rspamd-Queue-Id: 81F751A0016 X-Stat-Signature: dd7uefncthrikobm6a779s96sigetf79 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: 1734145831-291350 X-HE-Meta: U2FsdGVkX19MLWjYnImmrLpdopi3Cb2qrhT6Mc8t6kvYGgMOzVT1fJsWaRQb/OCg7nS5kr1u2sAdaUqYWcKku+7orDGoLQB31B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HQGkaw2BMdMvOah6KcbCS5Zjo5GkrUybV50ewclOE+cZSf5n+bEs7N+admeyTLvPqizQ9G+ayHGDNrKXuMq71fX64txgZbYMqjhENPMF7u7L46KKe9cLjHHOu41BrLWJwLyUTlBpvCm8zbsRxq8xqL7vEG3JH0nNMcYTlFPSDG7KJgNXcMOPYR4pQA7fz6nmab5e+kH3lO5PkV/DilW0PjQLgiqY6WlQ2IS5P7dxDHne8hz8NopTaP20PhnMlUpoJPki7Ge0AeTJxdM36/cPyVSFOVoUub2+OzVkXQ1CXkAM1k2JNeTcU8D+YXi/0mn/1UjnBdEP5cbQTkhn7Rq33B7mkth7p5MTiciOegz+d2jtVI4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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. Signed-off-by: Luis Chamberlain Reviewed-by: Hannes Reinecke --- fs/buffer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index f8e6a5454dbb..b4994c48e6ee 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -2410,7 +2410,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; @@ -2419,7 +2422,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 @@ -2431,16 +2434,18 @@ 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; /* 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)) continue; @@ -2457,7 +2462,8 @@ static struct buffer_head *bh_read_iter(struct folio *folio, iter->any_get_block_error = true; } if (!buffer_mapped(bh)) { - folio_zero_range(folio, i * blocksize, + folio_zero_range(folio, + (i + chunk_idx) * blocksize, blocksize); if (!err) set_buffer_uptodate(bh); @@ -2476,8 +2482,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) @@ -2507,6 +2512,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,