version 1.204, 2011/06/26 16:42:42 |
version 1.205, 2011/07/02 17:53:50 |
Line 92 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 92 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/kauth.h> |
#include <sys/kauth.h> |
#include <sys/mutex.h> |
#include <sys/mutex.h> |
#include <sys/condvar.h> |
#include <sys/condvar.h> |
|
#include <sys/kthread.h> |
|
|
#ifdef COMPAT_50 |
#ifdef COMPAT_50 |
#include <compat/sys/time.h> |
#include <compat/sys/time.h> |
Line 144 int sock_loan_thresh = 4096; |
|
Line 145 int sock_loan_thresh = 4096; |
|
#endif |
#endif |
|
|
static kmutex_t so_pendfree_lock; |
static kmutex_t so_pendfree_lock; |
static struct mbuf *so_pendfree; |
static struct mbuf *so_pendfree = NULL; |
|
|
#ifndef SOMAXKVA |
#ifndef SOMAXKVA |
#define SOMAXKVA (16 * 1024 * 1024) |
#define SOMAXKVA (16 * 1024 * 1024) |
Line 157 static kauth_listener_t socket_listener; |
|
Line 158 static kauth_listener_t socket_listener; |
|
|
|
#define SOCK_LOAN_CHUNK 65536 |
#define SOCK_LOAN_CHUNK 65536 |
|
|
static size_t sodopendfree(void); |
static void sopendfree_thread(void *); |
static size_t sodopendfreel(void); |
static kcondvar_t pendfree_thread_cv; |
|
static lwp_t *sopendfree_lwp; |
|
|
static void sysctl_kern_somaxkva_setup(void); |
static void sysctl_kern_somaxkva_setup(void); |
static struct sysctllog *socket_sysctllog; |
static struct sysctllog *socket_sysctllog; |
Line 170 sokvareserve(struct socket *so, vsize_t |
|
Line 172 sokvareserve(struct socket *so, vsize_t |
|
|
|
mutex_enter(&so_pendfree_lock); |
mutex_enter(&so_pendfree_lock); |
while (socurkva + len > somaxkva) { |
while (socurkva + len > somaxkva) { |
size_t freed; |
|
|
|
/* |
|
* try to do pendfree. |
|
*/ |
|
|
|
freed = sodopendfreel(); |
|
|
|
/* |
|
* if some kva was freed, try again. |
|
*/ |
|
|
|
if (freed) |
|
continue; |
|
|
|
SOSEND_COUNTER_INCR(&sosend_kvalimit); |
SOSEND_COUNTER_INCR(&sosend_kvalimit); |
error = cv_wait_sig(&socurkva_cv, &so_pendfree_lock); |
error = cv_wait_sig(&socurkva_cv, &so_pendfree_lock); |
if (error) { |
if (error) { |
Line 277 sodoloanfree(struct vm_page **pgs, void |
|
Line 264 sodoloanfree(struct vm_page **pgs, void |
|
sokvafree(sva, len); |
sokvafree(sva, len); |
} |
} |
|
|
static size_t |
|
sodopendfree(void) |
|
{ |
|
size_t rv; |
|
|
|
if (__predict_true(so_pendfree == NULL)) |
|
return 0; |
|
|
|
mutex_enter(&so_pendfree_lock); |
|
rv = sodopendfreel(); |
|
mutex_exit(&so_pendfree_lock); |
|
|
|
return rv; |
|
} |
|
|
|
/* |
/* |
* sodopendfreel: free mbufs on "pendfree" list. |
* sopendfree_thread: free mbufs on "pendfree" list. |
* unlock and relock so_pendfree_lock when freeing mbufs. |
* unlock and relock so_pendfree_lock when freeing mbufs. |
* |
|
* => called with so_pendfree_lock held. |
|
*/ |
*/ |
|
|
static size_t |
static void |
sodopendfreel(void) |
sopendfree_thread(void *v) |
{ |
{ |
struct mbuf *m, *next; |
struct mbuf *m, *next; |
size_t rv = 0; |
size_t rv; |
|
|
KASSERT(mutex_owned(&so_pendfree_lock)); |
|
|
|
while (so_pendfree != NULL) { |
mutex_enter(&so_pendfree_lock); |
m = so_pendfree; |
|
so_pendfree = NULL; |
|
mutex_exit(&so_pendfree_lock); |
|
|
|
for (; m != NULL; m = next) { |
for (;;) { |
next = m->m_next; |
rv = 0; |
KASSERT((~m->m_flags & (M_EXT|M_EXT_PAGES)) == 0); |
while (so_pendfree != NULL) { |
KASSERT(m->m_ext.ext_refcnt == 0); |
m = so_pendfree; |
|
so_pendfree = NULL; |
|
mutex_exit(&so_pendfree_lock); |
|
|
|
for (; m != NULL; m = next) { |
|
next = m->m_next; |
|
KASSERT((~m->m_flags & (M_EXT|M_EXT_PAGES)) == 0); |
|
KASSERT(m->m_ext.ext_refcnt == 0); |
|
|
|
rv += m->m_ext.ext_size; |
|
sodoloanfree(m->m_ext.ext_pgs, m->m_ext.ext_buf, |
|
m->m_ext.ext_size); |
|
pool_cache_put(mb_cache, m); |
|
} |
|
|
rv += m->m_ext.ext_size; |
mutex_enter(&so_pendfree_lock); |
sodoloanfree(m->m_ext.ext_pgs, m->m_ext.ext_buf, |
|
m->m_ext.ext_size); |
|
pool_cache_put(mb_cache, m); |
|
} |
} |
|
if (rv) |
mutex_enter(&so_pendfree_lock); |
cv_broadcast(&socurkva_cv); |
|
cv_wait(&pendfree_thread_cv, &so_pendfree_lock); |
} |
} |
|
panic("sopendfree_thread"); |
return (rv); |
/* NOTREACHED */ |
} |
} |
|
|
void |
void |
Line 345 soloanfree(struct mbuf *m, void *buf, si |
|
Line 321 soloanfree(struct mbuf *m, void *buf, si |
|
mutex_enter(&so_pendfree_lock); |
mutex_enter(&so_pendfree_lock); |
m->m_next = so_pendfree; |
m->m_next = so_pendfree; |
so_pendfree = m; |
so_pendfree = m; |
cv_broadcast(&socurkva_cv); |
cv_signal(&pendfree_thread_cv); |
mutex_exit(&so_pendfree_lock); |
mutex_exit(&so_pendfree_lock); |
} |
} |
|
|
Line 415 sokva_reclaim_callback(struct callback_e |
|
Line 391 sokva_reclaim_callback(struct callback_e |
|
KASSERT(ce == &sokva_reclaimerentry); |
KASSERT(ce == &sokva_reclaimerentry); |
KASSERT(obj == NULL); |
KASSERT(obj == NULL); |
|
|
sodopendfree(); |
|
if (!vm_map_starved_p(kernel_map)) { |
if (!vm_map_starved_p(kernel_map)) { |
return CALLBACK_CHAIN_ABORT; |
return CALLBACK_CHAIN_ABORT; |
} |
} |
|
|
mutex_init(&so_pendfree_lock, MUTEX_DEFAULT, IPL_VM); |
mutex_init(&so_pendfree_lock, MUTEX_DEFAULT, IPL_VM); |
softnet_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); |
softnet_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); |
cv_init(&socurkva_cv, "sokva"); |
cv_init(&socurkva_cv, "sokva"); |
|
cv_init(&pendfree_thread_cv, "sopendfr"); |
soinit2(); |
soinit2(); |
|
|
/* Set the initial adjusted socket buffer size. */ |
/* Set the initial adjusted socket buffer size. */ |
|
|
socket_listener_cb, NULL); |
socket_listener_cb, NULL); |
} |
} |
|
|
|
void |
|
soinit1(void) |
|
{ |
|
int error = kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL, |
|
sopendfree_thread, NULL, &sopendfree_lwp, "sopendfree"); |
|
if (error) |
|
panic("soinit1 %d", error); |
|
} |
|
|
/* |
/* |
* Socket operation routines. |
* Socket operation routines. |
* These routines are called by the routines in |
* These routines are called by the routines in |
Line 878 sodisconnect(struct socket *so) |
|
Line 863 sodisconnect(struct socket *so) |
|
error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, |
error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, |
NULL, NULL, NULL, NULL); |
NULL, NULL, NULL, NULL); |
} |
} |
sodopendfree(); |
|
return (error); |
return (error); |
} |
} |
|
|
Line 911 sosend(struct socket *so, struct mbuf *a |
|
Line 895 sosend(struct socket *so, struct mbuf *a |
|
short wakeup_state = 0; |
short wakeup_state = 0; |
|
|
p = l->l_proc; |
p = l->l_proc; |
sodopendfree(); |
|
clen = 0; |
clen = 0; |
|
|
/* |
/* |
Line 1187 soreceive(struct socket *so, struct mbuf |
|
Line 1170 soreceive(struct socket *so, struct mbuf |
|
else |
else |
flags = 0; |
flags = 0; |
|
|
if ((flags & MSG_DONTWAIT) == 0) |
|
sodopendfree(); |
|
|
|
if (flags & MSG_OOB) { |
if (flags & MSG_OOB) { |
m = m_get(M_WAIT, MT_DATA); |
m = m_get(M_WAIT, MT_DATA); |
solock(so); |
solock(so); |