Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/uvm uvm_fault: Pack variables shared during fault / re-f...
details: https://anonhg.NetBSD.org/src/rev/f9186821accc
branches: trunk
changeset: 751340:f9186821accc
user: uebayasi <uebayasi%NetBSD.org@localhost>
date: Mon Feb 01 06:56:22 2010 +0000
description:
uvm_fault: Pack variables shared during fault / re-fault into a struct named
uvm_faultctx. Unfortunately ~all of those values are overriden in various
ways. Constification doesn't help much...
diffstat:
sys/uvm/uvm_fault.c | 266 +++++++++++++++++++++++----------------------------
1 files changed, 120 insertions(+), 146 deletions(-)
diffs (truncated from 685 to 300 lines):
diff -r d45678be94b5 -r f9186821accc sys/uvm/uvm_fault.c
--- a/sys/uvm/uvm_fault.c Mon Feb 01 06:26:15 2010 +0000
+++ b/sys/uvm/uvm_fault.c Mon Feb 01 06:56:22 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_fault.c,v 1.139 2010/02/01 05:48:19 uebayasi Exp $ */
+/* $NetBSD: uvm_fault.c,v 1.140 2010/02/01 06:56:22 uebayasi Exp $ */
/*
*
@@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.139 2010/02/01 05:48:19 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.140 2010/02/01 06:56:22 uebayasi Exp $");
#include "opt_uvmhist.h"
@@ -692,14 +692,27 @@
#define UVM_FAULT_WIRE (1 << 0)
#define UVM_FAULT_MAXPROT (1 << 1)
+struct uvm_faultctx {
+ vm_prot_t access_type;
+ vm_prot_t enter_prot;
+ bool wired;
+ bool narrow;
+ bool shadowed;
+ bool wire_fault;
+ bool maxprot;
+ bool cow_now;
+ int npages;
+ int centeridx;
+ vaddr_t startva;
+ struct vm_anon *anon_spare;
+};
+
typedef int
uvm_fault_subfunc_t(
- struct uvm_faultinfo *ufi, vm_prot_t access_type, vm_prot_t enter_prot,
- bool wired, bool narrow, bool shadowed, bool wire_fault, bool cow_now,
- int npages, int centeridx, vaddr_t startva,
+ struct uvm_faultinfo *ufi,
+ struct uvm_faultctx *flt,
struct vm_amap *amap, struct uvm_object *uobj,
struct vm_anon **anons_store, struct vm_anon **anons,
- struct vm_anon **ranon_spare,
struct vm_page **pages, struct vm_page *uobjpage);
static uvm_fault_subfunc_t uvm_fault_lower;
static uvm_fault_subfunc_t uvm_fault_lower_special;
@@ -709,12 +722,10 @@
static uvm_fault_subfunc_t uvm_fault_lower_generic2;
static void
uvm_fault_lower_generic_lookup(
- struct uvm_faultinfo *ufi, vm_prot_t access_type, vm_prot_t enter_prot,
- bool wired, bool narrow, bool shadowed, bool wire_fault, bool cow_now,
- int npages, int centeridx, vaddr_t startva,
+ struct uvm_faultinfo *ufi,
+ struct uvm_faultctx *flt,
struct vm_amap *amap, struct uvm_object *uobj,
struct vm_anon **anons_store, struct vm_anon **anons,
- struct vm_anon **ranon_spare,
struct vm_page **pages, struct vm_page **ruobjpage);
int
@@ -722,22 +733,21 @@
vm_prot_t access_type, int fault_flag)
{
struct uvm_faultinfo ufi;
- vm_prot_t enter_prot;
- bool wired, narrow, shadowed, wire_fault, cow_now;
- int npages, centeridx, error;
- vaddr_t startva;
struct vm_amap *amap;
struct uvm_object *uobj;
+ struct uvm_faultctx flt = {
+ .access_type = access_type,
+ .wire_fault = (fault_flag & UVM_FAULT_WIRE) != 0,
+ .maxprot = (fault_flag & UVM_FAULT_MAXPROT) != 0,
+ };
struct vm_anon *anons_store[UVM_MAXRANGE], **anons;
- struct vm_anon *anon_spare;
struct vm_page *pages[UVM_MAXRANGE], *uobjpage = NULL;
+ int error;
UVMHIST_FUNC("uvm_fault"); UVMHIST_CALLED(maphist);
UVMHIST_LOG(maphist, "(map=0x%x, vaddr=0x%x, at=%d, ff=%d)",
orig_map, vaddr, access_type, fault_flag);
- anon_spare = NULL;
-
uvmexp.faults++; /* XXX: locking? */
/*
@@ -747,12 +757,11 @@
ufi.orig_map = orig_map;
ufi.orig_rvaddr = trunc_page(vaddr);
ufi.orig_size = PAGE_SIZE; /* can't get any smaller than this */
- wire_fault = (fault_flag & UVM_FAULT_WIRE) != 0;
- if (wire_fault)
- narrow = true; /* don't look for neighborhood
+ if (flt.wire_fault)
+ flt.narrow = true; /* don't look for neighborhood
* pages on wire */
else
- narrow = false; /* normal fault */
+ flt.narrow = false; /* normal fault */
/*
* "goto ReFault" means restart the page fault from ground zero.
@@ -765,28 +774,24 @@
goto uvm_fault_upper_lookup;
uvm_fault_upper_lookup_done:
- if (shadowed == true)
+ if (flt.shadowed == true)
error = uvm_fault_upper(
- &ufi, access_type, enter_prot,
- wired, narrow, shadowed, wire_fault, cow_now,
- npages, centeridx, startva,
- amap, uobj, anons_store, anons, &anon_spare,
+ &ufi, &flt,
+ amap, uobj, anons_store, anons,
pages, uobjpage);
else
error = uvm_fault_lower(
- &ufi, access_type, enter_prot,
- wired, narrow, shadowed, wire_fault, cow_now,
- npages, centeridx, startva,
- amap, uobj, anons_store, anons, &anon_spare,
+ &ufi, &flt,
+ amap, uobj, anons_store, anons,
pages, uobjpage);
if (error == ERESTART)
goto ReFault;
done:
- if (anon_spare != NULL) {
- anon_spare->an_ref--;
- uvm_anfree(anon_spare);
+ if (flt.anon_spare != NULL) {
+ flt.anon_spare->an_ref--;
+ uvm_anfree(flt.anon_spare);
}
return error;
@@ -822,10 +827,10 @@
check_prot = (fault_flag & UVM_FAULT_MAXPROT) ?
ufi.entry->max_protection : ufi.entry->protection;
- if ((check_prot & access_type) != access_type) {
+ if ((check_prot & flt.access_type) != flt.access_type) {
UVMHIST_LOG(maphist,
"<- protection failure (prot=0x%x, access=0x%x)",
- ufi.entry->protection, access_type, 0, 0);
+ ufi.entry->protection, flt.access_type, 0, 0);
uvmfault_unlockmaps(&ufi, false);
error = EACCES;
goto done;
@@ -838,13 +843,13 @@
* the entry is wired or we are fault-wiring the pg.
*/
- enter_prot = ufi.entry->protection;
- wired = VM_MAPENT_ISWIRED(ufi.entry) || wire_fault;
- if (wired) {
- access_type = enter_prot; /* full access for wired */
- cow_now = (check_prot & VM_PROT_WRITE) != 0;
+ flt.enter_prot = ufi.entry->protection;
+ flt.wired = VM_MAPENT_ISWIRED(ufi.entry) || flt.wire_fault;
+ if (flt.wired) {
+ flt.access_type = flt.enter_prot; /* full access for wired */
+ flt.cow_now = (check_prot & VM_PROT_WRITE) != 0;
} else {
- cow_now = (access_type & VM_PROT_WRITE) != 0;
+ flt.cow_now = (flt.access_type & VM_PROT_WRITE) != 0;
}
/*
@@ -855,7 +860,7 @@
*/
if (UVM_ET_ISNEEDSCOPY(ufi.entry)) {
- if (cow_now || (ufi.entry->object.uvm_obj == NULL)) {
+ if (flt.cow_now || (ufi.entry->object.uvm_obj == NULL)) {
KASSERT((fault_flag & UVM_FAULT_MAXPROT) == 0);
/* need to clear */
UVMHIST_LOG(maphist,
@@ -872,7 +877,7 @@
* needs_copy is still true
*/
- enter_prot &= ~VM_PROT_WRITE;
+ flt.enter_prot &= ~VM_PROT_WRITE;
}
}
@@ -902,14 +907,14 @@
* ReFault we will disable this by setting "narrow" to true.
*/
- if (narrow == false) {
+ if (flt.narrow == false) {
/* wide fault (!narrow) */
KASSERT(uvmadvice[ufi.entry->advice].advice ==
ufi.entry->advice);
nback = MIN(uvmadvice[ufi.entry->advice].nback,
(ufi.orig_rvaddr - ufi.entry->start) >> PAGE_SHIFT);
- startva = ufi.orig_rvaddr - (nback << PAGE_SHIFT);
+ flt.startva = ufi.orig_rvaddr - (nback << PAGE_SHIFT);
nforw = MIN(uvmadvice[ufi.entry->advice].nforw,
((ufi.entry->end - ufi.orig_rvaddr) >>
PAGE_SHIFT) - 1);
@@ -917,26 +922,26 @@
* note: "-1" because we don't want to count the
* faulting page as forw
*/
- npages = nback + nforw + 1;
- centeridx = nback;
+ flt.npages = nback + nforw + 1;
+ flt.centeridx = nback;
- narrow = true; /* ensure only once per-fault */
+ flt.narrow = true; /* ensure only once per-fault */
} else {
/* narrow fault! */
nback = nforw = 0;
- startva = ufi.orig_rvaddr;
- npages = 1;
- centeridx = 0;
+ flt.startva = ufi.orig_rvaddr;
+ flt.npages = 1;
+ flt.centeridx = 0;
}
/* offset from entry's start to pgs' start */
- const voff_t eoff = startva - ufi.entry->start;
+ const voff_t eoff = flt.startva - ufi.entry->start;
/* locked: maps(read) */
UVMHIST_LOG(maphist, " narrow=%d, back=%d, forw=%d, startva=0x%x",
- narrow, nback, nforw, startva);
+ flt.narrow, nback, nforw, flt.startva);
UVMHIST_LOG(maphist, " entry=0x%x, amap=0x%x, obj=0x%x", ufi.entry,
amap, uobj, 0);
@@ -947,7 +952,7 @@
if (amap) {
amap_lock(amap);
anons = anons_store;
- amap_lookups(&ufi.entry->aref, eoff, anons, npages);
+ amap_lookups(&ufi.entry->aref, eoff, anons, flt.npages);
} else {
anons = NULL; /* to be safe */
}
@@ -981,9 +986,9 @@
/* now forget about the backpages */
if (amap)
anons += nback;
- startva += (nback << PAGE_SHIFT);
- npages -= nback;
- centeridx = 0;
+ flt.startva += (nback << PAGE_SHIFT);
+ flt.npages -= nback;
+ flt.centeridx = 0;
}
}
goto uvm_fault_prepare_done;
@@ -1007,16 +1012,16 @@
* we go.
*/
- currva = startva;
- shadowed = false;
- for (lcv = 0 ; lcv < npages ; lcv++, currva += PAGE_SIZE) {
+ currva = flt.startva;
+ flt.shadowed = false;
+ for (lcv = 0 ; lcv < flt.npages ; lcv++, currva += PAGE_SIZE) {
struct vm_anon *anon;
/*
* dont play with VAs that are already mapped
* except for center)
*/
- if (lcv != centeridx &&
+ if (lcv != flt.centeridx &&
pmap_extract(ufi.orig_map->pmap, currva, NULL)) {
pages[lcv] = PGO_DONTCARE;
continue;
@@ -1035,8 +1040,8 @@
*/
pages[lcv] = PGO_DONTCARE;
- if (lcv == centeridx) { /* save center for later! */
- shadowed = true;
+ if (lcv == flt.centeridx) { /* save center for later! */
Home |
Main Index |
Thread Index |
Old Index