nicer reaper

2012-04-15 Thread Ariane van der Steldt
Hi,

The reaper is not very nice: it blocks any access to the kernel (i.e.
syscalls) until it is done with its work.  For big processes, this may
result in stalls in userspace.  This diff attempts to relieve it by
yielding the reaper during this operation.

Please test this diff (vmmap_reaperyield.diff.0).
-- 
Ariane


Index: uvm/uvm_extern.h
===
RCS file: /cvs/src/sys/uvm/uvm_extern.h,v
retrieving revision 1.104
diff -u -d -p -r1.104 uvm_extern.h
--- uvm/uvm_extern.h9 Mar 2012 13:01:29 -   1.104
+++ uvm/uvm_extern.h12 Apr 2012 12:13:36 -
@@ -236,6 +236,11 @@ typedef intvm_prot_t;
 #definePHYSLOAD_DEVICE 0x01/* don't add to the page queue */
 
 /*
+ * Flags to uvm_unmap_detach.
+ */
+#define UVM_UNMAP_DETACH_YIELD 0x0001  /* Yield during detach. */
+
+/*
  * structures
  */
 
Index: uvm/uvm_io.c
===
RCS file: /cvs/src/sys/uvm/uvm_io.c,v
retrieving revision 1.20
diff -u -d -p -r1.20 uvm_io.c
--- uvm/uvm_io.c9 Mar 2012 13:01:29 -   1.20
+++ uvm/uvm_io.c12 Apr 2012 12:16:56 -
@@ -143,7 +143,7 @@ uvm_io(vm_map_t map, struct uio *uio, in
uvm_unmap_remove(kernel_map, kva, kva+chunksz,
dead_entries, FALSE, TRUE);
vm_map_unlock(kernel_map);
-   uvm_unmap_detach(dead_entries, AMAP_REFALL);
+   uvm_unmap_detach(dead_entries, AMAP_REFALL, 0);
 
/*
 * We defer checking the error return from uiomove until
Index: uvm/uvm_km.c
===
RCS file: /cvs/src/sys/uvm/uvm_km.c,v
retrieving revision 1.107
diff -u -d -p -r1.107 uvm_km.c
--- uvm/uvm_km.c9 Mar 2012 13:01:29 -   1.107
+++ uvm/uvm_km.c12 Apr 2012 12:17:00 -
@@ -478,7 +478,7 @@ uvm_km_free_wakeup(struct vm_map *map, v
wakeup(map);
vm_map_unlock(map);
 
-   uvm_unmap_detach(dead_entries, 0);
+   uvm_unmap_detach(dead_entries, 0, 0);
 }
 
 /*
Index: uvm/uvm_map.c
===
RCS file: /cvs/src/sys/uvm/uvm_map.c,v
retrieving revision 1.151
diff -u -d -p -r1.151 uvm_map.c
--- uvm/uvm_map.c   11 Apr 2012 11:23:22 -  1.151
+++ uvm/uvm_map.c   12 Apr 2012 12:15:28 -
@@ -1208,7 +1208,7 @@ unlock:
 * uvm_map_mkentry may also create dead entries, when it attempts to
 * destroy free-space entries.
 */
-   uvm_unmap_detach(dead, 0);
+   uvm_unmap_detach(dead, 0, 0);
return error;
 }
 
@@ -1364,7 +1364,7 @@ uvm_mapent_tryjoin(struct vm_map *map, s
  * Kill entries that are no longer in a map.
  */
 void
-uvm_unmap_detach(struct uvm_map_deadq *deadq, int flags)
+uvm_unmap_detach(struct uvm_map_deadq *deadq, int amapflags, int flags)
 {
struct vm_map_entry *entry;
 
@@ -1376,7 +1376,7 @@ uvm_unmap_detach(struct uvm_map_deadq *d
amap_unref(entry-aref.ar_amap,
entry-aref.ar_pageoff,
atop(entry-end - entry-start),
-   flags);
+   amapflags);
 
/*
 * Drop reference to our backing object, if we've got one.
@@ -1395,6 +1395,13 @@ uvm_unmap_detach(struct uvm_map_deadq *d
 */
TAILQ_REMOVE(deadq, entry, dfree.deadq);
uvm_mapent_free(entry);
+
+   /*
+* Yield between steps in the map.
+* Only do this if instructed to do so.
+*/
+   if ((flags  UVM_UNMAP_DETACH_YIELD)  !curcpu_is_idle())
+   yield();
}
 }
 
