linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] memblock: introduce memsize showing reserved memory
       [not found] <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcas1p4.samsung.com>
@ 2022-03-24  7:01 ` Jaewon Kim
       [not found]   ` <CGME20220324065919epcas1p35bafcd9151cf0469e4e933250c491a88@epcas1p3.samsung.com>
                     ` (9 more replies)
  0 siblings, 10 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

Some of memory regions can be reserved for a specific purpose. They are
usually defined through reserved-memory in device tree. If only size
without address is specified in device tree, the address of the region
will be determined at boot time.

We may find the address of the memory regions through booting log, but
it does not show all. And it could be hard to catch the very beginning
log. The memblock_dump_all shows all memblock status but it does not
show region name and its information is difficult to summarize.

This patch introduce a debugfs node, memblock/memsize, to see reserved
memory easily.

Here's an example

$ cat debugfs/memblock/memsize
0x0f9000000-0x0fb000000 0x02000000 (   32768 KB )   map reusable linux,cma
0x0b1900000-0x0b1b00000 0x00200000 (    2048 KB ) nomap unusable test1
0x0b0200000-0x0b0400000 0x00200000 (    2048 KB )   map unusable test2
 (snipped)

Reserved    :  746924 KB
 .kernel    :  137027 KB
  .text     :   28158 KB
  .rwdata   :    3238 KB
  .rodata   :   13468 KB
  .bss      :   12570 KB
  .etc      :   79593 KB
 .unusable  :  609897 KB
System      : 3447380 KB
 .common    : 3152468 KB
 .reusable  :  294912 KB
Total       : 4194304 KB (  4096.00 MB )

Jaewon Kim (8):
  memblock: introduce memsize showing reserved memory
  memblock: detect hidden memory hole size
  memblock: handle overlapped reserved memory region
  memblock: track memblock changed at early param
  memblock: track kernel size on memsize
  memblock: recognize late free by checking PageReserved
  memblock: print memsize summary information
  memblock: print kernel internal size

 drivers/of/fdt.c             |  10 +
 drivers/of/of_reserved_mem.c |   7 +-
 include/linux/memblock.h     |  21 ++
 include/linux/mm.h           |   3 +
 init/main.c                  |  13 +-
 kernel/dma/contiguous.c      |   9 +-
 mm/Kconfig                   |   7 +
 mm/memblock.c                | 434 ++++++++++++++++++++++++++++++++++-
 mm/page_alloc.c              |  15 +-
 9 files changed, 506 insertions(+), 13 deletions(-)

-- 
2.17.1



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/8] memblock: introduce memsize showing reserved memory
       [not found]   ` <CGME20220324065919epcas1p35bafcd9151cf0469e4e933250c491a88@epcas1p3.samsung.com>
@ 2022-03-24  7:01     ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

Some of memory regions can be reserved for a specific purpose. They are
usually defined through reserved-memory in device tree. If only size
without address is specified in device tree, the address of the region
will be determined at boot time.

We may find the address of the memory regions through booting log, but
it does not show all. And it could be hard to catch the very beginning
log. The memblock_dump_all shows all memblock status but it does not
show region name and its information is difficult to summarize.

This patch introduce a debugfs node, memblock/memsize, to see reserved
memory easily.

The first patch here will show the only reserved-memory in device tree
like following example. The next patches will show more information.

$ cat debugfs/memblock/memsize
0x0f9000000-0x0fb000000 0x02000000 (   32768 KB )   map reusable linux,cma
0x0b1900000-0x0b1b00000 0x00200000 (    2048 KB ) nomap unusable test1
0x0b0200000-0x0b0400000 0x00200000 (    2048 KB )   map unusable test2

.unusable  :   4096 KB
.reusable  :  32768 KB

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 drivers/of/fdt.c             |   2 +
 drivers/of/of_reserved_mem.c |   7 ++-
 include/linux/memblock.h     |   9 +++
 kernel/dma/contiguous.c      |   2 +
 mm/Kconfig                   |   7 +++
 mm/memblock.c                | 103 +++++++++++++++++++++++++++++++++++
 6 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index ec315b060cd5..ec2f60a78f8f 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -619,6 +619,7 @@ static void __init fdt_reserve_elfcorehdr(void)
 	}
 
 	memblock_reserve(elfcorehdr_addr, elfcorehdr_size);
+	memblock_memsize_record("elfcorehdr", elfcorehdr_addr, size, false, false);
 
 	pr_info("Reserving %llu KiB of memory at 0x%llx for elfcorehdr\n",
 		elfcorehdr_size >> 10, elfcorehdr_addr);
@@ -645,6 +646,7 @@ void __init early_init_fdt_scan_reserved_mem(void)
 		if (!size)
 			break;
 		early_init_dt_reserve_memory_arch(base, size, false);
+		memblock_memsize_record("memreserve", base, size, false, false);
 	}
 
 	fdt_scan_reserved_mem();
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 75caa6f5d36f..40323751efb2 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -261,9 +261,10 @@ void __init fdt_init_reserved_mem(void)
 		int len;
 		const __be32 *prop;
 		int err = 0;
-		bool nomap;
+		bool nomap, reusable;
 
 		nomap = of_get_flat_dt_prop(node, "no-map", NULL) != NULL;
+		reusable = of_get_flat_dt_prop(node, "reusable", NULL) != NULL;
 		prop = of_get_flat_dt_prop(node, "phandle", &len);
 		if (!prop)
 			prop = of_get_flat_dt_prop(node, "linux,phandle", &len);
@@ -283,6 +284,10 @@ void __init fdt_init_reserved_mem(void)
 				else
 					memblock_phys_free(rmem->base,
 							   rmem->size);
+			} else {
+				memblock_memsize_record(rmem->name, rmem->base,
+							rmem->size, nomap,
+							reusable);
 			}
 		}
 	}
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 50ad19662a32..468b016e179b 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -604,5 +604,14 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end)
 }
 #endif
 
+#ifdef CONFIG_MEMBLOCK_MEMSIZE
+extern void memblock_memsize_record(const char *name, phys_addr_t base,
+				    phys_addr_t size, bool nomap,
+				    bool reusable);
+#else
+static inline void memblock_memsize_record(const char *name, phys_addr_t base,
+				    phys_addr_t size, bool nomap,
+				    bool reusable) { }
+#endif
 
 #endif /* _LINUX_MEMBLOCK_H */
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 6ea80ae42622..7415c1135afa 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -239,6 +239,8 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
 	dma_contiguous_early_fixup(cma_get_base(*res_cma),
 				cma_get_size(*res_cma));
 
+	memblock_memsize_record("dma_cma", cma_get_base(*res_cma),
+				cma_get_size(*res_cma), false, true);
 	return 0;
 }
 
diff --git a/mm/Kconfig b/mm/Kconfig
index 761f5021ba51..e29f6cd8394e 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -96,6 +96,13 @@ config HAVE_FAST_GUP
 	depends on MMU
 	bool
 
+config MEMBLOCK_MEMSIZE
+	bool "memblock based reserved memory profiling"
+	default n
+	help
+	  This patch introduce a debugfs node, memblock/memsize, to see reserved
+	  memory easily.
+
 # Don't discard allocated memory used to track "memory" and "reserved" memblocks
 # after early boot, so it can still be used to test for validity of memory.
 # Also, memblocks are updated with memory hot(un)plug.
diff --git a/mm/memblock.c b/mm/memblock.c
index b12a364f2766..8492757f7192 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -19,6 +19,7 @@
 
 #include <asm/sections.h>
 #include <linux/io.h>
+#include <linux/sort.h>
 
 #include "internal.h"
 
@@ -1928,6 +1929,49 @@ static int __init early_memblock(char *p)
 }
 early_param("memblock", early_memblock);
 
+#ifdef CONFIG_MEMBLOCK_MEMSIZE
+
+#define NAME_SIZE	30
+struct memsize_rgn_struct {
+	phys_addr_t	base;
+	long		size;
+	bool		nomap;			/*  1/32 byte */
+	bool		reusable;		/*  1/32 byte */
+	char		name[NAME_SIZE];	/* 30/32 byte */
+};
+
+#define MAX_MEMSIZE_RGN	64
+static struct memsize_rgn_struct memsize_rgn[MAX_MEMSIZE_RGN] __initdata_memblock;
+static int memsize_rgn_count __initdata_memblock;
+
+void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base,
+			     phys_addr_t size, bool nomap, bool reusable)
+{
+	struct memsize_rgn_struct *rgn;
+	phys_addr_t end;
+
+	if (memsize_rgn_count == MAX_MEMSIZE_RGN) {
+		pr_err("not enough space on memsize_rgn\n");
+		return;
+	}
+	rgn = &memsize_rgn[memsize_rgn_count++];
+	rgn->base = base;
+	rgn->size = size;
+	rgn->nomap = nomap;
+	rgn->reusable = reusable;
+
+	if (!name) {
+		strcpy(rgn->name, "unknown");
+	} else {
+		strncpy(rgn->name, name, NAME_SIZE - 1);
+		rgn->name[NAME_SIZE - 1] = '\0';
+	}
+	end = base + size - 1;
+	memblock_dbg("%s %pa..%pa nomap:%d reusable:%d\n",
+		     __func__, &base, &end, nomap, reusable);
+}
+#endif /* MEMBLOCK_MEMSIZE */
+
 static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn)
 {
 	struct page *start_pg, *end_pg;
@@ -2138,6 +2182,61 @@ static int memblock_debug_show(struct seq_file *m, void *private)
 }
 DEFINE_SHOW_ATTRIBUTE(memblock_debug);
 
