calculate the real number of pages used by segments and use it for killbig and proc

This commit is contained in:
cinap_lenrek 2011-08-26 04:47:34 +02:00
parent 00161ca7fc
commit a6e3c9fd83
5 changed files with 34 additions and 10 deletions

View file

@ -132,8 +132,7 @@ the six 11-character numbers also held in the process's
.B #c/cputime
file
.IP \-
the amount of memory used by the process, except its stack,
in units of 1024 bytes
the amount of memory used by the process in units of 1024 bytes
.IP \-
the base and current scheduling priority, each 11 character numbers
.PP

View file

@ -863,14 +863,15 @@ procread(Chan *c, void *va, long n, vlong off)
l = TK2MS(l);
readnum(0, statbuf+j+NUMSIZE*i, NUMSIZE, l, NUMSIZE);
}
/* ignore stack, which is mostly non-existent */
l = 0;
for(i=1; i<NSEG; i++){
s = p->seg[i];
if(s)
l += s->top - s->base;
for(i=0; i<NSEG; i++){
if(s = p->seg[i]){
eqlock(&s->lk);
l += mcountseg(s);
qunlock(&s->lk);
}
}
readnum(0, statbuf+j+NUMSIZE*6, NUMSIZE, l>>10, NUMSIZE);
readnum(0, statbuf+j+NUMSIZE*6, NUMSIZE, l*BY2PG/1024, NUMSIZE);
readnum(0, statbuf+j+NUMSIZE*7, NUMSIZE, p->basepri, NUMSIZE);
readnum(0, statbuf+j+NUMSIZE*8, NUMSIZE, p->priority, NUMSIZE);
memmove(a, statbuf+offset, n);

View file

@ -167,6 +167,7 @@ void* malloc(ulong);
void* mallocalign(ulong, ulong, long, ulong);
void mallocsummary(void);
Block* mem2bl(uchar*, int);
int mcountseg(Segment*);
void mfreeseg(Segment*, ulong, int);
void microdelay(int);
uvlong mk64fract(uvlong, uvlong);

View file

@ -1507,8 +1507,10 @@ killbig(char *why)
l = 0;
for(i=1; i<NSEG; i++) {
s = p->seg[i];
if(s != 0)
l += s->top - s->base;
if(s == 0 || !canqlock(&s->lk))
continue;
l += (ulong)mcountseg(s);
qunlock(&s->lk);
}
if(l > max && ((p->procmode&0222) || strcmp(eve, p->user)!=0)) {
kp = p;

View file

@ -510,6 +510,27 @@ ibrk(ulong addr, int seg)
return 0;
}
/*
* called with s->lk locked
*/
int
mcountseg(Segment *s)
{
int i, j, pages;
Page **map;
pages = 0;
for(i = 0; i < s->mapsize; i++){
if(s->map[i] == 0)
continue;
map = s->map[i]->pages;
for(j = 0; j < PTEPERTAB; j++)
if(map[j])
pages++;
}
return pages;
}
/*
* called with s->lk locked
*/