From patchwork Fri Jan 22 16:01:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 12039873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB145C433E0 for ; Fri, 22 Jan 2021 16:04:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4109C23159 for ; Fri, 22 Jan 2021 16:04:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4109C23159 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E2B16B0007; Fri, 22 Jan 2021 11:04:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 792DF6B000A; Fri, 22 Jan 2021 11:04:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CF426B000C; Fri, 22 Jan 2021 11:04:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 599A46B0007 for ; Fri, 22 Jan 2021 11:04:42 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 21676824999B for ; Fri, 22 Jan 2021 16:04:42 +0000 (UTC) X-FDA: 77733884004.19.land12_17088352756d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 95D5414D15 for ; Fri, 22 Jan 2021 16:04:12 +0000 (UTC) X-HE-Tag: land12_17088352756d X-Filterd-Recvd-Size: 3494 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Jan 2021 16:04:11 +0000 (UTC) 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=bJrHcc3TRuo3zacTOm7nFFwlB8n6a0vSf1BsFy5yvWQ=; b=UKPS+BewMN+ObHxdDV7pNY8in4 d9ph4PhrCy1FYoao5Lt9YvjBfIYfrHSEGPWJj5E9L9MqjqtRwEjM/ExkPiDCNm2Iz3kEYRU4oMpTF Bh206af6zhRXC8+wx7nYXN6SP3Ve3EiviJFg1ykq+SVM+jtVamePjfj5weYJDZYOgpXTa2fRcI+dB oU0g91XHwKHqpQ2mDQztKYZ1B3Jjh29uPgGR8Id45+TdAm/32EKm9715xAh/u3/DjrrzaAwFmJsbE +kIe6kkJZ6JqiFpGYQJlh0s4tFyqSWDzqI+mPBiplMywYnHsIIDzUZuJSfpSdVSMFhZ8RxrPbcUr9 9ZJlmsRg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1l2ytq-000wAw-An; Fri, 22 Jan 2021 16:03:09 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Miaohe Lin Subject: [PATCH v5 02/18] mm/filemap: Remove dynamically allocated array from filemap_read Date: Fri, 22 Jan 2021 16:01:24 +0000 Message-Id: <20210122160140.223228-3-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210122160140.223228-1-willy@infradead.org> References: <20210122160140.223228-1-willy@infradead.org> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Increasing the batch size runs into diminishing returns. It's probably better to make, eg, three calls to filemap_get_pages() than it is to call into kmalloc(). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: Miaohe Lin --- mm/filemap.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index afc0f674f2242..a5c4f7ddfc40c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2444,8 +2444,8 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, struct file_ra_state *ra = &filp->f_ra; struct address_space *mapping = filp->f_mapping; struct inode *inode = mapping->host; - struct page *pages_onstack[PAGEVEC_SIZE], **pages = NULL; - unsigned int nr_pages = min_t(unsigned int, 512, + struct page *pages[PAGEVEC_SIZE]; + unsigned int nr_pages = min_t(unsigned int, PAGEVEC_SIZE, ((iocb->ki_pos + iter->count + PAGE_SIZE - 1) >> PAGE_SHIFT) - (iocb->ki_pos >> PAGE_SHIFT)); int i, pg_nr, error = 0; @@ -2459,14 +2459,6 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, iov_iter_truncate(iter, inode->i_sb->s_maxbytes); - if (nr_pages > ARRAY_SIZE(pages_onstack)) - pages = kmalloc_array(nr_pages, sizeof(void *), GFP_KERNEL); - - if (!pages) { - pages = pages_onstack; - nr_pages = min_t(unsigned int, nr_pages, ARRAY_SIZE(pages_onstack)); - } - do { cond_resched(); @@ -2551,9 +2543,6 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, file_accessed(filp); - if (pages != pages_onstack) - kfree(pages); - return written ? written : error; } EXPORT_SYMBOL_GPL(generic_file_buffered_read);