diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2022-08-17 17:38:46 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2022-08-17 17:38:46 +0000 |
commit | 91f79ce9fab7c9920b6f331ca074d58c17755fc9 (patch) | |
tree | 66d35f064131f18746042a05773ca1ab61e29fa9 /sys/src | |
parent | c8e25d2a18c0395431abc5818a1d2f0561b0181f (diff) |
kernel: allocate notes in heap
de-bloat the proc structure by allocating notes
with on the heap instead of embedding them in
the proc structure.
This saves around 640 bytes per process.
Diffstat (limited to 'sys/src')
-rw-r--r-- | sys/src/9/bcm64/trap.c | 8 | ||||
-rw-r--r-- | sys/src/9/cycv/trap.c | 8 | ||||
-rw-r--r-- | sys/src/9/imx8/trap.c | 8 | ||||
-rw-r--r-- | sys/src/9/kw/syscall.c | 8 | ||||
-rw-r--r-- | sys/src/9/mtx/trap.c | 8 | ||||
-rw-r--r-- | sys/src/9/omap/syscall.c | 8 | ||||
-rw-r--r-- | sys/src/9/pc/trap.c | 8 | ||||
-rw-r--r-- | sys/src/9/pc64/trap.c | 8 | ||||
-rw-r--r-- | sys/src/9/port/devproc.c | 10 | ||||
-rw-r--r-- | sys/src/9/port/portdat.h | 4 | ||||
-rw-r--r-- | sys/src/9/port/portfns.h | 1 | ||||
-rw-r--r-- | sys/src/9/port/proc.c | 67 | ||||
-rw-r--r-- | sys/src/9/port/sysproc.c | 12 | ||||
-rw-r--r-- | sys/src/9/ppc/trap.c | 8 | ||||
-rw-r--r-- | sys/src/9/sgi/trap.c | 8 | ||||
-rw-r--r-- | sys/src/9/teg2/syscall.c | 8 | ||||
-rw-r--r-- | sys/src/9/xen/trap.c | 12 | ||||
-rw-r--r-- | sys/src/9/zynq/trap.c | 8 |
18 files changed, 117 insertions, 85 deletions
diff --git a/sys/src/9/bcm64/trap.c b/sys/src/9/bcm64/trap.c index e450139bf..a4527e9c3 100644 --- a/sys/src/9/bcm64/trap.c +++ b/sys/src/9/bcm64/trap.c @@ -384,13 +384,13 @@ noted(Ureg *ureg, ulong arg0) break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag != NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag != NDebug); } } diff --git a/sys/src/9/cycv/trap.c b/sys/src/9/cycv/trap.c index 3d2ca3b2e..2999137cf 100644 --- a/sys/src/9/cycv/trap.c +++ b/sys/src/9/cycv/trap.c @@ -395,13 +395,13 @@ noted(Ureg *ureg, ulong arg0) break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag != NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag != NDebug); } } diff --git a/sys/src/9/imx8/trap.c b/sys/src/9/imx8/trap.c index e450139bf..a4527e9c3 100644 --- a/sys/src/9/imx8/trap.c +++ b/sys/src/9/imx8/trap.c @@ -384,13 +384,13 @@ noted(Ureg *ureg, ulong arg0) break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag != NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag != NDebug); } } diff --git a/sys/src/9/kw/syscall.c b/sys/src/9/kw/syscall.c index d97aacfa5..47eb221a9 100644 --- a/sys/src/9/kw/syscall.c +++ b/sys/src/9/kw/syscall.c @@ -81,13 +81,13 @@ noted(Ureg* cur, uintptr arg0) cur->r0 = (uintptr)nf->arg0; break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /*FALLTHROUGH*/ case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag != NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag != NDebug); } } diff --git a/sys/src/9/mtx/trap.c b/sys/src/9/mtx/trap.c index 8e97dc7f6..b9f1cbf4f 100644 --- a/sys/src/9/mtx/trap.c +++ b/sys/src/9/mtx/trap.c @@ -779,13 +779,13 @@ noted(Ureg* ureg, ulong arg0) break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /* fall through */ case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag!=NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag!=NDebug); } } diff --git a/sys/src/9/omap/syscall.c b/sys/src/9/omap/syscall.c index 91e27fa5f..e31e2714d 100644 --- a/sys/src/9/omap/syscall.c +++ b/sys/src/9/omap/syscall.c @@ -81,13 +81,13 @@ noted(Ureg* cur, uintptr arg0) cur->r0 = (uintptr)nf->arg0; break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /*FALLTHROUGH*/ case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag != NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag != NDebug); } } diff --git a/sys/src/9/pc/trap.c b/sys/src/9/pc/trap.c index 92def96d8..c4b9a9470 100644 --- a/sys/src/9/pc/trap.c +++ b/sys/src/9/pc/trap.c @@ -685,14 +685,14 @@ if(0) print("%s %lud: noted %.8lux %.8lux\n", break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /* fall through */ case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag!=NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag!=NDebug); } } diff --git a/sys/src/9/pc64/trap.c b/sys/src/9/pc64/trap.c index 44379160d..646db883a 100644 --- a/sys/src/9/pc64/trap.c +++ b/sys/src/9/pc64/trap.c @@ -671,14 +671,14 @@ if(0) print("%s %lud: noted %#p %#p\n", break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /* fall through */ case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag!=NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag!=NDebug); } } diff --git a/sys/src/9/port/devproc.c b/sys/src/9/port/devproc.c index 503b00922..0d4ae5193 100644 --- a/sys/src/9/port/devproc.c +++ b/sys/src/9/port/devproc.c @@ -1138,14 +1138,18 @@ procread(Chan *c, void *va, long n, vlong off) if(p->nnote == 0) n = 0; else { - i = strlen(p->note[0].msg) + 1; + assert(p->note[0] != nil); + i = strlen(p->note[0]->msg) + 1; if(i < n) n = i; - memmove(va, p->note[0].msg, n-1); + memmove(va, p->note[0]->msg, n-1); ((char*)va)[n-1] = '\0'; + free(p->note[0]); if(--p->nnote == 0) p->notepending = 0; - memmove(p->note, p->note+1, p->nnote*sizeof(Note)); + else + memmove(&p->note[0], &p->note[1], p->nnote*sizeof(Note*)); + p->note[p->nnote] = nil; } break; diff --git a/sys/src/9/port/portdat.h b/sys/src/9/port/portdat.h index 5aaad9ada..e658346a1 100644 --- a/sys/src/9/port/portdat.h +++ b/sys/src/9/port/portdat.h @@ -745,10 +745,10 @@ struct Proc Chan *slash; Chan *dot; - Note note[NNOTE]; + Note *note[NNOTE]; short nnote; short notified; /* sysnoted is due */ - Note lastnote; + Note *lastnote; int (*notify)(void*, char*); Lock *lockwait; diff --git a/sys/src/9/port/portfns.h b/sys/src/9/port/portfns.h index 9a4f1824d..2b71625b7 100644 --- a/sys/src/9/port/portfns.h +++ b/sys/src/9/port/portfns.h @@ -121,6 +121,7 @@ void free(void*); void freeb(Block*); void freeblist(Block*); int freebroken(void); +void freenotes(Proc*); void freepages(Page*, Page*, ulong); void freepte(Segment*, Pte*); void getcolor(ulong, ulong*, ulong*, ulong*); diff --git a/sys/src/9/port/proc.c b/sys/src/9/port/proc.c index f0822f575..713e0818a 100644 --- a/sys/src/9/port/proc.c +++ b/sys/src/9/port/proc.c @@ -912,32 +912,35 @@ popnote(Ureg *u) if(up->nnote == 0) return nil; assert(up->nnote > 0); + assert(up->note[0] != nil); /* hold off user notes during note handling */ - if(up->notified && up->note[0].flag == NUser) + if(up->notified && up->note[0]->flag == NUser) return nil; - memmove(&up->lastnote, &up->note[0], sizeof(Note)); - if(--up->nnote) - memmove(&up->note[0], &up->note[1], up->nnote*sizeof(Note)); + free(up->lastnote); + up->lastnote = up->note[0]; + if(--up->nnote > 0) + memmove(&up->note[0], &up->note[1], up->nnote*sizeof(Note*)); + up->note[up->nnote] = nil; - if(u != nil && strncmp(up->lastnote.msg, "sys:", 4) == 0){ - int l = strlen(up->lastnote.msg); + if(u != nil && strncmp(up->lastnote->msg, "sys:", 4) == 0){ + int l = strlen(up->lastnote->msg); assert(l < ERRMAX); - snprint(up->lastnote.msg+l, ERRMAX-l, " pc=%#p", u->pc); + snprint(up->lastnote->msg+l, ERRMAX-l, " pc=%#p", u->pc); } if(up->notify == nil || up->notified){ qunlock(&up->debug); - if(up->lastnote.flag == NDebug){ + if(up->lastnote->flag == NDebug){ up->fpstate &= ~FPillegal; - pprint("suicide: %s\n", up->lastnote.msg); + pprint("suicide: %s\n", up->lastnote->msg); } - pexit(up->lastnote.msg, up->lastnote.flag!=NDebug); + pexit(up->lastnote->msg, up->lastnote->flag!=NDebug); } up->notified = 1; - return up->lastnote.msg; + return up->lastnote->msg; } /* @@ -948,10 +951,11 @@ popnote(Ureg *u) * lock if we can't get the r->lock and retrying. */ int -postnote(Proc *p, int dolock, char *n, int flag) +postnote(Proc *p, int dolock, char *msg, int flag) { int s, ret; QLock *q; + Note *n; if(p == nil) return 0; @@ -965,14 +969,22 @@ postnote(Proc *p, int dolock, char *n, int flag) return 0; } - if(n != nil && flag != NUser && (p->notify == nil || p->notified)) - p->nnote = 0; - ret = 0; - if(p->nnote < NNOTE && n != nil) { - kstrcpy(p->note[p->nnote].msg, n, ERRMAX); - p->note[p->nnote++].flag = flag; - ret = 1; + if(msg != nil){ + if(flag != NUser && (p->notify == nil || p->notified)) + freenotes(p); + if(p->nnote < NNOTE){ + if(flag != NUser) + n = smalloc(sizeof(Note)); + else + n = malloc(sizeof(Note)); + if(n != nil){ + kstrcpy(n->msg, msg, ERRMAX); + n->flag = flag; + p->note[p->nnote++] = n; + ret = 1; + } + } } p->notepending = 1; if(dolock) @@ -1121,6 +1133,15 @@ freebroken(void) } void +freenotes(Proc *p) +{ + while(p->nnote > 0){ + free(p->note[--p->nnote]); + up->note[p->nnote] = nil; + } +} + +void pexit(char *exitstr, int freemem) { Proc *p; @@ -1231,6 +1252,11 @@ pexit(char *exitstr, int freemem) free(wq); } + freenotes(up); + free(up->lastnote); + up->lastnote = nil; + up->notified = 0; + /* release debuggers */ if(up->pdbg != nil) { wakeup(&up->pdbg->sleep); @@ -1464,9 +1490,10 @@ kproc(char *name, void (*func)(void *), void *arg) } p->nnote = 0; - p->notify = nil; + p->notify = nil; p->notified = 0; p->notepending = 0; + p->lastnote = nil; p->procmode = 0640; p->privatemem = 1; diff --git a/sys/src/9/port/sysproc.c b/sys/src/9/port/sysproc.c index cd1e641cb..16bcf90a1 100644 --- a/sys/src/9/port/sysproc.c +++ b/sys/src/9/port/sysproc.c @@ -105,12 +105,12 @@ sysrfork(va_list list) p->dot = up->dot; incref(p->dot); - memmove(p->note, up->note, sizeof(p->note)); - p->nnote = up->nnote; - p->notify = up->notify; + p->nnote = 0; + p->notify = up->notify; p->notified = 0; p->notepending = 0; - p->lastnote = up->lastnote; + p->lastnote = nil; + if((flag & RFNOTEG) == 0) p->noteid = up->noteid; @@ -599,7 +599,9 @@ sysexec(va_list list) up->nargs = n; up->setargs = 0; - up->nnote = 0; + freenotes(up); + free(up->lastnote); + up->lastnote = nil; up->notify = nil; up->notified = 0; up->privatemem = 0; diff --git a/sys/src/9/ppc/trap.c b/sys/src/9/ppc/trap.c index 8c7965481..bc4b1b0c5 100644 --- a/sys/src/9/ppc/trap.c +++ b/sys/src/9/ppc/trap.c @@ -774,14 +774,14 @@ noted(Ureg* ureg, ulong arg0) break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /* fall through */ case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag!=NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag!=NDebug); } up->fpstate &= ~FPillegal; if (up->fpstate == FPactive) diff --git a/sys/src/9/sgi/trap.c b/sys/src/9/sgi/trap.c index da1542752..c580e557f 100644 --- a/sys/src/9/sgi/trap.c +++ b/sys/src/9/sgi/trap.c @@ -587,14 +587,14 @@ noted(Ureg *kur, ulong arg0) default: pprint("unknown noted arg %#lux\n", arg0); - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /* fall through */ case NDFLT: - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); qunlock(&up->debug); - pexit(up->lastnote.msg, up->lastnote.flag!=NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag!=NDebug); } } diff --git a/sys/src/9/teg2/syscall.c b/sys/src/9/teg2/syscall.c index ad84ffa30..b45e28b3f 100644 --- a/sys/src/9/teg2/syscall.c +++ b/sys/src/9/teg2/syscall.c @@ -87,13 +87,13 @@ noted(Ureg* cur, uintptr arg0) cur->r0 = (uintptr)nf->arg0; break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /*FALLTHROUGH*/ case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag != NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag != NDebug); } } diff --git a/sys/src/9/xen/trap.c b/sys/src/9/xen/trap.c index 6faf1ccbf..a88b40b66 100644 --- a/sys/src/9/xen/trap.c +++ b/sys/src/9/xen/trap.c @@ -613,16 +613,14 @@ noted(Ureg* ureg, ulong arg0) default: pprint("unknown noted arg 0x%lux\n", arg0); - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; /* fall through */ case NDFLT: - if(up->lastnote.flag == NDebug){ - qunlock(&up->debug); - pprint("suicide: %s\n", up->lastnote.msg); - } else - qunlock(&up->debug); - pexit(up->lastnote.msg, up->lastnote.flag!=NDebug); + qunlock(&up->debug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag!=NDebug); } } diff --git a/sys/src/9/zynq/trap.c b/sys/src/9/zynq/trap.c index 0fc34a573..d2349906a 100644 --- a/sys/src/9/zynq/trap.c +++ b/sys/src/9/zynq/trap.c @@ -395,13 +395,13 @@ noted(Ureg *ureg, ulong arg0) break; default: - up->lastnote.flag = NDebug; + up->lastnote->flag = NDebug; case NDFLT: qunlock(&up->debug); - if(up->lastnote.flag == NDebug) - pprint("suicide: %s\n", up->lastnote.msg); - pexit(up->lastnote.msg, up->lastnote.flag != NDebug); + if(up->lastnote->flag == NDebug) + pprint("suicide: %s\n", up->lastnote->msg); + pexit(up->lastnote->msg, up->lastnote->flag != NDebug); } } |