reserve_mem: add support for static memory
RFC PATCH v2 1/1 reserve_mem: add support for static memory
reserve_mem relies on dynamic memory allocation, this limits the usecase where memory is required to be preserved across the boots.
Eg: ramoops memory reservation on ACPI platforms
So add support to pass a pre-determined static address and reserve memory at a specified location. This enables use case like ramoops on ACPI platforms to reliably access ramoops region with previous boot logs.
Also skip the parsing of <align> when static address is passed.
Example syntax for static address
reserve_mem=4M@0x1E0000000:oops
---
v1: https://lore.kernel.org/lkml/[email protected]/
v2: Fix code logic and incorporate Randy's suggestion
--- .../admin-guide/kernel-parameters.txt | 15 ++++++ mm/memblock.c | 47 +++++++++++++------ 2 files changed, 47 insertions(+), 15 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +15 -0
@@ -6563,6 +6563,21 @@ Kernel parameters reserve_mem=12M:4096:oops ramoops.mem_name=oops + reserve_mem= [RAM] + Format: nn[KMG]:<@offset>:<label> + Reserve physical memory at predetermined location and label it with + a name that other subsystems can use to access it. This is typically + used for systems that do not wipe the RAM, and this command + line will try to reserve the same physical memory on + soft reboots. Note, it is guaranteed to be the same + location unless some other early allocation, e.g.: crashkernel=256M + (without static address) is reserved or overlaps this region. + + The format is size:offset:label for example, to request + 4 megabytes for ramoops at 0x1E0000000: + + reserve_mem=4M@0x1E0000000:oops ramoops.mem_name=oops + reservetop= [X86-32,EARLY] Format: nn[KMG] Reserves a hole at the top of the kernel virtual
mm/memblock.c +32 -15
71 lines not on this page · raw message
Signature · 1 line
2.43.0
Randy Dunlap
reviewerHi,
Quoted 11 lines · Shyam Saini
reserve_memrelies on dynamic memory allocation, this limits the usecase where memory is required to be preserved across the boots.
Eg: ramoops memory reservation on ACPI platformsSo add support to pass a pre-determined static address and reserve memory at a specified location. This enables use case like ramoops on ACPI platforms to reliably access ramoops region with previous boot logs.
Also skip the parsing of <align> when static address is passed.
Quoted 7 lines
Example syntax for static address
reserve_mem=4M@0x1E0000000:oopsSigned-off-by Shyam Saini <[email protected]>---
v1: https://lore.kernel.org/lkml/[email protected]/
v2: Fix code logic and incorporate Randy's suggestion
OK, you fixed a few typos.
There are some bigger things that you seem to have ignored.
Quoted 10 lines
--- .../admin-guide/kernel-parameters.txt | 15 ++++++ mm/memblock.c | 47 +++++++++++++------ 2 files changed, 47 insertions(+), 15 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0
Documentation/admin-guide/kernel-parameters.txt Kernel parameters · line 6566
Quoted 4 lines
Documentation/admin-guide/kernel-parameters.txt +1
-0@@ -6563,6 +6563,21 @@ Kernel parameters reserve_mem=12M:4096:oops ramoops.mem_name=oops + reserve_mem= [RAM]
[RAM] means "RAM disk support is enabled."
Is that the case here? Is "reserve_mem=" only for use in case RAM disk support is enabled?
ISTM that you need a new designator instead of RAM... or overload the use of RAM by adding more info near the top of Documentation/admin-guide/kernel-parameters.txt.
Quoted 69 lines
Documentation/admin-guide/kernel-parameters.txt +14
-0+ Format: nn[KMG]:<@offset>:<label> + Reserve physical memory at predetermined location and label it with + a name that other subsystems can use to access it. This is typically + used for systems that do not wipe the RAM, and this command + line will try to reserve the same physical memory on + soft reboots. Note, it is guaranteed to be the same + location unless some other early allocation, e.g.: crashkernel=256M + (without static address) is reserved or overlaps this region. + + The format is size:offset:label for example, to request + 4 megabytes for ramoops at 0x1E0000000: + + reserve_mem=4M@0x1E0000000:oops ramoops.mem_name=oops + reservetop= [X86-32,EARLY] Format: nn[KMG] Reserves a hole at the top of the kernel virtualmm/memblock.c +18
-9@@ -2721,6 +2721,7 @@ static int __init reserve_mem(char *p)char *name;char *oldp;int len; +bool addr_is_static = false;if (!p) goto err_param;@@ -2736,19 +2737,27 @@ static int __init reserve_mem(char *p)if (!size || p == oldp) goto err_param; -if (*p !=':' ) - goto err_param; +/* parse the static memory address */ +if (*p =='@' ) { + start =memparse (p+1 , &p); + addr_is_static = true; + } - align =memparse (p+1 , &p);if (*p !=':' ) goto err_param; -/* -* memblock_phys_alloc() doesn't like a zero size align, -* but it is OK for this command to have it. -*/ -if (align <SMP_CACHE_BYTES ) - align =SMP_CACHE_BYTES ; +if (!addr_is_static) { + align =memparse (p+1 , &p); +if (*p !=':' ) + goto err_param; + +/* +* memblock_phys_alloc() doesn't like a zero size align, +* but it is OK for this command to have it. +*/ +if (align <SMP_CACHE_BYTES ) + align =SMP_CACHE_BYTES ; + } name = p +1 ; len =strlen (name);@@ -2772,14 +2781,22 @@ static int __init reserve_mem(char *p) }
mm/memblock.c static int __init reserve_mem(char *p) · line 2782
Quoted 10 lines
mm/memblock.c +1
-6/* Pick previous allocations up from KHO if available */ -if (reserve_mem_kho_revive (name, size, align)) +if (!addr_is_static &&reserve_mem_kho_revive (name, size, align))return 1 ; -/* TODO: Allocation must be outside of scratch region */ - start =memblock_phys_alloc (size, align); -if (!start) { -pr_err ("reserve_mem: memblock allocation failed\n" ); -return -ENOMEM ;
return 1;
mm/memblock.c static int __init reserve_mem(char *p) · line 2790
Quoted 4 lines
mm/memblock.c +4
-0+if (addr_is_static) { +if (memblock_reserve (start, size)) { +pr_err ("reserve_mem: memblock reservation failed\n" ); +return -ENOMEM ;
return 1;
mm/memblock.c static int __init reserve_mem(char *p) · line 2798
Quoted 8 lines
mm/memblock.c +8
-0+ } + + }else { +/* TODO: Allocation must be outside of scratch region */ + start =memblock_phys_alloc (size, align); +if (!start) { +pr_err ("reserve_mem: memblock allocation failed\n" ); +return -ENOMEM ;
return 1;
mm/memblock.c static int __init reserve_mem(char *p) · line 2802
Quoted 4 lines
mm/memblock.c +1
-0+ } }reserved_mem_add (start, size, name);
__setup() functions return 1 for "yes, I recognized this string/option and attempted to handle it" or 0 for "This string/option is meaningless." There is no "return -Eerror".
If you need that, you could consider using early_param() [see <linux/init.h>].
Signature · 1 line
~Randy
Hi,
Quoted 17 lines · Randy Dunlap
Hi,
Quoted 14 lines · Shyam Saini
reserve_memrelies on dynamic memory allocation, this limits the usecase where memory is required to be preserved across the boots.
Eg: ramoops memory reservation on ACPI platformsSo add support to pass a pre-determined static address and reserve memory at a specified location. This enables use case like ramoops on ACPI platforms to reliably access ramoops region with previous boot logs.
Also skip the parsing of <align> when static address is passed.
Example syntax for static address
reserve_mem=4M@0x1E0000000:oops
Quoted 7 lines
Quoted 4 lines
Signed-off-by Shyam Saini <[email protected]>---
v1: https://lore.kernel.org/lkml/[email protected]/
v2: Fix code logic and incorporate Randy's suggestionOK, you fixed a few typos.
There are some bigger things that you seem to have ignored.
Thanks for calling this out. You are right that I did not address all comments in v2.
My goal for v2 was to quickly fix the core logic issue and keep discussion focused on the reserve_mem static address direction in this RFC cycle. I should have stated that clearly.
Quoted 19 lines
Quoted 10 lines
--- .../admin-guide/kernel-parameters.txt | 15 ++++++ mm/memblock.c | 47 +++++++++++++------ 2 files changed, 47 insertions(+), 15 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0Documentation/admin-guide/kernel-parameters.txt Kernel parameters · line 6566
Quoted 4 lines
Documentation/admin-guide/kernel-parameters.txt +1
-0@@ -6563,6 +6563,21 @@ Kernel parameters reserve_mem=12M:4096:oops ramoops.mem_name=oops + reserve_mem= [RAM][RAM] means "RAM disk support is enabled."
Is that the case here? Is "reserve_mem=" only for use in case RAM disk support is enabled?
Quoted 3 lines
ISTM that you need a new designator instead of RAM... or overload the use of RAM by adding more info near the top of
Documentation/admin-guide/kernel-parameters.txt.
will address them in future iterations
Quoted 104 lines
Quoted 70 lines
Documentation/admin-guide/kernel-parameters.txt +14
-0+ Format: nn[KMG]:<@offset>:<label> + Reserve physical memory at predetermined location and label it with + a name that other subsystems can use to access it. This is typically + used for systems that do not wipe the RAM, and this command + line will try to reserve the same physical memory on + soft reboots. Note, it is guaranteed to be the same + location unless some other early allocation, e.g.: crashkernel=256M + (without static address) is reserved or overlaps this region. + + The format is size:offset:label for example, to request + 4 megabytes for ramoops at 0x1E0000000: + + reserve_mem=4M@0x1E0000000:oops ramoops.mem_name=oops + reservetop= [X86-32,EARLY] Format: nn[KMG] Reserves a hole at the top of the kernel virtualmm/memblock.c +18
-9@@ -2721,6 +2721,7 @@ static int __init reserve_mem(char *p)char *name;char *oldp;int len; +bool addr_is_static = false;if (!p) goto err_param;@@ -2736,19 +2737,27 @@ static int __init reserve_mem(char *p)if (!size || p == oldp) goto err_param; -if (*p !=':' ) - goto err_param; +/* parse the static memory address */ +if (*p =='@' ) { + start =memparse (p+1 , &p); + addr_is_static = true; + } - align =memparse (p+1 , &p);if (*p !=':' ) goto err_param; -/* -* memblock_phys_alloc() doesn't like a zero size align, -* but it is OK for this command to have it. -*/ -if (align <SMP_CACHE_BYTES ) - align =SMP_CACHE_BYTES ; +if (!addr_is_static) { + align =memparse (p+1 , &p); +if (*p !=':' ) + goto err_param; + +/* +* memblock_phys_alloc() doesn't like a zero size align, +* but it is OK for this command to have it. +*/ +if (align <SMP_CACHE_BYTES ) + align =SMP_CACHE_BYTES ; + } name = p +1 ; len =strlen (name);@@ -2772,14 +2781,22 @@ static int __init reserve_mem(char *p) }mm/memblock.c static int __init reserve_mem(char *p) · line 2782
Quoted 10 lines
mm/memblock.c +1
-6/* Pick previous allocations up from KHO if available */ -if (reserve_mem_kho_revive (name, size, align)) +if (!addr_is_static &&reserve_mem_kho_revive (name, size, align))return 1 ; -/* TODO: Allocation must be outside of scratch region */ - start =memblock_phys_alloc (size, align); -if (!start) { -pr_err ("reserve_mem: memblock allocation failed\n" ); -return -ENOMEM ;return 1;mm/memblock.c static int __init reserve_mem(char *p) · line 2790
Quoted 4 lines
mm/memblock.c +4
-0+if (addr_is_static) { +if (memblock_reserve (start, size)) { +pr_err ("reserve_mem: memblock reservation failed\n" ); +return -ENOMEM ;return 1;mm/memblock.c static int __init reserve_mem(char *p) · line 2798
Quoted 8 lines
mm/memblock.c +8
-0+ } + + }else { +/* TODO: Allocation must be outside of scratch region */ + start =memblock_phys_alloc (size, align); +if (!start) { +pr_err ("reserve_mem: memblock allocation failed\n" ); +return -ENOMEM ;return 1;Quoted 3 lines
mm/memblock.c +1
-0+ } }
Quoted 9 lines
mm/memblock.c static int __init reserve_mem(char *p) · line 2802
Quoted 1 line
mm/memblock.c +0
-0reserved_mem_add (start, size, name);
__setup()functions return 1 for "yes, I recognized this string/option and attempted to handle it" or 0 for "This string/option is meaningless." There is no "return -Eerror".
If you need that, you could consider usingearly_param()[see <linux/init.h>].
same for this concern, will address them in next iteration.
Thanks,
Shyam
Mike Rapoport
maintainerQuoted 9 lines · Shyam Saini
reserve_memrelies on dynamic memory allocation, this limits the usecase where memory is required to be preserved across the boots.
Eg: ramoops memory reservation on ACPI platformsSo add support to pass a pre-determined static address and reserve memory at a specified location. This enables use case like ramoops on ACPI platforms to reliably access ramoops region with previous boot logs.
Quoted 4 lines
Also skip the parsing of <align> when static address is passed.
Example syntax for static address
reserve_mem=4M@0x1E0000000:oops
reserve_mem is best effort by design because such hacks as well as memmap= cannot guarantee this memory is actually free.
If you want to preserve ramoops reliably, use KHO with reserve_mem. The first kernel will allocate memory, this memory will be preserved by KHO and could be picked up by the second kernel.
Quoted 8 lines
Signed-off-by Shyam Saini <[email protected]>---
v1: https://lore.kernel.org/lkml/[email protected]/
v2: Fix code logic and incorporate Randy's suggestion--- .../admin-guide/kernel-parameters.txt | 15 ++++++ mm/memblock.c | 47 +++++++++++++------ 2 files changed, 47 insertions(+), 15 deletions(-)
Signature · 2 lines
Sincerely yours, Mike.
Hi Mike,
Quoted 15 lines · Mike Rapoport
Quoted 9 lines · Shyam Saini
reserve_memrelies on dynamic memory allocation, this limits the usecase where memory is required to be preserved across the boots.
Eg: ramoops memory reservation on ACPI platformsSo add support to pass a pre-determined static address and reserve memory at a specified location. This enables use case like ramoops on ACPI platforms to reliably access ramoops region with previous boot logs.
Quoted 4 lines
Also skip the parsing of <align> when static address is passed.
Example syntax for static address
reserve_mem=4M@0x1E0000000:oops
Quoted 6 lines
reserve_memis best effort by design because such hacks as well as memmap= cannot guarantee this memory is actually free.If you want to preserve ramoops reliably, use KHO with
reserve_mem. The first kernel will allocate memory, this memory will be preserved by KHO and could be picked up by the second kernel.
ok, On ARM64 DTS systems, we can reserve ramoops memory in the device tree during the warm reboot.
For an equivalent ARM64 ACPI platform, what is the recommended way to reserve and preserve that memory across the boots?
Quoted 12 lines
Quoted 8 lines
Signed-off-by Shyam Saini <[email protected]>---
v1: https://lore.kernel.org/lkml/[email protected]/
v2: Fix code logic and incorporate Randy's suggestion--- .../admin-guide/kernel-parameters.txt | 15 ++++++ mm/memblock.c | 47 +++++++++++++------ 2 files changed, 47 insertions(+), 15 deletions(-)Signature · 2 lines
Sincerely yours, Mike.
Thanks,
Shyam
Mike Rapoport
maintainerHi Shyam,
Quoted 19 lines · Shyam Saini
Quoted 18 lines · Mike Rapoport
Quoted 9 lines · Shyam Saini
reserve_memrelies on dynamic memory allocation, this limits the usecase where memory is required to be preserved across the boots.
Eg: ramoops memory reservation on ACPI platformsSo add support to pass a pre-determined static address and reserve memory at a specified location. This enables use case like ramoops on ACPI platforms to reliably access ramoops region with previous boot logs.
Quoted 4 lines
Also skip the parsing of <align> when static address is passed.
Example syntax for static address
reserve_mem=4M@0x1E0000000:oops
reserve_memis best effort by design because such hacks as well as memmap= cannot guarantee this memory is actually free.
Quoted 6 lines
Quoted 3 lines
If you want to preserve ramoops reliably, use KHO with
reserve_mem. The first kernel will allocate memory, this memory will be preserved by KHO and could be picked up by the second kernel.ok, On ARM64 DTS systems, we can reserve ramoops memory in the device tree during the warm reboot.
The cc list actually implied x86 ;-)
Added arm64 folks now.
Quoted 2 lines
For an equivalent ARM64 ACPI platform, what is the recommended way to reserve and preserve that memory across the boots?
I don't think it exists, but a command line option (be it memmap= or reserve_mem=) does not seem the right way to me.
Most of the arguments that were made against adding memmap= to arm64 [1] apply here.
If kexec is an option, KHO provides a reliable way to preserve memory across boots.
If kexec is not an option, we should look for a generic way to specify something like DT's reserved_mem for ACPI/EFI systems.
[1] https://lkml.kernel.org/lkml/[email protected]/T/
Quoted 2 lines
Thanks,
Shyam
Signature · 2 lines
Sincerely yours, Mike.
Quoted 26 lines · Mike Rapoport
Hi Shyam,
Quoted 23 lines · Shyam Saini
Quoted 21 lines · Mike Rapoport
Quoted 9 lines · Shyam Saini
reserve_memrelies on dynamic memory allocation, this limits the usecase where memory is required to be preserved across the boots.
Eg: ramoops memory reservation on ACPI platformsSo add support to pass a pre-determined static address and reserve memory at a specified location. This enables use case like ramoops on ACPI platforms to reliably access ramoops region with previous boot logs.
Quoted 4 lines
Also skip the parsing of <align> when static address is passed.
Example syntax for static address
reserve_mem=4M@0x1E0000000:oops
reserve_memis best effort by design because such hacks as well as memmap= cannot guarantee this memory is actually free.If you want to preserve ramoops reliably, use KHO with
reserve_mem. The first kernel will allocate memory, this memory will be preserved by KHO and could be picked up by the second kernel.
Quoted 5 lines
Quoted 2 lines
ok, On ARM64 DTS systems, we can reserve ramoops memory in the device tree during the warm reboot.
The cc list actually implied x86 ;-)
Added arm64 folks now.
Thanks for adding ARM folks, I had just included whatever get_maintainer script suggested, sorry.
Quoted 9 lines
Quoted 2 lines
For an equivalent ARM64 ACPI platform, what is the recommended way to reserve and preserve that memory across the boots?
I don't think it exists, but a command line option (be it memmap= or reserve_mem=) does not seem the right way to me.
Most of the arguments that were made against adding memmap= to arm64 [1] apply here.
Quoted 8 lines
If kexec is an option, KHO provides a reliable way to preserve memory across boots.
If kexec is not an option, we should look for a generic way to specify something like DT's
reserved_memfor ACPI/EFI systems.
Well, kexec is one of the option for my use case, it also requires memory reservation during warm reboot, I think memory can be reserved in the firmware but this will create a dependency on firmware for Linux reservation.
It would be great to have a in kernel memory reservation mechanism for ARM64 ACPI platforms. I believe some other use cases like PMEM reservation would also benefit from this.
Thanks,
Shyam
Hi Everyone,
Quoted 52 lines · Mike Rapoport
Quoted 26 lines
Hi Shyam,
Quoted 23 lines · Shyam Saini
Quoted 21 lines · Mike Rapoport
Quoted 9 lines · Shyam Saini
reserve_memrelies on dynamic memory allocation, this limits the usecase where memory is required to be preserved across the boots.
Eg: ramoops memory reservation on ACPI platformsSo add support to pass a pre-determined static address and reserve memory at a specified location. This enables use case like ramoops on ACPI platforms to reliably access ramoops region with previous boot logs.
Quoted 4 lines
Also skip the parsing of <align> when static address is passed.
Example syntax for static address
reserve_mem=4M@0x1E0000000:oops
reserve_memis best effort by design because such hacks as well as memmap= cannot guarantee this memory is actually free.If you want to preserve ramoops reliably, use KHO with
reserve_mem. The first kernel will allocate memory, this memory will be preserved by KHO and could be picked up by the second kernel.Quoted 5 lines
Quoted 2 lines
ok, On ARM64 DTS systems, we can reserve ramoops memory in the device tree during the warm reboot.
The cc list actually implied x86 ;-)
Added arm64 folks now.Thanks for adding ARM folks, I had just included whatever
get_maintainerscript suggested, sorry.Quoted 9 lines
Quoted 2 lines
For an equivalent ARM64 ACPI platform, what is the recommended way to reserve and preserve that memory across the boots?
I don't think it exists, but a command line option (be it memmap= or reserve_mem=) does not seem the right way to me.
Most of the arguments that were made against adding memmap= to arm64 [1] apply here.
Quoted 8 lines
If kexec is an option, KHO provides a reliable way to preserve memory across boots.
If kexec is not an option, we should look for a generic way to specify something like DT's
reserved_memfor ACPI/EFI systems.
Quoted 9 lines
Well, kexec is one of the option for my use case, it also requires memory reservation during warm reboot, I think memory can be reserved in the firmware but this will create a dependency on firmware for Linux reservation.
It would be great to have a in kernel memory reservation mechanism for ARM64 ACPI platforms. I believe some other use cases like PMEM reservation would also benefit from this.
Following up on this, As Mike pointed that reserve_mem is best effort reservation mechanism, so what is the recommended reliable Linux mechanism, if any, to reserve a predetermined memory range during early boot on ARM64/ACPI platforms for warm boot scenarios? KHO is one option, but I'm specifically looking for a solution that preserves the region across warm reboots.
Please let me know.
Thanks,
Shyam
Hi Shyam,
Adding Lorenzo, Hanjun, Sudeep.
Quoted 6 lines · Shyam Saini
Following up on this, As Mike pointed that
reserve_memis best effort reservation mechanism, so what is the recommended reliable Linux mechanism, if any, to reserve a predetermined memory range during early boot on ARM64/ACPI platforms for warm boot scenarios? KHO is one option, but I'm specifically looking for a solution that preserves the region across warm reboots.
If you need ramoops-like support, I think ACPI ERST is a better fit and we don't need any memory reservation tricks. I'll let the arm ACPI maintainers comment further.
Signature · 1 line
Catalin
Hi Catalin,
Quoted 12 lines · Catalin Marinas
Hi Shyam,
Adding Lorenzo, Hanjun, Sudeep.
Quoted 6 lines · Shyam Saini
Following up on this, As Mike pointed that
reserve_memis best effort reservation mechanism, so what is the recommended reliable Linux mechanism, if any, to reserve a predetermined memory range during early boot on ARM64/ACPI platforms for warm boot scenarios? KHO is one option, but I'm specifically looking for a solution that preserves the region across warm reboots.
Quoted 4 lines
If you need ramoops-like support, I think ACPI ERST is a better fit and we don't need any memory reservation tricks. I'll let the arm ACPI maintainers comment further.
while this patch mentions use case of ramoops, there are other uses cases that requires predetermined memory reservation at boot time, one of them is PMEM. Like Mike pointed out in this [1] thread, we don't seem to have an equivalent mechanism for reserving predetermined memory on ARM/ACPI platforms, as is available on ARM/DTS based platforms.
Thanks,
Shyam
Quoted 20 lines · Shyam Saini
Hi Catalin,
Quoted 12 lines · Catalin Marinas
Hi Shyam,
Adding Lorenzo, Hanjun, Sudeep.
Quoted 6 lines · Shyam Saini
Following up on this, As Mike pointed that
reserve_memis best effort reservation mechanism, so what is the recommended reliable Linux mechanism, if any, to reserve a predetermined memory range during early boot on ARM64/ACPI platforms for warm boot scenarios? KHO is one option, but I'm specifically looking for a solution that preserves the region across warm reboots.Quoted 4 lines
If you need ramoops-like support, I think ACPI ERST is a better fit and we don't need any memory reservation tricks. I'll let the arm ACPI maintainers comment further.
Quoted 6 lines
while this patch mentions use case of ramoops, there are other uses cases that requires predetermined memory reservation at boot time, one of them is PMEM. Like Mike pointed out in this [1] thread, we don't seem to have an equivalent mechanism for reserving predetermined memory on ARM/ACPI platforms, as is available on ARM/DTS based platforms.
Indeed, it was been discussed in several forums in the past but AFAIK there is no conclusion or a direction towards solving this yet.
Signature · 2 lines
Regards, Sudeep