Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2886107ybv; Mon, 24 Feb 2020 13:41:09 -0800 (PST) X-Google-Smtp-Source: APXvYqycDRbCo9Ji+r0laaiZZZDZw4bYuWysfa0HEKUTVnJ5opFDR6QYp4Hl4QiEHhcpIyB+nWBd X-Received: by 2002:a9d:268:: with SMTP id 95mr42739406otb.183.1582580469131; Mon, 24 Feb 2020 13:41:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582580469; cv=none; d=google.com; s=arc-20160816; b=vNhuuslQQKhXVscwwUmUSs7onRCvIHDrR9GU9y2omUKwdsbXHeU4jYZ9CGDIQ03E5q bIT1d3xZH7lBPrQgNZZOGdXQHjdvYQvhk5KYbf3SUGWNJOoag5z6M+79MahOVnLZzIed bO6/A+0gsAOg0BnLsVUDeI+Eqj2nttnrfPq4teey5pCTmfVReN66YSiVA3RhJrEinbg1 Ruw9QzRxEUtvPN1mrj6CZTnKnVht8HaLNvuYsujWobvgwCJfmjbeV6NvtZ4WYIuPxAvW LtggTvHY964WDbc92PRejaaAUD0JvrgiydwOvBS1LaHqdKAWb64m3dx7CeDyVS/351Cz tqbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=65KytlXyewvGVahoyRdvC+touLtUiIJaP98fPBSxLjQ=; b=jQ3+TQqaKj3uihpwlK8Ehz0qfwUhyVf2Fqi+Er4qdaCjs8Q5OCpIUBuh97rdFsRi9+ fGEOzs5YH42jbtkyCrKt0z2Jqj0ls3nyWrJmZDNBsxRqPT/4YDlN4iZcfM8YdxpRuhLP 5/3VYYRw2/QeyFZgS9GCXnmfXVmNoaxhHU0LeKT6Vwv5N49yayzzdHy823fMcxRzaGq+ VaJPHdZEP8smnSmPVod4oy1++shLd9snTdDDC2MzW1zTQKWfqIqVbyA1bCY5mTusiVlk BxGCalcdbFr64gD29ibz9ci15vT0FaAaqYa/bxbRX6TYQBk6MXo3TV4HPNMymqsHGr0m HI9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=g2l2vA7Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h18si6885625otr.265.2020.02.24.13.40.49; Mon, 24 Feb 2020 13:41:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=g2l2vA7Y; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727996AbgBXVkk (ORCPT + 99 others); Mon, 24 Feb 2020 16:40:40 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:33032 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727554AbgBXVkj (ORCPT ); Mon, 24 Feb 2020 16:40:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=65KytlXyewvGVahoyRdvC+touLtUiIJaP98fPBSxLjQ=; b=g2l2vA7YLEfvfs7PQ14x+FPEhp 1yaO+e12NroUCtyLzhwbqCapyooZwwnLxi+zYHYu3dx7j2bMNHjss/eCzGNTD/EgfSGkmy2vqfB/1 a8aXbUB4VDDYPX2I3IiQq/ggTnUl5tDhZIXMueCk6qBKa8Ikv0C4AABTBTz6X+htegap1EuJ3Cmuu XjjoRbv+jad91N6BXSewZH82e8r0TxczCQ6AY9KLZ9TAm9lelsNdvBqkpqpmmJyJriMqbLAFjvaTl 8tmbQcMyyKIENDLcVreqHkRX3rFqoaFnNOPMjt9KICrGTFJ9ulD8TPuf60nR4pqcPpkSV/GTxYPmA b7e5Yhug==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j6LSx-0007AA-4f; Mon, 24 Feb 2020 21:40:39 +0000 Date: Mon, 24 Feb 2020 13:40:39 -0800 From: Christoph Hellwig To: Matthew Wilcox Cc: 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 Subject: Re: [PATCH v7 09/24] mm: Put readahead pages in cache earlier Message-ID: <20200224214039.GF13895@infradead.org> References: <20200219210103.32400-1-willy@infradead.org> <20200219210103.32400-10-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219210103.32400-10-willy@infradead.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 19, 2020 at 01:00:48PM -0800, Matthew Wilcox wrote: > From: "Matthew Wilcox (Oracle)" > > When populating the page cache for readahead, mappings that use > ->readpages must populate the page cache themselves as the pages are > passed on a linked list which would normally be used for the page cache's > LRU. For mappings that use ->readpage or the upcoming ->readahead method, > we can put the pages into the page cache as soon as they're allocated, > which solves a race between readahead and direct IO. It also lets us > remove the gfp argument from read_pages(). > > Use the new readahead_page() API to implement the repeated calls to > ->readpage(), just like most filesystems will. This iterator also > supports huge pages, even though none of the filesystems have been > converted to use them yet. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > include/linux/pagemap.h | 20 +++++++++++++++++ > mm/readahead.c | 48 +++++++++++++++++++++++++---------------- > 2 files changed, 49 insertions(+), 19 deletions(-) > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > index 55fcea0249e6..4989d330fada 100644 > --- a/include/linux/pagemap.h > +++ b/include/linux/pagemap.h > @@ -647,8 +647,28 @@ struct readahead_control { > /* private: use the readahead_* accessors instead */ > pgoff_t _index; > unsigned int _nr_pages; > + unsigned int _batch_count; > }; > > +static inline struct page *readahead_page(struct readahead_control *rac) > +{ > + struct page *page; > + > + BUG_ON(rac->_batch_count > rac->_nr_pages); > + rac->_nr_pages -= rac->_batch_count; > + rac->_index += rac->_batch_count; > + rac->_batch_count = 0; > + > + if (!rac->_nr_pages) > + return NULL; > + > + page = xa_load(&rac->mapping->i_pages, rac->_index); > + VM_BUG_ON_PAGE(!PageLocked(page), page); > + rac->_batch_count = hpage_nr_pages(page); > + > + return page; > +} > + > /* The number of pages in this readahead block */ > static inline unsigned int readahead_count(struct readahead_control *rac) > { > diff --git a/mm/readahead.c b/mm/readahead.c > index 83df5c061d33..aaa209559ba2 100644 > --- a/mm/readahead.c > +++ b/mm/readahead.c > @@ -113,15 +113,14 @@ int read_cache_pages(struct address_space *mapping, struct list_head *pages, > > EXPORT_SYMBOL(read_cache_pages); > > -static void read_pages(struct readahead_control *rac, struct list_head *pages, > - gfp_t gfp) > +static void read_pages(struct readahead_control *rac, struct list_head *pages) > { > const struct address_space_operations *aops = rac->mapping->a_ops; > + struct page *page; > struct blk_plug plug; > - unsigned page_idx; > > if (!readahead_count(rac)) > - return; > + goto out; > > blk_start_plug(&plug); > > @@ -130,23 +129,23 @@ static void read_pages(struct readahead_control *rac, struct list_head *pages, > readahead_count(rac)); > /* Clean up the remaining pages */ > put_pages_list(pages); > - goto out; > - } > - > - for (page_idx = 0; page_idx < readahead_count(rac); page_idx++) { > - struct page *page = lru_to_page(pages); > - list_del(&page->lru); > - if (!add_to_page_cache_lru(page, rac->mapping, page->index, > - gfp)) > + rac->_index += rac->_nr_pages; > + rac->_nr_pages = 0; > + } else { > + while ((page = readahead_page(rac))) { > aops->readpage(rac->file, page); > - put_page(page); > + put_page(page); > + } > } > > -out: > blk_finish_plug(&plug); > > BUG_ON(!list_empty(pages)); > - rac->_nr_pages = 0; > + BUG_ON(readahead_count(rac)); > + > +out: > + /* If we were called due to a conflicting page, skip over it */ > + rac->_index++; > } > > /* > @@ -165,9 +164,11 @@ void __do_page_cache_readahead(struct address_space *mapping, > LIST_HEAD(page_pool); > loff_t isize = i_size_read(inode); > gfp_t gfp_mask = readahead_gfp_mask(mapping); > + bool use_list = mapping->a_ops->readpages; I find this single use variable a little weird. Not a dealbreaker, but just checking the methods would seem a little more obvious to me. Except for this and the other nitpick the patch looks good to me: Reviewed-by: Christoph Hellwig