@@ -1645,7 +1652,7 @@ uvm_unmap(struct vm_map *map, vaddr_t st
uvm_unmap_remove(map, start, end, dead, FALSE, TRUE);
vm_map_unlock(map);
 
-   uvm_unmap_detach(dead, 0);
+   uvm_unmap_detach(dead, 0, 0);
 }
 
 /*
@@ -2352,6 +2359,10 @@ uvm_map_teardown(struct vm_map *map)
DEAD_ENTRY_PUSH(dead_entries, tmp);
/* Update wave-front. */
entry = TAILQ_NEXT(entry, dfree.deadq);
+
+   /* Don't starve other processes. */
+   if (!curcpu_is_idle())
+   yield();
}
 
if ((map-flags  VM_MAP_INTRSAFE) == 0)
@@ -2365,7 +2376,7 @@ uvm_map_teardown(struct vm_map *map)
numq++;
KASSERT(numt == numq);
 #endif
-   uvm_unmap_detach(dead_entries, 0);
+   uvm_unmap_detach(dead_entries, 0, UVM_UNMAP_DETACH_YIELD);
pmap_destroy(map-pmap);
map-pmap = NULL;
 }
@@ -3219,7 +3230,7 @@ uvmspace_exec(struct proc *p, vaddr_t st
/*
 * Release dead entries
 */
-   uvm_unmap_detach(dead_entries, 0);
+   uvm_unmap_detach(dead_entries, 0, 0);
 }
 
 /*
@@ -3591,7 +3602,7 @@ 

Re: nicer reaper

2012-04-15 Thread Juan Francisco Cantero Hurtado
On Sun, Apr 15, 2012 at 07:30:21PM +0200, Ariane van der Steldt wrote:
 Hi,
 
 The reaper is not very nice: it blocks any access to the kernel (i.e.
 syscalls) until it is done with its work.  For big processes, this may
 result in stalls in userspace.  This diff attempts to relieve it by
 yielding the reaper during this operation.
 
 Please test this diff (vmmap_reaperyield.diff.0).

Hi. I can't compile the kernel with your patch.

OpenBSD 5.1-current (GENERIC.MP) #1: Thu Apr 12 01:08:24 CEST 2012
juan...@portatil.juanfra.info:/usr/src/sys/arch/i386/compile/GENERIC.MP


cc  -Werror -Wall -Wstrict-prototypes -Wmissing-prototypes  -Wno-main
-Wno-uninitialized -Wno-format  -Wstack-larger-than-2047
-fno-builtin-printf -fno-builtin-snprintf  -fno-builtin-vsnprintf
-fno-builtin-log  -fno-builtin-log2 -fno-builtin-malloc -O2 -pipe
-nostdinc -I. -I../../../..-I../../../../arch -DDDB -DDIAGNOSTIC
-DKTRACE -DACCOUNTING -DKMEMSTATS -DPTRACE -DPOOL_DEBUG -DCRYPTO
-DSYSVMSG -DSYSVSEM -DSYSVSHM -DUVM_SWAP_ENCRYPT -DCOMPAT_43
-DCOMPAT_O48 -DLKM -DFFS -DFFS2 -DFFS_SOFTUPDATES -DUFS_DIRHASH -DQUOTA
-DEXT2FS -DMFS -DNFSCLIENT -DNFSSERVER -DCD9660 -DUDF -DMSDOSFS -DFIFO
-DSOCKET_SPLICE -DTCP_SACK -DTCP_ECN -DTCP_SIGNATURE -DINET -DALTQ
-DINET6 -DIPSEC -DPPP_BSDCOMP -DPPP_DEFLATE -DPIPEX -DMROUTING -DMPLS
-DBOOT_CONFIG -DUSER_PCICONF -DKVM86 -DUSER_LDT -DAPERTURE
-DCOMPAT_LINUX -DPROCFS -DNTFS -DPCIVERBOSE -DEISAVERBOSE -DUSBVERBOSE
-DWSDISPLAY_COMPAT_USL -DWSDISPLAY_COMPAT_RAWKBD
-DWSDISPLAY_DEFAULTSCREENS=6 -DWSDISPLAY_COMPAT_PCVT -DX86EMU
-DONEWIREVERBOSE -DMULTIPROCESSOR -DMAXUSERS=80 -D_KERNEL -MD -MP  -c
../../../../arch/i386/i386/pmap.c
../../../../arch/i386/i386/pmap.c: In function 'pmap_free_pvpage':
../../../../arch/i386/i386/pmap.c:1275: error: too few arguments to
function 'uvm_unmap_detach'
*** Error code 1

Stop in /usr/src/sys/arch/i386/compile/GENERIC.MP (line 89 of
/usr/share/mk/sys.mk).

Cheers.

-- 
Juan Francisco Cantero Hurtado http://juanfra.info