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: name the anonymous MMOP enum as enum mmop

Give the MMOP enum (MMOP_OFFLINE, MMOP_ONLINE, etc) a proper type name so
the compiler can help catch invalid values being assigned to variables of
this type.

Leave the existing functions returning int alone to allow for
value-or-error pattern to remain unchanged without churn.

mmop_default_online_type is left as int because it uses the -1 sentinal
value to signal it hasn't been initialized yet.

Keep the uint8_t buffer in offline_and_remove_memory() as-is for space
efficiency, with an explicit cast when we consume the value.

Move the enum definition before the CONFIG_MEMORY_HOTPLUG guard so it is
unconditionally available for struct memory_block in memory.h.

No functional change.

Link: https://lore.kernel.org/linux-mm/3424eba7-523b-4351-abd0-3a888a3e5e61@kernel.org/
Link: https://lkml.kernel.org/r/20260211215447.2194189-1-gourry@gourry.net
Signed-off-by: Gregory Price <gourry@gourry.net>
Suggested-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Suggested-by: "David Hildenbrand (arm)" <david@kernel.org>
Reviewed-by: Ben Cheatham <benjamin.cheatham@amd.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Gregory Price and committed by
Andrew Morton
c5c48345 4e89004e

+16 -15
+1 -1
drivers/base/memory.c
··· 452 452 static int print_allowed_zone(char *buf, int len, int nid, 453 453 struct memory_group *group, 454 454 unsigned long start_pfn, unsigned long nr_pages, 455 - int online_type, struct zone *default_zone) 455 + enum mmop online_type, struct zone *default_zone) 456 456 { 457 457 struct zone *zone; 458 458
+2 -1
include/linux/memory.h
··· 19 19 #include <linux/node.h> 20 20 #include <linux/compiler.h> 21 21 #include <linux/mutex.h> 22 + #include <linux/memory_hotplug.h> 22 23 23 24 #define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS) 24 25 ··· 78 77 struct memory_block { 79 78 unsigned long start_section_nr; 80 79 enum memory_block_state state; /* serialized by the dev->lock */ 81 - int online_type; /* for passing data to online routine */ 80 + enum mmop online_type; /* for passing data to online routine */ 82 81 int nid; /* NID for this memory block */ 83 82 /* 84 83 * The single zone of this memory block if all PFNs of this memory block
+8 -8
include/linux/memory_hotplug.h
··· 16 16 struct vmem_altmap; 17 17 struct dev_pagemap; 18 18 19 - #ifdef CONFIG_MEMORY_HOTPLUG 20 - struct page *pfn_to_online_page(unsigned long pfn); 21 - 22 19 /* Types for control the zone type of onlined and offlined memory */ 23 - enum { 20 + enum mmop { 24 21 /* Offline the memory. */ 25 22 MMOP_OFFLINE = 0, 26 23 /* Online the memory. Zone depends, see default_zone_for_pfn(). */ ··· 27 30 /* Online the memory to ZONE_MOVABLE. */ 28 31 MMOP_ONLINE_MOVABLE, 29 32 }; 33 + 34 + #ifdef CONFIG_MEMORY_HOTPLUG 35 + struct page *pfn_to_online_page(unsigned long pfn); 30 36 31 37 /* Flags for add_memory() and friends to specify memory hotplug details. */ 32 38 typedef int __bitwise mhp_t; ··· 286 286 287 287 #ifdef CONFIG_MEMORY_HOTPLUG 288 288 /* Default online_type (MMOP_*) when new memory blocks are added. */ 289 - extern int mhp_get_default_online_type(void); 290 - extern void mhp_set_default_online_type(int online_type); 289 + extern enum mmop mhp_get_default_online_type(void); 290 + extern void mhp_set_default_online_type(enum mmop online_type); 291 291 extern void __ref free_area_init_core_hotplug(struct pglist_data *pgdat); 292 292 extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); 293 293 extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); ··· 310 310 struct vmem_altmap *altmap); 311 311 extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map, 312 312 unsigned long pnum); 313 - extern struct zone *zone_for_pfn_range(int online_type, int nid, 314 - struct memory_group *group, unsigned long start_pfn, 313 + extern struct zone *zone_for_pfn_range(enum mmop online_type, 314 + int nid, struct memory_group *group, unsigned long start_pfn, 315 315 unsigned long nr_pages); 316 316 extern int arch_create_linear_mapping(int nid, u64 start, u64 size, 317 317 struct mhp_params *params);
+5 -5
mm/memory_hotplug.c
··· 221 221 bool movable_node_enabled = false; 222 222 223 223 static int mhp_default_online_type = -1; 224 - int mhp_get_default_online_type(void) 224 + enum mmop mhp_get_default_online_type(void) 225 225 { 226 226 if (mhp_default_online_type >= 0) 227 227 return mhp_default_online_type; ··· 240 240 return mhp_default_online_type; 241 241 } 242 242 243 - void mhp_set_default_online_type(int online_type) 243 + void mhp_set_default_online_type(enum mmop online_type) 244 244 { 245 245 mhp_default_online_type = online_type; 246 246 } ··· 1046 1046 return movable_node_enabled ? movable_zone : kernel_zone; 1047 1047 } 1048 1048 1049 - struct zone *zone_for_pfn_range(int online_type, int nid, 1049 + struct zone *zone_for_pfn_range(enum mmop online_type, int nid, 1050 1050 struct memory_group *group, unsigned long start_pfn, 1051 1051 unsigned long nr_pages) 1052 1052 { ··· 2305 2305 2306 2306 static int try_offline_memory_block(struct memory_block *mem, void *arg) 2307 2307 { 2308 - uint8_t online_type = MMOP_ONLINE_KERNEL; 2308 + enum mmop online_type = MMOP_ONLINE_KERNEL; 2309 2309 uint8_t **online_types = arg; 2310 2310 struct page *page; 2311 2311 int rc; ··· 2338 2338 int rc; 2339 2339 2340 2340 if (**online_types != MMOP_OFFLINE) { 2341 - mem->online_type = **online_types; 2341 + mem->online_type = (enum mmop)**online_types; 2342 2342 rc = device_online(&mem->dev); 2343 2343 if (rc < 0) 2344 2344 pr_warn("%s: Failed to re-online memory: %d",