* [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size
2024-10-29 20:20 [PATCH v4 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
@ 2024-10-29 20:20 ` Gregory Price
2024-10-30 10:25 ` David Hildenbrand
2024-10-31 14:31 ` Mike Rapoport
2024-10-29 20:20 ` [PATCH v4 2/3] x86: probe memory block size advisement value during mm init Gregory Price
2024-10-29 20:20 ` [PATCH v4 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
2 siblings, 2 replies; 13+ messages in thread
From: Gregory Price @ 2024-10-29 20:20 UTC (permalink / raw)
To: x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, Jonathan.Cameron, dan.j.williams, rrichter,
Terry.Bowman, dave.jiang, ira.weiny, alison.schofield, gourry,
dave.hansen, luto, peterz, tglx, mingo, bp, hpa, rafael, lenb,
david, osalvador, gregkh, akpm, rppt
Hotplug memory sources may have opinions on what the memblock size
should be - usually for alignment purposes. For example, CXL memory
extents can be 256MB with a matching alignment. If this size/alignment
is smaller than the block size, it can result in stranded capacity.
Implement memory_block_advise_max_size for use prior to allocator init,
for software to advise the system on the max block size.
Implement memory_block_probe_max_size for use by arch init code to
calculate the best block size. Use of advice is architecture defined.
The probe value can never change after first probe. Calls to advise
after probe will return -EBUSY to aid debugging.
On systems without hotplug, always return -ENODEV and 0 respectively.
Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
---
drivers/base/memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++
include/linux/memory.h | 10 +++++++++
2 files changed, 58 insertions(+)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 67858eeb92ed..099a972c52dc 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -110,6 +110,54 @@ static void memory_block_release(struct device *dev)
kfree(mem);
}
+/**
+ * memory_block_advise_max_size() - advise memory hotplug on the max suggested
+ * block size, usually for alignment.
+ * @size: suggestion for maximum block size. must be aligned on power of 2.
+ *
+ * Early boot software (pre-allocator init) may advise archs on the max block
+ * size. This value can only decrease after initialization, as the intent is
+ * to identify the largest supported alignment for all sources.
+ *
+ * Use of this value is arch-defined, as is min/max block size.
+ *
+ * Return: 0 on success
+ * -EINVAL if size is 0 or not pow2 aligned
+ * -EBUSY if value has already been probed
+ */
+static size_t memory_block_advised_sz;
+static bool memory_block_advised_size_queried;
+int memory_block_advise_max_size(size_t size)
+{
+ if (!size || !is_power_of_2(size))
+ return -EINVAL;
+
+ if (memory_block_advised_size_queried)
+ return -EBUSY;
+
+ if (memory_block_advised_sz)
+ memory_block_advised_sz = min(size, memory_block_advised_sz);
+ else
+ memory_block_advised_sz = size;
+
+ return 0;
+}
+
+/**
+ * memory_block_advised_max_size() - query advised max hotplug block size.
+ *
+ * After the first call, the value can never change. Callers looking for the
+ * actual block size should use memory_block_size_bytes. This interface is
+ * intended for use by arch-init when initializing the hotplug block size.
+ *
+ * Return: advised size in bytes, or 0 if never set.
+ */
+size_t memory_block_advised_max_size(void)
+{
+ memory_block_advised_size_queried = true;
+ return memory_block_advised_sz;
+}
+
unsigned long __weak memory_block_size_bytes(void)
{
return MIN_MEMORY_BLOCK_SIZE;
diff --git a/include/linux/memory.h b/include/linux/memory.h
index c0afee5d126e..07e20a77b717 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -149,6 +149,14 @@ static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri)
{
return 0;
}
+static inline int memory_block_advise_max_size(size_t size)
+{
+ return -ENODEV;
+}
+static inline size_t memory_block_advised_max_size(void)
+{
+ return 0;
+}
#else /* CONFIG_MEMORY_HOTPLUG */
extern int register_memory_notifier(struct notifier_block *nb);
extern void unregister_memory_notifier(struct notifier_block *nb);
@@ -181,6 +189,8 @@ int walk_dynamic_memory_groups(int nid, walk_memory_groups_func_t func,
void memory_block_add_nid(struct memory_block *mem, int nid,
enum meminit_context context);
#endif /* CONFIG_NUMA */
+int memory_block_advise_max_size(size_t size);
+size_t memory_block_advised_max_size(void);
#endif /* CONFIG_MEMORY_HOTPLUG */
/*
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size
2024-10-29 20:20 ` [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
@ 2024-10-30 10:25 ` David Hildenbrand
2024-10-30 14:59 ` Gregory Price
2024-10-31 14:31 ` Mike Rapoport
1 sibling, 1 reply; 13+ messages in thread
From: David Hildenbrand @ 2024-10-30 10:25 UTC (permalink / raw)
To: Gregory Price, x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, Jonathan.Cameron, dan.j.williams, rrichter,
Terry.Bowman, dave.jiang, ira.weiny, alison.schofield,
dave.hansen, luto, peterz, tglx, mingo, bp, hpa, rafael, lenb,
osalvador, gregkh, akpm, rppt
On 29.10.24 21:20, Gregory Price wrote:
> Hotplug memory sources may have opinions on what the memblock size
> should be - usually for alignment purposes. For example, CXL memory
> extents can be 256MB with a matching alignment. If this size/alignment
> is smaller than the block size, it can result in stranded capacity.
>
> Implement memory_block_advise_max_size for use prior to allocator init,
> for software to advise the system on the max block size.
>
> Implement memory_block_probe_max_size for use by arch init code to
> calculate the best block size. Use of advice is architecture defined.
>
> The probe value can never change after first probe. Calls to advise
> after probe will return -EBUSY to aid debugging.
>
> On systems without hotplug, always return -ENODEV and 0 respectively.
>
> Suggested-by: Ira Weiny <ira.weiny@intel.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
> drivers/base/memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++
> include/linux/memory.h | 10 +++++++++
> 2 files changed, 58 insertions(+)
>
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index 67858eeb92ed..099a972c52dc 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -110,6 +110,54 @@ static void memory_block_release(struct device *dev)
> kfree(mem);
> }
>
> +/**
> + * memory_block_advise_max_size() - advise memory hotplug on the max suggested
> + * block size, usually for alignment.
> + * @size: suggestion for maximum block size. must be aligned on power of 2.
> + *
> + * Early boot software (pre-allocator init) may advise archs on the max block
> + * size. This value can only decrease after initialization, as the intent is
> + * to identify the largest supported alignment for all sources.
> + *
> + * Use of this value is arch-defined, as is min/max block size.
> + *
> + * Return: 0 on success
> + * -EINVAL if size is 0 or not pow2 aligned
> + * -EBUSY if value has already been probed
> + */
> +static size_t memory_block_advised_sz;
Nit: if everything is called "size", call this "size" as well.
> +static bool memory_block_advised_size_queried;
> +int memory_block_advise_max_size(size_t size)
Not that memory_block_size_bytes() uses "unsigned long". I don't think
it matters here. Or could it on 32bit? (I assume that code will not
really matter on 32bit)
> +{
> + if (!size || !is_power_of_2(size))
> + return -EINVAL;
> +
> + if (memory_block_advised_size_queried)
> + return -EBUSY;
> +
> + if (memory_block_advised_sz)
> + memory_block_advised_sz = min(size, memory_block_advised_sz);
> + else
> + memory_block_advised_sz = size;
> +
> + return 0;
> +}
> +
> +/**
> + * memory_block_advised_max_size() - query advised max hotplug block size.
> + *
> + * After the first call, the value can never change. Callers looking for the
> + * actual block size should use memory_block_size_bytes. This interface is
> + * intended for use by arch-init when initializing the hotplug block size.
> + *
> + * Return: advised size in bytes, or 0 if never set.
> + */
> +size_t memory_block_advised_max_size(void)
> +{
> + memory_block_advised_size_queried = true;
> + return memory_block_advised_sz;> +}
> +
I wonder if both should.could be "__init" ? So they could only be called
from __init ... which sounds like the tight thing to do?
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size
2024-10-30 10:25 ` David Hildenbrand
@ 2024-10-30 14:59 ` Gregory Price
2024-10-30 16:35 ` David Hildenbrand
0 siblings, 1 reply; 13+ messages in thread
From: Gregory Price @ 2024-10-30 14:59 UTC (permalink / raw)
To: David Hildenbrand
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl,
Jonathan.Cameron, dan.j.williams, rrichter, Terry.Bowman,
dave.jiang, ira.weiny, alison.schofield, dave.hansen, luto,
peterz, tglx, mingo, bp, hpa, rafael, lenb, osalvador, gregkh,
akpm, rppt
On Wed, Oct 30, 2024 at 11:25:33AM +0100, David Hildenbrand wrote:
> On 29.10.24 21:20, Gregory Price wrote:
> > Hotplug memory sources may have opinions on what the memblock size
> > should be - usually for alignment purposes. For example, CXL memory
> > extents can be 256MB with a matching alignment. If this size/alignment
> > is smaller than the block size, it can result in stranded capacity.
> >
> > Implement memory_block_advise_max_size for use prior to allocator init,
> > for software to advise the system on the max block size.
> >
> > Implement memory_block_probe_max_size for use by arch init code to
> > calculate the best block size. Use of advice is architecture defined.
> >
> > The probe value can never change after first probe. Calls to advise
> > after probe will return -EBUSY to aid debugging.
> >
> > On systems without hotplug, always return -ENODEV and 0 respectively.
> >
> > Suggested-by: Ira Weiny <ira.weiny@intel.com>
> > Signed-off-by: Gregory Price <gourry@gourry.net>
> > ---
> > drivers/base/memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++
> > include/linux/memory.h | 10 +++++++++
> > 2 files changed, 58 insertions(+)
> >
> > diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> > index 67858eeb92ed..099a972c52dc 100644
> > --- a/drivers/base/memory.c
> > +++ b/drivers/base/memory.c
> > @@ -110,6 +110,54 @@ static void memory_block_release(struct device *dev)
> > kfree(mem);
> > }
> > +/**
> > + * memory_block_advise_max_size() - advise memory hotplug on the max suggested
> > + * block size, usually for alignment.
> > + * @size: suggestion for maximum block size. must be aligned on power of 2.
> > + *
> > + * Early boot software (pre-allocator init) may advise archs on the max block
> > + * size. This value can only decrease after initialization, as the intent is
> > + * to identify the largest supported alignment for all sources.
> > + *
> > + * Use of this value is arch-defined, as is min/max block size.
> > + *
> > + * Return: 0 on success
> > + * -EINVAL if size is 0 or not pow2 aligned
> > + * -EBUSY if value has already been probed
> > + */
> > +static size_t memory_block_advised_sz;
>
> Nit: if everything is called "size", call this "size" as well.
>
Mostly shortened here because
if (memory_block_advised_sz)
memory_block_advised_size = min(size, memory_block_advised_size);
is over 80 characters lol. Happy to change if you have strong feelings.
> > +static bool memory_block_advised_size_queried;
> > +int memory_block_advise_max_size(size_t size)
>
> Not that memory_block_size_bytes() uses "unsigned long". I don't think it
> matters here. Or could it on 32bit? (I assume that code will not really
> matter on 32bit)
>
ack
> > +{
> > + if (!size || !is_power_of_2(size))
> > + return -EINVAL;
> > +
> > + if (memory_block_advised_size_queried)
> > + return -EBUSY;
> > +
> > + if (memory_block_advised_sz)
> > + memory_block_advised_sz = min(size, memory_block_advised_sz);
> > + else
> > + memory_block_advised_sz = size;
> > +
> > + return 0;
> > +}
> > +
> > +/**
> > + * memory_block_advised_max_size() - query advised max hotplug block size.
> > + *
> > + * After the first call, the value can never change. Callers looking for the
> > + * actual block size should use memory_block_size_bytes. This interface is
> > + * intended for use by arch-init when initializing the hotplug block size.
> > + *
> > + * Return: advised size in bytes, or 0 if never set.
> > + */
> > +size_t memory_block_advised_max_size(void)
> > +{
> > + memory_block_advised_size_queried = true;
> > + return memory_block_advised_sz;> +}
> > +
>
> I wonder if both should.could be "__init" ? So they could only be called
> from __init ... which sounds like the tight thing to do?
>
Was thinking the same thing in another thread, will go ahead and change it.
> Acked-by: David Hildenbrand <david@redhat.com>
>
> --
> Cheers,
>
> David / dhildenb
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size
2024-10-30 14:59 ` Gregory Price
@ 2024-10-30 16:35 ` David Hildenbrand
0 siblings, 0 replies; 13+ messages in thread
From: David Hildenbrand @ 2024-10-30 16:35 UTC (permalink / raw)
To: Gregory Price
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl,
Jonathan.Cameron, dan.j.williams, rrichter, Terry.Bowman,
dave.jiang, ira.weiny, alison.schofield, dave.hansen, luto,
peterz, tglx, mingo, bp, hpa, rafael, lenb, osalvador, gregkh,
akpm, rppt
On 30.10.24 15:59, Gregory Price wrote:
> On Wed, Oct 30, 2024 at 11:25:33AM +0100, David Hildenbrand wrote:
>> On 29.10.24 21:20, Gregory Price wrote:
>>> Hotplug memory sources may have opinions on what the memblock size
>>> should be - usually for alignment purposes. For example, CXL memory
>>> extents can be 256MB with a matching alignment. If this size/alignment
>>> is smaller than the block size, it can result in stranded capacity.
>>>
>>> Implement memory_block_advise_max_size for use prior to allocator init,
>>> for software to advise the system on the max block size.
>>>
>>> Implement memory_block_probe_max_size for use by arch init code to
>>> calculate the best block size. Use of advice is architecture defined.
>>>
>>> The probe value can never change after first probe. Calls to advise
>>> after probe will return -EBUSY to aid debugging.
>>>
>>> On systems without hotplug, always return -ENODEV and 0 respectively.
>>>
>>> Suggested-by: Ira Weiny <ira.weiny@intel.com>
>>> Signed-off-by: Gregory Price <gourry@gourry.net>
>>> ---
>>> drivers/base/memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++
>>> include/linux/memory.h | 10 +++++++++
>>> 2 files changed, 58 insertions(+)
>>>
>>> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
>>> index 67858eeb92ed..099a972c52dc 100644
>>> --- a/drivers/base/memory.c
>>> +++ b/drivers/base/memory.c
>>> @@ -110,6 +110,54 @@ static void memory_block_release(struct device *dev)
>>> kfree(mem);
>>> }
>>> +/**
>>> + * memory_block_advise_max_size() - advise memory hotplug on the max suggested
>>> + * block size, usually for alignment.
>>> + * @size: suggestion for maximum block size. must be aligned on power of 2.
>>> + *
>>> + * Early boot software (pre-allocator init) may advise archs on the max block
>>> + * size. This value can only decrease after initialization, as the intent is
>>> + * to identify the largest supported alignment for all sources.
>>> + *
>>> + * Use of this value is arch-defined, as is min/max block size.
>>> + *
>>> + * Return: 0 on success
>>> + * -EINVAL if size is 0 or not pow2 aligned
>>> + * -EBUSY if value has already been probed
>>> + */
>>> +static size_t memory_block_advised_sz;
>>
>> Nit: if everything is called "size", call this "size" as well.
>>
>
> Mostly shortened here because
>
> if (memory_block_advised_sz)
> memory_block_advised_size = min(size, memory_block_advised_size);
>
> is over 80 characters lol. Happy to change if you have strong feelings.
Feel free to exceed 80 chars if there is good reason to -- like in this
case. checkpatch.pl nowadays complains if you exceed 100 chars.
No strong feelings, making it consistent in some way would be "nice" ;)
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size
2024-10-29 20:20 ` [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
2024-10-30 10:25 ` David Hildenbrand
@ 2024-10-31 14:31 ` Mike Rapoport
2024-10-31 16:23 ` Gregory Price
1 sibling, 1 reply; 13+ messages in thread
From: Mike Rapoport @ 2024-10-31 14:31 UTC (permalink / raw)
To: Gregory Price
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl,
Jonathan.Cameron, dan.j.williams, rrichter, Terry.Bowman,
dave.jiang, ira.weiny, alison.schofield, dave.hansen, luto,
peterz, tglx, mingo, bp, hpa, rafael, lenb, david, osalvador,
gregkh, akpm
On Tue, Oct 29, 2024 at 04:20:39PM -0400, Gregory Price wrote:
> Hotplug memory sources may have opinions on what the memblock size
> should be - usually for alignment purposes. For example, CXL memory
> extents can be 256MB with a matching alignment. If this size/alignment
> is smaller than the block size, it can result in stranded capacity.
>
> Implement memory_block_advise_max_size for use prior to allocator init,
> for software to advise the system on the max block size.
>
> Implement memory_block_probe_max_size for use by arch init code to
> calculate the best block size. Use of advice is architecture defined.
>
> The probe value can never change after first probe. Calls to advise
> after probe will return -EBUSY to aid debugging.
>
> On systems without hotplug, always return -ENODEV and 0 respectively.
>
> Suggested-by: Ira Weiny <ira.weiny@intel.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
> drivers/base/memory.c | 48 ++++++++++++++++++++++++++++++++++++++++++
> include/linux/memory.h | 10 +++++++++
> 2 files changed, 58 insertions(+)
>
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index 67858eeb92ed..099a972c52dc 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -110,6 +110,54 @@ static void memory_block_release(struct device *dev)
> kfree(mem);
> }
>
> +/**
> + * memory_block_advise_max_size() - advise memory hotplug on the max suggested
> + * block size, usually for alignment.
> + * @size: suggestion for maximum block size. must be aligned on power of 2.
> + *
> + * Early boot software (pre-allocator init) may advise archs on the max block
> + * size. This value can only decrease after initialization, as the intent is
> + * to identify the largest supported alignment for all sources.
> + *
> + * Use of this value is arch-defined, as is min/max block size.
> + *
> + * Return: 0 on success
> + * -EINVAL if size is 0 or not pow2 aligned
> + * -EBUSY if value has already been probed
> + */
> +static size_t memory_block_advised_sz;
> +static bool memory_block_advised_size_queried;
kernel-doc will be unhappy about variable declarations between the doc
block and the function it describes
> +int memory_block_advise_max_size(size_t size)
> +{
> + if (!size || !is_power_of_2(size))
> + return -EINVAL;
> +
> + if (memory_block_advised_size_queried)
> + return -EBUSY;
> +
> + if (memory_block_advised_sz)
> + memory_block_advised_sz = min(size, memory_block_advised_sz);
> + else
> + memory_block_advised_sz = size;
> +
> + return 0;
> +}
> +
> +/**
> + * memory_block_advised_max_size() - query advised max hotplug block size.
> + *
> + * After the first call, the value can never change. Callers looking for the
> + * actual block size should use memory_block_size_bytes. This interface is
> + * intended for use by arch-init when initializing the hotplug block size.
> + *
> + * Return: advised size in bytes, or 0 if never set.
> + */
> +size_t memory_block_advised_max_size(void)
> +{
> + memory_block_advised_size_queried = true;
> + return memory_block_advised_sz;
> +}
> +
> unsigned long __weak memory_block_size_bytes(void)
> {
> return MIN_MEMORY_BLOCK_SIZE;
> diff --git a/include/linux/memory.h b/include/linux/memory.h
> index c0afee5d126e..07e20a77b717 100644
> --- a/include/linux/memory.h
> +++ b/include/linux/memory.h
> @@ -149,6 +149,14 @@ static inline int hotplug_memory_notifier(notifier_fn_t fn, int pri)
> {
> return 0;
> }
> +static inline int memory_block_advise_max_size(size_t size)
> +{
> + return -ENODEV;
> +}
> +static inline size_t memory_block_advised_max_size(void)
> +{
> + return 0;
> +}
> #else /* CONFIG_MEMORY_HOTPLUG */
> extern int register_memory_notifier(struct notifier_block *nb);
> extern void unregister_memory_notifier(struct notifier_block *nb);
> @@ -181,6 +189,8 @@ int walk_dynamic_memory_groups(int nid, walk_memory_groups_func_t func,
> void memory_block_add_nid(struct memory_block *mem, int nid,
> enum meminit_context context);
> #endif /* CONFIG_NUMA */
> +int memory_block_advise_max_size(size_t size);
> +size_t memory_block_advised_max_size(void);
> #endif /* CONFIG_MEMORY_HOTPLUG */
>
> /*
> --
> 2.43.0
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size
2024-10-31 14:31 ` Mike Rapoport
@ 2024-10-31 16:23 ` Gregory Price
0 siblings, 0 replies; 13+ messages in thread
From: Gregory Price @ 2024-10-31 16:23 UTC (permalink / raw)
To: Mike Rapoport
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl,
Jonathan.Cameron, dan.j.williams, rrichter, Terry.Bowman,
dave.jiang, ira.weiny, alison.schofield, dave.hansen, luto,
peterz, tglx, mingo, bp, hpa, rafael, lenb, david, osalvador,
gregkh, akpm
On Thu, Oct 31, 2024 at 04:31:03PM +0200, Mike Rapoport wrote:
> On Tue, Oct 29, 2024 at 04:20:39PM -0400, Gregory Price wrote:
> > + * Return: 0 on success
> > + * -EINVAL if size is 0 or not pow2 aligned
> > + * -EBUSY if value has already been probed
> > + */
> > +static size_t memory_block_advised_sz;
> > +static bool memory_block_advised_size_queried;
>
> kernel-doc will be unhappy about variable declarations between the doc
> block and the function it describes
>
Yup, that was the warning I was waiting to clear KLP.
Learning new things n.n;; - new version shortly
~Gregory
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v4 2/3] x86: probe memory block size advisement value during mm init
2024-10-29 20:20 [PATCH v4 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
2024-10-29 20:20 ` [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
@ 2024-10-29 20:20 ` Gregory Price
2024-10-30 10:26 ` David Hildenbrand
2024-10-29 20:20 ` [PATCH v4 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
2 siblings, 1 reply; 13+ messages in thread
From: Gregory Price @ 2024-10-29 20:20 UTC (permalink / raw)
To: x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, Jonathan.Cameron, dan.j.williams, rrichter,
Terry.Bowman, dave.jiang, ira.weiny, alison.schofield, gourry,
dave.hansen, luto, peterz, tglx, mingo, bp, hpa, rafael, lenb,
david, osalvador, gregkh, akpm, rppt
Systems with hotplug may provide an advisement value on what the
memblock size should be. Probe this value when the rest of the
configuration values are considered.
The new heuristic is as follows
1) set_memory_block_size_order value if already set (cmdline param)
2) minimum block size if memory is less than large block limit
3) if no hotplug advice: Max block size if system is bare-metal,
otherwise use end of memory alignment.
4) if hotplug advice: lesser of advice and end of memory alignment.
Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
Acked-by: David Hildenbrand <david@redhat.com>
---
arch/x86/mm/init_64.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index ff253648706f..01876629f21f 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1452,16 +1452,20 @@ static unsigned long probe_memory_block_size(void)
}
/*
- * Use max block size to minimize overhead on bare metal, where
- * alignment for memory hotplug isn't a concern.
+ * When hotplug alignment is not a concern, maximize blocksize
+ * to minimize overhead. Otherwise, align to the lesser of advice
+ * alignment and end of memory alignment.
*/
- if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
+ bz = memory_block_advised_max_size();
+ if (!bz) {
bz = MAX_BLOCK_SIZE;
- goto done;
- }
+ if (!boot_cpu_has(X86_FEATURE_HYPERVISOR))
+ goto done;
+ } else
+ bz = max(min(bz, MAX_BLOCK_SIZE), MIN_MEMORY_BLOCK_SIZE);
/* Find the largest allowed block size that aligns to memory end */
- for (bz = MAX_BLOCK_SIZE; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) {
+ for (; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) {
if (IS_ALIGNED(boot_mem_end, bz))
break;
}
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 2/3] x86: probe memory block size advisement value during mm init
2024-10-29 20:20 ` [PATCH v4 2/3] x86: probe memory block size advisement value during mm init Gregory Price
@ 2024-10-30 10:26 ` David Hildenbrand
0 siblings, 0 replies; 13+ messages in thread
From: David Hildenbrand @ 2024-10-30 10:26 UTC (permalink / raw)
To: Gregory Price, x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, Jonathan.Cameron, dan.j.williams, rrichter,
Terry.Bowman, dave.jiang, ira.weiny, alison.schofield,
dave.hansen, luto, peterz, tglx, mingo, bp, hpa, rafael, lenb,
osalvador, gregkh, akpm, rppt
On 29.10.24 21:20, Gregory Price wrote:
> Systems with hotplug may provide an advisement value on what the
> memblock size should be. Probe this value when the rest of the
> configuration values are considered.
>
> The new heuristic is as follows
>
> 1) set_memory_block_size_order value if already set (cmdline param)
> 2) minimum block size if memory is less than large block limit
> 3) if no hotplug advice: Max block size if system is bare-metal,
> otherwise use end of memory alignment.
> 4) if hotplug advice: lesser of advice and end of memory alignment.
>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> Acked-by: David Hildenbrand <david@redhat.com>
> ---
> arch/x86/mm/init_64.c | 16 ++++++++++------
> 1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
> index ff253648706f..01876629f21f 100644
> --- a/arch/x86/mm/init_64.c
> +++ b/arch/x86/mm/init_64.c
> @@ -1452,16 +1452,20 @@ static unsigned long probe_memory_block_size(void)
> }
>
> /*
> - * Use max block size to minimize overhead on bare metal, where
> - * alignment for memory hotplug isn't a concern.
> + * When hotplug alignment is not a concern, maximize blocksize
> + * to minimize overhead. Otherwise, align to the lesser of advice
> + * alignment and end of memory alignment.
> */
> - if (!boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
> + bz = memory_block_advised_max_size();
> + if (!bz) {
> bz = MAX_BLOCK_SIZE;
> - goto done;
> - }
> + if (!boot_cpu_has(X86_FEATURE_HYPERVISOR))
> + goto done;
> + } else
> + bz = max(min(bz, MAX_BLOCK_SIZE), MIN_MEMORY_BLOCK_SIZE);
Nit: coding style want you to use
if () {
} else {
}
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v4 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
2024-10-29 20:20 [PATCH v4 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
2024-10-29 20:20 ` [PATCH v4 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
2024-10-29 20:20 ` [PATCH v4 2/3] x86: probe memory block size advisement value during mm init Gregory Price
@ 2024-10-29 20:20 ` Gregory Price
2024-10-30 10:40 ` David Hildenbrand
2 siblings, 1 reply; 13+ messages in thread
From: Gregory Price @ 2024-10-29 20:20 UTC (permalink / raw)
To: x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, Jonathan.Cameron, dan.j.williams, rrichter,
Terry.Bowman, dave.jiang, ira.weiny, alison.schofield, gourry,
dave.hansen, luto, peterz, tglx, mingo, bp, hpa, rafael, lenb,
david, osalvador, gregkh, akpm, rppt
Capacity is stranded when CFMWS regions are not aligned to block size.
On x86, block size increases with capacity (2G blocks @ 64G capacity).
Use CFMWS base/size to report memory block size alignment advice.
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
---
drivers/acpi/numa/srat.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
index 44f91f2c6c5d..a24aff38c465 100644
--- a/drivers/acpi/numa/srat.c
+++ b/drivers/acpi/numa/srat.c
@@ -14,6 +14,7 @@
#include <linux/errno.h>
#include <linux/acpi.h>
#include <linux/memblock.h>
+#include <linux/memory.h>
#include <linux/numa.h>
#include <linux/nodemask.h>
#include <linux/topology.h>
@@ -338,12 +339,26 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header,
{
struct acpi_cedt_cfmws *cfmws;
int *fake_pxm = arg;
- u64 start, end;
+ u64 start, end, align, size;
int node;
cfmws = (struct acpi_cedt_cfmws *)header;
start = cfmws->base_hpa;
- end = cfmws->base_hpa + cfmws->window_size;
+ size = cfmws->window_size;
+ end = cfmws->base_hpa + size;
+
+ /* Align memblock size to CFMW regions if possible */
+ for (align = SZ_64T; align >= SZ_256M; align >>= 1) {
+ if (IS_ALIGNED(start, align) && IS_ALIGNED(size, align))
+ break;
+ }
+
+ if (align >= SZ_256M) {
+ if (memory_block_advise_max_size(align) < 0)
+ pr_warn("CFMWS: memblock size advise failed\n");
+ } else {
+ pr_err("CFMWS: [BIOS BUG] base/size alignment violates spec\n");
+ }
/*
* The SRAT may have already described NUMA details for all,
--
2.43.0
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
2024-10-29 20:20 ` [PATCH v4 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
@ 2024-10-30 10:40 ` David Hildenbrand
2024-10-30 15:01 ` Gregory Price
2024-10-30 15:25 ` Gregory Price
0 siblings, 2 replies; 13+ messages in thread
From: David Hildenbrand @ 2024-10-30 10:40 UTC (permalink / raw)
To: Gregory Price, x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, Jonathan.Cameron, dan.j.williams, rrichter,
Terry.Bowman, dave.jiang, ira.weiny, alison.schofield,
dave.hansen, luto, peterz, tglx, mingo, bp, hpa, rafael, lenb,
osalvador, gregkh, akpm, rppt
On 29.10.24 21:20, Gregory Price wrote:
> Capacity is stranded when CFMWS regions are not aligned to block size.
> On x86, block size increases with capacity (2G blocks @ 64G capacity).
>
> Use CFMWS base/size to report memory block size alignment advice.
>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
> drivers/acpi/numa/srat.c | 19 +++++++++++++++++--
> 1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> index 44f91f2c6c5d..a24aff38c465 100644
> --- a/drivers/acpi/numa/srat.c
> +++ b/drivers/acpi/numa/srat.c
> @@ -14,6 +14,7 @@
> #include <linux/errno.h>
> #include <linux/acpi.h>
> #include <linux/memblock.h>
> +#include <linux/memory.h>
> #include <linux/numa.h>
> #include <linux/nodemask.h>
> #include <linux/topology.h>
> @@ -338,12 +339,26 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header,
> {
> struct acpi_cedt_cfmws *cfmws;
> int *fake_pxm = arg;
> - u64 start, end;
> + u64 start, end, align, size;
> int node;
>
> cfmws = (struct acpi_cedt_cfmws *)header;
> start = cfmws->base_hpa;
> - end = cfmws->base_hpa + cfmws->window_size;
> + size = cfmws->window_size;
> + end = cfmws->base_hpa + size;
> +
> + /* Align memblock size to CFMW regions if possible */
> + for (align = SZ_64T; align >= SZ_256M; align >>= 1) {
> + if (IS_ALIGNED(start, align) && IS_ALIGNED(size, align))
> + break;
> + }
Are there maybe some nice tricks bi-tricks to avoid the loop and these
hardcoded limits? :)
align = 1UL << __ffs(start | end));
Assuming "unsigned long" is sufficient in this code (64bit) and "start |
end" will never be 0.
--
Cheers,
David / dhildenb
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
2024-10-30 10:40 ` David Hildenbrand
@ 2024-10-30 15:01 ` Gregory Price
2024-10-30 15:25 ` Gregory Price
1 sibling, 0 replies; 13+ messages in thread
From: Gregory Price @ 2024-10-30 15:01 UTC (permalink / raw)
To: David Hildenbrand
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl,
Jonathan.Cameron, dan.j.williams, rrichter, Terry.Bowman,
dave.jiang, ira.weiny, alison.schofield, dave.hansen, luto,
peterz, tglx, mingo, bp, hpa, rafael, lenb, osalvador, gregkh,
akpm, rppt
On Wed, Oct 30, 2024 at 11:40:08AM +0100, David Hildenbrand wrote:
> On 29.10.24 21:20, Gregory Price wrote:
> > Capacity is stranded when CFMWS regions are not aligned to block size.
> > On x86, block size increases with capacity (2G blocks @ 64G capacity).
> >
> > Use CFMWS base/size to report memory block size alignment advice.
> >
> > Suggested-by: Dan Williams <dan.j.williams@intel.com>
> > Signed-off-by: Gregory Price <gourry@gourry.net>
> > ---
> > drivers/acpi/numa/srat.c | 19 +++++++++++++++++--
> > 1 file changed, 17 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> > index 44f91f2c6c5d..a24aff38c465 100644
> > --- a/drivers/acpi/numa/srat.c
> > +++ b/drivers/acpi/numa/srat.c
> > @@ -14,6 +14,7 @@
> > #include <linux/errno.h>
> > #include <linux/acpi.h>
> > #include <linux/memblock.h>
> > +#include <linux/memory.h>
> > #include <linux/numa.h>
> > #include <linux/nodemask.h>
> > #include <linux/topology.h>
> > @@ -338,12 +339,26 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header,
> > {
> > struct acpi_cedt_cfmws *cfmws;
> > int *fake_pxm = arg;
> > - u64 start, end;
> > + u64 start, end, align, size;
> > int node;
> > cfmws = (struct acpi_cedt_cfmws *)header;
> > start = cfmws->base_hpa;
> > - end = cfmws->base_hpa + cfmws->window_size;
> > + size = cfmws->window_size;
> > + end = cfmws->base_hpa + size;
> > +
> > + /* Align memblock size to CFMW regions if possible */
> > + for (align = SZ_64T; align >= SZ_256M; align >>= 1) {
> > + if (IS_ALIGNED(start, align) && IS_ALIGNED(size, align))
> > + break;
> > + }
>
> Are there maybe some nice tricks bi-tricks to avoid the loop and these
> hardcoded limits? :)
>
> align = 1UL << __ffs(start | end));
>
> Assuming "unsigned long" is sufficient in this code (64bit) and "start |
> end" will never be 0.
>
I don't think 0 itself is necessarily invalid, but it would be strange.
I can look a bit.
> --
> Cheers,
>
> David / dhildenb
>
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v4 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
2024-10-30 10:40 ` David Hildenbrand
2024-10-30 15:01 ` Gregory Price
@ 2024-10-30 15:25 ` Gregory Price
1 sibling, 0 replies; 13+ messages in thread
From: Gregory Price @ 2024-10-30 15:25 UTC (permalink / raw)
To: David Hildenbrand
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl,
Jonathan.Cameron, dan.j.williams, rrichter, Terry.Bowman,
dave.jiang, ira.weiny, alison.schofield, dave.hansen, luto,
peterz, tglx, mingo, bp, hpa, rafael, lenb, osalvador, gregkh,
akpm, rppt
On Wed, Oct 30, 2024 at 11:40:08AM +0100, David Hildenbrand wrote:
> On 29.10.24 21:20, Gregory Price wrote:
> > Capacity is stranded when CFMWS regions are not aligned to block size.
> > On x86, block size increases with capacity (2G blocks @ 64G capacity).
> >
> > Use CFMWS base/size to report memory block size alignment advice.
> >
> > Suggested-by: Dan Williams <dan.j.williams@intel.com>
> > Signed-off-by: Gregory Price <gourry@gourry.net>
> > ---
> > drivers/acpi/numa/srat.c | 19 +++++++++++++++++--
> > 1 file changed, 17 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> > index 44f91f2c6c5d..a24aff38c465 100644
> > --- a/drivers/acpi/numa/srat.c
> > +++ b/drivers/acpi/numa/srat.c
> > @@ -14,6 +14,7 @@
> > #include <linux/errno.h>
> > #include <linux/acpi.h>
> > #include <linux/memblock.h>
> > +#include <linux/memory.h>
> > #include <linux/numa.h>
> > #include <linux/nodemask.h>
> > #include <linux/topology.h>
> > @@ -338,12 +339,26 @@ static int __init acpi_parse_cfmws(union acpi_subtable_headers *header,
> > {
> > struct acpi_cedt_cfmws *cfmws;
> > int *fake_pxm = arg;
> > - u64 start, end;
> > + u64 start, end, align, size;
> > int node;
> > cfmws = (struct acpi_cedt_cfmws *)header;
> > start = cfmws->base_hpa;
> > - end = cfmws->base_hpa + cfmws->window_size;
> > + size = cfmws->window_size;
> > + end = cfmws->base_hpa + size;
> > +
> > + /* Align memblock size to CFMW regions if possible */
> > + for (align = SZ_64T; align >= SZ_256M; align >>= 1) {
> > + if (IS_ALIGNED(start, align) && IS_ALIGNED(size, align))
> > + break;
> > + }
>
> Are there maybe some nice tricks bi-tricks to avoid the loop and these
> hardcoded limits? :)
>
> align = 1UL << __ffs(start | end));
>
> Assuming "unsigned long" is sufficient in this code (64bit) and "start |
> end" will never be 0.
>
This will work, if start | end is < 256MB, the ACPI table is invalid by
definition since either the block itself is <256MB or the size is 0 (which
is nonsense). So yeah i can simplify here.
Ack. will push v5 once i get KLP to clear another warning.
> --
> Cheers,
>
> David / dhildenb
>
^ permalink raw reply [flat|nested] 13+ messages in thread