summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@localhost>2011-08-26 04:47:34 +0200
committercinap_lenrek <cinap_lenrek@localhost>2011-08-26 04:47:34 +0200
commita6e3c9fd83e72e5c911e83f763e77ab6605a17d2 (patch)
tree7455ff570c40399e02deeac00525de1cae6cfce2 /sys
parent00161ca7fcd1422bfede7b50776fbf2f871e67c9 (diff)
calculate the real number of pages used by segments and use it for killbig and proc
Diffstat (limited to 'sys')
-rw-r--r--sys/man/3/proc3
-rw-r--r--sys/src/9/port/devproc.c13
-rw-r--r--sys/src/9/port/portfns.h1
-rw-r--r--sys/src/9/port/proc.c6
-rw-r--r--sys/src/9/port/segment.c21
5 files changed, 34 insertions, 10 deletions
diff --git a/sys/man/3/proc b/sys/man/3/proc
index d2d3b5eaf..c4c241d02 100644
--- a/sys/man/3/proc
+++ b/sys/man/3/proc
@@ -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
diff --git a/sys/src/9/port/devproc.c b/sys/src/9/port/devproc.c
index 90e0f1cbb..ec1e39a9e 100644
--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -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);
diff --git a/sys/src/9/port/portfns.h b/sys/src/9/port/portfns.h
index f8f6b809f..8c71593b6 100644
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -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);
diff --git a/sys/src/9/port/proc.c b/sys/src/9/port/proc.c
index fb7e6366a..99000a6fa 100644
--- a/sys/src/9/port/proc.c
+++ b/sys/src/9/port/proc.c
@@ -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;
diff --git a/sys/src/9/port/segment.c b/sys/src/9/port/segment.c
index 94267ae85..26a62998e 100644
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -513,6 +513,27 @@ ibrk(ulong addr, int seg)
/*
* 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
+ */
void
mfreeseg(Segment *s, ulong start, int pages)
{