summaryrefslogtreecommitdiff
path: root/sys/src/9/pc64
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2021-04-02 20:23:25 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2021-04-02 20:23:25 +0200
commit295acd7e0d711cfd2c7c6a1bd45d00c9727f5786 (patch)
treea1e02ca9b5d210447cee12bf0dfafa8848574a33 /sys/src/9/pc64
parentc77b3ba143da491f020a1c2871a57d10d5b8bf8f (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/pc64')
-rw-r--r--sys/src/9/pc64/mmu.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/sys/src/9/pc64/mmu.c b/sys/src/9/pc64/mmu.c
index 936955d4b..23a39f6d8 100644
--- a/sys/src/9/pc64/mmu.c
+++ b/sys/src/9/pc64/mmu.c
@@ -652,16 +652,16 @@ patwc(void *a, int n)
void
preallocpages(void)
{
- Pallocmem *pm;
+ Confmem *cm;
uintptr va, base, top;
vlong tsize, psize;
ulong np, nt;
int i;
np = 0;
- for(i=0; i<nelem(palloc.mem); i++){
- pm = &palloc.mem[i];
- np += pm->npage;
+ for(i=0; i<nelem(conf.mem); i++){
+ cm = &conf.mem[i];
+ np += cm->npage - nkpages(cm);
}
nt = np / 50; /* 2% for mmupool */
np -= nt;
@@ -676,16 +676,19 @@ preallocpages(void)
psize += tsize;
psize = ROUND(psize, PGLSZ(1));
- for(i=0; i<nelem(palloc.mem); i++){
- pm = &palloc.mem[i];
- base = ROUND(pm->base, PGLSZ(1));
- top = pm->base + (uvlong)pm->npage * BY2PG;
- if((base + psize) <= VMAPSIZE && (vlong)(top - base) >= psize){
- pm->base = base + psize;
- pm->npage = (top - pm->base)/BY2PG;
-
- va = base + VMAP;
- pmap(base | PTEGLOBAL|PTEWRITE|PTENOEXEC|PTEVALID, va, psize);
+ for(i=0; i<nelem(conf.mem); i++){
+ cm = &conf.mem[i];
+ base = cm->base;
+ top = base + (uvlong)cm->npage * BY2PG;
+ base += (uvlong)nkpages(cm) * BY2PG;
+ top &= -PGLSZ(1);
+ if(top <= VMAPSIZE && (vlong)(top - base) >= psize){
+ /* steal memory from the end of the bank */
+ top -= psize;
+ cm->npage = (top - cm->base) / BY2PG;
+
+ va = top + VMAP;
+ pmap(top | PTEGLOBAL|PTEWRITE|PTENOEXEC|PTEVALID, va, psize);
palloc.pages = (void*)(va + tsize);