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,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 4EAA8C33CB7 for ; Wed, 15 Jan 2020 02:38:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 16612222C3 for ; Wed, 15 Jan 2020 02:38:48 +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="gjPmbmyh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16612222C3 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 9ED768E0005; Tue, 14 Jan 2020 21:38:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9771F8E0003; Tue, 14 Jan 2020 21:38:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 818678E0005; Tue, 14 Jan 2020 21:38:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 6B2548E0003 for ; Tue, 14 Jan 2020 21:38:48 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 1B7B2181AEF00 for ; Wed, 15 Jan 2020 02:38:48 +0000 (UTC) X-FDA: 76378310736.08.swim78_86f15865dd707 X-HE-Tag: swim78_86f15865dd707 X-Filterd-Recvd-Size: 6673 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jan 2020 02:38:47 +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:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DylBmngUm5zkbhQxU3yncnTrsHanHBApne+CYo1JZUc=; b=gjPmbmyhS3zmvAS7pVCbBARoiu 575g/8UosIM8ZxYcU5V0YFcQDZG4gsmpRUtGZfvZLaQytJLxbdqCY+23sHa34cHoGfSN+Yb84GkCJ yg9aiuRvUQ2ReX8j1DvVtk+h6kwee43+htmiMdSrRNbAUqb1dXD+qb3NG8SJ16ssg2Qq26V277Y64 BlylH2J56oQiOTs+g5c8VW9vkAd8y6Kju7P5aWxKwh/2L4MF1NxFEDRVzJ3mYKzkyoLqjoLw7QGJc 6qX7Nh7/iMBu6FAxDUgFciX6vmT9QomJT8Bej9Dl3SycDkWhScqpuGxf8t09MQYEmJBS7eJiK94Ix AeIJl2nA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1irYZy-0008B7-9Y; Wed, 15 Jan 2020 02:38:46 +0000 From: Matthew Wilcox To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jeff Layton , Christoph Hellwig , Chris Mason Subject: [PATCH v2 9/9] mm: Unify all add_to_page_cache variants Date: Tue, 14 Jan 2020 18:38:43 -0800 Message-Id: <20200115023843.31325-10-willy@infradead.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200115023843.31325-1-willy@infradead.org> References: <20200115023843.31325-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)" We already have various bits of add_to_page_cache() executed conditionall= y on !PageHuge(page); add the add_to_page_cache_lru() pieces as some more code which isn't executed for huge pages. This lets us remove the old add_to_page_cache() and rename __add_to_page_cache_locked() to add_to_page_cache(). Include a compatibility define so we don't have to change all 20+ callers of add_to_page_cache_lru(). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 5 ++-- mm/filemap.c | 65 ++++++++++++----------------------------- 2 files changed, 21 insertions(+), 49 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 75075065dd0b..637770fa283f 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -606,14 +606,15 @@ static inline int fault_in_pages_readable(const cha= r __user *uaddr, int size) =20 int add_to_page_cache(struct page *page, struct address_space *mapping, pgoff_t index, gfp_t gfp); -int add_to_page_cache_lru(struct page *page, struct address_space *mappi= ng, - pgoff_t index, gfp_t gfp_mask); extern void delete_from_page_cache(struct page *page); extern void __delete_from_page_cache(struct page *page, void *shadow); int replace_page_cache_page(struct page *old, struct page *new, gfp_t gf= p_mask); void delete_from_page_cache_batch(struct address_space *mapping, struct pagevec *pvec); =20 +#define add_to_page_cache_lru(page, mapping, index, gfp) \ + add_to_page_cache(page, mapping, index, gfp) + /* * Only call this from a ->readahead implementation. */ diff --git a/mm/filemap.c b/mm/filemap.c index fb87f5fa75e6..83f45f31a00a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -847,19 +847,18 @@ int replace_page_cache_page(struct page *old, struc= t page *new, gfp_t gfp_mask) } EXPORT_SYMBOL_GPL(replace_page_cache_page); =20 -static int __add_to_page_cache_locked(struct page *page, - struct address_space *mapping, - pgoff_t offset, gfp_t gfp_mask, - void **shadowp) +int add_to_page_cache(struct page *page, struct address_space *mapping, + pgoff_t offset, gfp_t gfp_mask) { XA_STATE(xas, &mapping->i_pages, offset); int huge =3D PageHuge(page); struct mem_cgroup *memcg; int error; - void *old; + void *old, *shadow =3D NULL; =20 VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(PageSwapBacked(page), page); + __SetPageLocked(page); mapping_set_update(&xas, mapping); =20 if (!huge) { @@ -884,8 +883,7 @@ static int __add_to_page_cache_locked(struct page *pa= ge, =20 if (xa_is_value(old)) { mapping->nrexceptional--; - if (shadowp) - *shadowp =3D old; + shadow =3D old; } mapping->nrpages++; =20 @@ -899,45 +897,8 @@ static int __add_to_page_cache_locked(struct page *p= age, if (xas_error(&xas)) goto error; =20 - if (!huge) + if (!huge) { mem_cgroup_commit_charge(page, memcg, false, false); - trace_mm_filemap_add_to_page_cache(page); - return 0; -error: - page->mapping =3D NULL; - /* Leave page->index set: truncation relies upon it */ - if (!huge) - mem_cgroup_cancel_charge(page, memcg, false); - put_page(page); - return xas_error(&xas); -} -ALLOW_ERROR_INJECTION(__add_to_page_cache_locked, ERRNO); - -int add_to_page_cache(struct page *page, struct address_space *mapping, - pgoff_t offset, gfp_t gfp_mask) -{ - int err; - - __SetPageLocked(page); - err =3D __add_to_page_cache_locked(page, mapping, offset, - gfp_mask, NULL); - if (unlikely(err)) - __ClearPageLocked(page); - return err; -} - -int add_to_page_cache_lru(struct page *page, struct address_space *mappi= ng, - pgoff_t offset, gfp_t gfp_mask) -{ - void *shadow =3D NULL; - int ret; - - __SetPageLocked(page); - ret =3D __add_to_page_cache_locked(page, mapping, offset, - gfp_mask, &shadow); - if (unlikely(ret)) - __ClearPageLocked(page); - else { /* * The page might have been evicted from cache only * recently, in which case it should be activated like @@ -951,9 +912,19 @@ int add_to_page_cache_lru(struct page *page, struct = address_space *mapping, workingset_refault(page, shadow); lru_cache_add(page); } - return ret; + trace_mm_filemap_add_to_page_cache(page); + return 0; +error: + page->mapping =3D NULL; + /* Leave page->index set: truncation relies upon it */ + if (!huge) + mem_cgroup_cancel_charge(page, memcg, false); + put_page(page); + __ClearPageLocked(page); + return xas_error(&xas); } -EXPORT_SYMBOL_GPL(add_to_page_cache_lru); +ALLOW_ERROR_INJECTION(add_to_page_cache, ERRNO); +EXPORT_SYMBOL_GPL(add_to_page_cache); =20 #ifdef CONFIG_NUMA struct page *__page_cache_alloc(gfp_t gfp) --=20 2.24.1