From patchwork Wed Dec 8 04:22:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12663819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB186C433EF for ; Wed, 8 Dec 2021 07:09:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 603BD6B0074; Wed, 8 Dec 2021 02:08:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D0EE6B0073; Wed, 8 Dec 2021 02:08:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CFCF6B0074; Wed, 8 Dec 2021 02:08:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay025.a.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 1B97B6B0073 for ; Wed, 8 Dec 2021 02:08:37 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 7E374801DF for ; Wed, 8 Dec 2021 04:48:21 +0000 (UTC) X-FDA: 78893395602.17.4285097 Received: from relay.hostedemail.com (unknown [216.40.35.100]) by imf21.hostedemail.com (Postfix) with ESMTP id 0F6B5D0369C2 for ; Wed, 8 Dec 2021 04:48:20 +0000 (UTC) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5739420A95 for ; Wed, 8 Dec 2021 04:39:00 +0000 (UTC) X-FDA: 78893372040.24.9213F32 Received: from relay.hostedemail.com (relay028.a.hostedemail.com [64.99.140.28]) by imf26.hostedemail.com (Postfix) with ESMTP id CB09120019C3 for ; Wed, 8 Dec 2021 04:38:59 +0000 (UTC) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 71553601A7 for ; Wed, 8 Dec 2021 04:23:14 +0000 (UTC) X-FDA: 78893332266.27.95FA1B2 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 252A140002 for ; Wed, 8 Dec 2021 04:23:12 +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=0HiMfEBapSaJ76Nsadm/Hl6t4X5OTaxDIeW3md1qPS8=; b=F9HU2Jd0g8x9PI6I8QPzUDhc6q MFdRSl5wmj+dWbRQX83gKwBUJcqLj0+JbSjfqOyvaQYwso082bAt9wYOObgr6fUk7E7XDcg8rSLrP /qGpTchwgqAl2ozG4ogVUAApd8Sochh7JYtfh/F/eh/cWWa4uAZeGfmDJgUAwlbQTDbvsme77Th6y fRUKi/nsWA0FoqAljbhP63J/F5jz3mm5WAJAMa40UCRQhdMzxqPjGZGfkSds7em4kQjWjOFaR4fW0 jSO9YNOcc5HFxf5vdt4toY1onIICo1bNUNe5GxaAknlAs65hYEp8x3891te/f2RTSG4J9Z8eifbDS tQC1gR9w==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1muoU3-0084YJ-O1; Wed, 08 Dec 2021 04:23:11 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 19/48] filemap: Convert filemap_create_page to folio Date: Wed, 8 Dec 2021 04:22:27 +0000 Message-Id: <20211208042256.1923824-20-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211208042256.1923824-1-willy@infradead.org> References: <20211208042256.1923824-1-willy@infradead.org> MIME-Version: 1.0 X-HE-Tag-Orig: 1638937392-354665 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0F6B5D0369C2 X-Stat-Signature: ar58rqs4qmhucahohz3hj1efhyzhk1oz X-HE-Tag-Orig: 1638938339-148845 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=F9HU2Jd0; spf=none (imf21.hostedemail.com: domain of FILTER%FILTER%willy@infradead.org has no SPF policy when checking 216.40.35.100) smtp.mailfrom=FILTER%FILTER%willy@infradead.org; dmarc=none X-HE-Tag: 1638938900-573585 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: This is all internal to filemap and saves 100 bytes of text. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig --- mm/filemap.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 581f9fdb3406..b044afef78ef 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2475,47 +2475,48 @@ static int filemap_update_page(struct kiocb *iocb, return error; } -static int filemap_create_page(struct file *file, +static int filemap_create_folio(struct file *file, struct address_space *mapping, pgoff_t index, struct pagevec *pvec) { - struct page *page; + struct folio *folio; int error; - page = page_cache_alloc(mapping); - if (!page) + folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0); + if (!folio) return -ENOMEM; /* - * Protect against truncate / hole punch. Grabbing invalidate_lock here - * assures we cannot instantiate and bring uptodate new pagecache pages - * after evicting page cache during truncate and before actually - * freeing blocks. Note that we could release invalidate_lock after - * inserting the page into page cache as the locked page would then be - * enough to synchronize with hole punching. But there are code paths - * such as filemap_update_page() filling in partially uptodate pages or - * ->readpages() that need to hold invalidate_lock while mapping blocks - * for IO so let's hold the lock here as well to keep locking rules - * simple. + * Protect against truncate / hole punch. Grabbing invalidate_lock + * here assures we cannot instantiate and bring uptodate new + * pagecache folios after evicting page cache during truncate + * and before actually freeing blocks. Note that we could + * release invalidate_lock after inserting the folio into + * the page cache as the locked folio would then be enough to + * synchronize with hole punching. But there are code paths + * such as filemap_update_page() filling in partially uptodate + * pages or ->readpages() that need to hold invalidate_lock + * while mapping blocks for IO so let's hold the lock here as + * well to keep locking rules simple. */ filemap_invalidate_lock_shared(mapping); - error = add_to_page_cache_lru(page, mapping, index, + error = filemap_add_folio(mapping, folio, index, mapping_gfp_constraint(mapping, GFP_KERNEL)); if (error == -EEXIST) error = AOP_TRUNCATED_PAGE; if (error) goto error; - error = filemap_read_folio(file, mapping, page_folio(page)); + error = filemap_read_folio(file, mapping, folio); if (error) goto error; filemap_invalidate_unlock_shared(mapping); - pagevec_add(pvec, page); + pagevec_add(pvec, &folio->page); return 0; error: filemap_invalidate_unlock_shared(mapping); - put_page(page); + folio_put(folio); return error; } @@ -2557,7 +2558,7 @@ static int filemap_get_pages(struct kiocb *iocb, struct iov_iter *iter, if (!pagevec_count(pvec)) { if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ)) return -EAGAIN; - err = filemap_create_page(filp, mapping, + err = filemap_create_folio(filp, mapping, iocb->ki_pos >> PAGE_SHIFT, pvec); if (err == AOP_TRUNCATED_PAGE) goto retry;