High watermark memory usage feature
This commit is contained in:
parent
2bf8bfe126
commit
4bae163d37
6 changed files with 34 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue