mm/memblock: Excluded memory, free_all_bootmem
v3 cover mm/memblock: Excluded memory, free_all_bootmem
These two patches fit (only) on top of linux-next!
The first patch changes back the behavior of free_all_bootmem() to a more generic way: With CONFIG_DISCARD_MEMBLOCK memblock.memory and memblock.reserved will be freed (if allocated, of course). Removed the debugfs dependency. Think this is cleaner.
While further working on the s390 migration to memblock it is desirable to have memblock support unmapped (i.e. completely forgotten and unused) memory areas. The usual way of just forgetting about them by means of truncating the memblocks does not work for us because we still need the information about the real full memory structure at a later time.
(sorry for the two too bad versions before)
Philipp Hachtmann (2):
mm/nobootmem: free_all_bootmem again mm/memblock: Add support for excluded memory areas
arch/s390/Kconfig | 1 + include/linux/memblock.h | 50 +++++++-- mm/Kconfig | 3 + mm/memblock.c | 278 ++++++++++++++++++++++++++++++++++------------- mm/nobootmem.c | 13 ++- 5 files changed, 258 insertions(+), 87 deletions(-)
Signature · 7 lines
1.8.4.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 1/2 mm/nobootmem: free_all_bootmem again
get_allocated_memblock_reserved_regions_info() should work if it is compiled in. Extended the ifdef around get_allocated_memblock_memory_regions_info() to include get_allocated_memblock_reserved_regions_info() as well. Similar changes in nobootmem.c/free_low_memory_core_early() where the two functions are called.
--- mm/memblock.c | 17 ++--------------- mm/nobootmem.c | 4 ++-- 2 files changed, 4 insertions(+), 17 deletions(-)
mm/memblock.c +2 -15
@@ -266,33 +266,20 @@ static void __init_memblock memblock_remove_region(struct memblock_type *type, u } } +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK + phys_addr_t __init_memblock get_allocated_memblock_reserved_regions_info(phys_addr_t *addr) {if (memblock.reserved.regions == memblock_reserved_init_regions)return 0 ; -/* -* Don't allow nobootmem allocator to free reserved memory regions -* array if -* - CONFIG_DEBUG_FS is enabled; -* - CONFIG_ARCH_DISCARD_MEMBLOCK is not enabled; -* - reserved memory regions array have been resized during boot. -* Otherwise debug_fs entry "sys/kernel/debug/memblock/reserved" -* will show garbage instead of state of memory reservations. -*/ -if (IS_ENABLED (CONFIG_DEBUG_FS ) && - !IS_ENABLED (CONFIG_ARCH_DISCARD_MEMBLOCK )) -return 0 ; - *addr =__pa (memblock.reserved.regions);return PAGE_ALIGN (sizeof (struct memblock_region ) * memblock.reserved.max); } -#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK - phys_addr_t __init_memblock get_allocated_memblock_memory_regions_info(phys_addr_t *addr) {
mm/nobootmem.c +2 -2
@@ -122,13 +122,13 @@ static unsigned long __init free_low_memory_core_early(void)for_each_free_mem_range (i,NUMA_NO_NODE , &start, &end,NULL ) count +=__free_memory_core (start, end); +#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK +/* Free memblock.reserved array if it was allocated */ size =get_allocated_memblock_reserved_regions_info (&start);if (size) count +=__free_memory_core (start, start + size); -#ifdef CONFIG_ARCH_DISCARD_MEMBLOCK -/* Free memblock.memory array if it was allocated */ size =get_allocated_memblock_memory_regions_info (&start);if (size)
Signature · 7 lines
1.8.4.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v3 2/2 mm/memblock: Add support for excluded memory areas
In reply to Philipp HachtmannAdd a new memory state "nomap" to memblock. This can be used to truncate the usable memory in the system without forgetting about what is really installed.
--- arch/s390/Kconfig | 1 + include/linux/memblock.h | 50 +++++++-- mm/Kconfig | 3 + mm/memblock.c | 261 ++++++++++++++++++++++++++++++++++++----------- mm/nobootmem.c | 9 ++ 5 files changed, 254 insertions(+), 70 deletions(-)
arch/s390/Kconfig +1 -0
@@ -61,6 +61,7 @@ config PCI_QUIRKS config S390 def_bool y select ARCH_DISCARD_MEMBLOCK + select ARCH_MEMBLOCK_NOMAP select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select ARCH_HAVE_NMI_SAFE_CMPXCHG
include/linux/memblock.h +42 -8
89 lines not on this page · raw message
mm/Kconfig +3 -0
@@ -137,6 +137,9 @@ config HAVE_MEMBLOCK_NODE_MAP config ARCH_DISCARD_MEMBLOCK boolean +config ARCH_MEMBLOCK_NOMAP + boolean + config NO_BOOTMEM boolean
mm/memblock.c +199 -62
385 lines not on this page · raw message
mm/nobootmem.c +9 -0
@@ -133,6 +133,15 @@ static unsigned long __init free_low_memory_core_early(void) size =get_allocated_memblock_memory_regions_info (&start);if (size) count +=__free_memory_core (start, start + size); + +#ifdef CONFIG_ARCH_MEMBLOCK_NOMAP + +/* Free memblock.nomap array if it was allocated */ + size =get_allocated_memblock_memory_regions_info (&start); +if (size) + count +=__free_memory_core (start, start + size); + +#endif #endif return count;
Signature · 7 lines
1.8.4.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH V3 2/2] mm/memblock: Add support for excluded memory areas
Quoted 7 lines · On Mon, 13 Jan 2014 14:03:37 +0100 Philipp Hachtmann…
Add a new memory state "nomap" to memblock. This can be used to truncate the usable memory in the system without forgetting about what is really installed.
...
5 files changed, 254 insertions(+), 70 deletions(-)
Patch is big. I'll toss this in for some testing but it does look too large and late for 3.14. How will this affect your s390 development?
Hopefully some people who are familiar with memblock will have time to review this carefully, please.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH V3 2/2] mm/memblock: Add support for excluded memory areas
Am Mon, 13 Jan 2014 16:36:20 -0800
schrieb Andrew Morton <[email protected]>:
Quoted 2 lines
Patch is big. I'll toss this in for some testing but it does look too large and late for 3.14. How will this affect your s390 development?
It is needed for s390 bootmem -> memblock transition. The s390 dump mechanisms cannot be switched to memblock (from using something s390 specific called memory_chunk) without the nomap list.
I'm also working on another enhancement on s390 that will rely on a clean transition to memblock.
I have written and tested the stuff on top of our local development tree. And then realised that it does not fit the linux-next tree. So I converted it to fit linux-next and posted it. Have to maintain two versions now.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH V3 2/2] mm/memblock: Add support for excluded memory areas
Quoted 12 lines · On Tue, 14 Jan 2014 10:42:53 +0100 Philipp Hachtmann…
Am Mon, 13 Jan 2014 16:36:20 -0800
schrieb Andrew Morton <[email protected]>:Quoted 2 lines
Patch is big. I'll toss this in for some testing but it does look too large and late for 3.14. How will this affect your s390 development?
It is needed for s390 bootmem -> memblock transition. The s390 dump mechanisms cannot be switched to memblock (from using something s390 specific called
memory_chunk) without the nomap list.
I'm also working on another enhancement on s390 that will rely on a clean transition to memblock.
Quoted 4 lines
I have written and tested the stuff on top of our local development tree. And then realised that it does not fit the linux-next tree. So I converted it to fit linux-next and posted it. Have to maintain two versions now.
So at 3.14-rc1 everything will come good - get the review issues sorted out, add the patch to your tree (and hence linux-next).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH V3 2/2] mm/memblock: Add support for excluded memory areas
In reply to Philipp HachtmannHi Philipp,
Quoted 3 lines · Philipp Hachtmann
Add a new memory state "nomap" to memblock. This can be used to truncate the usable memory in the system without forgetting about what is really installed.
Sorry, but this solution looks a bit complex (and probably wrong - from design point of view)) if you need just to fix memblock_start_of_DRAM()/memblock_end_of_DRAM() APIs.
More over, other arches use at least below APIs:
- memblock_is_region_memory() !!!
- for_each_memblock(memory, reg) !!!
- __next_mem_pfn_range() !!!
- memblock_phys_mem_size()
- memblock_mem_size()
- memblock_start_of_DRAM()
- memblock_end_of_DRAM()
with assumption that "memory" regions array have been updated when mem block is stolen (no-mapped), as result this change may have unpredictable side effects :( if these new APIs will be re-used (for ARM arch, as example).
You can take a look on how ARM is using arm_memblock_steal() - the stolen memory is not accounted any more.
Seems, it would be safer to track separately memory, available for Linux ("memory" regions), and real phys memory. For example:
- add memblock type "phys_memory" and update it each time memblock_add()/memblock_remove() are called,
but don't update, if memblock_nomap()/memblock_remap() are called?
Another question is - Should the real phys memory configuration data be a part of memblock or not?
Also, I like more memblock_steal()/memblock_reclaim() names for new APIs )
regards,
-grygorii
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH V3 2/2] mm/memblock: Add support for excluded memory areas
Quoted 24 lines · Grygorii Strashko
Hi Philipp,
Quoted 3 lines · Philipp Hachtmann
Add a new memory state "nomap" to memblock. This can be used to truncate the usable memory in the system without forgetting about what is really installed.
Sorry, but this solution looks a bit complex (and probably wrong - from design point of view)) if you need just to fix memblock_start_of_DRAM()/memblock_end_of_DRAM() APIs.
More over, other arches use at least below APIs:
-memblock_is_region_memory()!!!
-for_each_memblock(memory, reg)!!!
-__next_mem_pfn_range()!!!
-memblock_phys_mem_size()
-memblock_mem_size()
-memblock_start_of_DRAM()
-memblock_end_of_DRAM()
with assumption that "memory" regions array have been updated when mem block is stolen (no-mapped), as result this change may have unpredictable side effects :( if these new APIs will be re-used (for ARM arch, as example).
Quoted 3 lines
You can take a look on how ARM is using
arm_memblock_steal()- the stolen memory is not accounted any more.
I was also wondering instead of nomap state, the memblock_add/remove() will do the same trick. arm_memblock_steal() wrapper does achieve similar functionality of reserving the DRAM without mapping it into the Linux. Why not just use the same idea ?
Regards,
Santosh
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH V3 2/2] mm/memblock: Add support for excluded memory areas
In reply to Grygorii StrashkoHello Grygorii,
thank you for your comments.
To clarify we have the following requirements for memblock:
(1) Reserved areas can be declared before memory is added.
(2) The physical memory is detected once only.
(3) The free memory (i.e. not reserved) memory can be iterated to add it to the buddy allocator.
(4) Memory designated to be mapped into the kernel address space can be iterated.
(5) Kdump on s390 requires knowledge about the full system memory layout.
The s390 kdump implementation works a bit different from the implementation on other architectures: The layout is not taken from the production system and saved for the kdump kernel. Instead the kdump kernel needs to gather information about the whole memory without respect to locked out areas (like mem= and OLDMEM etc.).
Without kdump's requirement it would of course be suitable and easy just to remove memory from memblock.memory. But then this information is lost for later use by kdump.
The patch does not change any behaviour of the current API - whether it is enabled or not.
The current patch seems to be overly complicated.
The following patch contains only the nomap functionality without any cleanup and refactoring. I will post a V4 patch set which will contain this patch.
Kind regards
Philipp
From eb1ad42c19c6f7bfdf3258a83dc54461c5f02d55 Mon Sep 17 00:00:00 2001
From: Philipp Hachtmann <[email protected]>
Date: Tue, 14 Jan 2014 19:49:39 +0100
Subject: [PATCH] mm/memblock: Add support for excluded memory areas
Add a new memory state "nomap" to memblock. This can be used to truncate the usable memory in the system without forgetting about what is really installed.
--- include/linux/memblock.h | 25 +++++++ mm/Kconfig | 3 + mm/memblock.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++- mm/nobootmem.c | 9 +++ 4 files changed, 211 insertions(+), 1 deletion(-)
include/linux/memblock.h +25 -0
@@ -18,6 +18,7 @@#include <linux/mm.h> #define INIT_MEMBLOCK_REGIONS 128 +#define INIT_MEMBLOCK_NOMAP_REGIONS 4/* Definition of memblock flags. */ #define MEMBLOCK_HOTPLUG 0x1/* hotpluggable region */
@@ -43,6 +44,9 @@ struct memblock {phys_addr_t current_limit;struct memblock_type memory;struct memblock_type reserved; +#ifdef CONFIG_ARCH_MEMBLOCK_NOMAP +struct memblock_type nomap; +#endif };extern struct memblock memblock;
@@ -68,6 +72,10 @@ int memblock_add(phys_addr_t base, phys_addr_t size);int memblock_remove (phys_addr_t base,phys_addr_t size);int memblock_free (phys_addr_t base,phys_addr_t size);int memblock_reserve (phys_addr_t base,phys_addr_t size); +#ifdef CONFIG_ARCH_MEMBLOCK_NOMAP +int memblock_nomap (phys_addr_t base,phys_addr_t size); +int memblock_remap (phys_addr_t base,phys_addr_t size); +#endif void memblock_trim_memory (phys_addr_t align);int memblock_mark_hotplug (phys_addr_t base,phys_addr_t size);int memblock_clear_hotplug (phys_addr_t base,phys_addr_t size);
@@ -133,6 +141,23 @@ void __next_free_mem_range(u64 *idx, int nid, phys_addr_t *out_start, i != (u64 )ULLONG_MAX ; \ __next_free_mem_range(&i, nid, p_start, p_end, p_nid)) + +#ifdef CONFIG_ARCH_MEMBLOCK_NOMAP +#define for_each_mapped_mem_range (i, nid, p_start, p_end, p_nid) \ + for (i = 0, \ + __next_mapped_mem_range(&i, nid, &memblock.memory, \ + &memblock.nomap, p_start, \ + p_end, p_nid); \ + i != (u64)ULLONG_MAX; \ + __next_mapped_mem_range(&i, nid, &memblock.memory, \ + &memblock.nomap, \ + p_start, p_end, p_nid)) + +void __next_mapped_mem_range (u64 *idx,int nid,phys_addr_t *out_start, +phys_addr_t *out_end,int *out_nid); + +#endif +void __next_free_mem_range_rev (u64 *idx,int nid,phys_addr_t *out_start,phys_addr_t *out_end,int *out_nid);
mm/Kconfig +3 -0
@@ -137,6 +137,9 @@ config HAVE_MEMBLOCK_NODE_MAP config ARCH_DISCARD_MEMBLOCK boolean +config ARCH_MEMBLOCK_NOMAP + boolean + config NO_BOOTMEM boolean
mm/memblock.c +174 -1
222 lines not on this page · raw message
mm/nobootmem.c +9 -0
@@ -133,6 +133,15 @@ static unsigned long __init free_low_memory_core_early(void) size =get_allocated_memblock_memory_regions_info (&start);if (size) count +=__free_memory_core (start, start + size); + +#ifdef CONFIG_ARCH_MEMBLOCK_NOMAP + +/* Free memblock.nomap array if it was allocated */ + size =get_allocated_memblock_memory_regions_info (&start); +if (size) + count +=__free_memory_core (start, start + size); + +#endif #endif return count;
Signature · 7 lines
1.8.4.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
RE: [PATCH V3 2/2] mm/memblock: Add support for excluded memory areas
Hi Philipp,
Quoted 21 lines · Philipp Hachtmann
Hello Grygorii,
thank you for your comments.
To clarify we have the following requirements for memblock:
(1) Reserved areas can be declared before memory is added.
(2) The physical memory is detected once only.
(3) The free memory (i.e. not reserved) memory can be iterated to add it to the buddy allocator.
(4) Memory designated to be mapped into the kernel address space can be iterated.
(5) Kdump on s390 requires knowledge about the full system memory layout.The s390 kdump implementation works a bit different from the implementation on other architectures: The layout is not taken from the production system and saved for the kdump kernel. Instead the kdump kernel needs to gather information about the whole memory without respect to locked out areas (like mem= and OLDMEM etc.).
Quoted 6 lines
Without kdump's requirement it would of course be suitable and easy just to remove memory from memblock.memory. But then this information is lost for later use by kdump.
The patch does not change any behaviour of the current API - whether it is enabled or not.
Sorry, for the delayed reply.
My main concern here was that you are introducing new *generic* API, but in fact it is not generic, because it can't be re-used without huge rework of existing code.
(at least as of wide usage of for_each_memblock(memory,...), because (if ARCH_MEMBLOCK_NOMAP=y) the meaning of "memory"
ranges will be changed form "mapped memory" to "real phys memory").
And therefore, I've proposed to keep things as is and introduce phys_memory ranges instead, to store real phys memory configuration.
Quoted 5 lines
The current patch seems to be overly complicated.
The following patch contains only the nomap functionality without any cleanup and refactoring. I will post a V4 patch set which will contain this patch.
Regards,
-grygorii
Re: [PATCH V3 2/2] mm/memblock: Add support for excluded memory areas
Am Fri, 17 Jan 2014 18:08:13 +0000
schrieb "Strashko, Grygorii" <[email protected]>:
Hello Grygorii,
Quoted 4 lines
Quoted 4 lines
The current patch seems to be overly complicated.
The following patch contains only the nomap functionality without any cleanup and refactoring. I will post a V4 patch set which will contain this patch.
please see the V4 patch set I've sent to the list. There you will clearly see that nothing is changed. No API is broken by the patch. The patch only adds functionality.
Everything that worked before keeps working as before without any changes needed in any arch's code.
Kind regards
Philipp