+#ifdef CONFIG_MEMBLOCK_MEMSIZE
+
+static int memsize_rgn_cmp(const void *a, const void *b)
+{
+	const struct memsize_rgn_struct *ra = a, *rb = b;
+
+	if (ra->base > rb->base)
+		return -1;
+
+	if (ra->base < rb->base)
+		return 1;
+
+	return 0;
+}
+
+static int memblock_memsize_show(struct seq_file *m, void *private)
+{
+	int i;
+	struct memsize_rgn_struct *rgn;
+	unsigned long reserved = 0, reusable = 0;
+
+	sort(memsize_rgn, memsize_rgn_count,
+	     sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL);
+	for (i = 0; i < memsize_rgn_count; i++) {
+		phys_addr_t base, end;
+		long size;
+
+		rgn = &memsize_rgn[i];
+		base = rgn->base;
+		size = rgn->size;
+		end = base + size;
+
+		seq_printf(m, "0x%09lx-0x%09lx 0x%08lx ( %7lu KB ) %s %s %s\n",
+			   &base, &end,
+			   size, DIV_ROUND_UP(size, SZ_1K),
+			   rgn->nomap ? "nomap" : "  map",
+			   rgn->reusable ? "reusable" : "unusable",
+			   rgn->name);
+		if (rgn->reusable)
+			reusable += (unsigned long)rgn->size;
+		else
+			reserved += (unsigned long)rgn->size;
+	}
+
+	seq_printf(m, "\n");
+	seq_printf(m, " .unusable  : %7lu KB\n",
+		   DIV_ROUND_UP(reserved, SZ_1K));
+	seq_printf(m, " .reusable  : %7lu KB\n",
+		   DIV_ROUND_UP(reusable, SZ_1K));
+	return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(memblock_memsize);
+#endif
+
 static int __init memblock_init_debugfs(void)
 {
 	struct dentry *root = debugfs_create_dir("memblock", NULL);
@@ -2150,6 +2249,10 @@ static int __init memblock_init_debugfs(void)
 	debugfs_create_file("physmem", 0444, root, &physmem,
 			    &memblock_debug_fops);
 #endif
+#ifdef CONFIG_MEMBLOCK_MEMSIZE
+	debugfs_create_file("memsize", 0444, root,
+			    NULL, &memblock_memsize_fops);
+#endif
 
 	return 0;
 }
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/8] memblock: detect hidden memory hole size
       [not found]   ` <CGME20220324065919epcas1p1b30eabc8bbe01da1ef90280b6ee8bcea@epcas1p1.samsung.com>
@ 2022-03-24  7:01     ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

Bootloader knows the actual memory size, but bootloader may reserve some
memory for a specific purpose and pass the only remaining memory region
to kernel.

Even though kernel does not know what it is, we need to detect those
regions to sum up all reserved memory. Let me call it memory hole. To
expect the hole size, this patch assume two things. One is that each
physical memory has 1GB aligned size and address. And the hole is less
than 1GB. For the hole, let it be shown as unknown in memsize logic.

This is an example.
0x0bf000000-0x0c0000000 0x01000000 (   16384 KB ) nomap unusable unknown

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

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index ec2f60a78f8f..9721a3d7b7ae 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1294,6 +1294,8 @@ void __init early_init_dt_scan_nodes(void)
 
 	/* Handle linux,usable-memory-range property */
 	early_init_dt_check_for_usable_mem_range();
+
+	memblock_memsize_detect_hole();
 }
 
 bool __init early_init_dt_scan(void *params)
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 468b016e179b..201f8723dfd8 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -608,10 +608,12 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end)
 extern void memblock_memsize_record(const char *name, phys_addr_t base,
 				    phys_addr_t size, bool nomap,
 				    bool reusable);
+extern void memblock_memsize_detect_hole(void);
 #else
 static inline void memblock_memsize_record(const char *name, phys_addr_t base,
 				    phys_addr_t size, bool nomap,
 				    bool reusable) { }
+static inline void memblock_memsize_detect_hole(void) { }
 #endif
 
 #endif /* _LINUX_MEMBLOCK_H */
diff --git a/mm/memblock.c b/mm/memblock.c
index 8492757f7192..8e032f44eb57 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1970,6 +1970,51 @@ void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base,
 	memblock_dbg("%s %pa..%pa nomap:%d reusable:%d\n",
 		     __func__, &base, &end, nomap, reusable);
 }
+
+/* This function will be called to by early_init_dt_scan_nodes */
+void __init memblock_memsize_detect_hole(void)
+{
+	phys_addr_t base, end;
+	phys_addr_t prev_end, hole_sz;
+	int idx;
+	struct memblock_region *rgn;
+	int memblock_cnt = (int)memblock.memory.cnt;
+
+	/* assume that the hole size is less than 1 GB */
+	for_each_memblock_type(idx, (&memblock.memory), rgn) {
+		prev_end = (idx == 0) ? round_down(rgn->base, SZ_1G) : end;
+		base = rgn->base;
+		end = rgn->base + rgn->size;
+
+		/* only for the last region, check a hole after the region */
+		if (idx + 1 == memblock_cnt) {
+			hole_sz = round_up(end, SZ_1G) - end;
+			if (hole_sz)
+				memblock_memsize_record(NULL, end, hole_sz,
+							true, false);
+		}
+
+		/* for each region, check a hole prior to the region */
+		hole_sz = base - prev_end;
+		if (!hole_sz)
+			continue;
+		if (hole_sz < SZ_1G) {
+			memblock_memsize_record(NULL, prev_end, hole_sz, true,
+						false);
+		} else {
+			phys_addr_t hole_sz1, hole_sz2;
+
+			hole_sz1 = round_up(prev_end, SZ_1G) - prev_end;
+			if (hole_sz1)
+				memblock_memsize_record(NULL, prev_end,
+							hole_sz1, true, false);
+			hole_sz2 = base % SZ_1G;
+			if (hole_sz2)
+				memblock_memsize_record(NULL, base - hole_sz2,
+							hole_sz2, true, false);
+		}
+	}
+}
 #endif /* MEMBLOCK_MEMSIZE */
 
 static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn)
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/8] memblock: handle overlapped reserved memory region
       [not found]   ` <CGME20220324065919epcas1p3429ec2c9595c54ffe4ee25f273febd1c@epcas1p3.samsung.com>
@ 2022-03-24  7:01     ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

It is not common, but defining an overlapped region is possible.
Actually memblock_add_range allows to overlap with existing ones.

The memsize currently does not handle this overlapped case. But this
patch tries to handle one overlapped case.

Here's the case.

There is an unknown memsize region, which means the region was removed
and not passed at bootloader stage. And there is a reserved memory
region defined in device tree which is overlapped with the unknown
region.

We expect that information in device tree make the unknown region clear.
This patch handle the overlapped region with following conditions.

1) The already existing overlapped region should be unknown and no-map.
2) The newly added region should have a name, and its region should be
same with or part of the existing one.

Here is an example.

Before this patch, memsize shows both overlapped region.

0x0ea000000-0x0ed900000 0x03900000 (   58368 KB ) nomap unusable overlapped
0x0ea000000-0x0f1400000 0x07400000 (  118784 KB ) nomap unusable unknown

After this patch, the overlapped region is named.

