From abd0b53e0a36455873c51c9699b545b09caa9e58 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 13 Oct 2005 12:48:43 +0000 Subject: [PATCH] PM: added possibility to copy hole list from alloc.c to outside, for misc.c to copy it away by getsysinfo IS: prints out hole list + stats such as largest contiguous chunk --- servers/is/dmp.c | 5 +++-- servers/is/dmp_pm.c | 38 ++++++++++++++++++++++++++++++++++++++ servers/is/is.c | 4 ++-- servers/is/proto.h | 1 + servers/pm/alloc.c | 30 ++++++++++++++++++++++-------- servers/pm/misc.c | 12 +++++++++++- servers/pm/proto.h | 1 + 7 files changed, 78 insertions(+), 13 deletions(-) diff --git a/servers/is/dmp.c b/servers/is/dmp.c index 21f34813f..5fe7cdd7c 100644 --- a/servers/is/dmp.c +++ b/servers/is/dmp.c @@ -9,7 +9,7 @@ #include "is.h" -#define NHOOKS 17 +#define NHOOKS 18 struct hook_entry { int key; @@ -33,6 +33,7 @@ struct hook_entry { { SF4, dtab_dmp, "Device/Driver mapping" }, { SF5, mapping_dmp, "Print key mappings" }, { SF6, rproc_dmp, "Reincarnation server process table" }, + { SF7, holes_dmp, "Memory free list" }, }; /*===========================================================================* @@ -53,7 +54,7 @@ PUBLIC int do_fkey_pressed(message *m) if (OK != (s=sendrec(TTY_PROC_NR, m))) report("IS", "warning, sendrec to TTY failed", s); - /* Now check which keys were pressed: F1-F12. */ + /* Now check which keys were pressed: F1-F12, SF1-SF12. */ for(h = 0; h < NHOOKS; h++) if(pressed(hooks[h].key)) hooks[h].function(); diff --git a/servers/is/dmp_pm.c b/servers/is/dmp_pm.c index 596ef7f29..4cfe479bb 100644 --- a/servers/is/dmp_pm.c +++ b/servers/is/dmp_pm.c @@ -10,6 +10,8 @@ #include "is.h" #include "../pm/mproc.h" #include +#include +#include PUBLIC struct mproc mproc[NR_PROCS]; @@ -97,3 +99,39 @@ PUBLIC void sigaction_dmp() prev_i = i; } +/*===========================================================================* + * holes_dmp * + *===========================================================================*/ +PUBLIC void holes_dmp(void) +{ + static struct hole holes[_NR_HOLES]; + int h; + int largest_bytes = 0, total_bytes = 0; + + if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, holes) != OK) { + printf("Obtaining memory hole list failed.\n"); + return; + } + printf("Available memory stats\n"); + + for(h = 0; h < _NR_HOLES; h++) { + if(holes[h].h_base && holes[h].h_len) { + int bytes; + bytes = (holes[h].h_len << CLICK_SHIFT); + printf("%08lx: %6d kB\n", + holes[h].h_base << CLICK_SHIFT, bytes / 1024); + if(bytes > largest_bytes) largest_bytes = bytes; + total_bytes += bytes; + } + } + printf("\nTotal memory free: %d kB\n" + "Largest contiguous chunk: %d kB\n" + "Uncontiguous rest: %d kB (%d%% of total free)\n", + total_bytes/1024, + largest_bytes/1024, + (total_bytes-largest_bytes)/1024, + 100*(total_bytes/100-largest_bytes/100)/total_bytes); + + return; +} + diff --git a/servers/is/is.c b/servers/is/is.c index 087c326df..e65d54c00 100644 --- a/servers/is/is.c +++ b/servers/is/is.c @@ -97,7 +97,7 @@ PRIVATE void init_server(int argc, char **argv) /* Set key mappings. IS takes all of F1-F12 and Shift+F1-F6. */ fkeys = sfkeys = 0; for (i=1; i<=12; i++) bit_set(fkeys, i); - for (i=1; i<= 6; i++) bit_set(sfkeys, i); + for (i=1; i<= 7; i++) bit_set(sfkeys, i); if ((s=fkey_map(&fkeys, &sfkeys)) != OK) report("IS", "warning, fkey_map failed:", s); } @@ -116,7 +116,7 @@ PRIVATE void exit_server() */ fkeys = sfkeys = 0; for (i=1; i<=12; i++) bit_set(fkeys, i); - for (i=1; i<= 6; i++) bit_set(sfkeys, i); + for (i=1; i<= 7; i++) bit_set(sfkeys, i); if ((s=fkey_unmap(&fkeys, &sfkeys)) != OK) report("IS", "warning, unfkey_map failed:", s); diff --git a/servers/is/proto.h b/servers/is/proto.h index 43f15cb69..a464a4b68 100644 --- a/servers/is/proto.h +++ b/servers/is/proto.h @@ -24,6 +24,7 @@ _PROTOTYPE( void timing_dmp, (void) ); /* dmp_pm.c */ _PROTOTYPE( void mproc_dmp, (void) ); _PROTOTYPE( void sigaction_dmp, (void) ); +_PROTOTYPE( void holes_dmp, (void) ); /* dmp_fs.c */ _PROTOTYPE( void dtab_dmp, (void) ); diff --git a/servers/pm/alloc.c b/servers/pm/alloc.c index edb8e8fcf..0cc9e1fae 100644 --- a/servers/pm/alloc.c +++ b/servers/pm/alloc.c @@ -13,26 +13,25 @@ * free_mem: release a previously allocated chunk of memory * mem_init: initialize the tables when PM start up * max_hole: returns the largest hole currently available + * mem_holes_copy: for outsiders who want a copy of the hole-list */ #include "pm.h" #include #include +#include +#include #include #include +#include #include "mproc.h" #include "../../kernel/const.h" #include "../../kernel/config.h" #include "../../kernel/type.h" -#define NR_HOLES (2*NR_PROCS) /* max # entries in hole table */ #define NIL_HOLE (struct hole *) 0 -PRIVATE struct hole { - struct hole *h_next; /* pointer to next entry on the list */ - phys_clicks h_base; /* where does the hole begin? */ - phys_clicks h_len; /* how big is the hole? */ -} hole[NR_HOLES]; +PRIVATE struct hole hole[_NR_HOLES]; PRIVATE struct hole *hole_head; /* pointer to first hole */ PRIVATE struct hole *free_slots;/* ptr to list of unused table slots */ @@ -161,6 +160,7 @@ register struct hole *hp; prev_ptr->h_next = hp->h_next; hp->h_next = free_slots; + hp->h_base = hp->h_len = 0; free_slots = hp; } @@ -218,8 +218,11 @@ phys_clicks *free; /* memory size summaries */ register struct hole *hp; /* Put all holes on the free list. */ - for (hp = &hole[0]; hp < &hole[NR_HOLES]; hp++) hp->h_next = hp + 1; - hole[NR_HOLES-1].h_next = NIL_HOLE; + for (hp = &hole[0]; hp < &hole[_NR_HOLES]; hp++) { + hp->h_next = hp + 1; + hp->h_base = hp->h_len = 0; + } + hole[_NR_HOLES-1].h_next = NIL_HOLE; hole_head = NIL_HOLE; free_slots = &hole[0]; @@ -247,6 +250,17 @@ phys_clicks *free; /* memory size summaries */ #endif } +/*===========================================================================* + * mem_holes_copy * + *===========================================================================*/ +PUBLIC int mem_holes_copy(struct hole *holecopies, size_t *bytes) +{ + if(*bytes < sizeof(hole)) return ENOSPC; + memcpy(holecopies, hole, sizeof(hole)); + *bytes = sizeof(hole); + return OK; +} + #if ENABLE_SWAP /*===========================================================================* * swap_on * diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 0364e5975..897fe8d1d 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include "mproc.h" #include "param.h" @@ -58,7 +60,9 @@ PUBLIC int do_getsysinfo() vir_bytes src_addr, dst_addr; struct kinfo kinfo; size_t len; - int s; + static struct hole holes[_NR_HOLES]; + int s, r; + size_t holesize; switch(m_in.info_what) { case SI_KINFO: /* kernel info is obtained via PM */ @@ -75,6 +79,12 @@ PUBLIC int do_getsysinfo() src_addr = (vir_bytes) mproc; len = sizeof(struct mproc) * NR_PROCS; break; + case SI_MEM_ALLOC: + holesize = sizeof(holes); + if((r=mem_holes_copy(holes, &holesize)) != OK) return r; + src_addr = (vir_bytes) holes; + len = holesize; + break; default: return(EINVAL); } diff --git a/servers/pm/proto.h b/servers/pm/proto.h index 49a1e4dd2..bd358ea09 100644 --- a/servers/pm/proto.h +++ b/servers/pm/proto.h @@ -20,6 +20,7 @@ _PROTOTYPE( void swap_inqueue, (struct mproc *rmp) ); #define swap_in() ((void)0) #define swap_inqueue(rmp) ((void)0) #endif /* !SWAP */ +_PROTOTYPE(int mem_holes_copy, (struct hole *, size_t *) ); /* break.c */ _PROTOTYPE( int adjust, (struct mproc *rmp,