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

mm: simplify and rename mm flags function for clarity

The __mm_flags_set_word() function is slightly ambiguous - we use 'set' to
refer to setting individual bits (such as in mm_flags_set()) but here we
use it to refer to overwriting the value altogether.

Rename it to __mm_flags_overwrite_word() to eliminate this ambiguity.

We additionally simplify the functions, eliminating unnecessary
bitmap_xxx() operations (the compiler would have optimised these out but
it's worth being as clear as we can be here).

Link: https://lkml.kernel.org/r/8f0bc556e1b90eca8ea5eba41f8d5d3f9cd7c98a.1764064557.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Pedro Falcato <pfalcato@suse.de>
Acked-by: Alice Ryhl <aliceryhl@google.com> [rust]
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Chris Li <chrisl@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Gary Guo <gary@garyguo.net>
Cc: Gregory Price <gourry@gourry.net>
Cc: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kairui Song <kasong@tencent.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mathew Brost <matthew.brost@intel.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Nico Pache <npache@redhat.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Rakie Kim <rakie.kim@sk.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Wei Xu <weixugc@google.com>
Cc: xu xin <xu.xin16@zte.com.cn>
Cc: Yuanchu Xie <yuanchu@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
58eac97a 2b6a3f06

+7 -11
+5 -9
include/linux/mm_types.h
··· 1314 1314 unsigned long cpu_bitmap[]; 1315 1315 }; 1316 1316 1317 - /* Set the first system word of mm flags, non-atomically. */ 1318 - static inline void __mm_flags_set_word(struct mm_struct *mm, unsigned long value) 1317 + /* Copy value to the first system word of mm flags, non-atomically. */ 1318 + static inline void __mm_flags_overwrite_word(struct mm_struct *mm, unsigned long value) 1319 1319 { 1320 - unsigned long *bitmap = ACCESS_PRIVATE(&mm->flags, __mm_flags); 1321 - 1322 - bitmap_copy(bitmap, &value, BITS_PER_LONG); 1320 + *ACCESS_PRIVATE(&mm->flags, __mm_flags) = value; 1323 1321 } 1324 1322 1325 - /* Obtain a read-only view of the bitmap. */ 1323 + /* Obtain a read-only view of the mm flags bitmap. */ 1326 1324 static inline const unsigned long *__mm_flags_get_bitmap(const struct mm_struct *mm) 1327 1325 { 1328 1326 return (const unsigned long *)ACCESS_PRIVATE(&mm->flags, __mm_flags); ··· 1329 1331 /* Read the first system word of mm flags, non-atomically. */ 1330 1332 static inline unsigned long __mm_flags_get_word(const struct mm_struct *mm) 1331 1333 { 1332 - const unsigned long *bitmap = __mm_flags_get_bitmap(mm); 1333 - 1334 - return bitmap_read(bitmap, 0, BITS_PER_LONG); 1334 + return *__mm_flags_get_bitmap(mm); 1335 1335 } 1336 1336 1337 1337 /*
+2 -2
kernel/fork.c
··· 1061 1061 if (current->mm) { 1062 1062 unsigned long flags = __mm_flags_get_word(current->mm); 1063 1063 1064 - __mm_flags_set_word(mm, mmf_init_legacy_flags(flags)); 1064 + __mm_flags_overwrite_word(mm, mmf_init_legacy_flags(flags)); 1065 1065 mm->def_flags = current->mm->def_flags & VM_INIT_DEF_MASK; 1066 1066 } else { 1067 - __mm_flags_set_word(mm, default_dump_filter); 1067 + __mm_flags_overwrite_word(mm, default_dump_filter); 1068 1068 mm->def_flags = 0; 1069 1069 } 1070 1070