0x0ea000000-0x0ed900000 0x03900000 (   58368 KB ) nomap unusable overlapped
0x0e9b00000-0x0ea000000 0x00500000 (    5120 KB ) nomap unusable unknown

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 mm/memblock.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 77 insertions(+), 1 deletion(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 8e032f44eb57..9195a51bfa5d 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1944,6 +1944,75 @@ struct memsize_rgn_struct {
 static struct memsize_rgn_struct memsize_rgn[MAX_MEMSIZE_RGN] __initdata_memblock;
 static int memsize_rgn_count __initdata_memblock;
 
+static inline struct memsize_rgn_struct * __init_memblock memsize_get_new_rgn(void)
+{
+	if (memsize_rgn_count == ARRAY_SIZE(memsize_rgn)) {
+		pr_err("not enough space on memsize_rgn\n");
+		return NULL;
+	}
+	return &memsize_rgn[memsize_rgn_count++];
+}
+
+static bool __init_memblock memsize_update_nomap_region(const char *name, phys_addr_t base,
+					phys_addr_t size, bool nomap)
+{
+	int i;
+	struct memsize_rgn_struct *rmem_rgn, *new_rgn;
+
+	if (!name)
+		return false;
+
+	for (i = 0; i < memsize_rgn_count; i++)	{
+		rmem_rgn = &memsize_rgn[i];
+
+		if (!rmem_rgn->nomap)
+			continue;
+		if (strcmp(rmem_rgn->name, "unknown"))
+			continue;
+		if (base < rmem_rgn->base)
+			continue;
+		if (base + size > rmem_rgn->base + rmem_rgn->size)
+			continue;
+
+		if (base == rmem_rgn->base && size == rmem_rgn->size) {
+			strncpy(new_rgn->name, name, NAME_SIZE);
+			new_rgn->name[NAME_SIZE - 1] = '\0';
+			return true;
+		}
+
+		new_rgn = memsize_get_new_rgn();
+		if (!new_rgn)
+			return true;
+		new_rgn->base = base;
+		new_rgn->size = size;
+		new_rgn->nomap = nomap;
+		new_rgn->reusable = false;
+		strncpy(new_rgn->name, name, NAME_SIZE);
+		new_rgn->name[NAME_SIZE - 1] = '\0';
+
+		if (base == rmem_rgn->base && size < rmem_rgn->size) {
+			rmem_rgn->base = base + size;
+			rmem_rgn->size -= size;
+		} else if (base + size == rmem_rgn->base + rmem_rgn->size) {
+			rmem_rgn->size -= size;
+		} else {
+			new_rgn = memsize_get_new_rgn();
+			if (!new_rgn)
+				return true;
+			new_rgn->base = base + size;
+			new_rgn->size = (rmem_rgn->base + rmem_rgn->size)
+					- (base + size);
+			new_rgn->nomap = nomap;
+			new_rgn->reusable = false;
+			strcpy(new_rgn->name, "unknown");
+			rmem_rgn->size = base - rmem_rgn->base;
+		}
+		return true;
+	}
+
+	return false;
+}
+
 void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base,
 			     phys_addr_t size, bool nomap, bool reusable)
 {
@@ -1954,7 +2023,14 @@ void __init_memblock memblock_memsize_record(const char *name, phys_addr_t base,
 		pr_err("not enough space on memsize_rgn\n");
 		return;
 	}
-	rgn = &memsize_rgn[memsize_rgn_count++];
+
+	if (memsize_update_nomap_region(name, base, size, nomap))
+		return;
+
+	rgn = memsize_get_new_rgn();
+	if (!rgn)
+		return;
+
 	rgn->base = base;
 	rgn->size = size;
 	rgn->nomap = nomap;
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/8] memblock: track memblock changed at early param
       [not found]   ` <CGME20220324065919epcas1p256ff799f37a765a432475808e708d639@epcas1p2.samsung.com>
@ 2022-03-24  7:01     ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

In addition to reserved-memory in device tree, an option in cmdline may
result in memblock allocation. This patch tries to distinguish memblock
changes done at early param.

A region in memsize will be created with name as the param string. And
the region size will be updated during the param function.

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 include/linux/memblock.h |   4 ++
 init/main.c              |  13 ++++-
 mm/memblock.c            | 101 +++++++++++++++++++++++++++++++++++++--
 3 files changed, 112 insertions(+), 6 deletions(-)

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 201f8723dfd8..4be4e0e6baf4 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -609,11 +609,15 @@ extern void memblock_memsize_record(const char *name, phys_addr_t base,
 				    phys_addr_t size, bool nomap,
 				    bool reusable);
 extern void memblock_memsize_detect_hole(void);
+extern void memblock_memsize_set_name(const char *name);
+extern void memblock_memsize_unset_name(void);
 #else
 static inline void memblock_memsize_record(const char *name, phys_addr_t base,
 				    phys_addr_t size, bool nomap,
 				    bool reusable) { }
 static inline void memblock_memsize_detect_hole(void) { }
+static inline void memblock_memsize_set_name(const char *name) { }
+static inline void memblock_memsize_unset_name(void) { }
 #endif
 
 #endif /* _LINUX_MEMBLOCK_H */
diff --git a/init/main.c b/init/main.c
index 560f45c27ffe..ce59521b5ae5 100644
--- a/init/main.c
+++ b/init/main.c
@@ -214,8 +214,15 @@ static bool __init obsolete_checksetup(char *line)
 				pr_warn("Parameter %s is obsolete, ignored\n",
 					p->str);
 				return true;
-			} else if (p->setup_func(line + n))
-				return true;
+			} else {
+				int ret;
+
+				memblock_memsize_set_name(p->str);
+				ret = p->setup_func(line + n);
+				memblock_memsize_unset_name();
+				if (ret)
+					return true;
+			}
 		}
 		p++;
 	} while (p < __setup_end);
@@ -736,8 +743,10 @@ static int __init do_early_param(char *param, char *val,
 		    (strcmp(param, "console") == 0 &&
 		     strcmp(p->str, "earlycon") == 0)
 		) {
+			memblock_memsize_set_name(p->str);
 			if (p->setup_func(val) != 0)
 				pr_warn("Malformed early option '%s'\n", param);
+			memblock_memsize_unset_name();
 		}
 	}
 	/* We accept everything at this stage. */
diff --git a/mm/memblock.c b/mm/memblock.c
index 9195a51bfa5d..4f21b596687e 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -169,6 +169,18 @@ static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size)
 	return *size = min(*size, PHYS_ADDR_MAX - base);
 }
 
+#ifdef CONFIG_MEMBLOCK_MEMSIZE
+static void memblock_memsize_record_add(struct memblock_type *type,
+			phys_addr_t base, phys_addr_t size);
+static void memblock_memsize_record_remove(struct memblock_type *type,
+			phys_addr_t base, phys_addr_t size);
+#else
+static inline void memblock_memsize_record_add(struct memblock_type *type,
+			phys_addr_t base, phys_addr_t size) { }
+static inline void memblock_memsize_record_remove(struct memblock_type *type,
+			phys_addr_t base, phys_addr_t size) { }
+#endif /* CONFIG_MEMBLOCK_MEMSIZE */
+
 /*
  * Address comparison utilities
  */
@@ -578,6 +590,7 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
 	bool insert = false;
 	phys_addr_t obase = base;
 	phys_addr_t end = base + memblock_cap_size(base, &size);
+	phys_addr_t new_size = 0;
 	int idx, nr_new;
 	struct memblock_region *rgn;
 
@@ -592,7 +605,8 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
 		type->regions[0].flags = flags;
 		memblock_set_region_node(&type->regions[0], nid);
 		type->total_size = size;
-		return 0;
+		new_size = size;
+		goto done;
 	}
 repeat:
 	/*
@@ -621,10 +635,12 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
 #endif
 			WARN_ON(flags != rgn->flags);
 			nr_new++;
-			if (insert)
+			if (insert) {
 				memblock_insert_region(type, idx++, base,
 						       rbase - base, nid,
 						       flags);
+				new_size += rbase - base;
+			}
 		}
 		/* area below @rend is dealt with, forget about it */
 		base = min(rend, end);
@@ -633,9 +649,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
 	/* insert the remaining portion */
 	if (base < end) {
 		nr_new++;
-		if (insert)
+		if (insert) {
 			memblock_insert_region(type, idx, base, end - base,
 					       nid, flags);
+			new_size += end - base;
+		}
 	}
 
 	if (!nr_new)
@@ -653,8 +671,11 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
 		goto repeat;
 	} else {
 		memblock_merge_regions(type);
-		return 0;
 	}
+done:
+	if (new_size == size)
+		memblock_memsize_record_add(type, obase, size);
+	return 0;
 }
 
 /**
@@ -790,6 +811,7 @@ static int __init_memblock memblock_remove_range(struct memblock_type *type,
 
 	for (i = end_rgn - 1; i >= start_rgn; i--)
 		memblock_remove_region(type, i);
+	memblock_memsize_record_remove(type, base, size);
 	return 0;
 }
 
@@ -2091,6 +2113,77 @@ void __init memblock_memsize_detect_hole(void)
 		}
 	}
 }
+
+/* assume that freeing region is NOT bigger than the previous region */
+static void __init_memblock memblock_memsize_free(phys_addr_t free_base,
+						  phys_addr_t free_size)
+{
+	int i;
+	struct memsize_rgn_struct *rgn;
+	phys_addr_t free_end, end;
+
+	free_end = free_base + free_size - 1;
+	memblock_dbg("%s %pa..%pa\n",
+		     __func__, &free_base, &free_end);
+
+	for (i = 0; i < memsize_rgn_count; i++) {
+		rgn = &memsize_rgn[i];
+
+		end = rgn->base + rgn->size;
+		if (free_base < rgn->base ||
+		    free_base >= end)
+			continue;
+
+		free_end = free_base + free_size;
+		if (free_base == rgn->base) {
+			rgn->size -= free_size;
+			if (rgn->size != 0)
+				rgn->base += free_size;
+		} else if (free_end == end) {
+			rgn->size -= free_size;
+		} else {
+			memblock_memsize_record(rgn->name, free_end,
+				end - free_end, rgn->nomap, rgn->reusable);
+			rgn->size = free_base - rgn->base;
+		}
+	}
+}
+
+static const char *memblock_memsize_name;
+
+void __init memblock_memsize_set_name(const char *name)
+{
+	memblock_memsize_name = name;
+}
+
+void __init memblock_memsize_unset_name(void)
+{
+	memblock_memsize_name = NULL;
+}
+
+static void __init_memblock memblock_memsize_record_add(struct memblock_type *type,
+				phys_addr_t base, phys_addr_t size)
+{
+	if (memblock_memsize_name) {
+		if (type == &memblock.reserved)
+			memblock_memsize_record(memblock_memsize_name,
+						base, size, false, false);
+		else if (type == &memblock.memory)
+			memblock_memsize_free(base, size);
+	}
+}
+
+static void __init_memblock memblock_memsize_record_remove(struct memblock_type *type,
+				phys_addr_t base, phys_addr_t size)
+{
+	if (memblock_memsize_name) {
+		if (type == &memblock.reserved)
+			memblock_memsize_free(base, size);
+		else if (type == &memblock.memory)
+			memblock_memsize_record(memblock_memsize_name,
+						base, size, true, false);
+	}
+}
 #endif /* MEMBLOCK_MEMSIZE */
 
 static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn)
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 5/8] memblock: track kernel size on memsize
       [not found]   ` <CGME20220324065919epcas1p3a3a267c4348be4fd3bb8437d4e6db142@epcas1p3.samsung.com>
@ 2022-03-24  7:01     ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

Some memory regions are already being tracked by previous patches. But
there are many memory allocations from memblock and frees to memblock
during the boot time.

This patch tracks the memblock size used for the common kernel. To to
this, tracking memblock size is disabled for some memory handling logics
like early param, device tree, and default cma size.

For precise kernel size, this patch counts not actually freed size to
buddy at boot time, and does not count freed size from ramdisk and init
section.

Additionally this patch does one important thing. This patch blocks
memblock_add_range of memblock_remove_range not to update memsize if
free pages were already released to the buddy allocator.

This is an example. The kernel size is newly added by this patch.

 .kernel    :  135137 KB
 .unusable  :  788073 KB
 .reusable  :  294912 KB

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 drivers/of/fdt.c         |  6 ++++++
 include/linux/memblock.h |  6 ++++++
 kernel/dma/contiguous.c  |  7 ++++--
 mm/memblock.c            | 46 ++++++++++++++++++++++++++++++++++++++++
 mm/page_alloc.c          |  9 +++++++-
 5 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 9721a3d7b7ae..8d38d1499d71 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -640,6 +640,8 @@ void __init early_init_fdt_scan_reserved_mem(void)
 	if (!initial_boot_params)
 		return;
 
+	memblock_memsize_disable_tracking();
+
 	/* Process header /memreserve/ fields */
 	for (n = 0; ; n++) {
 		fdt_get_mem_rsv(initial_boot_params, n, &base, &size);
@@ -652,6 +654,7 @@ void __init early_init_fdt_scan_reserved_mem(void)
 	fdt_scan_reserved_mem();
 	fdt_reserve_elfcorehdr();
 	fdt_init_reserved_mem();
+	memblock_memsize_enable_tracking();
 }
 
 /**
@@ -1289,12 +1292,15 @@ void __init early_init_dt_scan_nodes(void)
 	if (rc)
 		pr_warn("No chosen node found, continuing without\n");
 
+	memblock_memsize_disable_tracking();
+
 	/* Setup memory, calling early_init_dt_add_memory_arch */
 	early_init_dt_scan_memory();
 
 	/* Handle linux,usable-memory-range property */
 	early_init_dt_check_for_usable_mem_range();
 
+	memblock_memsize_enable_tracking();
 	memblock_memsize_detect_hole();
 }
 
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 4be4e0e6baf4..6d59c6e68467 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -611,6 +611,9 @@ extern void memblock_memsize_record(const char *name, phys_addr_t base,
 extern void memblock_memsize_detect_hole(void);
 extern void memblock_memsize_set_name(const char *name);
 extern void memblock_memsize_unset_name(void);
+extern void memblock_memsize_enable_tracking(void);
+extern void memblock_memsize_disable_tracking(void);
+extern void memblock_memsize_mod_kernel_size(long size);
 #else
 static inline void memblock_memsize_record(const char *name, phys_addr_t base,
 				    phys_addr_t size, bool nomap,
@@ -618,6 +621,9 @@ static inline void memblock_memsize_record(const char *name, phys_addr_t base,
 static inline void memblock_memsize_detect_hole(void) { }
 static inline void memblock_memsize_set_name(const char *name) { }
 static inline void memblock_memsize_unset_name(void) { }
+static inline void memblock_memsize_enable_tracking(void){ }
+static inline void memblock_memsize_disable_tracking(void){ }
+static inline void memblock_memsize_mod_kernel_size(long size) { }
 #endif
 
 #endif /* _LINUX_MEMBLOCK_H */
diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 7415c1135afa..2a3ecf6a6b22 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -230,10 +230,11 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
 {
 	int ret;
 
+	memblock_memsize_disable_tracking();
 	ret = cma_declare_contiguous(base, size, limit, 0, 0, fixed,
 					"reserved", res_cma);
 	if (ret)
-		return ret;
+		goto out;
 
 	/* Architecture specific contiguous memory fixup. */
 	dma_contiguous_early_fixup(cma_get_base(*res_cma),
@@ -241,7 +242,9 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
 
 	memblock_memsize_record("dma_cma", cma_get_base(*res_cma),
 				cma_get_size(*res_cma), false, true);
-	return 0;
+out:
+	memblock_memsize_enable_tracking();
+	return ret;
 }
 
 /**
diff --git a/mm/memblock.c b/mm/memblock.c
index 4f21b596687e..aee22dbc2500 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1965,6 +1965,23 @@ struct memsize_rgn_struct {
 #define MAX_MEMSIZE_RGN	64
 static struct memsize_rgn_struct memsize_rgn[MAX_MEMSIZE_RGN] __initdata_memblock;
 static int memsize_rgn_count __initdata_memblock;
+static long kernel_init_size;
+static bool do_memsize __initdata_memblock = true;
+
+void __init memblock_memsize_enable_tracking(void)
+{
+	do_memsize = true;
+}
+
+void __init memblock_memsize_disable_tracking(void)
+{
+	do_memsize = false;
+}
+
+void memblock_memsize_mod_kernel_size(long size)
+{
+	kernel_init_size += size;
+}
 
 static inline struct memsize_rgn_struct * __init_memblock memsize_get_new_rgn(void)
 {
@@ -2170,6 +2187,12 @@ static void __init_memblock memblock_memsize_record_add(struct memblock_type *ty
 						base, size, false, false);
 		else if (type == &memblock.memory)
 			memblock_memsize_free(base, size);
+	} else if (do_memsize) {
+		if (type == &memblock.reserved) {
+			memblock_dbg("%s: kernel %lu %+ld\n", __func__,
+				     kernel_init_size, (unsigned long)size);
+			kernel_init_size += size;
+		}
 	}
 }
 
@@ -2182,6 +2205,12 @@ static void __init_memblock memblock_memsize_record_remove(struct memblock_type
 		else if (type == &memblock.memory)
 			memblock_memsize_record(memblock_memsize_name,
 						base, size, true, false);
+	} else if (do_memsize) {
+		if (type == &memblock.reserved) {
+			memblock_dbg("%s: kernel %lu %+ld\n", __func__,
+				     kernel_init_size, (unsigned long)size);
+			kernel_init_size -= size;
+		}
 	}
 }
 #endif /* MEMBLOCK_MEMSIZE */
@@ -2289,6 +2318,19 @@ static unsigned long __init __free_memory_core(phys_addr_t start,
 	unsigned long end_pfn = min_t(unsigned long,
 				      PFN_DOWN(end), max_low_pfn);
 
+#ifdef CONFIG_MEMBLOCK_MEMSIZE
+	unsigned long start_align_up = PFN_ALIGN(start);
+	unsigned long end_align_down = PFN_PHYS(end_pfn);
+
+	if (start_pfn >= end_pfn) {
+		memblock_memsize_mod_kernel_size(end - start);
+	} else {
+		if (start_align_up > start)
+			memblock_memsize_mod_kernel_size(start_align_up - start);
+		if (end_pfn != max_low_pfn && end_align_down < end)
+			memblock_memsize_mod_kernel_size(end - end_align_down);
+	}
+#endif
 	if (start_pfn >= end_pfn)
 		return 0;
 
@@ -2374,6 +2416,8 @@ void __init memblock_free_all(void)
 
 	pages = free_low_memory_core_early();
 	totalram_pages_add(pages);
+
+	memblock_memsize_disable_tracking();
 }
 
 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_ARCH_KEEP_MEMBLOCK)
@@ -2441,6 +2485,8 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
 	}
 
 	seq_printf(m, "\n");
+	seq_printf(m, " .kernel    : %7lu KB\n",
+		   DIV_ROUND_UP(kernel_init_size, SZ_1K));
 	seq_printf(m, " .unusable  : %7lu KB\n",
 		   DIV_ROUND_UP(reserved, SZ_1K));
 	seq_printf(m, " .reusable  : %7lu KB\n",
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 6e0b4596cde9..bbbe314850b0 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8230,8 +8230,15 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
 		free_reserved_page(page);
 	}
 
-	if (pages && s)
+	if (pages && s) {
 		pr_info("Freeing %s memory: %ldK\n", s, K(pages));
+		if (!strcmp(s, "initrd") || !strcmp(s, "unused kernel")) {
+			long size;
+
+			size = -1 * (long)(pages << PAGE_SHIFT);
+			memblock_memsize_mod_kernel_size(size);
+		}
+	}
 
 	return pages;
 }
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 6/8] memblock: recognize late free by checking PageReserved
       [not found]   ` <CGME20220324065919epcas1p1058e2841b009d8c7d683bc0408f8a5a4@epcas1p1.samsung.com>
@ 2022-03-24  7:01     ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

There are some cases in which reserved pages are freed late after the
initial memblock_free_all of mem_init. We'd like to recognize this
late free pages, and update the memsize information.

Because additional job is needed to a no-map or reusable region, the
late free is usually done to a map and unusable region. So only for map
and unusable region, check if some pages within the region is freed. The
freed pages can be recoginzed by checking if PageReserved flag is clear.
To be fast, let's skip other pages within 1 MB range. And this check is
done when a user wants to see the memsize information.

This is an example. If all pages are freed the region size will be 0.

Before
0x0a2300000-0x0a2400000 0x00100000 (    1024 KB )   map unusable latefree

After
0x0a2300000-0x0a2300000 0x00000000 (       0 KB )   map unusable latefree

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 mm/memblock.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/mm/memblock.c b/mm/memblock.c
index aee22dbc2500..597ec7fb5bb2 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2455,6 +2455,39 @@ static int memsize_rgn_cmp(const void *a, const void *b)
 	return 0;
 }
 
+/* assume that freed size is always MB aligned */
+static inline void memblock_memsize_check_size(struct memsize_rgn_struct *rgn)
+{
+	phys_addr_t phy, end, freed = 0;
+	bool has_freed = false;
+	struct page *page;
+
+	if (rgn->reusable || rgn->nomap)
+		return;
+
+	/* check the first page of each 1 MB */
+	phy = rgn->base;
+	end = rgn->base + rgn->size;
+	while (phy < end) {
+		unsigned long pfn = __phys_to_pfn(phy);
+
+		if (!pfn_valid(pfn))
+			return;
+		page = pfn_to_page(pfn);
+		if (!has_freed && !PageReserved(page)) {
+			has_freed = true;
+			freed = phy;
+		} else if (has_freed && PageReserved(page)) {
+			has_freed = false;
+			memblock_memsize_free(freed, phy - freed);
+		}
+
+		if (has_freed && (phy + SZ_1M >= end))
+			memblock_memsize_free(freed, end - freed);
+		phy += SZ_1M;
+	}
+}
+
 static int memblock_memsize_show(struct seq_file *m, void *private)
 {
 	int i;
@@ -2468,6 +2501,7 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
 		long size;
 
 		rgn = &memsize_rgn[i];
+		memblock_memsize_check_size(rgn);
 		base = rgn->base;
 		size = rgn->size;
 		end = base + size;
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 7/8] memblock: print memsize summary information
       [not found]   ` <CGME20220324065919epcas1p4b935c884aa3fde0917f6dff8bff128ed@epcas1p4.samsung.com>
