Skip to content

Commit 8736cc2

Browse files
osalvadorvilardagatorvalds
authored andcommitted
drivers/base/memory: introduce memory_block_{online,offline}
Patch series "Allocate memmap from hotadded memory (per device)", v10. The primary goal of this patchset is to reduce memory overhead of the hot-added memory (at least for SPARSEMEM_VMEMMAP memory model). The current way we use to populate memmap (struct page array) has two main drawbacks: a) it consumes an additional memory until the hotadded memory itself is onlined and b) memmap might end up on a different numa node which is especially true for movable_node configuration. c) due to fragmentation we might end up populating memmap with base pages One way to mitigate all these issues is to simply allocate memmap array (which is the largest memory footprint of the physical memory hotplug) from the hot-added memory itself. SPARSEMEM_VMEMMAP memory model allows us to map any pfn range so the memory doesn't need to be online to be usable for the array. See patch 4 for more details. This feature is only usable when CONFIG_SPARSEMEM_VMEMMAP is set. [Overall design]: Implementation wise we reuse vmem_altmap infrastructure to override the default allocator used by vmemap_populate. memory_block structure gains a new field called nr_vmemmap_pages, which accounts for the number of vmemmap pages used by that memory_block. E.g: On x86_64, that is 512 vmemmap pages on small memory bloks and 4096 on large memory blocks (1GB) We also introduce new two functions: memory_block_{online,offline}. These functions take care of initializing/unitializing vmemmap pages prior to calling {online,offline}_pages, so the latter functions can remain totally untouched. More details can be found in the respective changelogs. This patch (of 8): This is a preparatory patch that introduces two new functions: memory_block_online() and memory_block_offline(). For now, these functions will only call online_pages() and offline_pages() respectively, but they will be later in charge of preparing the vmemmap pages, carrying out the initialization and proper accounting of such pages. Since memory_block struct contains all the information, pass this struct down the chain till the end functions. Link: https://lkml.kernel.org/r/20210421102701.25051-1-osalvador@suse.de Link: https://lkml.kernel.org/r/20210421102701.25051-2-osalvador@suse.de Signed-off-by: Oscar Salvador <osalvador@suse.de> Reviewed-by: David Hildenbrand <david@redhat.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Pavel Tatashin <pasha.tatashin@soleen.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8ca5591 commit 8736cc2

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

drivers/base/memory.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,30 +169,41 @@ int memory_notify(unsigned long val, void *v)
169169
return blocking_notifier_call_chain(&memory_chain, val, v);
170170
}
171171

172+
static int memory_block_online(struct memory_block *mem)
173+
{
174+
unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr);
175+
unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
176+
177+
return online_pages(start_pfn, nr_pages, mem->online_type, mem->nid);
178+
}
179+
180+
static int memory_block_offline(struct memory_block *mem)
181+
{
182+
unsigned long start_pfn = section_nr_to_pfn(mem->start_section_nr);
183+
unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
184+
185+
return offline_pages(start_pfn, nr_pages);
186+
}
187+
172188
/*
173189
* MEMORY_HOTPLUG depends on SPARSEMEM in mm/Kconfig, so it is
174190
* OK to have direct references to sparsemem variables in here.
175191
*/
176192
static int
177-
memory_block_action(unsigned long start_section_nr, unsigned long action,
178-
int online_type, int nid)
193+
memory_block_action(struct memory_block *mem, unsigned long action)
179194
{
180-
unsigned long start_pfn;
181-
unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block;
182195
int ret;
183196

184-
start_pfn = section_nr_to_pfn(start_section_nr);
185-
186197
switch (action) {
187198
case MEM_ONLINE:
188-
ret = online_pages(start_pfn, nr_pages, online_type, nid);
199+
ret = memory_block_online(mem);
189200
break;
190201
case MEM_OFFLINE:
191-
ret = offline_pages(start_pfn, nr_pages);
202+
ret = memory_block_offline(mem);
192203
break;
193204
default:
194205
WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
195-
"%ld\n", __func__, start_section_nr, action, action);
206+
"%ld\n", __func__, mem->start_section_nr, action, action);
196207
ret = -EINVAL;
197208
}
198209

@@ -210,9 +221,7 @@ static int memory_block_change_state(struct memory_block *mem,
210221
if (to_state == MEM_OFFLINE)
211222
mem->state = MEM_GOING_OFFLINE;
212223

213-
ret = memory_block_action(mem->start_section_nr, to_state,
214-
mem->online_type, mem->nid);
215-
224+
ret = memory_block_action(mem, to_state);
216225
mem->state = ret ? from_state_req : to_state;
217226

218227
return ret;

0 commit comments

Comments
 (0)