Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp1330118rwe; Fri, 14 Apr 2023 19:36:57 -0700 (PDT) X-Google-Smtp-Source: AKy350bW27fQqbop3mh8eMY1Pru66bCXEMkA3gQ6H62s+s6ge9cTqVoWQpUWq+Izcf45AfUQkCAR X-Received: by 2002:a17:902:6944:b0:1a6:99a6:3547 with SMTP id k4-20020a170902694400b001a699a63547mr4702246plt.16.1681526217700; Fri, 14 Apr 2023 19:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681526217; cv=none; d=google.com; s=arc-20160816; b=nuuC/MX1AIhL5Emxo90YKSQGI9aSyLEybSk/wFktCB5oWCCrn/UMbJAQcZMBePtvaJ h8d9VXhqsqyZL7XPIZIjglMrrZlgQGwAj/ECMbLYZEseXzsB5bYPYolLIcLs9ueZxFNm /UhgkiFQJJCqsBDPY0SAPkVvpB2zLHXztBFDsg5W9BoER1rwGHPKWBmU5nHBt9Hio5D1 WeimJT5YD7EyQ7r6bP7CXX3or3g2EZeK1V7Sf4Aw+CoxiKMjah3oOFn6fl8nBseo7knO gM1YTNA6jGPD8nLXOZDok49n1zsLPXiqFJrxpjeffyQOtUNVorFd+7RW5DTuqF40Th0c C3ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=LKu44/7divD7drUoUvhwbQweIThwjY6Ox0fiwkad+8M=; b=HNdThcfFG8nxRrwnx3+YClDpbCsbU79tw5EdrwZii6Wq3BFJBnxKNNz+/Jk1cZI9/p fGYSALTN9vrKj0Pj0cCmcn49rwnTFfXQqqAtcaWRXPCMRm8CemvFGiNyxnSEgNQguEtg vEmAFDmYgWqx80ly0BclohM5ugAtoA8D3MFf1pkRn19diVOZKeV5Z2iAU2W0aZV4HgyL R9G4rWktyELd3mIAeKTcwZDRCVT34w6VxtlIBNedYT4EicBQvBtfhdxP1+3S7+FJvAHe ivG91JXxjUWlynHXM2R6X2PP8nzA168rij7mMOeMQvfoHIUTtXXYdK02panB0Ub65f+C nCHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=jkOcp4tW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t11-20020a170902a5cb00b0019cf4957404si5742434plq.24.2023.04.14.19.36.36; Fri, 14 Apr 2023 19:36:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=jkOcp4tW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230180AbjDOCcF (ORCPT + 99 others); Fri, 14 Apr 2023 22:32:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjDOCcE (ORCPT ); Fri, 14 Apr 2023 22:32:04 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66B2D59D2; Fri, 14 Apr 2023 19:32:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=LKu44/7divD7drUoUvhwbQweIThwjY6Ox0fiwkad+8M=; b=jkOcp4tWYw5Dep25AqfvxqhTc4 GTCA3dP1WQgfymf/IooR40z7GLI6DLMgaeBasOvQVaaWYSmM4lh4dDW2fLel82NDzIZ54rPbUdBzF xGvbNAmM5pdLlIE7sS9cxobQ9+7HClxopbNumnWDoEVWsA1Vh7b4iYmCT4yTIIRJSWCY67XcTm4rR OxkafstpetKZvyEgWnM6lI1eEnlJ9+3hnMMXhm9n33RXXVT/l6PuA/Feqhjg1Xp4msf5SKcdVyT4F VFOYthuGpidWVrHCEv54eK76yMlcnMoa8POrsHHhRZlL6Ar004znok/fKBak7xVhndNnL5tNnqVsF 1/RCzSfg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pnVhi-009Hpb-FL; Sat, 15 Apr 2023 02:31:54 +0000 Date: Sat, 15 Apr 2023 03:31:54 +0100 From: Matthew Wilcox To: Luis Chamberlain Cc: Hannes Reinecke , Pankaj Raghav , brauner@kernel.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, gost.dev@samsung.com Subject: Re: [RFC 0/4] convert create_page_buffers to create_folio_buffers Message-ID: References: <20230414110821.21548-1-p.raghav@samsung.com> <1e68a118-d177-a218-5139-c8f13793dbbf@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 14, 2023 at 06:01:16PM -0700, Luis Chamberlain wrote: > a) dynamically allocate those now > b) do a cursory review of the users of that and prepare them > to grok buffer heads which are blocksize based rather than > PAGE_SIZE based. So we just try to kill MAX_BUF_PER_PAGE. > > Without a) I think buffers after PAGE_SIZE won't get submit_bh() or lock for > bs > PAGE_SIZE right now. Worse, we'll overflow the array and corrupt the stack. This one is a simple fix ... +++ b/fs/buffer.c @@ -2282,7 +2282,7 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) { struct inode *inode = folio->mapping->host; sector_t iblock, lblock; - struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE]; + struct buffer_head *bh, *head; unsigned int blocksize, bbits; int nr, i; int fully_mapped = 1; @@ -2335,7 +2335,6 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) if (buffer_uptodate(bh)) continue; } - arr[nr++] = bh; } while (i++, iblock++, (bh = bh->b_this_page) != head); if (fully_mapped) @@ -2353,24 +2352,27 @@ int block_read_full_folio(struct folio *folio, get_block_t *get_block) } /* Stage two: lock the buffers */ - for (i = 0; i < nr; i++) { - bh = arr[i]; + bh = head; + do { lock_buffer(bh); mark_buffer_async_read(bh); - } + bh = bh->b_this_page; + } while (bh != head); /* * 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]; + bh = head; + do { if (buffer_uptodate(bh)) end_buffer_async_read(bh, 1); else submit_bh(REQ_OP_READ, bh); - } + bh = bh->b_this_page; + } while (bh != head); + return 0; } EXPORT_SYMBOL(block_read_full_folio);