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=-12.8 required=3.0 tests=BAYES_00,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 2A227C433E2 for ; Thu, 3 Sep 2020 14:09:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C176C20578 for ; Thu, 3 Sep 2020 14:09:11 +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="Hxpv/A1Q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C176C20578 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 517226B0073; Thu, 3 Sep 2020 10:08:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CAED6B0074; Thu, 3 Sep 2020 10:08:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 340786B0075; Thu, 3 Sep 2020 10:08:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id 180AA6B0073 for ; Thu, 3 Sep 2020 10:08:59 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D391F8248076 for ; Thu, 3 Sep 2020 14:08:58 +0000 (UTC) X-FDA: 77221931556.24.spark20_04154cf270aa Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 7AD211A4A0 for ; Thu, 3 Sep 2020 14:08:57 +0000 (UTC) X-HE-Tag: spark20_04154cf270aa X-Filterd-Recvd-Size: 9285 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Sep 2020 14:08:56 +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=YQWDKR2b9vvYoo/rMiI9oBJwndGbzqY3ajRHCZjhecQ=; b=Hxpv/A1QHyX5wyGaacCqKEXdyT 7UBWHqRJT5AAR5FBsHZz40q+jNgy5o8yehAVs53Ma2bTVXzb5Au4w+n2tbeuv2mvLg4BTMGplebrY R72HZ19jf78uv201Y0pO5V3wen70UOdslavfuTheROvj3auSFi4slknH7EDe3VULPJdLE0I+/dzGM A1T+DMNeGemLb/q7BRoCBxDNwPEzG9XUUM3qRws10W33tjTuQ2X8PpI8pDkBWl/zeHVstLUco9mnj QkbdtnsOZNg2Jt8VT9Fqjpi3ZE99q/+ZqrTIpt9UZNvAjb2Sk0dbeiPI2co6SsA0lv6MQcNUaHRaz wUc15O6w==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDpv2-0003ib-V8; Thu, 03 Sep 2020 14:08:53 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , David Howells , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Eric Biggers Subject: [PATCH 7/9] mm/readahead: Add page_cache_sync_ra and page_cache_async_ra Date: Thu, 3 Sep 2020 15:08:42 +0100 Message-Id: <20200903140844.14194-8-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200903140844.14194-1-willy@infradead.org> References: <20200903140844.14194-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7AD211A4A0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: Reimplement page_cache_sync_readahead() and page_cache_async_readahead() as wrappers around versions of the function which take a readahead_contro= l in preparation for making do_sync_mmap_readahead() pass down an RAC struct. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 64 ++++++++++++++++++++++++++++++++++------- mm/readahead.c | 58 ++++++++----------------------------- 2 files changed, 66 insertions(+), 56 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 2b613c369a2f..12ab56c3a86f 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -698,16 +698,6 @@ int replace_page_cache_page(struct page *old, struct= page *new, gfp_t gfp_mask); void delete_from_page_cache_batch(struct address_space *mapping, struct pagevec *pvec); =20 -#define VM_READAHEAD_PAGES (SZ_128K / PAGE_SIZE) - -void page_cache_sync_readahead(struct address_space *, struct file_ra_st= ate *, - struct file *, pgoff_t index, unsigned long req_count); -void page_cache_async_readahead(struct address_space *, struct file_ra_s= tate *, - struct file *, struct page *, pgoff_t index, - unsigned long req_count); -void page_cache_ra_unbounded(struct readahead_control *, - unsigned long nr_to_read, unsigned long lookahead_count); - /* * Like add_to_page_cache_locked, but used to add newly allocated pages: * the page is new, so we can just run __SetPageLocked() against it. @@ -755,6 +745,60 @@ struct readahead_control { ._index =3D i, \ } =20 +#define VM_READAHEAD_PAGES (SZ_128K / PAGE_SIZE) + +void page_cache_ra_unbounded(struct readahead_control *, + unsigned long nr_to_read, unsigned long lookahead_count); +void page_cache_sync_ra(struct readahead_control *, struct file_ra_state= *, + unsigned long req_count); +void page_cache_async_ra(struct readahead_control *, struct file_ra_stat= e *, + struct page *, unsigned long req_count); + +/** + * page_cache_sync_readahead - generic file readahead + * @mapping: address_space which holds the pagecache and I/O vectors + * @ra: file_ra_state which holds the readahead state + * @file: Used by the filesystem for authentication. + * @index: Index of first page to be read. + * @req_count: Total number of pages being read by the caller. + * + * page_cache_sync_readahead() should be called when a cache miss happen= ed: + * it will submit the read. The readahead logic may decide to piggyback= more + * pages onto the read request if access patterns suggest it will improv= e + * performance. + */ +static inline +void page_cache_sync_readahead(struct address_space *mapping, + struct file_ra_state *ra, struct file *file, pgoff_t index, + unsigned long req_count) +{ + DEFINE_READAHEAD(ractl, file, mapping, index); + page_cache_sync_ra(&ractl, ra, req_count); +} + +/** + * page_cache_async_readahead - file readahead for marked pages + * @mapping: address_space which holds the pagecache and I/O vectors + * @ra: file_ra_state which holds the readahead state + * @file: Used by the filesystem for authentication. + * @page: The page at @index which triggered the readahead call. + * @index: Index of first page to be read. + * @req_count: Total number of pages being read by the caller. + * + * page_cache_async_readahead() should be called when a page is used whi= ch + * is marked as PageReadahead; this is a marker to suggest that the appl= ication + * has used up enough of the readahead window that we should start pulli= ng in + * more pages. + */ +static inline +void page_cache_async_readahead(struct address_space *mapping, + struct file_ra_state *ra, struct file *file, + struct page *page, pgoff_t index, unsigned long req_count) +{ + DEFINE_READAHEAD(ractl, file, mapping, index); + page_cache_async_ra(&ractl, ra, page, req_count); +} + /** * readahead_page - Get the next page to read. * @rac: The current readahead request. diff --git a/mm/readahead.c b/mm/readahead.c index 3115ced5faae..620ac83f35cc 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -550,25 +550,9 @@ static void ondemand_readahead(struct readahead_cont= rol *ractl, do_page_cache_ra(ractl, ra->size, ra->async_size); } =20 -/** - * page_cache_sync_readahead - generic file readahead - * @mapping: address_space which holds the pagecache and I/O vectors - * @ra: file_ra_state which holds the readahead state - * @filp: passed on to ->readpage() and ->readpages() - * @index: Index of first page to be read. - * @req_count: Total number of pages being read by the caller. - * - * page_cache_sync_readahead() should be called when a cache miss happen= ed: - * it will submit the read. The readahead logic may decide to piggyback= more - * pages onto the read request if access patterns suggest it will improv= e - * performance. - */ -void page_cache_sync_readahead(struct address_space *mapping, - struct file_ra_state *ra, struct file *filp, - pgoff_t index, unsigned long req_count) +void page_cache_sync_ra(struct readahead_control *ractl, + struct file_ra_state *ra, unsigned long req_count) { - DEFINE_READAHEAD(ractl, filp, mapping, index); - /* no read-ahead */ if (!ra->ra_pages) return; @@ -577,38 +561,20 @@ void page_cache_sync_readahead(struct address_space= *mapping, return; =20 /* be dumb */ - if (filp && (filp->f_mode & FMODE_RANDOM)) { - force_page_cache_ra(&ractl, req_count); + if (ractl->file && (ractl->file->f_mode & FMODE_RANDOM)) { + force_page_cache_ra(ractl, req_count); return; } =20 /* do read-ahead */ - ondemand_readahead(&ractl, ra, false, req_count); + ondemand_readahead(ractl, ra, false, req_count); } -EXPORT_SYMBOL_GPL(page_cache_sync_readahead); +EXPORT_SYMBOL_GPL(page_cache_sync_ra); =20 -/** - * page_cache_async_readahead - file readahead for marked pages - * @mapping: address_space which holds the pagecache and I/O vectors - * @ra: file_ra_state which holds the readahead state - * @filp: passed on to ->readpage() and ->readpages() - * @page: The page at @index which triggered the readahead call. - * @index: Index of first page to be read. - * @req_count: Total number of pages being read by the caller. - * - * page_cache_async_readahead() should be called when a page is used whi= ch - * is marked as PageReadahead; this is a marker to suggest that the appl= ication - * has used up enough of the readahead window that we should start pulli= ng in - * more pages. - */ -void -page_cache_async_readahead(struct address_space *mapping, - struct file_ra_state *ra, struct file *filp, - struct page *page, pgoff_t index, - unsigned long req_count) +void page_cache_async_ra(struct readahead_control *ractl, + struct file_ra_state *ra, struct page *page, + unsigned long req_count) { - DEFINE_READAHEAD(ractl, filp, mapping, index); - /* no read-ahead */ if (!ra->ra_pages) return; @@ -624,16 +590,16 @@ page_cache_async_readahead(struct address_space *ma= pping, /* * Defer asynchronous read-ahead on IO congestion. */ - if (inode_read_congested(mapping->host)) + if (inode_read_congested(ractl->mapping->host)) return; =20 if (blk_cgroup_congested()) return; =20 /* do read-ahead */ - ondemand_readahead(&ractl, ra, true, req_count); + ondemand_readahead(ractl, ra, true, req_count); } -EXPORT_SYMBOL_GPL(page_cache_async_readahead); +EXPORT_SYMBOL_GPL(page_cache_async_ra); =20 ssize_t ksys_readahead(int fd, loff_t offset, size_t count) { --=20 2.28.0