@ 2022-03-24  7:01     ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

With the previous patches, now we can print summary information.

Here's an example of 4GB DRAM device.

Reserved    :  746924 KB
 .kernel    :  137027 KB
 .unusable  :  609897 KB
System      : 3447380 KB
 .common    : 3152468 KB
 .reusable  :  294912 KB
Total       : 4194304 KB (  4096.00 MB )

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 mm/memblock.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 597ec7fb5bb2..ef8cec6242d2 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2492,7 +2492,8 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
 {
 	int i;
 	struct memsize_rgn_struct *rgn;
-	unsigned long reserved = 0, reusable = 0;
+	unsigned long reserved = 0, reusable = 0, total;
+	unsigned long system = totalram_pages() << PAGE_SHIFT;
 
 	sort(memsize_rgn, memsize_rgn_count,
 	     sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL);
@@ -2518,13 +2519,24 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
 			reserved += (unsigned long)rgn->size;
 	}
 
+	total = kernel_init_size + reserved + system;
+
 	seq_printf(m, "\n");
+	seq_printf(m, "Reserved    : %7lu KB\n",
+		   DIV_ROUND_UP(kernel_init_size + reserved, SZ_1K));
 	seq_printf(m, " .kernel    : %7lu KB\n",
 		   DIV_ROUND_UP(kernel_init_size, SZ_1K));
 	seq_printf(m, " .unusable  : %7lu KB\n",
 		   DIV_ROUND_UP(reserved, SZ_1K));
