Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/uipc_sockbuf.c
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
* can call back into the AIO module if it is loaded. | * can call back into the AIO module if it is loaded. | ||||
*/ | */ | ||||
void (*aio_swake)(struct socket *, struct sockbuf *); | void (*aio_swake)(struct socket *, struct sockbuf *); | ||||
/* | /* | ||||
* Primitive routines for operating on socket buffers | * Primitive routines for operating on socket buffers | ||||
*/ | */ | ||||
#define BUF_MAX_ADJ(_sz) (((u_quad_t)(_sz)) * MCLBYTES / (MSIZE + MCLBYTES)) | |||||
u_long sb_max = SB_MAX; | u_long sb_max = SB_MAX; | ||||
u_long sb_max_adj = | u_long sb_max_adj = BUF_MAX_ADJ(SB_MAX); | ||||
(quad_t)SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */ | |||||
static u_long sb_efficiency = 8; /* parameter for sbreserve() */ | static u_long sb_efficiency = 8; /* parameter for sbreserve() */ | ||||
#ifdef KERN_TLS | #ifdef KERN_TLS | ||||
static void sbcompress_ktls_rx(struct sockbuf *sb, struct mbuf *m, | static void sbcompress_ktls_rx(struct sockbuf *sb, struct mbuf *m, | ||||
struct mbuf *n); | struct mbuf *n); | ||||
#endif | #endif | ||||
static struct mbuf *sbcut_internal(struct sockbuf *sb, int len); | static struct mbuf *sbcut_internal(struct sockbuf *sb, int len); | ||||
▲ Show 20 Lines • Show All 526 Lines • ▼ Show 20 Lines | sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS) | ||||
u_long tmp_sb_max = sb_max; | u_long tmp_sb_max = sb_max; | ||||
error = sysctl_handle_long(oidp, &tmp_sb_max, arg2, req); | error = sysctl_handle_long(oidp, &tmp_sb_max, arg2, req); | ||||
if (error || !req->newptr) | if (error || !req->newptr) | ||||
return (error); | return (error); | ||||
if (tmp_sb_max < MSIZE + MCLBYTES) | if (tmp_sb_max < MSIZE + MCLBYTES) | ||||
return (EINVAL); | return (EINVAL); | ||||
sb_max = tmp_sb_max; | sb_max = tmp_sb_max; | ||||
sb_max_adj = (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES); | sb_max_adj = BUF_MAX_ADJ(sb_max); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Allot mbufs to a sockbuf. Attempt to scale mbmax so that mbcnt doesn't | * Allot mbufs to a sockbuf. Attempt to scale mbmax so that mbcnt doesn't | ||||
* become limiting if buffering efficiency is near the normal case. | * become limiting if buffering efficiency is near the normal case. | ||||
*/ | */ | ||||
bool | bool | ||||
sbreserve_locked(struct socket *so, sb_which which, u_long cc, | sbreserve_locked_limit(struct socket *so, sb_which which, u_long cc, | ||||
struct thread *td) | u_long buf_max, struct thread *td) | ||||
{ | { | ||||
struct sockbuf *sb = sobuf(so, which); | struct sockbuf *sb = sobuf(so, which); | ||||
rlim_t sbsize_limit; | rlim_t sbsize_limit; | ||||
SOCK_BUF_LOCK_ASSERT(so, which); | SOCK_BUF_LOCK_ASSERT(so, which); | ||||
/* | /* | ||||
* When a thread is passed, we take into account the thread's socket | * When a thread is passed, we take into account the thread's socket | ||||
* buffer size limit. The caller will generally pass curthread, but | * buffer size limit. The caller will generally pass curthread, but | ||||
* in the TCP input path, NULL will be passed to indicate that no | * in the TCP input path, NULL will be passed to indicate that no | ||||
* appropriate thread resource limits are available. In that case, | * appropriate thread resource limits are available. In that case, | ||||
* we don't apply a process limit. | * we don't apply a process limit. | ||||
*/ | */ | ||||
if (cc > sb_max_adj) | if (cc > BUF_MAX_ADJ(buf_max)) | ||||
return (false); | return (false); | ||||
if (td != NULL) { | if (td != NULL) { | ||||
sbsize_limit = lim_cur(td, RLIMIT_SBSIZE); | sbsize_limit = lim_cur(td, RLIMIT_SBSIZE); | ||||
} else | } else | ||||
sbsize_limit = RLIM_INFINITY; | sbsize_limit = RLIM_INFINITY; | ||||
if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc, | if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc, | ||||
sbsize_limit)) | sbsize_limit)) | ||||
return (false); | return (false); | ||||
sb->sb_mbmax = min(cc * sb_efficiency, sb_max); | sb->sb_mbmax = min(cc * sb_efficiency, buf_max); | ||||
if (sb->sb_lowat > sb->sb_hiwat) | if (sb->sb_lowat > sb->sb_hiwat) | ||||
sb->sb_lowat = sb->sb_hiwat; | sb->sb_lowat = sb->sb_hiwat; | ||||
return (true); | return (true); | ||||
} | |||||
bool | |||||
sbreserve_locked(struct socket *so, sb_which which, u_long cc, | |||||
struct thread *td) | |||||
{ | |||||
return (sbreserve_locked_limit(so, which, cc, sb_max, td)); | |||||
} | } | ||||
int | int | ||||
sbsetopt(struct socket *so, struct sockopt *sopt) | sbsetopt(struct socket *so, struct sockopt *sopt) | ||||
{ | { | ||||
struct sockbuf *sb; | struct sockbuf *sb; | ||||
sb_which wh; | sb_which wh; | ||||
short *flags; | short *flags; | ||||
▲ Show 20 Lines • Show All 1,197 Lines • Show Last 20 Lines |