Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: constify various inline functions for improved const-correctness

We select certain test functions plus folio_migrate_refs() from
mm_inline.h which either invoke each other, functions that are already
const-ified, or no further functions.

It is therefore relatively trivial to const-ify them, which provides a
basis for further const-ification further up the call stack.

One exception is the function folio_migrate_refs() which does write to the
"new" folio pointer; there, only the "old" folio pointer is being
constified; only its "flags" field is read, but nothing written.

Link: https://lkml.kernel.org/r/20250901205021.3573313-11-max.kellermann@ionos.com
Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christian Zankel <chris@zankel.net>
Cc: David Rientjes <rientjes@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Helge Deller <deller@gmx.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Bottomley <james.bottomley@HansenPartnership.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jocelyn Falempe <jfalempe@redhat.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: "Nysal Jan K.A" <nysal@linux.ibm.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russel King <linux@armlinux.org.uk>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Wei Xu <weixugc@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Max Kellermann and committed by
Andrew Morton
f346a947 89bf840b

+13 -12
+13 -12
include/linux/mm_inline.h
··· 25 25 * 0 if @folio is a normal anonymous folio, a tmpfs folio or otherwise 26 26 * ram or swap backed folio. 27 27 */ 28 - static inline int folio_is_file_lru(struct folio *folio) 28 + static inline int folio_is_file_lru(const struct folio *folio) 29 29 { 30 30 return !folio_test_swapbacked(folio); 31 31 } ··· 84 84 * Return: The LRU list a folio should be on, as an index 85 85 * into the array of LRU lists. 86 86 */ 87 - static __always_inline enum lru_list folio_lru_list(struct folio *folio) 87 + static __always_inline enum lru_list folio_lru_list(const struct folio *folio) 88 88 { 89 89 enum lru_list lru; 90 90 ··· 141 141 return workingset ? MAX_NR_TIERS - 1 : order_base_2(refs); 142 142 } 143 143 144 - static inline int folio_lru_refs(struct folio *folio) 144 + static inline int folio_lru_refs(const struct folio *folio) 145 145 { 146 146 unsigned long flags = READ_ONCE(folio->flags.f); 147 147 ··· 154 154 return ((flags & LRU_REFS_MASK) >> LRU_REFS_PGOFF) + 1; 155 155 } 156 156 157 - static inline int folio_lru_gen(struct folio *folio) 157 + static inline int folio_lru_gen(const struct folio *folio) 158 158 { 159 159 unsigned long flags = READ_ONCE(folio->flags.f); 160 160 161 161 return ((flags & LRU_GEN_MASK) >> LRU_GEN_PGOFF) - 1; 162 162 } 163 163 164 - static inline bool lru_gen_is_active(struct lruvec *lruvec, int gen) 164 + static inline bool lru_gen_is_active(const struct lruvec *lruvec, int gen) 165 165 { 166 166 unsigned long max_seq = lruvec->lrugen.max_seq; 167 167 ··· 217 217 VM_WARN_ON_ONCE(lru_gen_is_active(lruvec, old_gen) && !lru_gen_is_active(lruvec, new_gen)); 218 218 } 219 219 220 - static inline unsigned long lru_gen_folio_seq(struct lruvec *lruvec, struct folio *folio, 220 + static inline unsigned long lru_gen_folio_seq(const struct lruvec *lruvec, 221 + const struct folio *folio, 221 222 bool reclaiming) 222 223 { 223 224 int gen; 224 225 int type = folio_is_file_lru(folio); 225 - struct lru_gen_folio *lrugen = &lruvec->lrugen; 226 + const struct lru_gen_folio *lrugen = &lruvec->lrugen; 226 227 227 228 /* 228 229 * +-----------------------------------+-----------------------------------+ ··· 303 302 return true; 304 303 } 305 304 306 - static inline void folio_migrate_refs(struct folio *new, struct folio *old) 305 + static inline void folio_migrate_refs(struct folio *new, const struct folio *old) 307 306 { 308 307 unsigned long refs = READ_ONCE(old->flags.f) & LRU_REFS_MASK; 309 308 ··· 331 330 return false; 332 331 } 333 332 334 - static inline void folio_migrate_refs(struct folio *new, struct folio *old) 333 + static inline void folio_migrate_refs(struct folio *new, const struct folio *old) 335 334 { 336 335 337 336 } ··· 509 508 atomic_dec(&mm->tlb_flush_pending); 510 509 } 511 510 512 - static inline bool mm_tlb_flush_pending(struct mm_struct *mm) 511 + static inline bool mm_tlb_flush_pending(const struct mm_struct *mm) 513 512 { 514 513 /* 515 514 * Must be called after having acquired the PTL; orders against that ··· 522 521 return atomic_read(&mm->tlb_flush_pending); 523 522 } 524 523 525 - static inline bool mm_tlb_flush_nested(struct mm_struct *mm) 524 + static inline bool mm_tlb_flush_nested(const struct mm_struct *mm) 526 525 { 527 526 /* 528 527 * Similar to mm_tlb_flush_pending(), we must have acquired the PTL ··· 606 605 return false; 607 606 } 608 607 609 - static inline bool vma_has_recency(struct vm_area_struct *vma) 608 + static inline bool vma_has_recency(const struct vm_area_struct *vma) 610 609 { 611 610 if (vma->vm_flags & (VM_SEQ_READ | VM_RAND_READ)) 612 611 return false;