High watermark memory usage feature

This commit is contained in:
Ben Gras 2005-10-18 17:21:11 +00:00
parent 2bf8bfe126
commit 4bae163d37
6 changed files with 34 additions and 17 deletions

View file

@ -13,4 +13,4 @@ install::
cpdir . $(INC) cpdir . $(INC)
@chown -R bin $(INC) @chown -R bin $(INC)
@rm -f $(INC)/Makefile @rm -f $(INC)/Makefile
if [ -f $(MKHEADERS) ] ; then sh $(MKHEADERS) ; fi # if [ -f $(MKHEADERS) ] ; then sh $(MKHEADERS) ; fi

View file

@ -54,6 +54,12 @@ struct hole {
phys_clicks h_len; /* how big is the 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 #define phys_cp_req vir_cp_req
struct vir_cp_req { struct vir_cp_req {
struct vir_addr src; struct vir_addr src;

View file

@ -104,33 +104,36 @@ PUBLIC void sigaction_dmp()
*===========================================================================*/ *===========================================================================*/
PUBLIC void holes_dmp(void) PUBLIC void holes_dmp(void)
{ {
static struct hole holes[_NR_HOLES]; static struct pm_mem_info pmi;
int h; int h;
int largest_bytes = 0, total_bytes = 0; 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"); printf("Obtaining memory hole list failed.\n");
return; return;
} }
printf("Available memory stats\n"); printf("Available memory stats\n");
for(h = 0; h < _NR_HOLES; h++) { 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; int bytes;
bytes = (holes[h].h_len << CLICK_SHIFT); bytes = (pmi.pmi_holes[h].h_len << CLICK_SHIFT);
printf("%08lx: %6d kB\n", 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; if(bytes > largest_bytes) largest_bytes = bytes;
total_bytes += bytes; total_bytes += bytes;
} }
} }
printf("\nTotal memory free: %d kB\n" printf("\n"
"Largest contiguous chunk: %d kB\n" "Total memory free: %7d kB\n"
"Uncontiguous rest: %d kB (%d%% of total free)\n", "Largest chunk: %7d kB\n"
"Uncontiguous rest: %7d kB (%d%% of total free)\n"
"Memory high watermark: %7d kB\n",
total_bytes/1024, total_bytes/1024,
largest_bytes/1024, largest_bytes/1024,
(total_bytes-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; return;
} }

View file

@ -32,6 +32,7 @@
#define NIL_HOLE (struct hole *) 0 #define NIL_HOLE (struct hole *) 0
PRIVATE struct hole hole[_NR_HOLES]; PRIVATE struct hole hole[_NR_HOLES];
PRIVATE u32_t high_watermark = 0;
PRIVATE struct hole *hole_head; /* pointer to first hole */ PRIVATE struct hole *hole_head; /* pointer to first hole */
PRIVATE struct hole *free_slots;/* ptr to list of unused table slots */ 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_base += clicks; /* bite a piece off */
hp->h_len -= clicks; /* ditto */ 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. */ /* Delete the hole if used up completely. */
if (hp->h_len == 0) del_slot(prev_ptr, hp); if (hp->h_len == 0) del_slot(prev_ptr, hp);
@ -253,11 +258,12 @@ phys_clicks *free; /* memory size summaries */
/*===========================================================================* /*===========================================================================*
* mem_holes_copy * * 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; if(*bytes < sizeof(hole)) return ENOSPC;
memcpy(holecopies, hole, sizeof(hole)); memcpy(holecopies, hole, sizeof(hole));
*bytes = sizeof(hole); *bytes = sizeof(hole);
*hi = high_watermark;
return OK; return OK;
} }

View file

@ -60,7 +60,7 @@ PUBLIC int do_getsysinfo()
vir_bytes src_addr, dst_addr; vir_bytes src_addr, dst_addr;
struct kinfo kinfo; struct kinfo kinfo;
size_t len; size_t len;
static struct hole holes[_NR_HOLES]; static struct pm_mem_info pmi;
int s, r; int s, r;
size_t holesize; size_t holesize;
@ -80,10 +80,12 @@ PUBLIC int do_getsysinfo()
len = sizeof(struct mproc) * NR_PROCS; len = sizeof(struct mproc) * NR_PROCS;
break; break;
case SI_MEM_ALLOC: case SI_MEM_ALLOC:
holesize = sizeof(holes); holesize = sizeof(pmi.pmi_holes);
if((r=mem_holes_copy(holes, &holesize)) != OK) return r; if((r=mem_holes_copy(pmi.pmi_holes, &holesize,
src_addr = (vir_bytes) holes; &pmi.pmi_hi_watermark)) != OK)
len = holesize; return r;
src_addr = (vir_bytes) &pmi;
len = sizeof(pmi);
break; break;
default: default:
return(EINVAL); return(EINVAL);

View file

@ -20,7 +20,7 @@ _PROTOTYPE( void swap_inqueue, (struct mproc *rmp) );
#define swap_in() ((void)0) #define swap_in() ((void)0)
#define swap_inqueue(rmp) ((void)0) #define swap_inqueue(rmp) ((void)0)
#endif /* !SWAP */ #endif /* !SWAP */
_PROTOTYPE(int mem_holes_copy, (struct hole *, size_t *) ); _PROTOTYPE(int mem_holes_copy, (struct hole *, size_t *, u32_t *) );
/* break.c */ /* break.c */
_PROTOTYPE( int adjust, (struct mproc *rmp, _PROTOTYPE( int adjust, (struct mproc *rmp,