+	seq_printf(m, "System      : %7lu KB\n",
+		   DIV_ROUND_UP(system, SZ_1K));
+	seq_printf(m, " .common    : %7lu KB\n",
+		   DIV_ROUND_UP(system - reusable, SZ_1K));
 	seq_printf(m, " .reusable  : %7lu KB\n",
 		   DIV_ROUND_UP(reusable, SZ_1K));
+	seq_printf(m, "Total       : %7lu KB ( %5lu.%02lu MB )\n",
+		   DIV_ROUND_UP(total, SZ_1K),
+		   total >> 20, ((total % SZ_1M) * 100) >> 20);
 	return 0;
 }
 
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 8/8] memblock: print kernel internal size
       [not found]   ` <CGME20220324065919epcas1p46b5381b1b839d7076673c23e8f9b0bba@epcas1p4.samsung.com>
@ 2022-03-24  7:01     ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-24  7:01 UTC (permalink / raw)
  To: rppt, vbabka, akpm
  Cc: linux-mm, linux-kernel, ytk.lee, jaewon31.kim, Jaewon Kim

Kernel internal size information is also useful to compare with other
binary. This patch print kernel text, rwdata, rodata, bss, and others.

Here's an example.

Reserved    :  746924 KB
 .kernel    :  137027 KB
  .text     :   28158 KB
  .rwdata   :    3238 KB
  .rodata   :   13468 KB
  .bss      :   12570 KB
  .etc      :   79593 KB
 .unusable  :  609897 KB
System      : 3447380 KB
 .common    : 3152468 KB
 .reusable  :  294912 KB
Total       : 4194304 KB (  4096.00 MB )

Signed-off-by: Jaewon Kim <jaewon31.kim@samsung.com>
---
 include/linux/mm.h |  3 +++
 mm/memblock.c      | 17 +++++++++++++++++
 mm/page_alloc.c    |  6 +++---
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 7a3dd7e617e4..6b874c602b3b 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3387,4 +3387,7 @@ madvise_set_anon_name(struct mm_struct *mm, unsigned long start,
 }
 #endif
 
+extern unsigned long physpages, codesize, datasize, rosize, bss_size;
+extern unsigned long init_code_size, init_data_size;
+
 #endif /* _LINUX_MM_H */
diff --git a/mm/memblock.c b/mm/memblock.c
index ef8cec6242d2..083d19b1d061 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2494,6 +2494,13 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
 	struct memsize_rgn_struct *rgn;
 	unsigned long reserved = 0, reusable = 0, total;
 	unsigned long system = totalram_pages() << PAGE_SHIFT;
+	unsigned long text, rw, ro, bss, etc;
+
+	text = codesize;
+	rw = datasize;
+	ro = rosize;
+	bss = bss_size;
+	etc = kernel_init_size - text - rw - ro - bss;
 
 	sort(memsize_rgn, memsize_rgn_count,
 	     sizeof(memsize_rgn[0]), memsize_rgn_cmp, NULL);
@@ -2526,6 +2533,16 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
 		   DIV_ROUND_UP(kernel_init_size + reserved, SZ_1K));
 	seq_printf(m, " .kernel    : %7lu KB\n",
 		   DIV_ROUND_UP(kernel_init_size, SZ_1K));
+	seq_printf(m, "  .text     : %7lu KB\n"
+		      "  .rwdata   : %7lu KB\n"
+		      "  .rodata   : %7lu KB\n"
+		      "  .bss      : %7lu KB\n"
+		      "  .etc      : %7lu KB\n",
+			DIV_ROUND_UP(text, SZ_1K),
+			DIV_ROUND_UP(rw, SZ_1K),
+			DIV_ROUND_UP(ro, SZ_1K),
+			DIV_ROUND_UP(bss, SZ_1K),
+			DIV_ROUND_UP(etc, SZ_1K));
 	seq_printf(m, " .unusable  : %7lu KB\n",
 		   DIV_ROUND_UP(reserved, SZ_1K));
 	seq_printf(m, "System      : %7lu KB\n",
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index bbbe314850b0..2bf75ba3c66d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8243,11 +8243,11 @@ unsigned long free_reserved_area(void *start, void *end, int poison, const char
 	return pages;
 }
 
+unsigned long physpages, codesize, datasize, rosize, bss_size;
+unsigned long init_code_size, init_data_size;
+
 void __init mem_init_print_info(void)
 {
-	unsigned long physpages, codesize, datasize, rosize, bss_size;
-	unsigned long init_code_size, init_data_size;
-
 	physpages = get_num_physpages();
 	codesize = _etext - _stext;
 	datasize = _edata - _sdata;
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
  2022-03-24  7:01 ` [PATCH 0/8] memblock: introduce memsize showing reserved memory Jaewon Kim
                     ` (7 preceding siblings ...)
       [not found]   ` <CGME20220324065919epcas1p46b5381b1b839d7076673c23e8f9b0bba@epcas1p4.samsung.com>
