From patchwork Tue Nov 1 17:53:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13027299 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 0F4D5C43219 for ; Tue, 1 Nov 2022 17:53:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86A436B0073; Tue, 1 Nov 2022 13:53:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F2A76B0074; Tue, 1 Nov 2022 13:53:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61EE06B0075; Tue, 1 Nov 2022 13:53:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4F6236B0073 for ; Tue, 1 Nov 2022 13:53:55 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 28EC1160A55 for ; Tue, 1 Nov 2022 17:53:55 +0000 (UTC) X-FDA: 80085621630.28.5AF0F4C Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf21.hostedemail.com (Postfix) with ESMTP id C42C01C0019 for ; Tue, 1 Nov 2022 17:53:54 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id j12so14266774plj.5 for ; Tue, 01 Nov 2022 10:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FuGJz+KOe5nlhTqBhnCFZVh76KOjwWx4QzuxWRatQRw=; b=GLtbpdDagXfzzArPWFbzC1pLfwjGTFMl3yMdbdI+UPQWP6Safe9ZomEqovW5g78jsn u1gUxCUdpMfjPpRavHZw7PboDNLvOt2PJamvnpqII7rcm63F4RGcv2RcUj96F24eSfUd hxpSBMmmWfCzqKgvA7FhwffpTioO28REYvlpGitRbXdbz3iC3bTUAOjICPQXmDpUQGHC 8XdjD6Q+zhl4iIWf96kJzS6ftU+ra0QIcIxEHG6pPH8gzHev8fLbDEvqhW+2lpB5ruE/ /L7S0GqoVyp8Jl2KJeWLQEorqRqPJXZXVhX/NX1WBf+Q2G1KhhQ7tx14rlJXnQrmV5hP JIdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FuGJz+KOe5nlhTqBhnCFZVh76KOjwWx4QzuxWRatQRw=; b=GyzyDdRLZGDR3xLhrZgV6hUvWa4pLH5r7OywRc1gx1j/7sZ0GDO7XFBf8IhbHReD0o j9cgZzqfPZQ3vjd/IWXpkCxXFvNjfD+FgJZLa51lVq1YaA8THWRQ7xaXg39MrtbLH1bb ZY4Gw1kS/jWCjcoai7Cg5H9lNJgSzSuDAPudzL/T1bzVPzaQr0441W7eHfxEFeuuBzba xvk9GCcuVEhOh7jvPAgrXYJP64M5TBJGI/8ygaZh5cJojU4G/mXjyvysD4foqq2L/fZw o/h3ZWd7y2dycl0MA0eieFskf9hDayKgIoezgW4P49nmOaz1Ieft66TN0sfh/MEuWrv4 ohcg== X-Gm-Message-State: ACrzQf07J2i5Oc+ovLUion9XPllQa5M1R7JtADcvM2gYzLmeJL/FAgW3 oh3OyJbNjkpb7Mt+gBoeLnHZIavaGZGRrA== X-Google-Smtp-Source: AMsMyM4Lo9FQUAx4PCChA3A3lYDxPoKT3ikIU8naaS8JY51piB8RrefMXEBKCh8ZFG34NdjISTQlXQ== X-Received: by 2002:a17:902:cf02:b0:187:846:e007 with SMTP id i2-20020a170902cf0200b001870846e007mr18228062plg.70.1667325233484; Tue, 01 Nov 2022 10:53:53 -0700 (PDT) Received: from fedora.hsd1.ca.comcast.net ([2601:644:8002:1c20::8080]) by smtp.googlemail.com with ESMTPSA id e26-20020a056a0000da00b0056b9124d441sm6797987pfj.218.2022.11.01.10.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 10:53:53 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, willy@infradead.org, miklos@szeredi.hu, "Vishal Moola (Oracle)" Subject: [PATCH 1/5] filemap: Convert replace_page_cache_page() to replace_page_cache_folio() Date: Tue, 1 Nov 2022 10:53:22 -0700 Message-Id: <20221101175326.13265-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221101175326.13265-1-vishal.moola@gmail.com> References: <20221101175326.13265-1-vishal.moola@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667325234; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FuGJz+KOe5nlhTqBhnCFZVh76KOjwWx4QzuxWRatQRw=; b=YB3lyKpRnCW3kFDGd8VnxdOB/0EUQ1WOEvP/PElNow8P/6xkv/o8h6LjvZ9s0wxFWNcNmQ Z5tDCq6n7iAQhtYg54yxnR/N0j170btusuhsud8VGseCSIxZLwJ6feIWo7OkI+dAtBZXGS 860ptKRcvLpljK1ymMQ761g1Nhwrg1I= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GLtbpdDa; spf=pass (imf21.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667325234; a=rsa-sha256; cv=none; b=p0zBtcdO16GQyO+9zRZBua9X3rCB2FBjZWHBk3fKCAgo9wG1c35fnK/3bYcSG91D3wmwoA 1fEd/D4oMkN/0VtAbM+HpMFUwatTOw7epKwNoXT8Ey9DUjsdWMYLRGenNnfdifiD/6iYlG NwRjOtwUvLibyFieN60gCwQ70Rmn2QY= Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GLtbpdDa; spf=pass (imf21.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: ucsp4fsy74c34z65ny4bw5wepqgrc9fe X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: C42C01C0019 X-HE-Tag: 1667325234-627247 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: Eliminates 7 calls to compound_head(). Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Matthew Wilcox (Oracle) --- fs/fuse/dev.c | 2 +- include/linux/pagemap.h | 2 +- mm/filemap.c | 52 ++++++++++++++++++++--------------------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index b4a6e0a1b945..26817a2db463 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -837,7 +837,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) if (WARN_ON(PageMlocked(oldpage))) goto out_fallback_unlock; - replace_page_cache_page(oldpage, newpage); + replace_page_cache_folio(page_folio(oldpage), page_folio(newpage)); get_page(newpage); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index bbccb4044222..275810697d71 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -1104,7 +1104,7 @@ int filemap_add_folio(struct address_space *mapping, struct folio *folio, void filemap_remove_folio(struct folio *folio); void delete_from_page_cache(struct page *page); void __filemap_remove_folio(struct folio *folio, void *shadow); -void replace_page_cache_page(struct page *old, struct page *new); +void replace_page_cache_folio(struct folio *old, struct folio *new); void delete_from_page_cache_batch(struct address_space *mapping, struct folio_batch *fbatch); int try_to_release_page(struct page *page, gfp_t gfp); diff --git a/mm/filemap.c b/mm/filemap.c index 08341616ae7a..c61dfaa81fee 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -785,56 +785,54 @@ int file_write_and_wait_range(struct file *file, loff_t lstart, loff_t lend) EXPORT_SYMBOL(file_write_and_wait_range); /** - * replace_page_cache_page - replace a pagecache page with a new one - * @old: page to be replaced - * @new: page to replace with - * - * This function replaces a page in the pagecache with a new one. On - * success it acquires the pagecache reference for the new page and - * drops it for the old page. Both the old and new pages must be - * locked. This function does not add the new page to the LRU, the + * replace_page_cache_folio - replace a pagecache folio with a new one + * @old: folio to be replaced + * @new: folio to replace with + * + * This function replaces a folio in the pagecache with a new one. On + * success it acquires the pagecache reference for the new folio and + * drops it for the old folio. Both the old and new folios must be + * locked. This function does not add the new folio to the LRU, the * caller must do that. * * The remove + add is atomic. This function cannot fail. */ -void replace_page_cache_page(struct page *old, struct page *new) +void replace_page_cache_folio(struct folio *old, struct folio *new) { - struct folio *fold = page_folio(old); - struct folio *fnew = page_folio(new); struct address_space *mapping = old->mapping; void (*free_folio)(struct folio *) = mapping->a_ops->free_folio; pgoff_t offset = old->index; XA_STATE(xas, &mapping->i_pages, offset); - VM_BUG_ON_PAGE(!PageLocked(old), old); - VM_BUG_ON_PAGE(!PageLocked(new), new); - VM_BUG_ON_PAGE(new->mapping, new); + VM_BUG_ON_FOLIO(!folio_test_locked(old), old); + VM_BUG_ON_FOLIO(!folio_test_locked(new), new); + VM_BUG_ON_FOLIO(new->mapping, new); - get_page(new); + folio_get(new); new->mapping = mapping; new->index = offset; - mem_cgroup_migrate(fold, fnew); + mem_cgroup_migrate(old, new); xas_lock_irq(&xas); xas_store(&xas, new); old->mapping = NULL; /* hugetlb pages do not participate in page cache accounting. */ - if (!PageHuge(old)) - __dec_lruvec_page_state(old, NR_FILE_PAGES); - if (!PageHuge(new)) - __inc_lruvec_page_state(new, NR_FILE_PAGES); - if (PageSwapBacked(old)) - __dec_lruvec_page_state(old, NR_SHMEM); - if (PageSwapBacked(new)) - __inc_lruvec_page_state(new, NR_SHMEM); + if (!folio_test_hugetlb(old)) + __lruvec_stat_sub_folio(old, NR_FILE_PAGES); + if (!folio_test_hugetlb(new)) + __lruvec_stat_add_folio(new, NR_FILE_PAGES); + if (folio_test_swapbacked(old)) + __lruvec_stat_sub_folio(old, NR_SHMEM); + if (folio_test_swapbacked(new)) + __lruvec_stat_add_folio(new, NR_SHMEM); xas_unlock_irq(&xas); if (free_folio) - free_folio(fold); - folio_put(fold); + free_folio(old); + folio_put(old); } -EXPORT_SYMBOL_GPL(replace_page_cache_page); +EXPORT_SYMBOL_GPL(replace_page_cache_folio); noinline int __filemap_add_folio(struct address_space *mapping, struct folio *folio, pgoff_t index, gfp_t gfp, void **shadowp)