From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 5F537C34024 for ; Mon, 17 Feb 2020 18:47:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 29F8620836 for ; Mon, 17 Feb 2020 18:47:02 +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="l7hv3PdT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 29F8620836 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 0F2CE6B007D; Mon, 17 Feb 2020 13:46:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 005426B0080; Mon, 17 Feb 2020 13:46:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5E0C6B007E; Mon, 17 Feb 2020 13:46:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 8609D6B0075 for ; Mon, 17 Feb 2020 13:46:23 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 38244180AD802 for ; Mon, 17 Feb 2020 18:46:23 +0000 (UTC) X-FDA: 76500499446.10.owl70_1a9af3bede650 X-HE-Tag: owl70_1a9af3bede650 X-Filterd-Recvd-Size: 4464 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Mon, 17 Feb 2020 18:46:22 +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=f6e1vXABPDL0rMBXcPDUicTcSHShodWe/Rf26ms+MIM=; b=l7hv3PdTD5FlyDvtWj7UIPyYIh pFC/dM1GbjDjHpQBTch+Ju7Tj6oFrw59IcILNGPJj2pRhPguzUqywp4ihcqCujOiORMcLauMi6++M kn6iUgpEid7/AdCzyF06VM+n6zhEa4s9iKGvJ120z70Va5ZAEKt7ybAjLiNO1ZRtcnYM7cRhfYHny FViLwoiNRNq0gdWXh6D6fvopIONeuQBtk3up9M2TW0Ly/0YrIA1GEBuqfD5GflLHZuRNw8q2V6UNg AioV/Bgo3ETArbEHNGlWf/KkKm7VWOmabymzPwLel4x8sURqCjyXn6tWcxXkHiaNRugSbhMboBXBa CMyA7Qyw==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j3lPL-00058v-ER; Mon, 17 Feb 2020 18:46:15 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , 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 Subject: [PATCH v6 04/16] mm: Tweak readahead loop slightly Date: Mon, 17 Feb 2020 10:45:46 -0800 Message-Id: <20200217184613.19668-6-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200217184613.19668-1-willy@infradead.org> References: <20200217184613.19668-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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)" Eliminate the page_offset variable which was just confusing; record the start of each consecutive run of pages in the readahead_control, and move the 'kick off a fresh batch' code to the end of the function for easier use in the next patch. Signed-off-by: Matthew Wilcox (Oracle) --- mm/readahead.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mm/readahead.c b/mm/readahead.c index 15329309231f..74791b96013f 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -154,7 +154,6 @@ void __do_page_cache_readahead(struct address_space *= mapping, unsigned long lookahead_size) { struct inode *inode =3D mapping->host; - struct page *page; unsigned long end_index; /* The last page we want to read */ LIST_HEAD(page_pool); int page_idx; @@ -163,6 +162,7 @@ void __do_page_cache_readahead(struct address_space *= mapping, struct readahead_control rac =3D { .mapping =3D mapping, .file =3D filp, + ._start =3D offset, ._nr_pages =3D 0, }; =20 @@ -175,32 +175,39 @@ void __do_page_cache_readahead(struct address_space= *mapping, * Preallocate as many pages as we will need. */ for (page_idx =3D 0; page_idx < nr_to_read; page_idx++) { - pgoff_t page_offset =3D offset + page_idx; + struct page *page; =20 - if (page_offset > end_index) + if (offset > end_index) break; =20 - page =3D xa_load(&mapping->i_pages, page_offset); + page =3D xa_load(&mapping->i_pages, offset); if (page && !xa_is_value(page)) { /* - * Page already present? Kick off the current batch of - * contiguous pages before continuing with the next - * batch. + * Page already present? Kick off the current batch + * of contiguous pages before continuing with the + * next batch. This page may be the one we would + * have intended to mark as Readahead, but we don't + * have a stable reference to this page, and it's + * not worth getting one just for that. */ - if (readahead_count(&rac)) - read_pages(&rac, &page_pool, gfp_mask); - rac._nr_pages =3D 0; - continue; + goto read; } =20 page =3D __page_cache_alloc(gfp_mask); if (!page) break; - page->index =3D page_offset; + page->index =3D offset; list_add(&page->lru, &page_pool); if (page_idx =3D=3D nr_to_read - lookahead_size) SetPageReadahead(page); rac._nr_pages++; + offset++; + continue; +read: + if (readahead_count(&rac)) + read_pages(&rac, &page_pool, gfp_mask); + rac._nr_pages =3D 0; + rac._start =3D ++offset; } =20 /* --=20 2.25.0