Skip to content

Commit 7764990

Browse files
davidhildenbrandhcahca
authored andcommitted
mm/memblock: expose only miminal interface to add/walk physmem
"physmem" in the memblock allocator is somewhat weird: it's not actually used for allocation, it's simply information collected during boot, which describes the unmodified physical memory map at boot time, without any standby/hotplugged memory. It's only used on s390 and is currently the only reason s390 keeps using CONFIG_ARCH_KEEP_MEMBLOCK. Physmem isn't numa aware and current users don't specify any flags. Let's hide it from the user, exposing only for_each_physmem(), and simplify. The interface for physmem is now really minimalistic: - memblock_physmem_add() to add ranges - for_each_physmem() / __next_physmem_range() to walk physmem ranges Don't place it into an __init section and don't discard it without CONFIG_ARCH_KEEP_MEMBLOCK. As we're reusing __next_mem_range(), remove the __meminit notifier to avoid section mismatch warnings once CONFIG_ARCH_KEEP_MEMBLOCK is no longer used with CONFIG_HAVE_MEMBLOCK_PHYS_MAP. While fixing up the documentation, sneak in some related cleanups. We can stop setting CONFIG_ARCH_KEEP_MEMBLOCK for s390 next. Cc: Vasily Gorbik <[email protected]> Cc: Christian Borntraeger <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Reviewed-by: Mike Rapoport <[email protected]> Message-Id: <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent a303e88 commit 7764990

File tree

3 files changed

+55
-36
lines changed

3 files changed

+55
-36
lines changed

arch/s390/kernel/crash_dump.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,7 @@ static int get_mem_chunk_cnt(void)
549549
int cnt = 0;
550550
u64 idx;
551551

552-
for_each_mem_range(idx, &memblock.physmem, &oldmem_type, NUMA_NO_NODE,
553-
MEMBLOCK_NONE, NULL, NULL, NULL)
552+
for_each_physmem_range(idx, &oldmem_type, NULL, NULL)
554553
cnt++;
555554
return cnt;
556555
}
@@ -563,8 +562,7 @@ static void loads_init(Elf64_Phdr *phdr, u64 loads_offset)
563562
phys_addr_t start, end;
564563
u64 idx;
565564

