]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
CLI: show memory also displays cold pages
authorMaria Matejka <mq@ucw.cz>
Fri, 15 Nov 2024 07:20:17 +0000 (08:20 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Tue, 3 Dec 2024 03:07:53 +0000 (04:07 +0100)
Minor changes by committer.

nest/cmds.c
sysdep/unix/alloc.c

index 09996c46c6762952f7a5897296ea390e89575eae..16862eb7bcbfacbc41791737f7782cd8c2f25d89 100644 (file)
@@ -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, "");
 }
 
index 2117d919df74c6d157cf7539f20c640942cb529a..7f0aabd461631e9ca8b1b7871acde82d96c04c3d 100644 (file)
@@ -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; i<ep->pos; i++)
       RDUMP("    %p\n", ep->pages[i]);
   }
+  RDUMP("This request: %p\n", dreq);
 #endif
 }