@ 2022-03-25  7:46   ` Mike Rapoport
       [not found]   ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p3>
  9 siblings, 0 replies; 17+ messages in thread
From: Mike Rapoport @ 2022-03-25  7:46 UTC (permalink / raw)
  To: Jaewon Kim; +Cc: vbabka, akpm, linux-mm, linux-kernel, ytk.lee, jaewon31.kim

Hi,

On Thu, Mar 24, 2022 at 04:01:50PM +0900, Jaewon Kim wrote:
> Some of memory regions can be reserved for a specific purpose. They are
> usually defined through reserved-memory in device tree. If only size
> without address is specified in device tree, the address of the region
> will be determined at boot time.
> 
> We may find the address of the memory regions through booting log, but
> it does not show all. And it could be hard to catch the very beginning
> log. The memblock_dump_all shows all memblock status but it does not
> show region name and its information is difficult to summarize.
> 
> This patch introduce a debugfs node, memblock/memsize, to see reserved
> memory easily.
> 
> Here's an example
> 
> $ cat debugfs/memblock/memsize
> 0x0f9000000-0x0fb000000 0x02000000 (   32768 KB )   map reusable linux,cma
> 0x0b1900000-0x0b1b00000 0x00200000 (    2048 KB ) nomap unusable test1
> 0x0b0200000-0x0b0400000 0x00200000 (    2048 KB )   map unusable test2
>  (snipped)
> 
> Reserved    :  746924 KB
>  .kernel    :  137027 KB
>   .text     :   28158 KB
>   .rwdata   :    3238 KB
>   .rodata   :   13468 KB
>   .bss      :   12570 KB
>   .etc      :   79593 KB
>  .unusable  :  609897 KB
> System      : 3447380 KB
>  .common    : 3152468 KB
>  .reusable  :  294912 KB
> Total       : 4194304 KB (  4096.00 MB )

Most of this information information is already available at various
places, like the existing memblock debugfs, /proc/iomem and DT sysfs.

I don't see why we need yet another debugfs file to expose it.
 
> Jaewon Kim (8):
>   memblock: introduce memsize showing reserved memory
>   memblock: detect hidden memory hole size
>   memblock: handle overlapped reserved memory region
>   memblock: track memblock changed at early param
>   memblock: track kernel size on memsize
>   memblock: recognize late free by checking PageReserved
>   memblock: print memsize summary information
>   memblock: print kernel internal size
> 
>  drivers/of/fdt.c             |  10 +
>  drivers/of/of_reserved_mem.c |   7 +-
>  include/linux/memblock.h     |  21 ++
>  include/linux/mm.h           |   3 +
>  init/main.c                  |  13 +-
>  kernel/dma/contiguous.c      |   9 +-
>  mm/Kconfig                   |   7 +
>  mm/memblock.c                | 434 ++++++++++++++++++++++++++++++++++-
>  mm/page_alloc.c              |  15 +-
>  9 files changed, 506 insertions(+), 13 deletions(-)
> 
> -- 
> 2.17.1
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [PATCH 0/8] memblock: introduce memsize showing reserved memory
       [not found]   ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p3>
@ 2022-03-25  8:38     ` Jaewon Kim
  2022-03-27  7:40       ` Mike Rapoport
       [not found]       ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p1>
  0 siblings, 2 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-25  8:38 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: vbabka, akpm, linux-mm, linux-kernel, YongTaek Lee, jaewon31.kim

> 
> 
>--------- Original Message ---------
>Sender : Mike Rapoport <rppt@kernel.org>
>Date : 2022-03-25 16:46 (GMT+9)
>Title : Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
> 
>Hi,
> 
>On Thu, Mar 24, 2022 at 04:01:50PM +0900, Jaewon Kim wrote:
>> Some of memory regions can be reserved for a specific purpose. They are
>> usually defined through reserved-memory in device tree. If only size
>> without address is specified in device tree, the address of the region
>> will be determined at boot time.
>> 
>> We may find the address of the memory regions through booting log, but
>> it does not show all. And it could be hard to catch the very beginning
>> log. The memblock_dump_all shows all memblock status but it does not
>> show region name and its information is difficult to summarize.
>> 
>> This patch introduce a debugfs node, memblock/memsize, to see reserved
>> memory easily.
>> 
>> Here's an example
>> 
>> $ cat debugfs/memblock/memsize
>> 0x0f9000000-0x0fb000000 0x02000000 (   32768 KB )   map reusable linux,cma
>> 0x0b1900000-0x0b1b00000 0x00200000 (    2048 KB ) nomap unusable test1
>> 0x0b0200000-0x0b0400000 0x00200000 (    2048 KB )   map unusable test2
>>  (snipped)
>> 
>> Reserved    :  746924 KB
>>  .kernel    :  137027 KB
>>   .text     :   28158 KB
>>   .rwdata   :    3238 KB
>>   .rodata   :   13468 KB
>>   .bss      :   12570 KB
>>   .etc      :   79593 KB
>>  .unusable  :  609897 KB
>> System      : 3447380 KB
>>  .common    : 3152468 KB
>>  .reusable  :  294912 KB
>> Total       : 4194304 KB (  4096.00 MB )
> 
>Most of this information information is already available at various
>places, like the existing memblock debugfs, /proc/iomem and DT sysfs.
> 
>I don't see why we need yet another debugfs file to expose it.

Hi.
Thank you for your reply.

I don't think existing memblock debugfs or /proc/iomem shows information I want.
They don't show name and actually allocated address and size. And it does not
handle pages freed to buddy allocator after boot.

And which DT sysfs do you mean? If it is /proc/device-tree/reserved-memory, it
shows name and size, but it does not show address for only size defined regions.
It does not recognize the freed pages, either.

Especially I'd like to create a node showing all reserved memory status, their 
total size is same as the physical memory size. This was very useful when I 
compare reserved memory and kernel init time memory between different chipsets,
or between different sw release versions.

Thank you
Jaewon Kim

> 
>> Jaewon Kim (8):
>>   memblock: introduce memsize showing reserved memory
>>   memblock: detect hidden memory hole size
>>   memblock: handle overlapped reserved memory region
>>   memblock: track memblock changed at early param
>>   memblock: track kernel size on memsize
>>   memblock: recognize late free by checking PageReserved
>>   memblock: print memsize summary information
>>   memblock: print kernel internal size
>> 
>>  drivers/of/fdt.c             |  10 +
>>  drivers/of/of_reserved_mem.c |   7 +-
>>  include/linux/memblock.h     |  21 ++
>>  include/linux/mm.h           |   3 +
>>  init/main.c                  |  13 +-
>>  kernel/dma/contiguous.c      |   9 +-
>>  mm/Kconfig                   |   7 +
>>  mm/memblock.c                | 434 ++++++++++++++++++++++++++++++++++-
>>  mm/page_alloc.c              |  15 +-
>>  9 files changed, 506 insertions(+), 13 deletions(-)
>> 
>> -- 
>> 2.17.1
>> 
> 
>-- 
>Sincerely yours,
>Mike.
> 


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
  2022-03-25  8:38     ` Jaewon Kim
