version 1.83.2.3, 2004/08/25 06:58:58 |
version 1.115.2.1, 2005/12/31 11:14:01 |
Line 105 int somaxconn = SOMAXCONN; |
|
Line 105 int somaxconn = SOMAXCONN; |
|
#ifdef SOSEND_COUNTERS |
#ifdef SOSEND_COUNTERS |
#include <sys/device.h> |
#include <sys/device.h> |
|
|
struct evcnt sosend_loan_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
static struct evcnt sosend_loan_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
NULL, "sosend", "loan big"); |
NULL, "sosend", "loan big"); |
struct evcnt sosend_copy_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
static struct evcnt sosend_copy_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
NULL, "sosend", "copy big"); |
NULL, "sosend", "copy big"); |
struct evcnt sosend_copy_small = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
static struct evcnt sosend_copy_small = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
NULL, "sosend", "copy small"); |
NULL, "sosend", "copy small"); |
struct evcnt sosend_kvalimit = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
static struct evcnt sosend_kvalimit = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
NULL, "sosend", "kva limit"); |
NULL, "sosend", "kva limit"); |
|
|
#define SOSEND_COUNTER_INCR(ev) (ev)->ev_count++ |
#define SOSEND_COUNTER_INCR(ev) (ev)->ev_count++ |
|
|
|
|
/* 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\n", sb_max); |
panic("bad initial sb_max value: %lu", sb_max); |
|
|
} |
} |
|
|
Line 142 int use_sosend_loan = 0; |
|
Line 142 int use_sosend_loan = 0; |
|
int use_sosend_loan = 1; |
int use_sosend_loan = 1; |
#endif |
#endif |
|
|
struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER; |
static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER; |
struct mbuf *so_pendfree; |
static struct mbuf *so_pendfree; |
|
|
#ifndef SOMAXKVA |
#ifndef SOMAXKVA |
#define SOMAXKVA (16 * 1024 * 1024) |
#define SOMAXKVA (16 * 1024 * 1024) |
#endif |
#endif |
int somaxkva = SOMAXKVA; |
int somaxkva = SOMAXKVA; |
int socurkva; |
static int socurkva; |
int sokvawaiters; |
static int sokvawaiters; |
|
|
#define SOCK_LOAN_THRESH 4096 |
#define SOCK_LOAN_THRESH 4096 |
#define SOCK_LOAN_CHUNK 65536 |
#define SOCK_LOAN_CHUNK 65536 |
|
|
static size_t sodopendfree(struct socket *); |
static size_t sodopendfree(struct socket *); |
static size_t sodopendfreel(struct socket *); |
static size_t sodopendfreel(struct socket *); |
static __inline vsize_t sokvareserve(struct socket *, vsize_t); |
|
static __inline void sokvaunreserve(vsize_t); |
|
|
|
static __inline vsize_t |
static vsize_t |
sokvareserve(struct socket *so, vsize_t len) |
sokvareserve(struct socket *so, vsize_t len) |
{ |
{ |
int s; |
int s; |
Line 200 sokvareserve(struct socket *so, vsize_t |
|
Line 198 sokvareserve(struct socket *so, vsize_t |
|
return len; |
return len; |
} |
} |
|
|
static __inline void |
static void |
sokvaunreserve(vsize_t len) |
sokvaunreserve(vsize_t len) |
{ |
{ |
int s; |
int s; |
Line 234 sokvaalloc(vsize_t len, struct socket *s |
|
Line 232 sokvaalloc(vsize_t len, struct socket *s |
|
* allocate kva. |
* allocate kva. |
*/ |
*/ |
|
|
lva = uvm_km_valloc_wait(kernel_map, len); |
lva = uvm_km_alloc(kernel_map, len, 0, UVM_KMF_VAONLY | UVM_KMF_WAITVA); |
if (lva == 0) { |
if (lva == 0) { |
sokvaunreserve(len); |
sokvaunreserve(len); |
return (0); |
return (0); |
Line 255 sokvafree(vaddr_t sva, vsize_t len) |
|
Line 253 sokvafree(vaddr_t sva, vsize_t len) |
|
* free kva. |
* free kva. |
*/ |
*/ |
|
|
uvm_km_free(kernel_map, sva, len); |
uvm_km_free(kernel_map, sva, len, UVM_KMF_VAONLY); |
|
|
/* |
/* |
* unreserve kva. |
* unreserve kva. |
Line 392 sosend_loan(struct socket *so, struct ui |
|
Line 390 sosend_loan(struct socket *so, struct ui |
|
vaddr_t lva, va; |
vaddr_t lva, va; |
int npgs, i, error; |
int npgs, i, error; |
|
|
if (uio->uio_segflg != UIO_USERSPACE) |
if (VM_MAP_IS_KERNEL(&uio->uio_vmspace->vm_map)) |
return (0); |
return (0); |
|
|
if (iov->iov_len < (size_t) space) |
if (iov->iov_len < (size_t) space) |
Line 407 sosend_loan(struct socket *so, struct ui |
|
Line 405 sosend_loan(struct socket *so, struct ui |
|
|
|
/* XXX KDASSERT */ |
/* XXX KDASSERT */ |
KASSERT(npgs <= M_EXT_MAXPAGES); |
KASSERT(npgs <= M_EXT_MAXPAGES); |
KASSERT(uio->uio_lwp != NULL); |
|
|
|
lva = sokvaalloc(len, so); |
lva = sokvaalloc(len, so); |
if (lva == 0) |
if (lva == 0) |
return 0; |
return 0; |
|
|
error = uvm_loan(&uio->uio_lwp->l_proc->p_vmspace->vm_map, sva, len, |
error = uvm_loan(&uio->uio_vmspace->vm_map, sva, len, |
m->m_ext.ext_pgs, UVM_LOAN_TOPAGE); |
m->m_ext.ext_pgs, UVM_LOAN_TOPAGE); |
if (error) { |
if (error) { |
sokvafree(lva, len); |
sokvafree(lva, len); |
Line 455 socreate(int dom, struct socket **aso, i |
|
Line 452 socreate(int dom, struct socket **aso, i |
|
{ |
{ |
const struct protosw *prp; |
const struct protosw *prp; |
struct socket *so; |
struct socket *so; |
struct proc *p; |
uid_t uid; |
int error, s; |
int error, s; |
|
|
p = l->l_proc; |
|
if (proto) |
if (proto) |
prp = pffindproto(dom, proto, type); |
prp = pffindproto(dom, proto, type); |
else |
else |
Line 481 socreate(int dom, struct socket **aso, i |
|
Line 477 socreate(int dom, struct socket **aso, i |
|
so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; |
so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; |
so->so_mowner = &prp->pr_domain->dom_mowner; |
so->so_mowner = &prp->pr_domain->dom_mowner; |
#endif |
#endif |
if (p != 0) |
if (l != NULL) { |
so->so_uid = p->p_ucred->cr_uid; |
uid = l->l_proc->p_ucred->cr_uid; |
else |
} else { |
so->so_uid = UID_MAX; |
uid = 0; |
|
} |
|
so->so_uidinfo = uid_find(uid); |
error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, |
error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, |
(struct mbuf *)(long)proto, (struct mbuf *)0, l); |
(struct mbuf *)(long)proto, (struct mbuf *)0, l); |
if (error) { |
if (error) { |
Line 547 sofree(struct socket *so) |
|
Line 545 sofree(struct socket *so) |
|
return; |
return; |
} |
} |
if (so->so_rcv.sb_hiwat) |
if (so->so_rcv.sb_hiwat) |
(void)chgsbsize(so->so_uid, &so->so_rcv.sb_hiwat, 0, |
(void)chgsbsize(so->so_uidinfo, &so->so_rcv.sb_hiwat, 0, |
RLIM_INFINITY); |
RLIM_INFINITY); |
if (so->so_snd.sb_hiwat) |
if (so->so_snd.sb_hiwat) |
(void)chgsbsize(so->so_uid, &so->so_snd.sb_hiwat, 0, |
(void)chgsbsize(so->so_uidinfo, &so->so_snd.sb_hiwat, 0, |
RLIM_INFINITY); |
RLIM_INFINITY); |
sbrelease(&so->so_snd, so); |
sbrelease(&so->so_snd, so); |
sorflush(so); |
sorflush(so); |
Line 877 sosend(struct socket *so, struct mbuf *a |
|
Line 875 sosend(struct socket *so, struct mbuf *a |
|
break; |
break; |
} |
} |
} while (space > 0 && atomic); |
} while (space > 0 && atomic); |
|
|
s = splsoftnet(); |
s = splsoftnet(); |
|
|
if (so->so_state & SS_CANTSENDMORE) |
if (so->so_state & SS_CANTSENDMORE) |
|
|
soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, |
soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, |
struct mbuf **mp0, struct mbuf **controlp, int *flagsp) |
struct mbuf **mp0, struct mbuf **controlp, int *flagsp) |
{ |
{ |
struct lwp *l; |
struct lwp *l = curlwp; |
struct proc *p; |
|
struct mbuf *m, **mp; |
struct mbuf *m, **mp; |
int flags, len, error, s, offset, moff, type, orig_resid; |
int flags, len, error, s, offset, moff, type, orig_resid; |
const struct protosw *pr; |
const struct protosw *pr; |
Line 947 soreceive(struct socket *so, struct mbuf |
|
Line 944 soreceive(struct socket *so, struct mbuf |
|
mp = mp0; |
mp = mp0; |
type = 0; |
type = 0; |
orig_resid = uio->uio_resid; |
orig_resid = uio->uio_resid; |
l = uio->uio_lwp; |
|
p = l->l_proc; |
|
|
|
if (paddr) |
if (paddr) |
*paddr = 0; |
*paddr = 0; |
Line 1056 soreceive(struct socket *so, struct mbuf |
|
Line 1051 soreceive(struct socket *so, struct mbuf |
|
* While we process the initial mbufs containing address and control |
* While we process the initial mbufs containing address and control |
* info, we save a copy of m->m_nextpkt into nextrecord. |
* info, we save a copy of m->m_nextpkt into nextrecord. |
*/ |
*/ |
if (p) |
if (l) |
p->p_stats->p_ru.ru_msgrcv++; |
l->l_proc->p_stats->p_ru.ru_msgrcv++; |
KASSERT(m == so->so_rcv.sb_mb); |
KASSERT(m == so->so_rcv.sb_mb); |
SBLASTRECORDCHK(&so->so_rcv, "soreceive 1"); |
SBLASTRECORDCHK(&so->so_rcv, "soreceive 1"); |
SBLASTMBUFCHK(&so->so_rcv, "soreceive 1"); |
SBLASTMBUFCHK(&so->so_rcv, "soreceive 1"); |
Line 1096 soreceive(struct socket *so, struct mbuf |
|
Line 1091 soreceive(struct socket *so, struct mbuf |
|
mbuf_removed = 1; |
mbuf_removed = 1; |
if (controlp) { |
if (controlp) { |
struct domain *dom = pr->pr_domain; |
struct domain *dom = pr->pr_domain; |
if (dom->dom_externalize && p && |
if (dom->dom_externalize && l && |
mtod(m, struct cmsghdr *)->cmsg_type == |
mtod(m, struct cmsghdr *)->cmsg_type == |
SCM_RIGHTS) |
SCM_RIGHTS) |
error = (*dom->dom_externalize)(m, l); |
error = (*dom->dom_externalize)(m, l); |
Line 1105 soreceive(struct socket *so, struct mbuf |
|
Line 1100 soreceive(struct socket *so, struct mbuf |
|
m->m_next = 0; |
m->m_next = 0; |
m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
} else { |
} else { |
|
/* |
|
* Dispose of any SCM_RIGHTS message that went |
|
* through the read path rather than recv. |
|
*/ |
|
if (pr->pr_domain->dom_dispose && |
|
mtod(m, struct cmsghdr *)->cmsg_type == SCM_RIGHTS) |
|
(*pr->pr_domain->dom_dispose)(m); |
MFREE(m, so->so_rcv.sb_mb); |
MFREE(m, so->so_rcv.sb_mb); |
m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
} |
} |
Line 1330 soreceive(struct socket *so, struct mbuf |
|
Line 1332 soreceive(struct socket *so, struct mbuf |
|
splx(s); |
splx(s); |
goto restart; |
goto restart; |
} |
} |
|
|
if (flagsp) |
if (flagsp) |
*flagsp |= flags; |
*flagsp |= flags; |
release: |
release: |
Line 1404 sosetopt(struct socket *so, int level, i |
|
Line 1406 sosetopt(struct socket *so, int level, i |
|
error = EINVAL; |
error = EINVAL; |
goto bad; |
goto bad; |
} |
} |
|
if (mtod(m, struct linger *)->l_linger < 0 || |
|
mtod(m, struct linger *)->l_linger > (INT_MAX / hz)) { |
|
error = EDOM; |
|
goto bad; |
|
} |
so->so_linger = mtod(m, struct linger *)->l_linger; |
so->so_linger = mtod(m, struct linger *)->l_linger; |
/* fall thru... */ |
/* fall thru... */ |
|
|
Line 1599 sogetopt(struct socket *so, int level, i |
|
Line 1606 sogetopt(struct socket *so, int level, i |
|
break; |
break; |
} |
} |
|
|
|
case SO_OVERFLOWED: |
|
*mtod(m, int *) = so->so_rcv.sb_overflowed; |
|
break; |
|
|
default: |
default: |
(void)m_free(m); |
(void)m_free(m); |
return (ENOPROTOOPT); |
return (ENOPROTOOPT); |
Line 1635 filt_soread(struct knote *kn, long hint) |
|
Line 1646 filt_soread(struct knote *kn, long hint) |
|
so = (struct socket *)kn->kn_fp->f_data; |
so = (struct socket *)kn->kn_fp->f_data; |
kn->kn_data = so->so_rcv.sb_cc; |
kn->kn_data = so->so_rcv.sb_cc; |
if (so->so_state & SS_CANTRCVMORE) { |
if (so->so_state & SS_CANTRCVMORE) { |
kn->kn_flags |= EV_EOF; |
kn->kn_flags |= EV_EOF; |
kn->kn_fflags = so->so_error; |
kn->kn_fflags = so->so_error; |
return (1); |
return (1); |
} |
} |
Line 1666 filt_sowrite(struct knote *kn, long hint |
|
Line 1677 filt_sowrite(struct knote *kn, long hint |
|
so = (struct socket *)kn->kn_fp->f_data; |
so = (struct socket *)kn->kn_fp->f_data; |
kn->kn_data = sbspace(&so->so_snd); |
kn->kn_data = sbspace(&so->so_snd); |
if (so->so_state & SS_CANTSENDMORE) { |
if (so->so_state & SS_CANTSENDMORE) { |
kn->kn_flags |= EV_EOF; |
kn->kn_flags |= EV_EOF; |
kn->kn_fflags = so->so_error; |
kn->kn_fflags = so->so_error; |
return (1); |
return (1); |
} |
} |
Line 1691 filt_solisten(struct knote *kn, long hin |
|
Line 1702 filt_solisten(struct knote *kn, long hin |
|
/* |
/* |
* Set kn_data to number of incoming connections, not |
* Set kn_data to number of incoming connections, not |
* counting partial (incomplete) connections. |
* counting partial (incomplete) connections. |
*/ |
*/ |
kn->kn_data = so->so_qlen; |
kn->kn_data = so->so_qlen; |
return (kn->kn_data > 0); |
return (kn->kn_data > 0); |
} |
} |