* [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement
@ 2024-11-06 15:58 Gregory Price
2024-11-06 15:58 ` [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Gregory Price @ 2024-11-06 15:58 UTC (permalink / raw)
To: x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, kernel-team, 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
When physical address regions are not aligned to memory block size,
the misaligned portion is lost (stranded capacity).
Block size (min/max/selected) is architecture defined. Most architectures
tend to use the minimum block size or some simplistic heurist. On x86,
memory block size increases up to 2GB, and is otherwise fitted to the
alignment of non-hotplug (i.e. not special purpose memory).
CXL exposes its memory for management through the ACPI CEDT (CXL Early
Detection Table) in a field called the CXL Fixed Memory Window. Per
the CXL specification, this memory must be aligned to at least 256MB.
When a CFMW aligns on a size less than the block size, this causes a
loss of up to 2GB per CFMW on x86. It is not uncommon for CFMW to be
allocated per-device - though this behavior is BIOS defined.
This patch set provides 3 things:
1) implement advise/query functions in driverse/base/memory.c to
report/query architecture agnostic hotplug block alignment advice.
2) update x86 memblock size logic to consider the hotplug advice
3) add code in acpi/numa/srat.c to report CFMW alignment advice
The advisement interfaces are design to be called during arch_init
code prior to allocator and smp_init. start_kernel will call these
through setup_arch() (via acpi and mm/init_64.c on x86), which occurs
prior to mm_core_init and smp_init - so no need for atomics.
There's an attempt to signal callers to advise() that query has already
occurred, but this is predicated on the notion that query actually
occurs (which presently only happens on the x86 arch). This is to
assist debugging future users. Otherwise, the advise() call has
been marked __init to help static discovery of bad call times.
Once query is called the first time, it will always return the same value.
Interfaces return -EBUSY and 0 respectively on systems without hotplug.
v6:
- boot_cpu_has -> cpu_feature_enabled() in x86 code
- ack tags
Suggested-by: Ira Weiny <ira.weiny@intel.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
Gregory Price (3):
memory: implement memory_block_advise/probe_max_size
x86: probe memory block size advisement value during mm init
acpi,srat: give memory block size advice based on CFMWS alignment
arch/x86/mm/init_64.c | 15 ++++++++----
drivers/acpi/numa/srat.c | 12 ++++++++-
drivers/base/memory.c | 53 ++++++++++++++++++++++++++++++++++++++++
include/linux/memory.h | 10 ++++++++
4 files changed, 84 insertions(+), 6 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size
2024-11-06 15:58 [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
@ 2024-11-06 15:58 ` Gregory Price
2024-11-12 21:28 ` Dan Williams
2024-11-06 15:58 ` [PATCH v6 2/3] x86: probe memory block size advisement value during mm init Gregory Price
` (2 subsequent siblings)
3 siblings, 1 reply; 12+ messages in thread
From: Gregory Price @ 2024-11-06 15:58 UTC (permalink / raw)
To: x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, kernel-team, 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>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
drivers/base/memory.c | 53 ++++++++++++++++++++++++++++++++++++++++++
include/linux/memory.h | 10 ++++++++
2 files changed, 63 insertions(+)
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 67858eeb92ed..835793150b41 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -110,6 +110,59 @@ static void memory_block_release(struct device *dev)
kfree(mem);
}
+
+/* Max block size to be set by memory_block_advise_max_size */
+static unsigned long memory_block_advised_size;
+static bool memory_block_advised_size_queried;
+
+/**
+ * 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
+ */
+int __init memory_block_advise_max_size(unsigned long size)
+{
+ if (!size || !is_power_of_2(size))
+ return -EINVAL;
+
+ if (memory_block_advised_size_queried)
+ return -EBUSY;
+
+ if (memory_block_advised_size) {
+ memory_block_advised_size = min(memory_block_advised_size,
+ size);
+ } else {
+ memory_block_advised_size = 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.
+ */
+unsigned long memory_block_advised_max_size(void)
+{
+ memory_block_advised_size_queried = true;
+ return memory_block_advised_size;
+}
+
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..8202d0efbf46 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(unsigned long size)
+{
+ return -ENODEV;
+}
+static inline unsigned long 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(unsigned long size);
+unsigned long memory_block_advised_max_size(void);
#endif /* CONFIG_MEMORY_HOTPLUG */
/*
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v6 2/3] x86: probe memory block size advisement value during mm init
2024-11-06 15:58 [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
2024-11-06 15:58 ` [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
@ 2024-11-06 15:58 ` Gregory Price
2024-11-12 21:34 ` Dan Williams
2024-11-06 15:58 ` [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
2024-11-20 19:20 ` [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement Fan Ni
3 siblings, 1 reply; 12+ messages in thread
From: Gregory Price @ 2024-11-06 15:58 UTC (permalink / raw)
To: x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, kernel-team, 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.
Convert to cpu_feature_enabled() while at it.[1]
[1] https://lore.kernel.org/all/20241031103401.GBZyNdGQ-ZyXKyzC_z@fat_crate.local/
Suggested-by: Borislav Petkov <bp@alien8.de>
Suggested-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Gregory Price <gourry@gourry.net>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
arch/x86/mm/init_64.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index ff253648706f..2622dc7c78ba 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1452,16 +1452,21 @@ 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 (!cpu_feature_enabled(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] 12+ messages in thread
* [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
2024-11-06 15:58 [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
2024-11-06 15:58 ` [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
2024-11-06 15:58 ` [PATCH v6 2/3] x86: probe memory block size advisement value during mm init Gregory Price
@ 2024-11-06 15:58 ` Gregory Price
2024-11-12 21:41 ` Dan Williams
2024-11-20 19:20 ` [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement Fan Ni
3 siblings, 1 reply; 12+ messages in thread
From: Gregory Price @ 2024-11-06 15:58 UTC (permalink / raw)
To: x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, kernel-team, 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>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: David Hildenbrand <david@redhat.com>
---
drivers/acpi/numa/srat.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
index 44f91f2c6c5d..34b6993e7d6c 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,13 +339,22 @@ 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;
int node;
cfmws = (struct acpi_cedt_cfmws *)header;
start = cfmws->base_hpa;
end = cfmws->base_hpa + cfmws->window_size;
+ /* Align memblock size to CFMW regions if possible */
+ align = 1UL << __ffs(start | end);
+ 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,
* or a portion of, this CFMWS HPA range. Extend the memblks
--
2.43.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size
2024-11-06 15:58 ` [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
@ 2024-11-12 21:28 ` Dan Williams
2024-11-13 4:14 ` Gregory Price
0 siblings, 1 reply; 12+ messages in thread
From: Dan Williams @ 2024-11-12 21:28 UTC (permalink / raw)
To: Gregory Price, x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, kernel-team, 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
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.
Should the advice just succeed when the result does not matter?
Otherwise, it depends on the caller to not care based on config.
I do not feel that strongly about it, so either way:
Acked-by: Dan Williams <dan.j.williams@intel.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v6 2/3] x86: probe memory block size advisement value during mm init
2024-11-06 15:58 ` [PATCH v6 2/3] x86: probe memory block size advisement value during mm init Gregory Price
@ 2024-11-12 21:34 ` Dan Williams
2024-11-25 22:35 ` Gregory Price
0 siblings, 1 reply; 12+ messages in thread
From: Dan Williams @ 2024-11-12 21:34 UTC (permalink / raw)
To: Gregory Price, x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, kernel-team, 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
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.
This seems like documentation that also belongs in-line in the code.
Perhaps a follow-on to add this to memory_block_advised_max_size()?
For this one:
Acked-by: Dan Williams <dan.j.williams@intel.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
2024-11-06 15:58 ` [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
@ 2024-11-12 21:41 ` Dan Williams
2024-11-12 23:47 ` Gregory Price
0 siblings, 1 reply; 12+ messages in thread
From: Dan Williams @ 2024-11-12 21:41 UTC (permalink / raw)
To: Gregory Price, x86, linux-kernel, linux-acpi, linux-mm
Cc: linux-cxl, kernel-team, 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
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>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Acked-by: David Hildenbrand <david@redhat.com>
> ---
> drivers/acpi/numa/srat.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> index 44f91f2c6c5d..34b6993e7d6c 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,13 +339,22 @@ 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;
> int node;
>
> cfmws = (struct acpi_cedt_cfmws *)header;
> start = cfmws->base_hpa;
> end = cfmws->base_hpa + cfmws->window_size;
>
> + /* Align memblock size to CFMW regions if possible */
> + align = 1UL << __ffs(start | end);
> + if (align >= SZ_256M) {
> + if (memory_block_advise_max_size(align) < 0)
> + pr_warn("CFMWS: memblock size advise failed\n");
Oh, this made me go back to look at what happens if CFMWS has multiple
alignment suggestions. Should not memory_block_advise_max_size() be
considering the max advice?
if (memory_block_advised_size) {
...
} else {
memory_block_advised_size = max(memory_block_advised_size, size);
}
For example, if region0 is an x4 region and region1 is an x1 region then
the memory block size should be 1GB, not 256M. I.e. CFMWS alignment
follows CXL hardware decoder alignment of "256M * InterleaveWays".
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
2024-11-12 21:41 ` Dan Williams
@ 2024-11-12 23:47 ` Gregory Price
2024-11-13 0:12 ` Dan Williams
0 siblings, 1 reply; 12+ messages in thread
From: Gregory Price @ 2024-11-12 23:47 UTC (permalink / raw)
To: Dan Williams
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl, kernel-team,
Jonathan.Cameron, rrichter, Terry.Bowman, dave.jiang, ira.weiny,
alison.schofield, dave.hansen, luto, peterz, tglx, mingo, bp,
hpa, rafael, lenb, david, osalvador, gregkh, akpm, rppt
On Tue, Nov 12, 2024 at 01:41:55PM -0800, Dan Williams wrote:
> 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>
> > Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > Acked-by: David Hildenbrand <david@redhat.com>
> > ---
> > drivers/acpi/numa/srat.c | 12 +++++++++++-
> > 1 file changed, 11 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> > index 44f91f2c6c5d..34b6993e7d6c 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,13 +339,22 @@ 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;
> > int node;
> >
> > cfmws = (struct acpi_cedt_cfmws *)header;
> > start = cfmws->base_hpa;
> > end = cfmws->base_hpa + cfmws->window_size;
> >
> > + /* Align memblock size to CFMW regions if possible */
> > + align = 1UL << __ffs(start | end);
> > + if (align >= SZ_256M) {
> > + if (memory_block_advise_max_size(align) < 0)
> > + pr_warn("CFMWS: memblock size advise failed\n");
>
> Oh, this made me go back to look at what happens if CFMWS has multiple
> alignment suggestions. Should not memory_block_advise_max_size() be
> considering the max advice?
>
> if (memory_block_advised_size) {
> ...
> } else {
> memory_block_advised_size = max(memory_block_advised_size, size);
> }
>
> For example, if region0 is an x4 region and region1 is an x1 region then
> the memory block size should be 1GB, not 256M. I.e. CFMWS alignment
> follows CXL hardware decoder alignment of "256M * InterleaveWays".
Max size to minimize capacity loss to due alignment truncation.
If CFMW-0 is aligned at 1GB and CFMW-1 is aligned at 256MB, if you select 1GB
then some portion of CFMW-1 will be unmappable.
so you want min(memory_block_advised_size, size) to ensure the hotplug memblock
size aligns to the *smallest* CFMW (or any other source) alignment.
Unless I'm misunderstanding your feedback here.
I'm not clear on why the interleave data is relevant here - that just tells us
how decoders line up with the memory region described in the CFMW. The window
still gets chopped up into N memblocks of memory_block_advised_size.
~Gregory
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment
2024-11-12 23:47 ` Gregory Price
@ 2024-11-13 0:12 ` Dan Williams
0 siblings, 0 replies; 12+ messages in thread
From: Dan Williams @ 2024-11-13 0:12 UTC (permalink / raw)
To: Gregory Price, Dan Williams
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl, kernel-team,
Jonathan.Cameron, rrichter, Terry.Bowman, dave.jiang, ira.weiny,
alison.schofield, dave.hansen, luto, peterz, tglx, mingo, bp,
hpa, rafael, lenb, david, osalvador, gregkh, akpm, rppt
Gregory Price wrote:
> On Tue, Nov 12, 2024 at 01:41:55PM -0800, Dan Williams wrote:
> > 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>
> > > Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > > Acked-by: David Hildenbrand <david@redhat.com>
> > > ---
> > > drivers/acpi/numa/srat.c | 12 +++++++++++-
> > > 1 file changed, 11 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
> > > index 44f91f2c6c5d..34b6993e7d6c 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,13 +339,22 @@ 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;
> > > int node;
> > >
> > > cfmws = (struct acpi_cedt_cfmws *)header;
> > > start = cfmws->base_hpa;
> > > end = cfmws->base_hpa + cfmws->window_size;
> > >
> > > + /* Align memblock size to CFMW regions if possible */
> > > + align = 1UL << __ffs(start | end);
> > > + if (align >= SZ_256M) {
> > > + if (memory_block_advise_max_size(align) < 0)
> > > + pr_warn("CFMWS: memblock size advise failed\n");
> >
> > Oh, this made me go back to look at what happens if CFMWS has multiple
> > alignment suggestions. Should not memory_block_advise_max_size() be
> > considering the max advice?
> >
> > if (memory_block_advised_size) {
> > ...
> > } else {
> > memory_block_advised_size = max(memory_block_advised_size, size);
> > }
> >
> > For example, if region0 is an x4 region and region1 is an x1 region then
> > the memory block size should be 1GB, not 256M. I.e. CFMWS alignment
> > follows CXL hardware decoder alignment of "256M * InterleaveWays".
>
> Max size to minimize capacity loss to due alignment truncation.
>
> If CFMW-0 is aligned at 1GB and CFMW-1 is aligned at 256MB, if you select 1GB
> then some portion of CFMW-1 will be unmappable.
>
> so you want min(memory_block_advised_size, size) to ensure the hotplug memblock
> size aligns to the *smallest* CFMW (or any other source) alignment.
>
> Unless I'm misunderstanding your feedback here.
No, whoops, you didn't misundertand, I just misread
memory_block_advise_max_size(). Makes sense and current code looks good,
you can add:
Acked-by: Dan Williams <dan.j.williams@intel.com>
> I'm not clear on why the interleave data is relevant here - that just tells us
> how decoders line up with the memory region described in the CFMW. The window
> still gets chopped up into N memblocks of memory_block_advised_size.
Yes the window still gets chopped, but the alignment is meant to follow
256M * InterleaveWays. The algorithm as you have it will pick that
up. So, no concerns from me from the CXL side.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size
2024-11-12 21:28 ` Dan Williams
@ 2024-11-13 4:14 ` Gregory Price
0 siblings, 0 replies; 12+ messages in thread
From: Gregory Price @ 2024-11-13 4:14 UTC (permalink / raw)
To: Dan Williams
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl, kernel-team,
Jonathan.Cameron, rrichter, Terry.Bowman, dave.jiang, ira.weiny,
alison.schofield, dave.hansen, luto, peterz, tglx, mingo, bp,
hpa, rafael, lenb, david, osalvador, gregkh, akpm, rppt
On Tue, Nov 12, 2024 at 01:28:03PM -0800, Dan Williams wrote:
> 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.
>
> Should the advice just succeed when the result does not matter?
>
I figure at some point during __init the value will be probed and subsequent
calls will be ignored. I'd rather fail explicitly in that case to assist
debugging - otherwise it might be a little maddening to discover your callsite
is too late in the process.
> Otherwise, it depends on the caller to not care based on config.
>
> I do not feel that strongly about it, so either way:
>
> Acked-by: Dan Williams <dan.j.williams@intel.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement
2024-11-06 15:58 [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
` (2 preceding siblings ...)
2024-11-06 15:58 ` [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
@ 2024-11-20 19:20 ` Fan Ni
3 siblings, 0 replies; 12+ messages in thread
From: Fan Ni @ 2024-11-20 19:20 UTC (permalink / raw)
To: Gregory Price
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl, kernel-team,
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, rppt
On Wed, Nov 06, 2024 at 10:58:44AM -0500, Gregory Price wrote:
> When physical address regions are not aligned to memory block size,
> the misaligned portion is lost (stranded capacity).
>
> Block size (min/max/selected) is architecture defined. Most architectures
> tend to use the minimum block size or some simplistic heurist. On x86,
> memory block size increases up to 2GB, and is otherwise fitted to the
> alignment of non-hotplug (i.e. not special purpose memory).
>
> CXL exposes its memory for management through the ACPI CEDT (CXL Early
> Detection Table) in a field called the CXL Fixed Memory Window. Per
> the CXL specification, this memory must be aligned to at least 256MB.
>
> When a CFMW aligns on a size less than the block size, this causes a
> loss of up to 2GB per CFMW on x86. It is not uncommon for CFMW to be
> allocated per-device - though this behavior is BIOS defined.
>
> This patch set provides 3 things:
> 1) implement advise/query functions in driverse/base/memory.c to
> report/query architecture agnostic hotplug block alignment advice.
> 2) update x86 memblock size logic to consider the hotplug advice
> 3) add code in acpi/numa/srat.c to report CFMW alignment advice
>
> The advisement interfaces are design to be called during arch_init
> code prior to allocator and smp_init. start_kernel will call these
> through setup_arch() (via acpi and mm/init_64.c on x86), which occurs
> prior to mm_core_init and smp_init - so no need for atomics.
>
> There's an attempt to signal callers to advise() that query has already
> occurred, but this is predicated on the notion that query actually
> occurs (which presently only happens on the x86 arch). This is to
> assist debugging future users. Otherwise, the advise() call has
> been marked __init to help static discovery of bad call times.
>
> Once query is called the first time, it will always return the same value.
>
> Interfaces return -EBUSY and 0 respectively on systems without hotplug.
>
> v6:
> - boot_cpu_has -> cpu_feature_enabled() in x86 code
> - ack tags
>
> Suggested-by: Ira Weiny <ira.weiny@intel.com>
> Suggested-by: David Hildenbrand <david@redhat.com>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Gregory Price <gourry@gourry.net>
>
Tested on a CXL server with a directly attached cxl device, works as
expected.
Tested-by: Fan Ni <fan.ni@samsung.com>
Fan
> Gregory Price (3):
> memory: implement memory_block_advise/probe_max_size
> x86: probe memory block size advisement value during mm init
> acpi,srat: give memory block size advice based on CFMWS alignment
>
> arch/x86/mm/init_64.c | 15 ++++++++----
> drivers/acpi/numa/srat.c | 12 ++++++++-
> drivers/base/memory.c | 53 ++++++++++++++++++++++++++++++++++++++++
> include/linux/memory.h | 10 ++++++++
> 4 files changed, 84 insertions(+), 6 deletions(-)
>
> --
> 2.43.0
>
--
Fan Ni (From gmail)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v6 2/3] x86: probe memory block size advisement value during mm init
2024-11-12 21:34 ` Dan Williams
@ 2024-11-25 22:35 ` Gregory Price
0 siblings, 0 replies; 12+ messages in thread
From: Gregory Price @ 2024-11-25 22:35 UTC (permalink / raw)
To: Dan Williams
Cc: x86, linux-kernel, linux-acpi, linux-mm, linux-cxl, kernel-team,
Jonathan.Cameron, rrichter, Terry.Bowman, dave.jiang, ira.weiny,
alison.schofield, dave.hansen, luto, peterz, tglx, mingo, bp,
hpa, rafael, lenb, david, osalvador, gregkh, akpm, rppt
On Tue, Nov 12, 2024 at 01:34:09PM -0800, Dan Williams wrote:
> 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.
>
> This seems like documentation that also belongs in-line in the code.
It actually is, just ahead of every check instead of in a numbered list :P
~Gregory
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-11-25 22:35 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-06 15:58 [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement Gregory Price
2024-11-06 15:58 ` [PATCH v6 1/3] memory: implement memory_block_advise/probe_max_size Gregory Price
2024-11-12 21:28 ` Dan Williams
2024-11-13 4:14 ` Gregory Price
2024-11-06 15:58 ` [PATCH v6 2/3] x86: probe memory block size advisement value during mm init Gregory Price
2024-11-12 21:34 ` Dan Williams
2024-11-25 22:35 ` Gregory Price
2024-11-06 15:58 ` [PATCH v6 3/3] acpi,srat: give memory block size advice based on CFMWS alignment Gregory Price
2024-11-12 21:41 ` Dan Williams
2024-11-12 23:47 ` Gregory Price
2024-11-13 0:12 ` Dan Williams
2024-11-20 19:20 ` [PATCH v6 0/3] memory,x86,acpi: hotplug memory alignment advisement Fan Ni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox