From patchwork Tue Apr 14 15:02:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11488021 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 0513115AB for ; Tue, 14 Apr 2020 15:03:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC9D52078B for ; Tue, 14 Apr 2020 15:03:20 +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="utxnrz3v" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC9D52078B 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 8B40B8E0013; Tue, 14 Apr 2020 11:02:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 825C68E0014; Tue, 14 Apr 2020 11:02:43 -0400 (EDT) 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 408D78E000F; Tue, 14 Apr 2020 11:02:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id D7F9C8E000F for ; Tue, 14 Apr 2020 11:02:42 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 98A75283C for ; Tue, 14 Apr 2020 15:02:42 +0000 (UTC) X-FDA: 76706777364.05.rate91_51d184841354a X-Spam-Summary: 20,1.5,0,e62f38691d3f74e3,d41d8cd98f00b204,willy@infradead.org,,RULES_HIT:41:355:379:541:800:929:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:4321:5007:6261:6653:6742:7576:7808:7875:9036:10004:11026:11658:11914:12043:12296:12297:12438:12555:12895:13069:13311:13357:13894:14096:14181:14384:14394:14721:21063:21080:21451:21627:21990:30054:30064:30070,0,RBL:198.137.202.133:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.0.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:40,LUA_SUMMARY:none X-HE-Tag: rate91_51d184841354a X-Filterd-Recvd-Size: 3782 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Apr 2020 15:02:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=WfxVIQbzH9o8gavebp1mRU1CPxrl55pCfYyCVUPCjeY=; b=utxnrz3vTeaE2MmO4KHCnLGYE3 MY8TBtA84T93LzmFRoxfwGLXp+AnifxNBEOyHkVUt++LE3uFa0N3wrQ+nK5RSU43Ia4XRn+/1K2k+ r4j4MH4CtMN/haSqJ64Dvs3gdCAtZpnYlZYMnazXiRjrJJurwomFH1sNMn8MsFrvJA/qDB6icJxIw BXPKVOVd6QrksY7rKyX5iofBaSwRFzD7mr7XhT1dnLg+jqSAoOE8pjI587n6VfT7jYx9/5U/5ihzv c9cG1tYHLDvaqE/AyWcOznXdGGOxCLuTfgf/sOG1tBw0ZXe53z26EPaTvad2escHU84R8pJx/h0+2 udGUVreA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jON5A-0006Ol-4U; Tue, 14 Apr 2020 15:02:36 +0000 From: Matthew Wilcox To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, ocfs2-devel@oss.oracle.com, linux-xfs@vger.kernel.org, John Hubbard , William Kucharski Subject: [PATCH v11 12/25] mm: Move end_index check out of readahead loop Date: Tue, 14 Apr 2020 08:02:20 -0700 Message-Id: <20200414150233.24495-13-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200414150233.24495-1-willy@infradead.org> References: <20200414150233.24495-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: From: "Matthew Wilcox (Oracle)" By reducing nr_to_read, we can eliminate this check from inside the loop. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: John Hubbard Reviewed-by: William Kucharski --- mm/readahead.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index d01531ef9f3c..998fdd23c0b1 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -167,8 +167,6 @@ void __do_page_cache_readahead(struct address_space *mapping, unsigned long lookahead_size) { struct inode *inode = mapping->host; - struct page *page; - unsigned long end_index; /* The last page we want to read */ LIST_HEAD(page_pool); loff_t isize = i_size_read(inode); gfp_t gfp_mask = readahead_gfp_mask(mapping); @@ -178,22 +176,26 @@ void __do_page_cache_readahead(struct address_space *mapping, ._index = index, }; unsigned long i; + pgoff_t end_index; /* The last page we want to read */ if (isize == 0) return; - end_index = ((isize - 1) >> PAGE_SHIFT); + end_index = (isize - 1) >> PAGE_SHIFT; + if (index > end_index) + return; + /* Don't read past the page containing the last byte of the file */ + if (nr_to_read > end_index - index) + nr_to_read = end_index - index + 1; /* * Preallocate as many pages as we will need. */ for (i = 0; i < nr_to_read; i++) { - if (index + i > end_index) - break; + struct page *page = xa_load(&mapping->i_pages, index + i); BUG_ON(index + i != rac._index + rac._nr_pages); - page = xa_load(&mapping->i_pages, index + i); if (page && !xa_is_value(page)) { /* * Page already present? Kick off the current batch of