@ 2022-03-27  7:40       ` Mike Rapoport
       [not found]       ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p1>
  1 sibling, 0 replies; 17+ messages in thread
From: Mike Rapoport @ 2022-03-27  7:40 UTC (permalink / raw)
  To: Jaewon Kim
  Cc: vbabka, akpm, linux-mm, linux-kernel, YongTaek Lee, jaewon31.kim

Hi,

On Fri, Mar 25, 2022 at 05:38:46PM +0900, Jaewon Kim wrote:

> >--------- Original Message ---------
> >Sender : Mike Rapoport <rppt@kernel.org>
> >Date : 2022-03-25 16:46 (GMT+9)
> >Title : Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
> > 
> >Hi,
> > 
> >On Thu, Mar 24, 2022 at 04:01:50PM +0900, Jaewon Kim wrote:
> >> Some of memory regions can be reserved for a specific purpose. They are
> >> usually defined through reserved-memory in device tree. If only size
> >> without address is specified in device tree, the address of the region
> >> will be determined at boot time.
> >> 
> >> We may find the address of the memory regions through booting log, but
> >> it does not show all. And it could be hard to catch the very beginning
> >> log. The memblock_dump_all shows all memblock status but it does not
> >> show region name and its information is difficult to summarize.
> >> 
> >> This patch introduce a debugfs node, memblock/memsize, to see reserved
> >> memory easily.
> >> 
> >> Here's an example
> >> 
> >> $ cat debugfs/memblock/memsize
> >> 0x0f9000000-0x0fb000000 0x02000000 (   32768 KB )   map reusable linux,cma
> >> 0x0b1900000-0x0b1b00000 0x00200000 (    2048 KB ) nomap unusable test1
> >> 0x0b0200000-0x0b0400000 0x00200000 (    2048 KB )   map unusable test2
> >>  (snipped)
> >> 
> >> Reserved    :  746924 KB
> >>  .kernel    :  137027 KB
> >>   .text     :   28158 KB
> >>   .rwdata   :    3238 KB
> >>   .rodata   :   13468 KB
> >>   .bss      :   12570 KB
> >>   .etc      :   79593 KB
> >>  .unusable  :  609897 KB
> >> System      : 3447380 KB
> >>  .common    : 3152468 KB
> >>  .reusable  :  294912 KB
> >> Total       : 4194304 KB (  4096.00 MB )
> > 
> >Most of this information information is already available at various
> >places, like the existing memblock debugfs, /proc/iomem and DT sysfs.
> > 
> >I don't see why we need yet another debugfs file to expose it.
> 
> Hi.
> Thank you for your reply.
> 
> Especially I'd like to create a node showing all reserved memory status, their 
> total size is same as the physical memory size. This was very useful when I 
> compare reserved memory and kernel init time memory between different chipsets,
> or between different sw release versions.

I'm still not following. The reserved region sizes are available in the
existing memblock debugfs.
Why the names are important? What is the value of having names for *some*
of the reserved regions?
 
> Thank you
> Jaewon Kim

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [PATCH 0/8] memblock: introduce memsize showing reserved memory
       [not found]       ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p1>
@ 2022-03-27 13:53         ` Jaewon Kim
  2022-03-27 15:15           ` Mike Rapoport
       [not found]           ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p7>
  0 siblings, 2 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-27 13:53 UTC (permalink / raw)
  To: Mike Rapoport, Jaewon Kim
  Cc: vbabka, akpm, linux-mm, linux-kernel, YongTaek Lee, jaewon31.kim

> 
> 
>--------- Original Message ---------
>Sender : Mike Rapoport <rppt@kernel.org>
>Date : 2022-03-27 16:40 (GMT+9)
>Title : Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
> 
>Hi,
> 
>On Fri, Mar 25, 2022 at 05:38:46PM +0900, Jaewon Kim wrote:
> 
>> >--------- Original Message ---------
>> >Sender : Mike Rapoport <rppt@kernel.org>
>> >Date : 2022-03-25 16:46 (GMT+9)
>> >Title : Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
>> > 
>> >Hi,
>> > 
>> >On Thu, Mar 24, 2022 at 04:01:50PM +0900, Jaewon Kim wrote:
>> >> Some of memory regions can be reserved for a specific purpose. They are
>> >> usually defined through reserved-memory in device tree. If only size
>> >> without address is specified in device tree, the address of the region
>> >> will be determined at boot time.
>> >> 
>> >> We may find the address of the memory regions through booting log, but
>> >> it does not show all. And it could be hard to catch the very beginning
>> >> log. The memblock_dump_all shows all memblock status but it does not
>> >> show region name and its information is difficult to summarize.
>> >> 
>> >> This patch introduce a debugfs node, memblock/memsize, to see reserved
>> >> memory easily.
>> >> 
>> >> Here's an example
>> >> 
>> >> $ cat debugfs/memblock/memsize
>> >> 0x0f9000000-0x0fb000000 0x02000000 (   32768 KB )   map reusable linux,cma
>> >> 0x0b1900000-0x0b1b00000 0x00200000 (    2048 KB ) nomap unusable test1
>> >> 0x0b0200000-0x0b0400000 0x00200000 (    2048 KB )   map unusable test2
>> >>  (snipped)
>> >> 
>> >> Reserved    :  746924 KB
>> >>  .kernel    :  137027 KB
>> >>   .text     :   28158 KB
>> >>   .rwdata   :    3238 KB
>> >>   .rodata   :   13468 KB
>> >>   .bss      :   12570 KB
>> >>   .etc      :   79593 KB
>> >>  .unusable  :  609897 KB
>> >> System      : 3447380 KB
>> >>  .common    : 3152468 KB
>> >>  .reusable  :  294912 KB
>> >> Total       : 4194304 KB (  4096.00 MB )
>> > 
>> >Most of this information information is already available at various
>> >places, like the existing memblock debugfs, /proc/iomem and DT sysfs.
>> > 
>> >I don't see why we need yet another debugfs file to expose it.
>> 
>> Hi.
>> Thank you for your reply.
>> 
>> I don't think existing memblock debugfs or /proc/iomem shows information I want.
>> They don't show name and actually allocated address and size. And it does not
>> handle pages freed to buddy allocator after boot.
>> 
>> And which DT sysfs do you mean? If it is /proc/device-tree/reserved-memory, it
>> shows name and size, but it does not show address for only size defined regions.
>> It does not recognize the freed pages, either.
>> 
>> Especially I'd like to create a node showing all reserved memory status, their 
>> total size is same as the physical memory size. This was very useful when I 
>> compare reserved memory and kernel init time memory between different chipsets,
>> or between different sw release versions.
> 
>I'm still not following. The reserved region sizes are available in the
>existing memblock debugfs.
>Why the names are important? What is the value of having names for *some*
>of the reserved regions?

Hi

There are many memory regions in memblock debugfs memory/reserved, and some might
be splited or merged with other region. Among regions in debugfs, we can't find 
the one we defined in device tree. Especially it is difficult to find the region we
described size only without start address.

On mobile environment, memory is used by not only CPU but also GPU, Camera, Secure
world, Audio, ETC. To support them, there are many reserved regions described in
device tree. So the name is quite important to recognize a region. And with thename
we can compare reserved memory map with other map.

Additionally as I said, we need one simple knob to look overall reservecd memory
status.

Thank you
Jaewon Kim

> 
>> Thank you
>> Jaewon Kim
> 
>-- 
>Sincerely yours,
>Mike.
> 


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
  2022-03-27 13:53         ` Jaewon Kim
@ 2022-03-27 15:15           ` Mike Rapoport
       [not found]           ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p7>
  1 sibling, 0 replies; 17+ messages in thread
From: Mike Rapoport @ 2022-03-27 15:15 UTC (permalink / raw)
  To: Jaewon Kim
  Cc: vbabka, akpm, linux-mm, linux-kernel, YongTaek Lee, jaewon31.kim

On Sun, Mar 27, 2022 at 10:53:47PM +0900, Jaewon Kim wrote:
> > 
> >--------- Original Message ---------
> >Sender : Mike Rapoport <rppt@kernel.org>
> >Date : 2022-03-27 16:40 (GMT+9)
> >Title : Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
> > 
> > 
> >I'm still not following. The reserved region sizes are available in the
> >existing memblock debugfs.
> >Why the names are important? What is the value of having names for *some*
> >of the reserved regions?
> 
> Hi
> 
> There are many memory regions in memblock debugfs memory/reserved, and some might
> be splited or merged with other region. Among regions in debugfs, we can't find 
> the one we defined in device tree. Especially it is difficult to find the region we
> described size only without start address.
> 
> On mobile environment, memory is used by not only CPU but also GPU, Camera, Secure
> world, Audio, ETC. To support them, there are many reserved regions described in
> device tree. So the name is quite important to recognize a region. And with thename
> we can compare reserved memory map with other map.

You still didn't describe your use case. What is the problem your patches
are trying to solve? Why is it important to know what is the use of particular
reserved region? 

You propose complex mechanism that seems to fit very particular scenario
and sprinkle some calls to this mechanism at random places because you need
to "compare reserved memory map with other map".

Does not sound convincing to me, sorry.

> Thank you
> Jaewon Kim

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [PATCH 0/8] memblock: introduce memsize showing reserved memory
       [not found]           ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p7>
@ 2022-03-29  2:46             ` Jaewon Kim
  2022-03-30  7:08               ` Mike Rapoport
       [not found]               ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p8>
  0 siblings, 2 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-29  2:46 UTC (permalink / raw)
  To: Mike Rapoport, Jaewon Kim
  Cc: vbabka, akpm, linux-mm, linux-kernel, YongTaek Lee, jaewon31.kim

>> > 
>> >--------- Original Message ---------
>> >Sender : Mike Rapoport <rppt@kernel.org>
>> >Date : 2022-03-27 16:40 (GMT+9)
>> >Title : Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
>> > 
>> > 
>> >I'm still not following. The reserved region sizes are available in the
>> >existing memblock debugfs.
>> >Why the names are important? What is the value of having names for *some*
>> >of the reserved regions?
>> 
>> Hi
>> 
>> There are many memory regions in memblock debugfs memory/reserved, and some might
>> be splited or merged with other region. Among regions in debugfs, we can't find 
>> the one we defined in device tree. Especially it is difficult to find the region we
>> described size only without start address.
>> 
>> On mobile environment, memory is used by not only CPU but also GPU, Camera, Secure
>> world, Audio, ETC. To support them, there are many reserved regions described in
>> device tree. So the name is quite important to recognize a region. And with thename
>> we can compare reserved memory map with other map.
>
>You still didn't describe your use case. What is the problem your patches
>are trying to solve? Why is it important to know what is the use of particular
>reserved region? 
>
>You propose complex mechanism that seems to fit very particular scenario
>and sprinkle some calls to this mechanism at random places because you need
>to "compare reserved memory map with other map".
>
>Does not sound convincing to me, sorry.

As I said serveral times, I want a simple knob showing all reserved memory status.
The current debugfs, device tree do not show all those information I want. I think you also know that.
 i.e. late freed pages, splited or merged memblock, address defined at boot time, kernel size, ETC. 

Anyway I think I touched too many points to do this. Let me drop this.

>
>> Thank you
>> Jaewon Kim
>
>-- 
>Sincerely yours,
>Mike.
>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/8] memblock: introduce memsize showing reserved memory
  2022-03-29  2:46             ` Jaewon Kim
