version 1.134, 2007/03/04 06:03:11 |
version 1.134.2.1, 2007/03/13 16:51:58 |
Line 92 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 92 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/event.h> |
#include <sys/event.h> |
#include <sys/poll.h> |
#include <sys/poll.h> |
#include <sys/kauth.h> |
#include <sys/kauth.h> |
|
#include <sys/mutex.h> |
|
#include <sys/condvar.h> |
|
|
#include <uvm/uvm.h> |
#include <uvm/uvm.h> |
|
|
POOL_INIT(socket_pool, sizeof(struct socket), 0, 0, 0, "sockpl", NULL); |
POOL_INIT(socket_pool, sizeof(struct socket), 0, 0, 0, "sockpl", NULL, |
|
IPL_SOFTNET); |
|
|
MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options"); |
MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options"); |
MALLOC_DEFINE(M_SONAME, "soname", "socket name"); |
MALLOC_DEFINE(M_SONAME, "soname", "socket name"); |
Line 135 int sock_loan_thresh = -1; |
|
Line 138 int sock_loan_thresh = -1; |
|
int sock_loan_thresh = 4096; |
int sock_loan_thresh = 4096; |
#endif |
#endif |
|
|
static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER; |
static kmutex_t so_pendfree_lock; |
static struct mbuf *so_pendfree; |
static struct mbuf *so_pendfree; |
|
|
#ifndef SOMAXKVA |
#ifndef SOMAXKVA |
Line 143 static struct mbuf *so_pendfree; |
|
Line 146 static struct mbuf *so_pendfree; |
|
#endif |
#endif |
int somaxkva = SOMAXKVA; |
int somaxkva = SOMAXKVA; |
static int socurkva; |
static int socurkva; |
static int sokvawaiters; |
static kcondvar_t socurkva_cv; |
|
|
#define SOCK_LOAN_CHUNK 65536 |
#define SOCK_LOAN_CHUNK 65536 |
|
|
Line 153 static size_t sodopendfreel(void); |
|
Line 156 static size_t sodopendfreel(void); |
|
static vsize_t |
static vsize_t |
sokvareserve(struct socket *so, vsize_t len) |
sokvareserve(struct socket *so, vsize_t len) |
{ |
{ |
int s; |
|
int error; |
int error; |
|
|
s = splvm(); |
mutex_enter(&so_pendfree_lock); |
simple_lock(&so_pendfree_slock); |
|
while (socurkva + len > somaxkva) { |
while (socurkva + len > somaxkva) { |
size_t freed; |
size_t freed; |
|
|
Line 175 sokvareserve(struct socket *so, vsize_t |
|
Line 176 sokvareserve(struct socket *so, vsize_t |
|
continue; |
continue; |
|
|
SOSEND_COUNTER_INCR(&sosend_kvalimit); |
SOSEND_COUNTER_INCR(&sosend_kvalimit); |
sokvawaiters++; |
error = cv_wait_sig(&socurkva_cv, &so_pendfree_lock); |
error = ltsleep(&socurkva, PVM | PCATCH, "sokva", 0, |
|
&so_pendfree_slock); |
|
sokvawaiters--; |
|
if (error) { |
if (error) { |
len = 0; |
len = 0; |
break; |
break; |
} |
} |
} |
} |
socurkva += len; |
socurkva += len; |
simple_unlock(&so_pendfree_slock); |
mutex_exit(&so_pendfree_lock); |
splx(s); |
|
return len; |
return len; |
} |
} |
|
|
static void |
static void |
sokvaunreserve(vsize_t len) |
sokvaunreserve(vsize_t len) |
{ |
{ |
int s; |
|
|
|
s = splvm(); |
mutex_enter(&so_pendfree_lock); |
simple_lock(&so_pendfree_slock); |
|
socurkva -= len; |
socurkva -= len; |
if (sokvawaiters) |
cv_broadcast(&socurkva_cv); |
wakeup(&socurkva); |
mutex_exit(&so_pendfree_lock); |
simple_unlock(&so_pendfree_slock); |
|
splx(s); |
|
} |
} |
|
|
/* |
/* |
Line 286 sodoloanfree(struct vm_page **pgs, void |
|
Line 279 sodoloanfree(struct vm_page **pgs, void |
|
static size_t |
static size_t |
sodopendfree() |
sodopendfree() |
{ |
{ |
int s; |
|
size_t rv; |
size_t rv; |
|
|
s = splvm(); |
mutex_enter(&so_pendfree_lock); |
simple_lock(&so_pendfree_slock); |
|
rv = sodopendfreel(); |
rv = sodopendfreel(); |
simple_unlock(&so_pendfree_slock); |
mutex_exit(&so_pendfree_lock); |
splx(s); |
|
|
|
return rv; |
return rv; |
} |
} |
|
|
/* |
/* |
* sodopendfreel: free mbufs on "pendfree" list. |
* sodopendfreel: free mbufs on "pendfree" list. |
* unlock and relock so_pendfree_slock when freeing mbufs. |
* unlock and relock so_pendfree_lock when freeing mbufs. |
* |
* |
* => called with so_pendfree_slock held. |
* => called with so_pendfree_lock held. |
* => called at splvm. |
|
*/ |
*/ |
|
|
static size_t |
static size_t |
|
|
{ |
{ |
size_t rv = 0; |
size_t rv = 0; |
|
|
LOCK_ASSERT(simple_lock_held(&so_pendfree_slock)); |
KASSERT(mutex_owned(&so_pendfree_lock)); |
|
|
for (;;) { |
for (;;) { |
struct mbuf *m; |
struct mbuf *m; |
|
|
if (m == NULL) |
if (m == NULL) |
break; |
break; |
so_pendfree = NULL; |
so_pendfree = NULL; |
simple_unlock(&so_pendfree_slock); |
mutex_exit(&so_pendfree_lock); |
/* XXX splx */ |
|
|
|
for (; m != NULL; m = next) { |
for (; m != NULL; m = next) { |
next = m->m_next; |
next = m->m_next; |
|
|
pool_cache_put(&mbpool_cache, m); |
pool_cache_put(&mbpool_cache, m); |
} |
} |
|
|
/* XXX splvm */ |
mutex_enter(&so_pendfree_lock); |
simple_lock(&so_pendfree_slock); |
|
} |
} |
|
|
return (rv); |
return (rv); |
|
|
void |
void |
soloanfree(struct mbuf *m, void *buf, size_t size, void *arg) |
soloanfree(struct mbuf *m, void *buf, size_t size, void *arg) |
{ |
{ |
int s; |
|
|
|
if (m == NULL) { |
if (m == NULL) { |
|
|
Line 363 soloanfree(struct mbuf *m, void *buf, si |
|
Line 349 soloanfree(struct mbuf *m, void *buf, si |
|
* because we need to put kva back to kernel_map. |
* because we need to put kva back to kernel_map. |
*/ |
*/ |
|
|
s = splvm(); |
mutex_enter(&so_pendfree_lock); |
simple_lock(&so_pendfree_slock); |
|
m->m_next = so_pendfree; |
m->m_next = so_pendfree; |
so_pendfree = m; |
so_pendfree = m; |
if (sokvawaiters) |
cv_broadcast(&socurkva_cv); |
wakeup(&socurkva); |
mutex_exit(&so_pendfree_lock); |
simple_unlock(&so_pendfree_slock); |
|
splx(s); |
|
} |
} |
|
|
static long |
static long |
|
|
soinit(void) |
soinit(void) |
{ |
{ |
|
|
|
mutex_init(&so_pendfree_lock, MUTEX_DRIVER, IPL_VM); |
|
cv_init(&socurkva_cv, "sokva"); |
|
|
/* Set the initial adjusted socket buffer size. */ |
/* Set the initial adjusted socket buffer size. */ |
if (sb_max_set(sb_max)) |
if (sb_max_set(sb_max)) |
panic("bad initial sb_max value: %lu", sb_max); |
panic("bad initial sb_max value: %lu", sb_max); |
Line 1794 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
Line 1780 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
{ |
{ |
int error, new_somaxkva; |
int error, new_somaxkva; |
struct sysctlnode node; |
struct sysctlnode node; |
int s; |
|
|
|
new_somaxkva = somaxkva; |
new_somaxkva = somaxkva; |
node = *rnode; |
node = *rnode; |
Line 1806 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
Line 1791 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
if (new_somaxkva < (16 * 1024 * 1024)) /* sanity */ |
if (new_somaxkva < (16 * 1024 * 1024)) /* sanity */ |
return (EINVAL); |
return (EINVAL); |
|
|
s = splvm(); |
mutex_enter(&so_pendfree_lock); |
simple_lock(&so_pendfree_slock); |
|
somaxkva = new_somaxkva; |
somaxkva = new_somaxkva; |
wakeup(&socurkva); |
cv_broadcast(&socurkva_cv); |
simple_unlock(&so_pendfree_slock); |
mutex_exit(&so_pendfree_lock); |
splx(s); |
|
|
|
return (error); |
return (error); |
} |
} |