From patchwork Mon Jan 13 15:37:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 11330457 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C7E913A0 for ; Mon, 13 Jan 2020 15:38:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5B29C222C4 for ; Mon, 13 Jan 2020 15:38:00 +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="HIDZ4epq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B29C222C4 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 78B9C8E0013; Mon, 13 Jan 2020 10:37:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6EE938E0011; Mon, 13 Jan 2020 10:37:55 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DFE88E0013; Mon, 13 Jan 2020 10:37:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id 0804F8E0010 for ; Mon, 13 Jan 2020 10:37:55 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id C5F3140CA for ; Mon, 13 Jan 2020 15:37:54 +0000 (UTC) X-FDA: 76373016468.26.chain99_7f3a981c0072e X-Spam-Summary: 2,0,0,790aa522d1a3e640,d41d8cd98f00b204,willy@infradead.org,:linux-xfs@vger.kernel.org:linux-fsdevel@vger.kernel.org::willy@infradead.org:jlayton@kernel.org:hch@infradead.org,RULES_HIT:41:69:355:379:541:800:960:968:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1544:1605:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3872:4117:4321:4605:5007:6261:6653:7576:8603:8957:9036:9592:10004:11026:11473:11658:11914:12043:12296:12297:12438:12555:12683:12895:13161:13229:13894:14096:14181:14394:14721:21080:21451:21627:21740:21990:30012:30051:30054:30070,0,RBL:198.137.202.133:@infradead.org:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:37,LUA_SUMMARY:none X-HE-Tag: chain99_7f3a981c0072e X-Filterd-Recvd-Size: 6666 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Mon, 13 Jan 2020 15:37:54 +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=fWczM9DLx1FK48u8XSx4af+h330mJlxpghJsvnVaqrA=; b=HIDZ4epq926UxT06NFoqXP0QdF Ur59vo1stJEQAhFpBPj902qub5AA6aZ7tjmo1T7b4Bcn2M748hVk7zbdKY5MFiDnyCP+EYp83n7c1 mIJcpbWNlLa7w7YYPsTor72vLw7U68oj1pYpktn7LtqKhB4sKnJdMw0h3gxGqpUYaK6bWb5mh6yKK 2SMI4g3AZ8CLnrcxV+gcRnOtTaubpDDvHj6O/oiGqptYxwiI2sBHJao24upsbhSZi9mspf5lxIi0T d+vrwlC5bGgBsGaC9TUwvsYkclacLYkvAufbbyeDvAgDj79k2tTURRn3PVsKZN2y7KebhYvSxpSWy j0iUJV7w==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1ir1mr-00077G-CN; Mon, 13 Jan 2020 15:37:53 +0000 From: Matthew Wilcox To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , jlayton@kernel.org, hch@infradead.org Subject: [PATCH 8/8] mm: Unify all add_to_page_cache variants Date: Mon, 13 Jan 2020 07:37:46 -0800 Message-Id: <20200113153746.26654-9-willy@infradead.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200113153746.26654-1-willy@infradead.org> References: <20200113153746.26654-1-willy@infradead.org> MIME-Version: 1.0 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 conditionally 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 3ce051fb9c73..753e8df6a5b1 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -606,14 +606,15 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size) 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 *mapping, - 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 gfp_mask); void delete_from_page_cache_batch(struct address_space *mapping, struct pagevec *pvec); +#define add_to_page_cache_lru(page, mapping, index, gfp) \ + add_to_page_cache(page, mapping, index, gfp) + static inline unsigned long dir_pages(struct inode *inode) { return (unsigned long)(inode->i_size + PAGE_SIZE - 1) >> 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, struct page *new, gfp_t gfp_mask) } EXPORT_SYMBOL_GPL(replace_page_cache_page); -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 = PageHuge(page); struct mem_cgroup *memcg; int error; - void *old; + void *old, *shadow = NULL; VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(PageSwapBacked(page), page); + __SetPageLocked(page); mapping_set_update(&xas, mapping); if (!huge) { @@ -884,8 +883,7 @@ static int __add_to_page_cache_locked(struct page *page, if (xa_is_value(old)) { mapping->nrexceptional--; - if (shadowp) - *shadowp = old; + shadow = old; } mapping->nrpages++; @@ -899,45 +897,8 @@ static int __add_to_page_cache_locked(struct page *page, if (xas_error(&xas)) goto error; - 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 = 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 = __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 *mapping, - pgoff_t offset, gfp_t gfp_mask) -{ - void *shadow = NULL; - int ret; - - __SetPageLocked(page); - ret = __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 = 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); #ifdef CONFIG_NUMA struct page *__page_cache_alloc(gfp_t gfp)