[RESEND PATCH 10/10] memblock: support memsize reusable to consider as reusable

Jaewon Kim
2024-05-21T02:40:18Z

Sometimes we'd like to include some memory region as reusable even
though it is actually not CMA type. In that case, add reusable in its
device tree description, then memsize will consider it is reusuable and
add its size to the system total memory size.

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
drivers/of/of_reserved_mem.c | 3 +++
include/linux/memblock.h | 2 ++
mm/memblock.c | 7 +++++++
3 files changed, 12 insertions(+)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index ece678e07304..7aedac213995 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -468,6 +468,9 @@ void __init fdt_init_reserved_mem(void)
memblock_memsize_record(rmem->name, rmem->base,
rmem->size, nomap,
reusable);
+ if (reusable &&
+ !of_flat_dt_is_compatible(node, "shared-dma-pool"))
+ memblock_memsize_mod_reusable_size(rmem->size);
}
}
}
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 7ab8b59bfbc1..0aa6202a7a6a 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -626,6 +626,7 @@ extern void memblock_memsize_mod_kernel_size(long size);
extern void memblock_memsize_mod_memmap_size(long size);
extern void memblock_memsize_kernel_code_data(unsigned long code,
unsigned long data, unsigned long ro, unsigned long bss);
+extern void memblock_memsize_mod_reusable_size(long size);
#else
static inline void memblock_memsize_record(const char *name, phys_addr_t base,
phys_addr_t size, bool nomap,
@@ -639,6 +640,7 @@ static inline void memblock_memsize_mod_kernel_size(long size) { }
static inline void memblock_memsize_mod_memmap_size(long size) { }
static inline void memblock_memsize_kernel_code_data(unsigned long code,
unsigned long data, unsigned long ro, unsigned long bss) { }
+static inline void memblock_memsize_mod_reusable_size(long size) { }
#endif

#endif /* _LINUX_MEMBLOCK_H */
diff --git a/mm/memblock.c b/mm/memblock.c
index 2fe0dc2575c5..a20d60d3bb40 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2066,6 +2066,7 @@ static unsigned long memsize_code __initdata_memblock;
static unsigned long memsize_data __initdata_memblock;
static unsigned long memsize_ro __initdata_memblock;
static unsigned long memsize_bss __initdata_memblock;
+static long memsize_reusable_size __initdata_memblock;
static bool memblock_memsize_tracking __initdata_memblock = true;

void __init memblock_memsize_enable_tracking(void)
@@ -2117,6 +2118,11 @@ static void __init_memblock memsize_get_valid_name(char *valid_name, const char
valid_name[val_size] = '\0';
}

+void memblock_memsize_mod_reusable_size(long size)
+{
+ memsize_reusable_size += size;
+}
+
static inline struct memsize_rgn_struct * __init_memblock memsize_get_new_rgn(void)
{
if (memsize_rgn_count == ARRAY_SIZE(memsize_rgn)) {
@@ -2716,6 +2722,7 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
etc -= memsize_code + memsize_data + memsize_ro + memsize_bss +
memsize_memap;

+ system += memsize_reusable_size;
sort(memsize_rgn, memsize_rgn_count,
sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL);
for (i = 0; i < memsize_rgn_count; i++) {
--
2.25.1