Simplify pmap_change_attr() a bit:

- Always calculate the cache bits instead of doing it on-demand.
- Always set changed to TRUE rather than only doing it if it is false.

Discussed with:	alc
MFC after:	3 days
This commit is contained in:
John Baldwin 2009-08-31 18:41:13 +00:00
parent 9e2bcb5a69
commit 8101afb656
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=196707
2 changed files with 9 additions and 30 deletions

View file

@ -4476,7 +4476,8 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode)
if (base < DMAP_MIN_ADDRESS)
return (EINVAL);
cache_bits_pde = cache_bits_pte = -1;
cache_bits_pde = pmap_cache_bits(mode, 1);
cache_bits_pte = pmap_cache_bits(mode, 0);
changed = FALSE;
/*
@ -4493,8 +4494,6 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode)
* memory type, then we need not demote this page. Just
* increment tmpva to the next 1GB page frame.
*/
if (cache_bits_pde < 0)
cache_bits_pde = pmap_cache_bits(mode, 1);
if ((*pdpe & PG_PDE_CACHE) == cache_bits_pde) {
tmpva = trunc_1gpage(tmpva) + NBPDP;
continue;
@ -4522,8 +4521,6 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode)
* memory type, then we need not demote this page. Just
* increment tmpva to the next 2MB page frame.
*/
if (cache_bits_pde < 0)
cache_bits_pde = pmap_cache_bits(mode, 1);
if ((*pde & PG_PDE_CACHE) == cache_bits_pde) {
tmpva = trunc_2mpage(tmpva) + NBPDR;
continue;
@ -4557,12 +4554,9 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode)
for (tmpva = base; tmpva < base + size; ) {
pdpe = pmap_pdpe(kernel_pmap, tmpva);
if (*pdpe & PG_PS) {
if (cache_bits_pde < 0)
cache_bits_pde = pmap_cache_bits(mode, 1);
if ((*pdpe & PG_PDE_CACHE) != cache_bits_pde) {
pmap_pde_attr(pdpe, cache_bits_pde);
if (!changed)
changed = TRUE;
changed = TRUE;
}
if (tmpva >= VM_MIN_KERNEL_ADDRESS) {
if (pa_start == pa_end) {
@ -4588,12 +4582,9 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode)
}
pde = pmap_pdpe_to_pde(pdpe, tmpva);
if (*pde & PG_PS) {
if (cache_bits_pde < 0)
cache_bits_pde = pmap_cache_bits(mode, 1);
if ((*pde & PG_PDE_CACHE) != cache_bits_pde) {
pmap_pde_attr(pde, cache_bits_pde);
if (!changed)
changed = TRUE;
changed = TRUE;
}
if (tmpva >= VM_MIN_KERNEL_ADDRESS) {
if (pa_start == pa_end) {
@ -4616,13 +4607,10 @@ pmap_change_attr_locked(vm_offset_t va, vm_size_t size, int mode)
}
tmpva = trunc_2mpage(tmpva) + NBPDR;
} else {
if (cache_bits_pte < 0)
cache_bits_pte = pmap_cache_bits(mode, 0);
pte = pmap_pde_to_pte(pde, tmpva);
if ((*pte & PG_PTE_CACHE) != cache_bits_pte) {
pmap_pte_attr(pte, cache_bits_pte);
if (!changed)
changed = TRUE;
changed = TRUE;
}
if (tmpva >= VM_MIN_KERNEL_ADDRESS) {
if (pa_start == pa_end) {

View file

@ -4635,7 +4635,8 @@ pmap_change_attr(vm_offset_t va, vm_size_t size, int mode)
if (base < VM_MIN_KERNEL_ADDRESS)
return (EINVAL);
cache_bits_pde = cache_bits_pte = -1;
cache_bits_pde = pmap_cache_bits(mode, 1);
cache_bits_pte = pmap_cache_bits(mode, 0);
changed = FALSE;
/*
@ -4656,8 +4657,6 @@ pmap_change_attr(vm_offset_t va, vm_size_t size, int mode)
* demote this page. Just increment tmpva to
* the next 2/4MB page frame.
*/
if (cache_bits_pde < 0)
cache_bits_pde = pmap_cache_bits(mode, 1);
if ((*pde & PG_PDE_CACHE) == cache_bits_pde) {
tmpva = trunc_4mpage(tmpva) + NBPDR;
continue;
@ -4688,8 +4687,6 @@ pmap_change_attr(vm_offset_t va, vm_size_t size, int mode)
}
PMAP_UNLOCK(kernel_pmap);
changed = FALSE;
/*
* Ok, all the pages exist, so run through them updating their
* cache mode if required.
@ -4697,22 +4694,16 @@ pmap_change_attr(vm_offset_t va, vm_size_t size, int mode)
for (tmpva = base; tmpva < base + size; ) {
pde = pmap_pde(kernel_pmap, tmpva);
if (*pde & PG_PS) {
if (cache_bits_pde < 0)
cache_bits_pde = pmap_cache_bits(mode, 1);
if ((*pde & PG_PDE_CACHE) != cache_bits_pde) {
pmap_pde_attr(pde, cache_bits_pde);
if (!changed)
changed = TRUE;
changed = TRUE;
}
tmpva = trunc_4mpage(tmpva) + NBPDR;
} else {
if (cache_bits_pte < 0)
cache_bits_pte = pmap_cache_bits(mode, 0);
pte = vtopte(tmpva);
if ((*pte & PG_PTE_CACHE) != cache_bits_pte) {
pmap_pte_attr(pte, cache_bits_pte);
if (!changed)
changed = TRUE;
changed = TRUE;
}
tmpva += PAGE_SIZE;
}