ref: a6e3c9fd83e72e5c911e83f763e77ab6605a17d2
parent: 00161ca7fcd1422bfede7b50776fbf2f871e67c9
author: cinap_lenrek <cinap_lenrek@localhost>
date: Fri Aug 26 00:47:34 EDT 2011
calculate the real number of pages used by segments and use it for killbig and proc
--- a/sys/man/3/proc
+++ b/sys/man/3/proc
@@ -132,8 +132,7 @@
.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
--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -863,14 +863,15 @@
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);
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -167,6 +167,7 @@
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);
--- a/sys/src/9/port/proc.c
+++ b/sys/src/9/port/proc.c
@@ -1507,8 +1507,10 @@
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;
--- a/sys/src/9/port/segment.c
+++ b/sys/src/9/port/segment.c
@@ -513,6 +513,27 @@
/*
* 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)
{