From e6938912b13bc186d375b111cfaaceba993f03b1 Mon Sep 17 00:00:00 2001 From: Samuel J. Greear Date: Mon, 8 Feb 2010 13:24:00 -0700 Subject: [PATCH 2/4] Add new sf_buf control variables --- sys/boot/common/help.common | 11 +++++++++-- sys/boot/common/loader.8 | 6 ++++++ sys/boot/forth/loader-bootp.conf | 3 ++- sys/boot/forth/loader.conf | 3 ++- sys/config/LINT | 14 ++++++++++---- sys/kern/kern_sfbuf.c | 6 ++++++ sys/kern/subr_param.c | 10 ++++++++-- sys/sys/sfbuf.h | 1 + 8 files changed, 44 insertions(+), 10 deletions(-) diff --git a/sys/boot/common/help.common b/sys/boot/common/help.common index b87de33..f91017e 100644 --- a/sys/boot/common/help.common +++ b/sys/boot/common/help.common @@ -242,8 +242,15 @@ set kern.ipc.nsfbufs= NSFBUFS - Set the number of sendfile buffers to be allocated. This - overrides the value determined when the kernel was compiled. + Set the initial number of sendfile buffers to be allocated. + This overrides the value determined when the kernel was + compiled. + + set kern.ipc.maxsfbufs= MAXSFBUFS + + Set the maximum number of sendfile buffers that the kernel is + allowed to allocate. This overrides the value determined + when the kernel was compiled. set kern.vm.kmem.size= diff --git a/sys/boot/common/loader.8 b/sys/boot/common/loader.8 index 3ef914a..801d327 100644 --- a/sys/boot/common/loader.8 +++ b/sys/boot/common/loader.8 @@ -494,6 +494,12 @@ Set the number of buffers to be allocated. Overrides .Dv NSFBUFS . +.It Va kern.ipc.maxsfbufs +Set the maximum number of +.Xr sendfile 2 +buffers that can be allocated. +Overrides +.Dv MAXSFBUFS . .It Va kern.mmxopt Toggles the mmx optimizations for the bcopy/copyin/copyout routines .It Va kern.vm.kmem.size diff --git a/sys/boot/forth/loader-bootp.conf b/sys/boot/forth/loader-bootp.conf index 42cdeb6..454b54c 100644 --- a/sys/boot/forth/loader-bootp.conf +++ b/sys/boot/forth/loader-bootp.conf @@ -97,7 +97,8 @@ module_path="/boot;/boot/modules;/;/modules" # Set the module search path #kern.ipc.maxsockets="" # Set the maximum number of sockets avaliable #kern.ipc.nmbclusters="" # Set the number of mbuf clusters #kern.ipc.nmbufs="" # Set the maximum number of mbufs -#kern.ipc.nsfbufs="" # Set the number of sendfile(2) bufs +#kern.ipc.nsfbufs="" # Set the initial number of sendfile(2) bufs +#kern.ipc.maxsfbufs="" # Set the maximum number of sendfile(2) bufs #kern.vm.kmem.size="" # Sets the size of kernel memory (bytes) #net.inet.tcp.tcbhashsize="" # Set the value of TCBHASHSIZE #vfs.root.mountfrom="" # Specify root partition in a way the diff --git a/sys/boot/forth/loader.conf b/sys/boot/forth/loader.conf index ace3780..3c08144 100644 --- a/sys/boot/forth/loader.conf +++ b/sys/boot/forth/loader.conf @@ -99,7 +99,8 @@ module_path="/boot;/boot/modules;/;/modules" # Set the module search path #kern.ipc.maxsockets="" # Set the maximum number of sockets avaliable #kern.ipc.nmbclusters="" # Set the number of mbuf clusters #kern.ipc.nmbufs="" # Set the maximum number of mbufs -#kern.ipc.nsfbufs="" # Set the number of sendfile(2) bufs +#kern.ipc.nsfbufs="" # Set the initial number of sendfile(2) bufs +#kern.ipc.maxsfbufs="" # Set the maximum number of sendfile(2) bufs #kern.vm.kmem.size="" # Sets the size of kernel memory (bytes) #net.inet.tcp.tcbhashsize="" # Set the value of TCBHASHSIZE #vfs.root.mountfrom="" # Specify root partition in a way the diff --git a/sys/config/LINT b/sys/config/LINT index e7fe741..db14fac 100644 --- a/sys/config/LINT +++ b/sys/config/LINT @@ -2398,12 +2398,18 @@ options KVA_PAGES=260 # #options NO_SWAPPING -# Set the number of sf_bufs to allocate. sf_bufs are virtual buffers -# for sendfile(2) that are used to map file VM pages, and normally -# default to a quantity that is roughly 16*MAXUSERS+512. You would +# Set the initial number of sf_bufs to allocate. sf_bufs are virtual +# buffers for sendfile(2) that are used to map file VM pages, and normally +# default to a quantity that is roughly MAXUSERS+64. You would # typically want about 4 of these for each simultaneous file send. # -options NSFBUFS=1024 +options NSFBUFS=512 + +# Set the maximum number of sf_bufs that the system is allowed to allocate. +# Kernel virtual memory is used to persistently cache VM page mappings +# once allocated by the sf_buf subsystem, as such it is not returned to +# the system and setting this value too high can cause KVM exhaustion. +options MAXSFBUFS=2048 # Set the size of the buffer cache KVM reservation, in buffers. This is # scaled by approximately 16384 bytes. The system will auto-size the buffer diff --git a/sys/kern/kern_sfbuf.c b/sys/kern/kern_sfbuf.c index e5b01dd..24f77ff 100644 --- a/sys/kern/kern_sfbuf.c +++ b/sys/kern/kern_sfbuf.c @@ -49,6 +49,8 @@ SYSINIT(sock_sf, SI_BOOT2_MACHDEP, SI_ORDER_ANY, sf_buf_init, NULL) LIST_HEAD(sf_buf_list, sf_buf); SYSCTL_INT(_kern_ipc, OID_AUTO, nsfbufs, CTLFLAG_RD, &nsfbufs, 0, + "Initial number of sf_bufs allocated by the system"); +SYSCTL_INT(_kern_ipc, OID_AUTO, maxsfbufs, CTLFLAG_RW, &maxsfbufs, 0, "Maximum number of sf_bufs available to the system"); /* @@ -66,6 +68,9 @@ static struct spinlock sf_buf_spin; static int sfbuf_quick = 1; SYSCTL_INT(_debug, OID_AUTO, sfbuf_quick, CTLFLAG_RW, &sfbuf_quick, 0, ""); +static int nsfalloc; +SYSCTL_INT(_kern_ipc, OID_AUTO, nsfalloc, CTLFLAG_RD, &nsfalloc, 0, + "Number of sf_bufs allocated by the system"); static int nsffree; SYSCTL_INT(_kern_ipc, OID_AUTO, nsffree, CTLFLAG_RD, &nsffree, 0, "Number of free sf_bufs available to the system"); @@ -94,6 +99,7 @@ sf_buf_init(void *arg) sf_base = kmem_alloc_nofault(&kernel_map, nsfbufs * PAGE_SIZE); sf_bufs = kmalloc(nsfbufs * sizeof(struct sf_buf), M_TEMP, M_WAITOK | M_ZERO); + nsfalloc = nsfbufs; for (i = 0; i < nsfbufs; i++) { sf_bufs[i].kva = sf_base + i * PAGE_SIZE; sf_bufs[i].flags |= SFBA_ONFREEQ; diff --git a/sys/kern/subr_param.c b/sys/kern/subr_param.c index f3af67e..a502134 100644 --- a/sys/kern/subr_param.c +++ b/sys/kern/subr_param.c @@ -64,7 +64,10 @@ #define MAXFILES (maxproc * 16) #endif #ifndef NSFBUFS -#define NSFBUFS (512 + maxusers * 16) +#define NSFBUFS (64 + maxusers) +#endif +#ifndef MAXSFBUFS +#define MAXSFBUFS (512 + maxusers * 16) #endif #ifndef MAXPOSIXLOCKSPERUID #define MAXPOSIXLOCKSPERUID (maxusers * 64) /* Should be a safe value */ @@ -95,8 +98,9 @@ u_quad_t dflssiz; /* initial stack size limit */ u_quad_t maxssiz; /* max stack size */ u_quad_t sgrowsiz; /* amount to grow stack */ -/* maximum # of sf_bufs (sendfile(2) zero-copy virtual buffers) */ +/* initial and maximum # of sf_bufs (sendfile(2) zero-copy virtual buffers) */ int nsfbufs; +int maxsfbufs; /* * These have to be allocated somewhere; allocating @@ -187,6 +191,8 @@ init_param2(int physpages) */ nsfbufs = NSFBUFS; TUNABLE_INT_FETCH("kern.ipc.nsfbufs", &nsfbufs); + maxsfbufs = MAXSFBUFS; + TUNABLE_INT_FETCH("kern.ipc.maxsfbufs", &maxsfbufs); nbuf = NBUF; TUNABLE_INT_FETCH("kern.nbuf", &nbuf); diff --git a/sys/sys/sfbuf.h b/sys/sys/sfbuf.h index b13f3b1..4db8d07 100644 --- a/sys/sys/sfbuf.h +++ b/sys/sys/sfbuf.h @@ -74,6 +74,7 @@ sf_buf_page(struct sf_buf *sf) #if defined(_KERNEL) extern int nsfbufs; +extern int maxsfbufs; struct sf_buf *sf_buf_alloc(struct vm_page *, int flags); void sf_buf_free(struct sf_buf *); -- 1.6.4