diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-04-02 20:23:25 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-04-02 20:23:25 +0200 |
commit | 295acd7e0d711cfd2c7c6a1bd45d00c9727f5786 (patch) | |
tree | a1e02ca9b5d210447cee12bf0dfafa8848574a33 /sys/src/9/port/xalloc.c | |
parent | c77b3ba143da491f020a1c2871a57d10d5b8bf8f (diff) |
kernel: get rid of physical page bank array and use conf.mem[] instead
We can take advantage of the fact that xinit() allocates
kernel memory from conf.mem[] banks always at the beginning
of a bank, so the separate palloc.mem[] array can be eleminated
as we can calculate the amount of non-kernel memory like:
upages = cm->npage - (PGROUND(cm->klimit - cm->kbase)/BY2PG)
for the number of reserved kernel pages,
we provide the new function: ulong nkpages(Confmem*)
This eleminates the error case of running out of slots in
the array and avoids wasting memory in ports that have simple
memory configurations (compared to pc/pc64).
Diffstat (limited to 'sys/src/9/port/xalloc.c')
-rw-r--r-- | sys/src/9/port/xalloc.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/sys/src/9/port/xalloc.c b/sys/src/9/port/xalloc.c index 13550d4ba..149985719 100644 --- a/sys/src/9/port/xalloc.c +++ b/sys/src/9/port/xalloc.c @@ -43,10 +43,8 @@ void xinit(void) { ulong maxpages, kpages, n; - uintptr size; - Confmem *m; - Pallocmem *pm; Hole *h, *eh; + Confmem *cm; int i; eh = &xlists.hole[Nhole-1]; @@ -57,36 +55,28 @@ xinit(void) kpages = conf.npage - conf.upages; - pm = palloc.mem; for(i=0; i<nelem(conf.mem); i++){ - m = &conf.mem[i]; - n = m->npage; + cm = &conf.mem[i]; + n = cm->npage; if(n > kpages) n = kpages; /* don't try to use non-KADDR-able memory for kernel */ - maxpages = cankaddr(m->base)/BY2PG; + maxpages = cankaddr(cm->base)/BY2PG; if(n > maxpages) n = maxpages; - size = (uintptr)n*BY2PG; - /* first give to kernel */ + /* give to kernel */ if(n > 0){ - m->kbase = (uintptr)KADDR(m->base); - m->klimit = (uintptr)m->kbase+size; - if(m->klimit == 0) - m->klimit = (uintptr)-BY2PG; - xhole(m->base, m->klimit - m->kbase); + cm->kbase = (uintptr)KADDR(cm->base); + cm->klimit = (uintptr)cm->kbase+(uintptr)n*BY2PG; + if(cm->klimit == 0) + cm->klimit = (uintptr)-BY2PG; + xhole(cm->base, cm->klimit - cm->kbase); kpages -= n; } - /* if anything left over, give to user */ - if(n < m->npage){ - if(pm >= palloc.mem+nelem(palloc.mem)){ - print("xinit: losing %lud pages\n", m->npage-n); - continue; - } - pm->base = m->base+size; - pm->npage = m->npage - n; - pm++; - } + /* + * anything left over: cm->npage - nkpages(cm) + * will be given to user by pageinit() + */ } xsummary(); } |