From: Ben Gras Date: Tue, 18 Oct 2005 17:21:11 +0000 (+0000) Subject: High watermark memory usage feature X-Git-Tag: v3.1.2a~611 X-Git-Url: http://zhaoyanbai.com/repos/%22/xml/v3/mem/static/gitweb.js?a=commitdiff_plain;h=4bae163d377a768d3724ce063d5cc00ec982c50e;p=minix.git High watermark memory usage feature --- diff --git a/include/Makefile b/include/Makefile index 78a5d2447..dcd8c1161 100644 --- a/include/Makefile +++ b/include/Makefile @@ -13,4 +13,4 @@ install:: cpdir . $(INC) @chown -R bin $(INC) @rm -f $(INC)/Makefile - if [ -f $(MKHEADERS) ] ; then sh $(MKHEADERS) ; fi +# if [ -f $(MKHEADERS) ] ; then sh $(MKHEADERS) ; fi diff --git a/include/minix/type.h b/include/minix/type.h index 4760de0c0..b5456ddd1 100755 --- a/include/minix/type.h +++ b/include/minix/type.h @@ -54,6 +54,12 @@ struct hole { phys_clicks h_len; /* how big is the hole? */ }; +/* Memory info from PM. */ +struct pm_mem_info { + struct hole pmi_holes[_NR_HOLES];/* memory (un)allocations */ + u32_t pmi_hi_watermark; /* highest ever-used click + 1 */ +}; + #define phys_cp_req vir_cp_req struct vir_cp_req { struct vir_addr src; diff --git a/servers/is/dmp_pm.c b/servers/is/dmp_pm.c index 4cfe479bb..9fd3b7f2f 100644 --- a/servers/is/dmp_pm.c +++ b/servers/is/dmp_pm.c @@ -104,33 +104,36 @@ PUBLIC void sigaction_dmp() *===========================================================================*/ PUBLIC void holes_dmp(void) { - static struct hole holes[_NR_HOLES]; + static struct pm_mem_info pmi; int h; int largest_bytes = 0, total_bytes = 0; - if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, holes) != OK) { + if(getsysinfo(PM_PROC_NR, SI_MEM_ALLOC, &pmi) != 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) { + if(pmi.pmi_holes[h].h_base && pmi.pmi_holes[h].h_len) { int bytes; - bytes = (holes[h].h_len << CLICK_SHIFT); + bytes = (pmi.pmi_holes[h].h_len << CLICK_SHIFT); printf("%08lx: %6d kB\n", - holes[h].h_base << CLICK_SHIFT, bytes / 1024); + pmi.pmi_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", + printf("\n" + "Total memory free: %7d kB\n" + "Largest chunk: %7d kB\n" + "Uncontiguous rest: %7d kB (%d%% of total free)\n" + "Memory high watermark: %7d kB\n", total_bytes/1024, largest_bytes/1024, (total_bytes-largest_bytes)/1024, - 100*(total_bytes/100-largest_bytes/100)/total_bytes); + 100*(total_bytes/100-largest_bytes/100)/total_bytes, + (pmi.pmi_hi_watermark/1024 << CLICK_SHIFT)); return; } diff --git a/servers/pm/alloc.c b/servers/pm/alloc.c index 0cc9e1fae..a40cac280 100644 --- a/servers/pm/alloc.c +++ b/servers/pm/alloc.c @@ -32,6 +32,7 @@ #define NIL_HOLE (struct hole *) 0 PRIVATE struct hole hole[_NR_HOLES]; +PRIVATE u32_t high_watermark = 0; PRIVATE struct hole *hole_head; /* pointer to first hole */ PRIVATE struct hole *free_slots;/* ptr to list of unused table slots */ @@ -79,6 +80,10 @@ phys_clicks clicks; /* amount of memory requested */ hp->h_base += clicks; /* bite a piece off */ hp->h_len -= clicks; /* ditto */ + /* Remember new high watermark of used memory. */ + if(hp->h_base > high_watermark) + high_watermark = hp->h_base; + /* Delete the hole if used up completely. */ if (hp->h_len == 0) del_slot(prev_ptr, hp); @@ -253,11 +258,12 @@ phys_clicks *free; /* memory size summaries */ /*===========================================================================* * mem_holes_copy * *===========================================================================*/ -PUBLIC int mem_holes_copy(struct hole *holecopies, size_t *bytes) +PUBLIC int mem_holes_copy(struct hole *holecopies, size_t *bytes, u32_t *hi) { if(*bytes < sizeof(hole)) return ENOSPC; memcpy(holecopies, hole, sizeof(hole)); *bytes = sizeof(hole); + *hi = high_watermark; return OK; } diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 75e509586..8e25dbdde 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -60,7 +60,7 @@ PUBLIC int do_getsysinfo() vir_bytes src_addr, dst_addr; struct kinfo kinfo; size_t len; - static struct hole holes[_NR_HOLES]; + static struct pm_mem_info pmi; int s, r; size_t holesize; @@ -80,10 +80,12 @@ PUBLIC int do_getsysinfo() 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; + holesize = sizeof(pmi.pmi_holes); + if((r=mem_holes_copy(pmi.pmi_holes, &holesize, + &pmi.pmi_hi_watermark)) != OK) + return r; + src_addr = (vir_bytes) &pmi; + len = sizeof(pmi); break; default: return(EINVAL); diff --git a/servers/pm/proto.h b/servers/pm/proto.h index bd358ea09..937bac846 100644 --- a/servers/pm/proto.h +++ b/servers/pm/proto.h @@ -20,7 +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 *) ); +_PROTOTYPE(int mem_holes_copy, (struct hole *, size_t *, u32_t *) ); /* break.c */ _PROTOTYPE( int adjust, (struct mproc *rmp,