提交 5c3e499d 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

fix pt invalidation bug + slight speedup

上级 6477987b
...@@ -277,6 +277,7 @@ vmap::insert(vmnode *n, uptr vma_start, int dotlb) ...@@ -277,6 +277,7 @@ vmap::insert(vmnode *n, uptr vma_start, int dotlb)
ANON_REGION("vmap::insert", &perfgroup); ANON_REGION("vmap::insert", &perfgroup);
vma *e; vma *e;
bool replaced = false;
{ {
// new scope to release the search lock before tlbflush // new scope to release the search lock before tlbflush
...@@ -288,7 +289,7 @@ vmap::insert(vmnode *n, uptr vma_start, int dotlb) ...@@ -288,7 +289,7 @@ vmap::insert(vmnode *n, uptr vma_start, int dotlb)
return -1; return -1;
} }
// XXX handle overlaps // XXX handle overlaps, set replaced=true
e = new vma(this, vma_start, vma_start+len, PRIVATE, n); e = new vma(this, vma_start, vma_start+len, PRIVATE, n);
if (e == 0) { if (e == 0) {
...@@ -300,17 +301,20 @@ vmap::insert(vmnode *n, uptr vma_start, int dotlb) ...@@ -300,17 +301,20 @@ vmap::insert(vmnode *n, uptr vma_start, int dotlb)
} }
bool needtlb = false; bool needtlb = false;
updatepages(pml4, e->vma_start, e->vma_end, [&needtlb](atomic<pme_t> *p) { if (replaced)
for (;;) { updatepages(pml4, e->vma_start, e->vma_end, [&needtlb](atomic<pme_t> *p) {
pme_t v = p->load(); for (;;) {
if (v & PTE_LOCK) pme_t v = p->load();
continue; if (v & PTE_LOCK)
if (cmpxch(p, v, (pme_t) 0)) continue;
break; if (!(v & PTE_P))
if (v != 0) break;
needtlb = true; if (cmpxch(p, v, (pme_t) 0)) {
} needtlb = true;
}); break;
}
}
});
if (needtlb && dotlb) if (needtlb && dotlb)
tlbflush(); tlbflush();
return 0; return 0;
...@@ -343,10 +347,12 @@ vmap::remove(uptr vma_start, uptr len) ...@@ -343,10 +347,12 @@ vmap::remove(uptr vma_start, uptr len)
pme_t v = p->load(); pme_t v = p->load();
if (v & PTE_LOCK) if (v & PTE_LOCK)
continue; continue;
if (cmpxch(p, v, (pme_t) 0)) if (!(v & PTE_P))
break; break;
if (v != 0) if (cmpxch(p, v, (pme_t) 0)) {
needtlb = true; needtlb = true;
break;
}
} }
}); });
if (needtlb) if (needtlb)
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论