From patchwork Tue Jul 23 15:34:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13740178 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 58E8FC3DA49 for ; Tue, 23 Jul 2024 15:35:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 131D56B009C; Tue, 23 Jul 2024 11:35:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E3D86B00BE; Tue, 23 Jul 2024 11:35:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9DB36B00C0; Tue, 23 Jul 2024 11:35:24 -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 CA0E46B00BE for ; Tue, 23 Jul 2024 11:35:24 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 56BF7401E8 for ; Tue, 23 Jul 2024 15:35:24 +0000 (UTC) X-FDA: 82371416568.24.8EE6DD7 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 996111C0034 for ; Tue, 23 Jul 2024 15:35:22 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=oUDnBoDl; spf=none (imf20.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=1721748860; 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=G2dy+oHwkbXO1j0uagI55DaZsuRPTbQymaQhjtDfwLI=; b=1rl4j/FZenPSxTdMmNZvV50G106CU5CTsxA7HMzh8XI6+VBSQuMhyAj4mGEFkQteIFNgZQ 4DYX+xDqjRmB6Wpc/TduR/pyDGeWwfNExv5s0WP6bRXLWNi/xafckC1EyjTZDJCJYvO/iP QXU1hOFN3T2/CMLvky9dT+MYmOEtqBY= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=oUDnBoDl; spf=none (imf20.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721748860; a=rsa-sha256; cv=none; b=42qA1wUfPgiKJw0u56kfZdFPR//CCPUYUgCT+fS2tMLDWFl/EM81ngwlYt5MR0zQ2F4evz Svl7RQ9HK89zULyHjQtcGmhvILNDqon6x5Gn26xT4bDhyF5nlXuTbHNxMNF94lsuwFurMP bJ29CygHRrltZJL74TLPFTvAggoF08c= 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=G2dy+oHwkbXO1j0uagI55DaZsuRPTbQymaQhjtDfwLI=; b=oUDnBoDlgf5pIgsuZoZhYTltAH tWO9E8PYxpcFGKfYLi/YjEsQaGmZuviGBmtw4MtE+Jmbz/BOPtghGk/lN7Gwq3bBvdoeQxZ7ckoJG pfTMWhzdLaoR3uHntopGFlHICHd9rK3SbYXeOlKZp7kiALCQneq7s6n1U+Yw8KbN60ApjHFXuH6FJ j97GQlJzLk3ouCCoyfOPGdVTCyPZK+XbfbNKSJQPphy0k0AVUtpXT1LUvdN4xydW+QrpMHLfoa2JH 9CT/P7p+IjPAr+LxBtcomrw8S4yfRJFJ49oZxzRJh9uE1Y1Xe0mRLzdyxwKx2z+hUf+I1quWfozEg y5qFUnqA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWHXd-000000070LM-1FvC; Tue, 23 Jul 2024 15:35:05 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 4/6] mm: Mass constification of folio/page pointers Date: Tue, 23 Jul 2024 16:34:59 +0100 Message-ID: <20240723153503.1669586-5-willy@infradead.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723153503.1669586-1-willy@infradead.org> References: <20240723153503.1669586-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 996111C0034 X-Stat-Signature: i446kz48ebo77tgihb9gjqqbibjhtudt X-Rspam-User: X-HE-Tag: 1721748922-505730 X-HE-Meta: U2FsdGVkX18D/dVwSaqkRYrWUJNcg4IJzEBEqXKHkH10PynvM23LrmXQUoVozScBBY1HOERRdlVLT5R13tR/g3hPRx29UD6zSHbDX79QsXisblciM0VjVXyWsHoyJFJuc4tPuYhUYyN+/dQzoXLbMyPhN5W4pNZnom5hae8dUOHBWiKXLEzkQ1ubA9yJ3FaP9AJOnkwyW+b0Hlbv1GHeRXyEhtvWJwYA+MpRvSqCjbb7fzY3UX4nlNMlmXE075KVlNwXN2v56c0OE7XQrBbqijNQaTo3O7lMn0ZuhSuGydv84ouj57mLc/U4i2K9ubSSxfO7V/+Y8l2dzccrr4GTDTJGaB1IfCyvsKqPJLWal3Ifyqg0kXHQoB+JTIC7nrg/U/QDjYkT5UghY5xlDL59mUwn4G/oQJat6hIaRqdr19m+kkf99uqa5xZVzu5dMX2P2G9n2O8HAp480V2UOIduIZBNgkkBie8LTJ1uDFMU+RDvWxm0l/CuVPdjf7y599tFarcHGcY11yHXzxr5KhF+OcqgKYj1zefeMBMh1H43XH6WtceEWzqjFtdtYzgQTkUKypqFvIqFrmeuqKXDl2qXy5zMkFcDfMi/srH8G41FzJmXE1DN0FM+ebjx5FoxwI3O/f7jJGwXmQ9BljjQ5osd5LILyX+9dsqTq8ePdjsPkhVXvv8PhhCGtv9Lo+pu43d7EhYTNd1JPu5JwkgrsRNkW9tIxPUyx5/GRXxC35q/TJ6161mAiztUUPbB77Js9fbNn8fe7HulTwlVFni0ixWfVjrlIByRuZjzD0bKJqoEJoe9e+Agqzasifdf0FlHoy2kDyiXjYhRwPTNz1VuTrVZPARxeyXOu8QwyYYBJGIGpFiKI5yA/bhM3kGpBf4cA5aeckrMxcnmPGy24x6okQQ3OQLNZL5+3334ToOqRSVeGQMawln4oAfyoP5Dl4ihvh036Ctw+khZqTsbGJUuM0y 4sIWVm5Z G7jE6z7NNu243RJkYZ+ga8Cg8V6UKWrEfzqKEtDVxLQwjTjWMNr1UdBTafHjNU0CAXMmxHQUWt7JqBzcK9ds4WNRBF9h2W9ntNFIkbQHTgCR13pHsx8pdVNgq4IXELxh1diZfJjfir5eQtpVs6D1HU58bRuprdkzE7dnqGuN2kjN8H906/k/QR8QExAr6j2D7AoF8mDiV6ewWvwqFzo4s8i/LRg== 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 d1fca5b76039..bef597736e60 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); @@ -769,14 +769,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 8dfd9527ac1e..ec01e63572ae 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1090,10 +1090,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); extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long, unsigned long, unsigned long, diff --git a/mm/ksm.c b/mm/ksm.c index df6bae3a5a2c..8d45cfe7671f 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1080,7 +1080,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; } @@ -3085,7 +3086,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 572c742ecf48..729e9c49cc57 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 ae5cc42aa208..9b6632aab5f7 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); pgoff_t pgoff = folio->index + folio_page_idx(folio, page); struct page_vma_mapped_walk pvmw = { .pfn = page_to_pfn(page), diff --git a/mm/rmap.c b/mm/rmap.c index ba1920291ac6..9bcddd8ec228 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -496,7 +496,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; @@ -540,7 +540,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; @@ -1250,8 +1250,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 @@ -2535,7 +2536,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;