diff options
author | 2014-04-03 20:21:01 +0000 | |
---|---|---|
committer | 2014-04-03 20:21:01 +0000 | |
commit | 1c7ad6bdabccd0696981d0b12e95f5b494ce7418 (patch) | |
tree | 43a1aca83c95d5868af0aa84e47694f4390f023e | |
parent | When finding a file in a non-existant directory: (diff) | |
download | wireguard-openbsd-1c7ad6bdabccd0696981d0b12e95f5b494ce7418.tar.xz wireguard-openbsd-1c7ad6bdabccd0696981d0b12e95f5b494ce7418.zip |
uvm_fault() will try to fault neighbouring pages for the MADV_NORMAL case,
which is the default, unless the fault call is explicitly used to wire a given
page.
The amount of pages being faulted in was borrowed from the FreeBSD VM code,
about 15 years ago, at a time FreeBSD was only reliably running on 4KB page
size systems.
It is questionable whether faulting the same amount of pages, on platforms
where the page size is larger, is a good idea, as it may cause too much I/O.
Add an uvmfault_init() routine, which will compute the proper number of pages
at runtime, depending upon the actual page size, and attempting to fault in
the same overall size the previous code would have done with 4KB pages.
ok tedu@
-rw-r--r-- | sys/uvm/uvm_fault.c | 39 | ||||
-rw-r--r-- | sys/uvm/uvm_fault.h | 3 | ||||
-rw-r--r-- | sys/uvm/uvm_init.c | 8 |
3 files changed, 36 insertions, 14 deletions
diff --git a/sys/uvm/uvm_fault.c b/sys/uvm/uvm_fault.c index 835f30498c5..08212b2136b 100644 --- a/sys/uvm/uvm_fault.c +++ b/sys/uvm/uvm_fault.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_fault.c,v 1.70 2014/03/31 20:16:39 miod Exp $ */ +/* $OpenBSD: uvm_fault.c,v 1.71 2014/04/03 20:21:01 miod Exp $ */ /* $NetBSD: uvm_fault.c,v 1.51 2000/08/06 00:22:53 thorpej Exp $ */ /* @@ -152,22 +152,15 @@ */ struct uvm_advice { - int advice; int nback; int nforw; }; /* - * page range array: - * note: index in array must match "advice" value - * XXX: borrowed numbers from freebsd. do they work well for us? + * page range array: set up in uvmfault_init(). */ -static struct uvm_advice uvmadvice[] = { - { MADV_NORMAL, 3, 4 }, - { MADV_RANDOM, 0, 0 }, - { MADV_SEQUENTIAL, 8, 7}, -}; +static struct uvm_advice uvmadvice[UVM_ADV_MASK + 1]; #define UVM_MAXRANGE 16 /* must be max() of nback+nforw+1 */ @@ -220,6 +213,30 @@ uvmfault_anonflush(struct vm_anon **anons, int n) */ /* + * uvmfault_init: compute proper values for the uvmadvice[] array. + */ + +void +uvmfault_init() +{ + int npages; + + npages = atop(16384); + if (npages > 0) { + KASSERT(npages <= UVM_MAXRANGE / 2); + uvmadvice[UVM_ADV_NORMAL].nforw = npages; + uvmadvice[UVM_ADV_NORMAL].nback = npages - 1; + } + + npages = atop(32768); + if (npages > 0) { + KASSERT(npages <= UVM_MAXRANGE / 2); + uvmadvice[UVM_ADV_SEQUENTIAL].nforw = npages - 1; + uvmadvice[UVM_ADV_SEQUENTIAL].nback = npages; + } +} + +/* * uvmfault_amapcopy: clear "needs_copy" in a map. * * => if we are out of RAM we sleep (waiting for more) @@ -687,8 +704,6 @@ ReFault: if (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); diff --git a/sys/uvm/uvm_fault.h b/sys/uvm/uvm_fault.h index dd19cdf9262..484d139a7fa 100644 --- a/sys/uvm/uvm_fault.h +++ b/sys/uvm/uvm_fault.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_fault.h,v 1.13 2009/03/25 20:00:18 oga Exp $ */ +/* $OpenBSD: uvm_fault.h,v 1.14 2014/04/03 20:21:01 miod Exp $ */ /* $NetBSD: uvm_fault.h,v 1.14 2000/06/26 14:21:17 mrg Exp $ */ /* @@ -72,6 +72,7 @@ struct uvm_faultinfo { * fault prototypes */ +void uvmfault_init(void); boolean_t uvmfault_lookup(struct uvm_faultinfo *, boolean_t); boolean_t uvmfault_relock(struct uvm_faultinfo *); diff --git a/sys/uvm/uvm_init.c b/sys/uvm/uvm_init.c index c7668767fd3..e3ad18e233f 100644 --- a/sys/uvm/uvm_init.c +++ b/sys/uvm/uvm_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_init.c,v 1.30 2012/03/15 17:52:28 ariane Exp $ */ +/* $OpenBSD: uvm_init.c,v 1.31 2014/04/03 20:21:01 miod Exp $ */ /* $NetBSD: uvm_init.c,v 1.14 2000/06/27 17:29:23 mrg Exp $ */ /* @@ -114,6 +114,12 @@ uvm_init(void) uvm_km_init(kvm_start, kvm_end); /* + * step 4.5: init (tune) the fault recovery code. + */ + + uvmfault_init(); + + /* * step 5: init the pmap module. the pmap module is free to allocate * memory for its private use (e.g. pvlists). */ |