From patchwork Sat Oct 5 20:01:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13823465 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 CB5DFCFB42C for ; Sat, 5 Oct 2024 20:01:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C12E36B0326; Sat, 5 Oct 2024 16:01:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC2C96B0328; Sat, 5 Oct 2024 16:01:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3C536B0329; Sat, 5 Oct 2024 16:01:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 81A876B0326 for ; Sat, 5 Oct 2024 16:01:49 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4AA7EA13EE for ; Sat, 5 Oct 2024 20:01:49 +0000 (UTC) X-FDA: 82640619138.25.073CC2F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id 8ADB1C000B for ; Sat, 5 Oct 2024 20:01:47 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hv632I3D; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728158376; 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=DDL9D7cGGKvpmkZP5t1+zKThExNjqx/l2gjBg0/23Cs=; b=V7It+pSf3JIXBSX8Y0xGJp6mpQWAeOUE6yJ6BsjF0X/8bKkqSaQY++tnkiEC4IhFuNl6gi JRt/Bk3AztBlvTVuzu4ZEN6dB3CkkeYF0CWzdoBwPTDG9oMvCiudCMQWcKwQDRcmhE8NO2 qsmUjK9J58Y/KmCd2yU9LdrBSnZfdPc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728158376; a=rsa-sha256; cv=none; b=Vg3z1gdTnVJ0KEHPdpab8yLNihepyZBUykkw3cBDBMNAYaF1+IQCEs9BekTh9jdCmNQOqr Z97PHb3Edsk3v5Y/3EgBvKwQHXt+ozYFGMtkKB4gDDLj+iT1j0X58b5Mz/nXrpq4ypyz2B Tjvh0jNHwksvCFQ3AAdSc2I0kVBcmAM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=hv632I3D; spf=none (imf22.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=DDL9D7cGGKvpmkZP5t1+zKThExNjqx/l2gjBg0/23Cs=; b=hv632I3D+GzcOYgrREWgYWw/d8 lIHnDO2btpmtZF8hqJmWd5gsm18IOux0cxf/n6E2546YhVhcyhRPlfeeQ1axy/ESTwVZQYYJlvNim ZgLSueLTD+gZxFZyUmtACrIg5IPrC4lAq5/lNchgF/W2kkrLur0s8DNJ5hTG+9ajOLwBippwV6YWY m6uu5PqjfB+SNfyKh54zc/oglO41AvTVRPfFGAwhLDsVs1JbGM306IoSlCwDpVWuJr2PnXuHHLiq5 1sOqQZ6SrZhNmN+sMOsDt609xsY2L1WlnpUDKph+6G0SthKqMoRi3R4jtUJM2nSCKrFjhqZ88/cZT bMMkFM8w==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sxAxw-0000000DYZi-3aS2; Sat, 05 Oct 2024 20:01:24 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 4/7] mm: Mass constification of folio/page pointers Date: Sat, 5 Oct 2024 21:01:15 +0100 Message-ID: <20241005200121.3231142-5-willy@infradead.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241005200121.3231142-1-willy@infradead.org> References: <20241005200121.3231142-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8ADB1C000B X-Stat-Signature: h3ebuk6cc71gauu7q1d6x4opm9narxid X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1728158507-549490 X-HE-Meta: U2FsdGVkX1/jyWdiKeQ9JIOxtImMof4KBYnRQgAJvD63COJyktWbuUTh+4JMUcZkLa53dSM6/RWvCIGy3x1k3iaJTqyAFJAWNUCkkD9JbK64BI3r61UG1Z5pq2dULn/C6/eso2p5d636V0L/jMfDKJkaAQteoMOOdvHu+LuzzhNCeUPNmk8janTzudh6BoHNo88ZnpzkSdV/oIaHaFeJvTL4KjVZEXSidgMgM6wHS37GsfKo6KKGJQyc+dOylSnc2p6dQCTnvcpREaHWrobzjLjprBxKmLIFNfTgX7bsVwlvka3xGXcFPfM0wwlzpqoeFyfiC9yVJTWRqJmqSVNkT3AOlb/Eg5nzlKdd3sdGEkgFXTn7h73Sz1jUduWsb99GQpsNOe8CppUisYV1RbRO93tt3vyuQhvIMoQsSuzPr9wZ/JP6G6jPFX9Ig4Cc9MKWLZby5fCrSN/ylJAbqS/Nw7XXkzqTira0YD8KMvBUB4BCvAn0AEv0uFaCFFldKKg3ltQwpw01A3vXB+TDQCpqwgTldZoVJFfAkAlpvHsyYKZeQetNRrnX4e4HwIfQw3XvhJ9fmhOqA8SoZrb04Mq+smC+c8bvf+sebJjPCjxMNFfnmioPDZ64ldZtYb9kb7alM8hnEZ1Xab7AzlgUFtWvXHVxO/gtYhITnqMhkr6a5TcLPvSriCVxTrYQkdMS8VhkQa8qIR5u4M5GO6Xkk7FKC1lKPoYFrlI6f1OGevqE5tkUCEmldZvvqtJOeF8A99r21QjR0xZ5TYrA2iPHwVWI3NXJAbJkGd6+iLSdmiomdQV5Flk5aQNxLvT2ryKcSOLw2A0FJs73svxb1G/kBPrVCoQCBhRA/4MIobC4TSo5lUhtSfAnEdAgbYIAZys3BkgAAsdnGOrGW/JOKwVl6q2yZ0xzdyMtE0Sp+vI7lHoJhQ8QfjWPTIQco9VQQcSgVsSwB1TU7KEvt/3uLfxzbye AtGoZehu midnWClYbC/YDh5oU/Q3J/LzX/4MQePWxmHWFjZ0Vk3lJ8fy+MzwtJmk1IH7GKQEhPYo0D6Ags93F85iGRh+8wvAquZ8ciPS8HyCIRPb4r11y6RAi/KSHOTjRb2mY0JmwHp13qK0/4bnnI5lSGNgHcxiUHdGl3rp8nutxs6hGuEnDQS9wtdX3JRXwBxr20hQ7AT2JqUZww57vlizXl9pMp3TAQYReCdoduZXp59fm5/h6LPA= 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: List-Subscribe: List-Unsubscribe: Now that page_pgoff() takes const pointers, we can constify the pointers to a lot of functions. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/ksm.h | 7 ++++--- include/linux/rmap.h | 10 +++++----- mm/internal.h | 5 +++-- mm/ksm.c | 5 +++-- mm/memory-failure.c | 24 +++++++++++++----------- mm/page_vma_mapped.c | 5 +++-- mm/rmap.c | 11 ++++++----- 7 files changed, 37 insertions(+), 30 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index 11690dacd986..c4a8891f6e7d 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -92,7 +92,7 @@ struct folio *ksm_might_need_to_copy(struct folio *folio, void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc); void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); -void collect_procs_ksm(struct folio *folio, struct page *page, +void collect_procs_ksm(const struct folio *folio, const struct page *page, struct list_head *to_kill, int force_early); long ksm_process_profit(struct mm_struct *); @@ -125,8 +125,9 @@ static inline void ksm_might_unmap_zero_page(struct mm_struct *mm, pte_t pte) { } -static inline void collect_procs_ksm(struct folio *folio, struct page *page, - struct list_head *to_kill, int force_early) +static inline void collect_procs_ksm(const struct folio *folio, + const struct page *page, struct list_head *to_kill, + int force_early) { } diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 78923015a2e8..683a04088f3f 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -171,7 +171,7 @@ static inline void anon_vma_merge(struct vm_area_struct *vma, unlink_anon_vmas(next); } -struct anon_vma *folio_get_anon_vma(struct folio *folio); +struct anon_vma *folio_get_anon_vma(const struct folio *folio); /* RMAP flags, currently only relevant for some anon rmap operations. */ typedef int __bitwise rmap_t; @@ -194,8 +194,8 @@ enum rmap_level { RMAP_LEVEL_PMD, }; -static inline void __folio_rmap_sanity_checks(struct folio *folio, - struct page *page, int nr_pages, enum rmap_level level) +static inline void __folio_rmap_sanity_checks(const struct folio *folio, + const struct page *page, int nr_pages, enum rmap_level level) { /* hugetlb folios are handled separately. */ VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); @@ -771,14 +771,14 @@ struct rmap_walk_control { bool (*rmap_one)(struct folio *folio, struct vm_area_struct *vma, unsigned long addr, void *arg); int (*done)(struct folio *folio); - struct anon_vma *(*anon_lock)(struct folio *folio, + struct anon_vma *(*anon_lock)(const struct folio *folio, struct rmap_walk_control *rwc); bool (*invalid_vma)(struct vm_area_struct *vma, void *arg); }; void rmap_walk(struct folio *folio, struct rmap_walk_control *rwc); void rmap_walk_locked(struct folio *folio, struct rmap_walk_control *rwc); -struct anon_vma *folio_lock_anon_vma_read(struct folio *folio, +struct anon_vma *folio_lock_anon_vma_read(const struct folio *folio, struct rmap_walk_control *rwc); #else /* !CONFIG_MMU */ diff --git a/mm/internal.h b/mm/internal.h index fffa9df41495..71a30e779223 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1072,10 +1072,11 @@ void ClearPageHWPoisonTakenOff(struct page *page); bool take_page_off_buddy(struct page *page); bool put_page_back_buddy(struct page *page); struct task_struct *task_early_kill(struct task_struct *tsk, int force_early); -void add_to_kill_ksm(struct task_struct *tsk, struct page *p, +void add_to_kill_ksm(struct task_struct *tsk, const struct page *p, struct vm_area_struct *vma, struct list_head *to_kill, unsigned long ksm_addr); -unsigned long page_mapped_in_vma(struct page *page, struct vm_area_struct *vma); +unsigned long page_mapped_in_vma(const struct page *page, + struct vm_area_struct *vma); #else static inline void unmap_poisoned_folio(struct folio *folio, enum ttu_flags ttu) diff --git a/mm/ksm.c b/mm/ksm.c index 2bbb321f92ac..1fed2e3e01e0 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1052,7 +1052,8 @@ static int unmerge_ksm_pages(struct vm_area_struct *vma, return err; } -static inline struct ksm_stable_node *folio_stable_node(struct folio *folio) +static inline +struct ksm_stable_node *folio_stable_node(const struct folio *folio) { return folio_test_ksm(folio) ? folio_raw_mapping(folio) : NULL; } @@ -3066,7 +3067,7 @@ void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc) /* * Collect processes when the error hit an ksm page. */ -void collect_procs_ksm(struct folio *folio, struct page *page, +void collect_procs_ksm(const struct folio *folio, const struct page *page, struct list_head *to_kill, int force_early) { struct ksm_stable_node *stable_node; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index ea9d883c01c1..7ce7ba8586f5 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -445,7 +445,7 @@ static unsigned long dev_pagemap_mapping_shift(struct vm_area_struct *vma, * Schedule a process for later kill. * Uses GFP_ATOMIC allocations to avoid potential recursions in the VM. */ -static void __add_to_kill(struct task_struct *tsk, struct page *p, +static void __add_to_kill(struct task_struct *tsk, const struct page *p, struct vm_area_struct *vma, struct list_head *to_kill, unsigned long addr) { @@ -461,7 +461,7 @@ static void __add_to_kill(struct task_struct *tsk, struct page *p, if (is_zone_device_page(p)) tk->size_shift = dev_pagemap_mapping_shift(vma, tk->addr); else - tk->size_shift = page_shift(compound_head(p)); + tk->size_shift = folio_shift(page_folio(p)); /* * Send SIGKILL if "tk->addr == -EFAULT". Also, as @@ -486,7 +486,7 @@ static void __add_to_kill(struct task_struct *tsk, struct page *p, list_add_tail(&tk->nd, to_kill); } -static void add_to_kill_anon_file(struct task_struct *tsk, struct page *p, +static void add_to_kill_anon_file(struct task_struct *tsk, const struct page *p, struct vm_area_struct *vma, struct list_head *to_kill, unsigned long addr) { @@ -509,7 +509,7 @@ static bool task_in_to_kill_list(struct list_head *to_kill, return false; } -void add_to_kill_ksm(struct task_struct *tsk, struct page *p, +void add_to_kill_ksm(struct task_struct *tsk, const struct page *p, struct vm_area_struct *vma, struct list_head *to_kill, unsigned long addr) { @@ -606,8 +606,9 @@ struct task_struct *task_early_kill(struct task_struct *tsk, int force_early) /* * Collect processes when the error hit an anonymous page. */ -static void collect_procs_anon(struct folio *folio, struct page *page, - struct list_head *to_kill, int force_early) +static void collect_procs_anon(const struct folio *folio, + const struct page *page, struct list_head *to_kill, + int force_early) { struct task_struct *tsk; struct anon_vma *av; @@ -643,8 +644,9 @@ static void collect_procs_anon(struct folio *folio, struct page *page, /* * Collect processes when the error hit a file mapped page. */ -static void collect_procs_file(struct folio *folio, struct page *page, - struct list_head *to_kill, int force_early) +static void collect_procs_file(const struct folio *folio, + const struct page *page, struct list_head *to_kill, + int force_early) { struct vm_area_struct *vma; struct task_struct *tsk; @@ -680,7 +682,7 @@ static void collect_procs_file(struct folio *folio, struct page *page, } #ifdef CONFIG_FS_DAX -static void add_to_kill_fsdax(struct task_struct *tsk, struct page *p, +static void add_to_kill_fsdax(struct task_struct *tsk, const struct page *p, struct vm_area_struct *vma, struct list_head *to_kill, pgoff_t pgoff) { @@ -691,7 +693,7 @@ static void add_to_kill_fsdax(struct task_struct *tsk, struct page *p, /* * Collect processes when the error hit a fsdax page. */ -static void collect_procs_fsdax(struct page *page, +static void collect_procs_fsdax(const struct page *page, struct address_space *mapping, pgoff_t pgoff, struct list_head *to_kill, bool pre_remove) { @@ -725,7 +727,7 @@ static void collect_procs_fsdax(struct page *page, /* * Collect the processes who have the corrupted page mapped to kill. */ -static void collect_procs(struct folio *folio, struct page *page, +static void collect_procs(const struct folio *folio, const struct page *page, struct list_head *tokill, int force_early) { if (!folio->mapping) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index ade3c6833587..82e20dbbedb7 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -325,9 +325,10 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) * outside the VMA or not present, returns -EFAULT. * Only valid for normal file or anonymous VMAs. */ -unsigned long page_mapped_in_vma(struct page *page, struct vm_area_struct *vma) +unsigned long page_mapped_in_vma(const struct page *page, + struct vm_area_struct *vma) { - struct folio *folio = page_folio(page); + const struct folio *folio = page_folio(page); struct page_vma_mapped_walk pvmw = { .pfn = page_to_pfn(page), .nr_pages = 1, diff --git a/mm/rmap.c b/mm/rmap.c index a7b4f9ba9a14..2c561b1e52cc 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -497,7 +497,7 @@ void __init anon_vma_init(void) * concurrently without folio lock protection). See folio_lock_anon_vma_read() * which has already covered that, and comment above remap_pages(). */ -struct anon_vma *folio_get_anon_vma(struct folio *folio) +struct anon_vma *folio_get_anon_vma(const struct folio *folio) { struct anon_vma *anon_vma = NULL; unsigned long anon_mapping; @@ -541,7 +541,7 @@ struct anon_vma *folio_get_anon_vma(struct folio *folio) * reference like with folio_get_anon_vma() and then block on the mutex * on !rwc->try_lock case. */ -struct anon_vma *folio_lock_anon_vma_read(struct folio *folio, +struct anon_vma *folio_lock_anon_vma_read(const struct folio *folio, struct rmap_walk_control *rwc) { struct anon_vma *anon_vma = NULL; @@ -1275,8 +1275,9 @@ static void __folio_set_anon(struct folio *folio, struct vm_area_struct *vma, * @vma: the vm area in which the mapping is added * @address: the user virtual address mapped */ -static void __page_check_anon_rmap(struct folio *folio, struct page *page, - struct vm_area_struct *vma, unsigned long address) +static void __page_check_anon_rmap(const struct folio *folio, + const struct page *page, struct vm_area_struct *vma, + unsigned long address) { /* * The page's anon-rmap details (mapping and index) are guaranteed to @@ -2573,7 +2574,7 @@ void __put_anon_vma(struct anon_vma *anon_vma) anon_vma_free(root); } -static struct anon_vma *rmap_walk_anon_lock(struct folio *folio, +static struct anon_vma *rmap_walk_anon_lock(const struct folio *folio, struct rmap_walk_control *rwc) { struct anon_vma *anon_vma;