From 2ab3f22e4a7ff9c566b38a9075620bdd61fef6b0 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 15 Nov 2024 08:20:17 +0100 Subject: [PATCH 1/2] CLI: show memory also displays cold pages Minor changes by committer. --- nest/cmds.c | 17 +++++++++++++++-- sysdep/unix/alloc.c | 12 ++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/nest/cmds.c b/nest/cmds.c index 09996c46..16862eb7 100644 --- a/nest/cmds.c +++ b/nest/cmds.c @@ -111,6 +111,7 @@ print_size(char *dsc, struct resmem vals) extern pool *rt_table_pool; extern pool *rta_pool; extern uint *pages_kept; +extern uint pages_kept_cold, pages_kept_cold_index, pages_total; void cmd_show_memory(void) @@ -123,10 +124,22 @@ cmd_show_memory(void) print_size("Current config:", rmemsize(config_pool)); struct resmem total = rmemsize(&root_pool); #ifdef HAVE_MMAP - print_size("Standby memory:", (struct resmem) { .overhead = page_size * *pages_kept }); - total.overhead += page_size * *pages_kept; + uint pages_standby = *pages_kept + pages_kept_cold_index; + print_size("Standby memory:", (struct resmem) { .overhead = page_size * pages_standby }); + total.overhead += page_size * pages_standby; #endif print_size("Total:", total); + cli_msg(-1018, ""); + + uint pages_active = pages_total - *pages_kept - pages_kept_cold; + struct size_args active = get_size_args(page_size * pages_active); + struct size_args kept = get_size_args(page_size * *pages_kept); + struct size_args cold = get_size_args(page_size * pages_kept_cold); + + cli_msg(-1018, "%-17s " SIZE_FORMAT, "Active pages:", SIZE_ARGS(active)); + cli_msg(-1018, "%-17s " SIZE_FORMAT, "Kept free pages:", SIZE_ARGS(kept)); + cli_msg(-1018, "%-17s " SIZE_FORMAT, "Cold free pages:", SIZE_ARGS(cold)); + cli_msg(0, ""); } diff --git a/sysdep/unix/alloc.c b/sysdep/unix/alloc.c index 2117d919..7f0aabd4 100644 --- a/sysdep/unix/alloc.c +++ b/sysdep/unix/alloc.c @@ -74,10 +74,13 @@ static struct free_pages global_free_pages = { }; uint *pages_kept = &global_free_pages.cnt; +uint pages_kept_cold, pages_kept_cold_index, pages_total; static void * alloc_sys_page(void) { + pages_total++; + void *ptr = mmap(NULL, page_size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ptr == MAP_FAILED) @@ -98,6 +101,7 @@ alloc_page(void) /* If the system page allocator is goofy, we use posix_memalign to get aligned blocks of memory. */ if (use_fake) { + pages_total++; void *ptr = NULL; int err = posix_memalign(&ptr, page_size, page_size); @@ -138,9 +142,13 @@ alloc_cold_page(void) /* Either the keeper page contains at least one cold page pointer, return that */ if (ep->pos) + { + pages_kept_cold--; return ep->pages[--ep->pos]; + } /* Or the keeper page has no more cold page pointer, return the keeper page */ + pages_kept_cold_index--; rem_node(&ep->n); return ep; } @@ -156,6 +164,7 @@ free_page(void *ptr) /* If the system page allocator is goofy, we just free the block and care no more. */ if (use_fake) { + pages_total--; free(ptr); return; } @@ -202,11 +211,13 @@ global_free_pages_cleanup_event(void *data UNUSED) ep = (struct empty_pages *) fp; *ep = (struct empty_pages) {}; add_head(&fps->empty, &ep->n); + pages_kept_cold_index++; } else { /* We store this block as a pointer into the first free place * and tell the OS that the underlying memory is trash. */ + pages_kept_cold++; ep->pages[ep->pos++] = fp; if (madvise(fp, page_size, #ifdef CONFIG_MADV_DONTNEED_TO_FREE @@ -243,6 +254,7 @@ page_dump(struct dump_request *dreq) for (uint i=0; ipos; i++) RDUMP(" %p\n", ep->pages[i]); } + RDUMP("This request: %p\n", dreq); #endif } From 707cad6188313bc289ced5eaac44f10a9e056d13 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Tue, 3 Dec 2024 10:57:10 +0100 Subject: [PATCH 2/2] CLI: Dumping forces new file creation instead of truncating. --- doc/bird.sgml | 11 ++++++----- sysdep/unix/io.c | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/bird.sgml b/doc/bird.sgml index 5393edb2..5bed6df3 100644 --- a/doc/bird.sgml +++ b/doc/bird.sgml @@ -1455,11 +1455,12 @@ This argument can be omitted if there exists only a single instance. Control protocol debugging.