566-
for_each_mem_range(idx, &memblock.physmem, &oldmem_type, NUMA_NO_NODE,
567-
MEMBLOCK_NONE, &start, &end, NULL) {
565+
for_each_physmem_range(idx, &oldmem_type, &start, &end) {
568566
phdr->p_filesz = end - start;
569567
phdr->p_type = PT_LOAD;
570568
phdr->p_offset = start;

include/linux/memblock.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,12 @@ struct memblock_type {
7777
* @current_limit: physical address of the current allocation limit
7878
* @memory: usable memory regions
7979
* @reserved: reserved memory regions
80-
* @physmem: all physical memory
8180
*/
8281
struct memblock {
8382
bool bottom_up; /* is bottom up direction? */
8483
phys_addr_t current_limit;
8584
struct memblock_type memory;
8685
struct memblock_type reserved;
87-
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
88-
struct memblock_type physmem;
89-
#endif
9086
};
9187

9288
extern struct memblock memblock;
@@ -145,6 +141,30 @@ void __next_reserved_mem_region(u64 *idx, phys_addr_t *out_start,
145141

146142
void __memblock_free_late(phys_addr_t base, phys_addr_t size);
147143

144+
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
145+
static inline void __next_physmem_range(u64 *idx, struct memblock_type *type,
146+
phys_addr_t *out_start,
147+
phys_addr_t *out_end)
148+
{
149+
extern struct memblock_type physmem;
150+
151+
__next_mem_range(idx, NUMA_NO_NODE, MEMBLOCK_NONE, &physmem, type,
152+
out_start, out_end, NULL);
153+
}
154+
155+
/**
156+
* for_each_physmem_range - iterate through physmem areas not included in type.
157+
* @i: u64 used as loop variable
158+
* @type: ptr to memblock_type which excludes from the iteration, can be %NULL
159+
* @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
160+
* @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
161+
*/
162+
#define for_each_physmem_range(i, type, p_start, p_end) \
163+
for (i = 0, __next_physmem_range(&i, type, p_start, p_end); \
164+
i != (u64)ULLONG_MAX; \
165+
__next_physmem_range(&i, type, p_start, p_end))
166+
#endif /* CONFIG_HAVE_MEMBLOCK_PHYS_MAP */
167+
148168
/**
149169
* for_each_mem_range - iterate through memblock areas from type_a and not
150170
* included in type_b. Or just type_a if type_b is NULL.

mm/memblock.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,20 @@
4444
* in the system, for instance when the memory is restricted with
4545
* ``mem=`` command line parameter
4646
* * ``reserved`` - describes the regions that were allocated
47-
* * ``physmap`` - describes the actual physical memory regardless of
48-
* the possible restrictions; the ``physmap`` type is only available
49-
* on some architectures.
47+
* * ``physmem`` - describes the actual physical memory available during
48+
* boot regardless of the possible restrictions and memory hot(un)plug;
49+
* the ``physmem`` type is only available on some architectures.
5050
*
5151
* Each region is represented by :c:type:`struct memblock_region` that
5252
* defines the region extents, its attributes and NUMA node id on NUMA
5353
* systems. Every memory type is described by the :c:type:`struct
5454
* memblock_type` which contains an array of memory regions along with
55-
* the allocator metadata. The memory types are nicely wrapped with
56-
* :c:type:`struct memblock`. This structure is statically initialzed
57-
* at build time. The region arrays for the "memory" and "reserved"
58-
* types are initially sized to %INIT_MEMBLOCK_REGIONS and for the
59-
* "physmap" type to %INIT_PHYSMEM_REGIONS.
55+
* the allocator metadata. The "memory" and "reserved" types are nicely
56+
* wrapped with :c:type:`struct memblock`. This structure is statically
57+
* initialized at build time. The region arrays are initially sized to
58+
* %INIT_MEMBLOCK_REGIONS for "memory" and %INIT_MEMBLOCK_RESERVED_REGIONS
59+
* for "reserved". The region array for "physmem" is initially sized to
60+
* %INIT_PHYSMEM_REGIONS.
6061
* The memblock_allow_resize() enables automatic resizing of the region
6162
* arrays during addition of new regions. This feature should be used
6263
* with care so that memory allocated for the region array will not
@@ -87,8 +88,8 @@
8788
* function frees all the memory to the buddy page allocator.
8889
*
8990
* Unless an architecture enables %CONFIG_ARCH_KEEP_MEMBLOCK, the
90-
* memblock data structures will be discarded after the system
91-
* initialization completes.
91+
* memblock data structures (except "physmem") will be discarded after the
92+
* system initialization completes.
9293
*/
9394

9495
#ifndef CONFIG_NEED_MULTIPLE_NODES
@@ -104,7 +105,7 @@ unsigned long long max_possible_pfn;
104105
static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
105106
static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_RESERVED_REGIONS] __initdata_memblock;
106107
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
107-
static struct memblock_region memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS] __initdata_memblock;
108+
static struct memblock_region memblock_physmem_init_regions[INIT_PHYSMEM_REGIONS];
108109
#endif
109110

110111
struct memblock memblock __initdata_memblock = {
@@ -118,17 +119,19 @@ struct memblock memblock __initdata_memblock = {
118119
.reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS,
119120
.reserved.name = "reserved",
120121

121-
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
122-
.physmem.regions = memblock_physmem_init_regions,
123-
.physmem.cnt = 1, /* empty dummy entry */
124-
.physmem.max = INIT_PHYSMEM_REGIONS,
125-
.physmem.name = "physmem",
126-
#endif
127-
128122
.bottom_up = false,
129123
.current_limit = MEMBLOCK_ALLOC_ANYWHERE,
130124
};
131125

126+
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
127+
struct memblock_type physmem = {
128+
.regions = memblock_physmem_init_regions,
129+
.cnt = 1, /* empty dummy entry */
130+
.max = INIT_PHYSMEM_REGIONS,
131+
.name = "physmem",
132+
};
133+
#endif
134+
132135
int memblock_debug __initdata_memblock;
133136
static bool system_has_some_mirror __initdata_memblock = false;
134137
static int memblock_can_resize __initdata_memblock;
@@ -838,7 +841,7 @@ int __init_memblock memblock_physmem_add(phys_addr_t base, phys_addr_t size)
838841
memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
839842
&base, &end, (void *)_RET_IP_);
840843

841-
return memblock_add_range(&memblock.physmem, base, size, MAX_NUMNODES, 0);
844+
return memblock_add_range(&physmem, base, size, MAX_NUMNODES, 0);
842845
}
843846
#endif
844847

@@ -1019,12 +1022,10 @@ static bool should_skip_region(struct memblock_region *m, int nid, int flags)
10191022
* As both region arrays are sorted, the function advances the two indices
10201023
* in lockstep and returns each intersection.
10211024
*/
1022-
void __init_memblock __next_mem_range(u64 *idx, int nid,
1023-
enum memblock_flags flags,
1024-
struct memblock_type *type_a,
1025-
struct memblock_type *type_b,
1026-
phys_addr_t *out_start,
1027-
phys_addr_t *out_end, int *out_nid)
1025+
void __next_mem_range(u64 *idx, int nid, enum memblock_flags flags,
1026+
struct memblock_type *type_a,
1027+
struct memblock_type *type_b, phys_addr_t *out_start,
1028+
phys_addr_t *out_end, int *out_nid)
10281029
{
10291030
int idx_a = *idx & 0xffffffff;
10301031
int idx_b = *idx >> 32;
@@ -1924,7 +1925,7 @@ void __init_memblock __memblock_dump_all(void)
19241925
memblock_dump(&memblock.memory);
19251926
memblock_dump(&memblock.reserved);
19261927
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
1927-
memblock_dump(&memblock.physmem);
1928+
memblock_dump(&physmem);
19281929
#endif
19291930
}
19301931

@@ -2064,8 +2065,8 @@ static int __init memblock_init_debugfs(void)
20642065
debugfs_create_file("reserved", 0444, root,
20652066
&memblock.reserved, &memblock_debug_fops);
20662067
#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
2067-
debugfs_create_file("physmem", 0444, root,
2068-
&memblock.physmem, &memblock_debug_fops);
2068+
debugfs_create_file("physmem", 0444, root, &physmem,
2069+
&memblock_debug_fops);
20692070
#endif
20702071

20712072
return 0;

0 commit comments

Comments
 (0)