Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6927782rdb; Fri, 15 Dec 2023 12:06:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEwO6L8/O9SEijsErgyRO8V/LHv6xKVWKFiXP7SnQJnww2EsqOwa+JiL4z7vFQ/eKdrYqKC X-Received: by 2002:a05:6e02:1bc6:b0:35d:690d:9996 with SMTP id x6-20020a056e021bc600b0035d690d9996mr16710056ilv.3.1702670801538; Fri, 15 Dec 2023 12:06:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702670801; cv=none; d=google.com; s=arc-20160816; b=wQHXkhnVAH1pE3utdQIrbzu/cjfTpfMIm5xZCYT3XuVdiEWyXSB6JDUQu2ME5tRUis 7wDEvAKFCGKNT4dXtuKNv7RR0RIBoRrnr7+qLQN4/D0wzgUpxdIPUmbIg3LTIVeoud6Y XTRzLULR5oxkgvRDge9vX+wb3IlxFx/IQ8MwT021JXsas3Y+wurYgPgk89YEwvbRwce2 1NgmyTRdsZ0ARp6bx8HU0Ab+N21DLIGrDnaPTA7nZpYForiZP+LF4otuQxV53YL3offA 16gTRgZV4YCdXelZ8X5ZWHZ7s5Jj4imF/upW2JYXj7+LqCxg3z5I7SoBO7T8H6J4NzTc 2Caw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=y2LTUl+ZxJP8korj46ZIojz6qFBZmH/UltM1ueD//bY=; fh=timWtHA7UGScEpXk98kbQKGrJEBXaf2Y1JfEnqzAnNI=; b=0LLaiBqlToXqBWyJYHSJRP0Ti7gMZKXLpNIG9h/rOM/3yik0zJhStaz0yQFYR5Q3SD CGth+csZFFLYvQazRV7lzbiTuz4354CID9LNMWTqVB1cMw+lhwufZAjEmOYdM/j+AmrQ iZu7FmsSdxseGQRoJtgTHfnY6WePWhVOaWUAGkhjSVNy3foxMEAusSOMYsjBvpF1XDUu mL2N/oDGuB8vp0tIKZt9JAFbY+s6iT95aaemU/Q86zT9hxqB9KRg/hOMwF0C9lSPkzV7 GAo4zVcZ4RWPvwHl7AqQfQIm9Bl8dPQwIi7LHN4MRa8G7N2pJTcCbL+HJTm75iNdl8tv NXqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=CgLipEpS; spf=pass (google.com: domain of linux-kernel+bounces-1602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1602-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z25-20020a656659000000b005c67791904bsi12911481pgv.777.2023.12.15.12.06.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 12:06:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=CgLipEpS; spf=pass (google.com: domain of linux-kernel+bounces-1602-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1602-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 562FA287215 for ; Fri, 15 Dec 2023 20:06:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 214A9692A1; Fri, 15 Dec 2023 20:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CgLipEpS" X-Original-To: linux-kernel@vger.kernel.org Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBBE45639E; Fri, 15 Dec 2023 20:02:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=y2LTUl+ZxJP8korj46ZIojz6qFBZmH/UltM1ueD//bY=; b=CgLipEpSQeL7n3K7h5qv//dI1J Hyxu1SNcuc6KE8jhGSWFs58vYD3Ub89XHd7GA8EZWVff0bnCAQ2AUPlYAcWmRslUjziZa2Txj/tdR lZb6urewEhwHsr+FYouUuqEuHYuh6LVjV4L23AiWMXhDxMJGDXScMgR0BKTTWz/qXkwG/ZCxdq8Ir lPuibOk7rQWaudaDIcmh+imazfOubEGNxtJd+4tg2i92riw+HuTk67lZpzaAQ5j8acssDeDrM1W2d RQEqLCazr3B5+hkCZ5B8FYOaHepMoxpgtSmO8YS/auXztCf+iqOwvANUpuLNAb3LtykX77pNzIHHZ PDjxz1zg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rEEOV-0038iK-3c; Fri, 15 Dec 2023 20:02:47 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , Christoph Hellwig , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH 03/14] fs: Reduce stack usage in __mpage_writepage Date: Fri, 15 Dec 2023 20:02:34 +0000 Message-Id: <20231215200245.748418-4-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231215200245.748418-1-willy@infradead.org> References: <20231215200245.748418-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some architectures support a very large PAGE_SIZE, so instead of the 8 pointers we see with a 4kB PAGE_SIZE, we can see 128 pointers with 64kB or so many on Hexagon that it trips compiler warnings about exceeding stack frame size. All we're doing with this array is checking for block contiguity, which we can as well do by remembering the address of the first block in the page and checking this block is at the appropriate offset from that address. Signed-off-by: Matthew Wilcox (Oracle) --- fs/mpage.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/mpage.c b/fs/mpage.c index 630f4a7c7d03..84b02098e7a5 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -466,7 +466,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, const unsigned blocks_per_page = PAGE_SIZE >> blkbits; sector_t last_block; sector_t block_in_file; - sector_t blocks[MAX_BUF_PER_PAGE]; + sector_t first_block; unsigned page_block; unsigned first_unmapped = blocks_per_page; struct block_device *bdev = NULL; @@ -504,10 +504,12 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, if (!buffer_dirty(bh) || !buffer_uptodate(bh)) goto confused; if (page_block) { - if (bh->b_blocknr != blocks[page_block-1] + 1) + if (bh->b_blocknr != first_block + page_block) goto confused; + } else { + first_block = bh->b_blocknr; } - blocks[page_block++] = bh->b_blocknr; + page_block++; boundary = buffer_boundary(bh); if (boundary) { boundary_block = bh->b_blocknr; @@ -556,10 +558,12 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, boundary_bdev = map_bh.b_bdev; } if (page_block) { - if (map_bh.b_blocknr != blocks[page_block-1] + 1) + if (map_bh.b_blocknr != first_block + page_block) goto confused; + } else { + first_block = map_bh.b_blocknr; } - blocks[page_block++] = map_bh.b_blocknr; + page_block++; boundary = buffer_boundary(&map_bh); bdev = map_bh.b_bdev; if (block_in_file == last_block) @@ -591,7 +595,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, /* * This page will go to BIO. Do we need to send this BIO off first? */ - if (bio && mpd->last_block_in_bio != blocks[0] - 1) + if (bio && mpd->last_block_in_bio != first_block - 1) bio = mpage_bio_submit_write(bio); alloc_new: @@ -599,7 +603,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, bio = bio_alloc(bdev, BIO_MAX_VECS, REQ_OP_WRITE | wbc_to_write_flags(wbc), GFP_NOFS); - bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9); + bio->bi_iter.bi_sector = first_block << (blkbits - 9); wbc_init_bio(wbc, bio); } @@ -627,7 +631,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, boundary_block, 1 << blkbits); } } else { - mpd->last_block_in_bio = blocks[blocks_per_page - 1]; + mpd->last_block_in_bio = first_block + blocks_per_page - 1; } goto out; -- 2.42.0