[Intel-gfx] [PATCH v6 55/57] dyndbg: dynamic_debug_sites_reclaim() using free_reserved_page() WAG

Jim Cromie
2022-09-04T21:49:37Z

STATUS:

broken with some over-free, punt and comment out late_initcall

Implement dymamic_debug_sites_reclaim(as a late_initcall) to free the
tail~47% of the builtin __dyndbg_sites[] vector back to the buddy
allocator. Code is copied from mm/init.c:free_initmem(), wo the
poisoning. Comments cargo culted wo grokking.

v3pr_info:

dyndbg: freeing range: ffffea00000c5500-ffffea00000c5700, ffffffff83154668-ffffffff8315c480
dyndbg: ie range: ffffea00000c5500-ffffea00000c5700, ffffffff83154000-ffffffff8315c000
dyndbg: freeing page: ffffea00000c5540, ffffffff83155000
dyndbg: freeing page: ffffea00000c5580, ffffffff83156000
dyndbg: freeing page: ffffea00000c55c0, ffffffff83157000
dyndbg: freeing page: ffffea00000c5600, ffffffff83158000
dyndbg: freeing page: ffffea00000c5640, ffffffff83159000
dyndbg: freeing page: ffffea00000c5680, ffffffff8315a000
dyndbg: freeing page: ffffea00000c56c0, ffffffff8315b000

Presuming those are 4k pages, 28kb is reclaimed, which is reasonably
consistent with the numbers below; 1532/2761 compresson of 64KiB.

I have fixed one edge-case over-free, which gave me a coredump on
```cat control```, there may be (one) other.

dyndbg: 2762 prdebugs in 235 modules, 11 KiB in ddebug tables, 86 KiB \
in __dyndbg section, 64 KiB in __dyndbg_sites section

CC: david@redhat.com # free_reserved_page() tip
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
lib/dynamic_debug.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 0a68fbfd8432..194367bc13fb 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -1542,6 +1542,7 @@ static int __init dynamic_debug_init_control(void)
fs_initcall(dynamic_debug_init_control);

static struct _ddebug_info builtin_state;
+static __initdata struct _ddebug_site *last_site;

static int __init dynamic_debug_init(void)
{
@@ -1622,11 +1623,12 @@ static int __init dynamic_debug_init(void)
if (ret)
goto out_err;

+ last_site = &__start___dyndbg_sites[site_base];
ddebug_init_success = 1;

- vpr_info("%d prdebugs in %d modules, %d KiB in ddebug tables, %d kiB in __dyndbg section\n",
- i, mod_ct, (int)((mod_ct * sizeof(struct ddebug_table)) >> 10),
- (int)((i * sizeof(struct _ddebug)) >> 10));
+ vpr_info("%d prdebugs in %d functions, %d modules, %d KiB in ddebug tables, %d,%d kiB in __dyndbg,_sites sections\n",
+ i, site_base, mod_ct, (int)((mod_ct * sizeof(struct ddebug_table)) >> 10),
+ (int)((i * sizeof(struct _ddebug)) >> 10), (int)((site_base * sizeof(struct _ddebug_site)) >> 10));

if (di.num_classes)
v2pr_info(" %d builtin ddebug class-maps\n", di.num_classes);
@@ -1652,3 +1654,40 @@ static int __init dynamic_debug_init(void)
/* Allow early initialization for boot messages via boot param */
early_initcall(dynamic_debug_init);

+static int __init dynamic_debug_sites_reclaim(void)
+{
+ unsigned long addr, end, start;
+ /*
+ * from mm/init.c:free_initmem (void) wo poisoning
+ * The init section is aligned to 8k in vmlinux.lds.
+ * Page align for >8k pagesizes.
+ */
+ start = (unsigned long)__start___dyndbg_sites;
+ end = (unsigned long)__stop___dyndbg_sites;
+ addr = (unsigned long)last_site;
+
+ vpr_info("full range: %px-%px, %lx-%lx\n",
+ virt_to_page(start), virt_to_page(end), start, end);
+
+ vpr_info("freeing range: %px-%px, %lx-%lx\n",
+ virt_to_page(addr), virt_to_page(end), addr, end);
+
+ addr &= PAGE_MASK;
+ addr += PAGE_SIZE;
+ end &= PAGE_MASK;
+ end += PAGE_SIZE;
+
+ vpr_info("ie range: %px-%px, %lx-%lx\n",
+ virt_to_page(addr), virt_to_page(end), addr, end);
+
+ if (verbose < 2) {
+ vpr_info(" skipping reclaim cuz its broken by `cat control`\n");
+ return 0;
+ }
+ for (; addr < end; addr += PAGE_SIZE) {
+ vpr_info("freeing page: %px, %lx\n", virt_to_page(addr), addr);
+ free_reserved_page(virt_to_page(addr));
+ }
+ return 0;
+}
+//late_initcall(dynamic_debug_sites_reclaim);
--
2.37.2