@ 2022-03-30  7:08               ` Mike Rapoport
       [not found]               ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p8>
  1 sibling, 0 replies; 17+ messages in thread
From: Mike Rapoport @ 2022-03-30  7:08 UTC (permalink / raw)
  To: Jaewon Kim
  Cc: vbabka, akpm, linux-mm, linux-kernel, YongTaek Lee, jaewon31.kim

Hi,

On Tue, Mar 29, 2022 at 11:46:20AM +0900, Jaewon Kim wrote:
> >> > 
> >> >I'm still not following. The reserved region sizes are available in the
> >> >existing memblock debugfs.
> >> >Why the names are important? What is the value of having names for *some*
> >> >of the reserved regions?
> >> 
> >> Hi
> >> 
> >> There are many memory regions in memblock debugfs memory/reserved, and some might
> >> be splited or merged with other region. Among regions in debugfs, we can't find 
> >> the one we defined in device tree. Especially it is difficult to find the region we
> >> described size only without start address.
> >> 
> >> On mobile environment, memory is used by not only CPU but also GPU, Camera, Secure
> >> world, Audio, ETC. To support them, there are many reserved regions described in
> >> device tree. So the name is quite important to recognize a region. And with thename
> >> we can compare reserved memory map with other map.
> >
> >You still didn't describe your use case. What is the problem your patches
> >are trying to solve? Why is it important to know what is the use of particular
> >reserved region? 
> >
> >You propose complex mechanism that seems to fit very particular scenario
> >and sprinkle some calls to this mechanism at random places because you need
> >to "compare reserved memory map with other map".
> >
> >Does not sound convincing to me, sorry.
> 
> As I said serveral times, I want a simple knob showing all reserved
> memory status.  The current debugfs, device tree do not show all those
> information I want. I think you also know that.  i.e. late freed pages,
> splited or merged memblock, address defined at boot time, kernel size,
> ETC. 

I know that there is not much information about reserved memory exposed and
I understand *what* are you trying to achieve. But you never provided
details about *why* you want this information exposed.

I don't mind providing more visibility into reserved memory attributes in
general, but I'd like to see something way more simple and localized.

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* RE: [PATCH 0/8] memblock: introduce memsize showing reserved memory
       [not found]               ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p8>
@ 2022-03-30  7:22                 ` Jaewon Kim
  0 siblings, 0 replies; 17+ messages in thread
From: Jaewon Kim @ 2022-03-30  7:22 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: vbabka, akpm, linux-mm, linux-kernel, YongTaek Lee, jaewon31.kim

>Hi,
>
>On Tue, Mar 29, 2022 at 11:46:20AM +0900, Jaewon Kim wrote:
>> >> > 
>> >> >I'm still not following. The reserved region sizes are available in the
>> >> >existing memblock debugfs.
>> >> >Why the names are important? What is the value of having names for *some*
>> >> >of the reserved regions?
>> >> 
>> >> Hi
>> >> 
>> >> There are many memory regions in memblock debugfs memory/reserved, and some might
>> >> be splited or merged with other region. Among regions in debugfs, we can't find 
>> >> the one we defined in device tree. Especially it is difficult to find the region we
>> >> described size only without start address.
>> >> 
>> >> On mobile environment, memory is used by not only CPU but also GPU, Camera, Secure
>> >> world, Audio, ETC. To support them, there are many reserved regions described in
>> >> device tree. So the name is quite important to recognize a region. And with thename
>> >> we can compare reserved memory map with other map.
>> >
>> >You still didn't describe your use case. What is the problem your patches
>> >are trying to solve? Why is it important to know what is the use of particular
>> >reserved region? 
>> >
>> >You propose complex mechanism that seems to fit very particular scenario
>> >and sprinkle some calls to this mechanism at random places because you need
>> >to "compare reserved memory map with other map".
>> >
>> >Does not sound convincing to me, sorry.
>> 
>> As I said serveral times, I want a simple knob showing all reserved
>> memory status.  The current debugfs, device tree do not show all those
>> information I want. I think you also know that.  i.e. late freed pages,
>> splited or merged memblock, address defined at boot time, kernel size,
>> ETC. 
>
>I know that there is not much information about reserved memory exposed and
>I understand *what* are you trying to achieve. But you never provided
>details about *why* you want this information exposed.
>
>I don't mind providing more visibility into reserved memory attributes in
>general, but I'd like to see something way more simple and localized.
>

I think the "what" is same as "why".
I want to look at all reservced memory status simply in a knob.

I also want to make in more simple and localized way, but there seems be
several ways to change reserved memory such as cmdline way, freeing after
boot, etc. I wanted to cover all those things.

That's OK. I hope someone later to try this again to show all the info.

>-- 
>Sincerely yours,
>Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2022-03-30  7:22 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcas1p4.samsung.com>
2022-03-24  7:01 ` [PATCH 0/8] memblock: introduce memsize showing reserved memory Jaewon Kim
     [not found]   ` <CGME20220324065919epcas1p35bafcd9151cf0469e4e933250c491a88@epcas1p3.samsung.com>
2022-03-24  7:01     ` [PATCH 1/8] " Jaewon Kim
     [not found]   ` <CGME20220324065919epcas1p1b30eabc8bbe01da1ef90280b6ee8bcea@epcas1p1.samsung.com>
2022-03-24  7:01     ` [PATCH 2/8] memblock: detect hidden memory hole size Jaewon Kim
     [not found]   ` <CGME20220324065919epcas1p3429ec2c9595c54ffe4ee25f273febd1c@epcas1p3.samsung.com>
2022-03-24  7:01     ` [PATCH 3/8] memblock: handle overlapped reserved memory region Jaewon Kim
     [not found]   ` <CGME20220324065919epcas1p256ff799f37a765a432475808e708d639@epcas1p2.samsung.com>
2022-03-24  7:01     ` [PATCH 4/8] memblock: track memblock changed at early param Jaewon Kim
     [not found]   ` <CGME20220324065919epcas1p3a3a267c4348be4fd3bb8437d4e6db142@epcas1p3.samsung.com>
2022-03-24  7:01     ` [PATCH 5/8] memblock: track kernel size on memsize Jaewon Kim
     [not found]   ` <CGME20220324065919epcas1p1058e2841b009d8c7d683bc0408f8a5a4@epcas1p1.samsung.com>
2022-03-24  7:01     ` [PATCH 6/8] memblock: recognize late free by checking PageReserved Jaewon Kim
     [not found]   ` <CGME20220324065919epcas1p4b935c884aa3fde0917f6dff8bff128ed@epcas1p4.samsung.com>
2022-03-24  7:01     ` [PATCH 7/8] memblock: print memsize summary information Jaewon Kim
     [not found]   ` <CGME20220324065919epcas1p46b5381b1b839d7076673c23e8f9b0bba@epcas1p4.samsung.com>
2022-03-24  7:01     ` [PATCH 8/8] memblock: print kernel internal size Jaewon Kim
2022-03-25  7:46   ` [PATCH 0/8] memblock: introduce memsize showing reserved memory Mike Rapoport
     [not found]   ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p3>
2022-03-25  8:38     ` Jaewon Kim
2022-03-27  7:40       ` Mike Rapoport
     [not found]       ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p1>
2022-03-27 13:53         ` Jaewon Kim
2022-03-27 15:15           ` Mike Rapoport
     [not found]           ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p7>
2022-03-29  2:46             ` Jaewon Kim
2022-03-30  7:08               ` Mike Rapoport
     [not found]               ` <CGME20220324065919epcas1p4c79da5f6ec4fa0311409ca24a38785d8@epcms1p8>
2022-03-30  7:22                 ` Jaewon Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).