From patchwork Tue Nov 10 03:36:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11893133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA501697 for ; Tue, 10 Nov 2020 03:38:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7DB8020897 for ; Tue, 10 Nov 2020 03:37:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Hl/PQO2F" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7DB8020897 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 ECAE66B0072; Mon, 9 Nov 2020 22:37:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E02706B0075; Mon, 9 Nov 2020 22:37:14 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD9656B0072; Mon, 9 Nov 2020 22:37:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 6FD0B6B0074 for ; Mon, 9 Nov 2020 22:37:14 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0F45B180AD811 for ; Tue, 10 Nov 2020 03:37:14 +0000 (UTC) X-FDA: 77467097988.16.pear64_2917b39272f1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id DD066100E690C for ; Tue, 10 Nov 2020 03:37:13 +0000 (UTC) X-Spam-Summary: 1,0,0,94dac1f70e16c2c5,d41d8cd98f00b204,willy@infradead.org,,RULES_HIT:41:69:355:379:541:800:960:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3867:3871:3872:4385:5007:6261:6653:8603:8660:9036:9592:10004:11026:11473:11658:11914:12043:12296:12297:12438:12555:12895:13069:13148:13230:13255:13311:13357:13894:14096:14181:14384:14394:14721:21080:21212:21451:21627:21939:21990:30054,0,RBL:90.155.50.34:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.15.100;04yrg9a5ocbugabwu4ihrmyamkc6sypmf6sg9znxgda1a3k7rymqdosxzan51qf.m1rmxwqb4eum5pjfxxd4gfiynutspmrwyqcz1t795x73uwqrzbw5qmz4fr5x68f.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:68,LUA_SUMMARY:none X-HE-Tag: pear64_2917b39272f1 X-Filterd-Recvd-Size: 3304 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 03:37: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=IEtkIPQsQeLEcKSFUu4N+/Cun43SD1V6eMts9/zmGx4=; b=Hl/PQO2FwemV3wj9gFckd/k1bb QaKrhl83gqTYX0WnUJ9jf3dEN5UboqfjNIojp5j8tMj+XiMBYPQSPtTJzXQyS5kIrYiVE7ieu0j3K h8EgrvXYmFbz7ctdNQsKrsJ/BzY/2d+k/iEkbOKebEedPcIkSF5ehwUepFxDsV+QqcuXEDNcaFyEL aPg69wlCihBhyGTQ55rRbVhq7rG9OqZMcnIMh9/G6wsIRRFWbkzHNQfJj9yujQV3zlwxwrSYv6URg x/GvQ8i6CYUYo9i06rG7rrMP9uh+agpPr4yFIT4yFeP97ITAyOmV/5BuT54lCYS3W4KQqpub1C4bG fBK9Jolw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcKSv-00064X-Q6; Tue, 10 Nov 2020 03:37:05 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , hch@lst.de, kent.overstreet@gmail.com Subject: [PATCH v3 02/18] mm/filemap: Remove dynamically allocated array from filemap_read Date: Tue, 10 Nov 2020 03:36:47 +0000 Message-Id: <20201110033703.23261-3-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201110033703.23261-1-willy@infradead.org> References: <20201110033703.23261-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 --- mm/filemap.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 23e3781b3aef..bb1c42d0223c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2429,8 +2429,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; @@ -2441,14 +2441,6 @@ ssize_t generic_file_buffered_read(struct kiocb *iocb, return 0; 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(); @@ -2533,9 +2525,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);