Allow for nmbclusters and maxsockets to be increased via sysctl.

An eventhandler is used to update all the various zones that depend
on these values.
This commit is contained in:
ps 2006-04-21 09:25:40 +00:00
parent 71dd157044
commit 10b2fe8dea
15 changed files with 184 additions and 6 deletions

View File

@ -112,7 +112,25 @@ SYSINIT(tunable_mbinit, SI_SUB_TUNABLES, SI_ORDER_ANY, tunable_mbinit, NULL);
SYSCTL_DECL(_kern_ipc);
/* XXX: These should be tuneables. Can't change UMA limits on the fly. */
SYSCTL_INT(_kern_ipc, OID_AUTO, nmbclusters, CTLFLAG_RW, &nmbclusters, 0,
static int
sysctl_nmbclusters(SYSCTL_HANDLER_ARGS)
{
int error, newnmbclusters;
newnmbclusters = nmbclusters;
error = sysctl_handle_int(oidp, &newnmbclusters, sizeof(int), req);
if (error == 0 && req->newptr) {
if (newnmbclusters > nmbclusters) {
nmbclusters = newnmbclusters;
uma_zone_set_max(zone_clust, nmbclusters);
EVENTHANDLER_INVOKE(nmbclusters_change);
} else
error = EINVAL;
}
return (error);
}
SYSCTL_PROC(_kern_ipc, OID_AUTO, nmbclusters, CTLTYPE_INT|CTLFLAG_RW,
&nmbclusters, 0, sysctl_nmbclusters, "IU",
"Maximum number of mbuf clusters allowed");
SYSCTL_INT(_kern_ipc, OID_AUTO, nmbjumbop, CTLFLAG_RW, &nmbjumbop, 0,
"Maximum number of mbuf page size jumbo clusters allowed");

View File

@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/socket.h>
#include <sys/protosw.h>
#include <sys/domain.h>
#include <sys/eventhandler.h>
#include <sys/mbuf.h>
#include <sys/kernel.h>
#include <sys/lock.h>
@ -189,6 +190,13 @@ net_add_domain(void *data)
net_init_domain(dp);
}
static void
socket_zone_change(void *tag)
{
uma_zone_set_max(socket_zone, maxsockets);
}
/* ARGSUSED*/
static void
domaininit(void *dummy)
@ -201,6 +209,8 @@ domaininit(void *dummy)
socket_zone = uma_zcreate("socket", sizeof(struct socket), NULL, NULL,
NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uma_zone_set_max(socket_zone, maxsockets);
EVENTHANDLER_REGISTER(maxsockets_change, socket_zone_change, NULL,
EVENTHANDLER_PRI_FIRST);
if (max_linkhdr < 16) /* XXX */
max_linkhdr = 16;

View File

@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <sys/aio.h> /* for aio_swake proto */
#include <sys/domain.h>
#include <sys/event.h>
#include <sys/eventhandler.h>
#include <sys/file.h> /* for maxfiles */
#include <sys/kernel.h>
#include <sys/lock.h>
@ -1508,8 +1509,29 @@ static int dummy;
SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW, &dummy, 0, "");
SYSCTL_OID(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf, CTLTYPE_ULONG|CTLFLAG_RW,
&sb_max, 0, sysctl_handle_sb_max, "LU", "Maximum socket buffer size");
SYSCTL_INT(_kern_ipc, OID_AUTO, maxsockets, CTLFLAG_RDTUN,
&maxsockets, 0, "Maximum number of sockets avaliable");
static int
sysctl_maxsockets(SYSCTL_HANDLER_ARGS)
{
int error, newmaxsockets;
newmaxsockets = maxsockets;
error = sysctl_handle_int(oidp, &newmaxsockets, sizeof(int), req);
if (error == 0 && req->newptr) {
if (newmaxsockets > maxsockets) {
maxsockets = newmaxsockets;
if (maxsockets > ((maxfiles / 4) * 3)) {
maxfiles = (maxsockets * 5) / 4;
maxfilesperproc = (maxfiles * 9) / 10;
}
EVENTHANDLER_INVOKE(maxsockets_change);
} else
error = EINVAL;
}
return (error);
}
SYSCTL_PROC(_kern_ipc, OID_AUTO, maxsockets, CTLTYPE_INT|CTLFLAG_RW,
&maxsockets, 0, sysctl_maxsockets, "IU",
"Maximum number of sockets avaliable");
SYSCTL_ULONG(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW,
&sb_efficiency, 0, "");

View File

@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <sys/aio.h> /* for aio_swake proto */
#include <sys/domain.h>
#include <sys/event.h>
#include <sys/eventhandler.h>
#include <sys/file.h> /* for maxfiles */
#include <sys/kernel.h>
#include <sys/lock.h>
@ -1508,8 +1509,29 @@ static int dummy;
SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW, &dummy, 0, "");
SYSCTL_OID(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf, CTLTYPE_ULONG|CTLFLAG_RW,
&sb_max, 0, sysctl_handle_sb_max, "LU", "Maximum socket buffer size");
SYSCTL_INT(_kern_ipc, OID_AUTO, maxsockets, CTLFLAG_RDTUN,
&maxsockets, 0, "Maximum number of sockets avaliable");
static int
sysctl_maxsockets(SYSCTL_HANDLER_ARGS)
{
int error, newmaxsockets;
newmaxsockets = maxsockets;
error = sysctl_handle_int(oidp, &newmaxsockets, sizeof(int), req);
if (error == 0 && req->newptr) {
if (newmaxsockets > maxsockets) {
maxsockets = newmaxsockets;
if (maxsockets > ((maxfiles / 4) * 3)) {
maxfiles = (maxsockets * 5) / 4;
maxfilesperproc = (maxfiles * 9) / 10;
}
EVENTHANDLER_INVOKE(maxsockets_change);
} else
error = EINVAL;
}
return (error);
}
SYSCTL_PROC(_kern_ipc, OID_AUTO, maxsockets, CTLTYPE_INT|CTLFLAG_RW,
&maxsockets, 0, sysctl_maxsockets, "IU",
"Maximum number of sockets avaliable");
SYSCTL_ULONG(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW,
&sb_efficiency, 0, "");

View File

@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include <sys/domain.h>
#include <sys/fcntl.h>
#include <sys/malloc.h> /* XXX must be before <sys/file.h> */
#include <sys/eventhandler.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/jail.h>
@ -1325,6 +1326,13 @@ unp_externalize(struct mbuf *control, struct mbuf **controlp)
return (error);
}
static void
unp_zone_change(void *tag)
{
uma_zone_set_max(unp_zone, maxsockets);
}
void
unp_init(void)
{
@ -1332,7 +1340,9 @@ unp_init(void)
NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
if (unp_zone == NULL)
panic("unp_init");
uma_zone_set_max(unp_zone, nmbclusters);
uma_zone_set_max(unp_zone, maxsockets);
EVENTHANDLER_REGISTER(maxsockets_change, unp_zone_change,
NULL, EVENTHANDLER_PRI_ANY);
LIST_INIT(&unp_dhead);
LIST_INIT(&unp_shead);
TASK_INIT(&unp_gc_task, 0, unp_gc, NULL);

View File

@ -116,6 +116,13 @@ static u_long div_recvspace = DIVRCVQ; /* XXX sysctl ? */
/*
* Initialize divert connection block queue.
*/
static void
div_zone_change(void *tag)
{
uma_zone_set_max(divcbinfo.ipi_zone, maxsockets);
}
void
div_init(void)
{
@ -132,6 +139,8 @@ div_init(void)
divcbinfo.ipi_zone = uma_zcreate("divcb", sizeof(struct inpcb),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uma_zone_set_max(divcbinfo.ipi_zone, maxsockets);
EVENTHANDLER_REGISTER(maxsockets_change, div_zone_change,
NULL, EVENTHANDLER_PRI_ANY);
}
/*

View File

@ -167,6 +167,7 @@ static struct mtx ipqlock;
#define IPQ_LOCK_ASSERT() mtx_assert(&ipqlock, MA_OWNED)
static void maxnipq_update(void);
static void ipq_zone_change(void *);
static int maxnipq; /* Administrative limit on # reass queues. */
static int nipq = 0; /* Total # of reass queues */
@ -256,6 +257,8 @@ ip_init()
ipport_tick(NULL);
EVENTHANDLER_REGISTER(shutdown_pre_sync, ip_fini, NULL,
SHUTDOWN_PRI_DEFAULT);
EVENTHANDLER_REGISTER(nmbclusters_change, ipq_zone_change,
NULL, EVENTHANDLER_PRI_ANY);
/* Initialize various other remaining things. */
ip_id = time_second & 0xffff;
@ -687,6 +690,16 @@ maxnipq_update(void)
uma_zone_set_max(ipq_zone, 1);
}
static void
ipq_zone_change(void *tag)
{
if (maxnipq > 0 && maxnipq < (nmbclusters / 32)) {
maxnipq = nmbclusters / 32;
maxnipq_update();
}
}
static int
sysctl_maxnipq(SYSCTL_HANDLER_ARGS)
{

View File

@ -116,6 +116,13 @@ void (*ip_rsvp_force_done)(struct socket *);
/*
* Initialize raw connection block q.
*/
static void
rip_zone_change(void *tag)
{
uma_zone_set_max(ripcbinfo.ipi_zone, maxsockets);
}
void
rip_init()
{
@ -132,6 +139,8 @@ rip_init()
ripcbinfo.ipi_zone = uma_zcreate("ripcb", sizeof(struct inpcb),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uma_zone_set_max(ripcbinfo.ipi_zone, maxsockets);
EVENTHANDLER_REGISTER(maxsockets_change, rip_zone_change,
NULL, EVENTHANDLER_PRI_ANY);
}
static struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET };

View File

@ -202,6 +202,14 @@ do { \
(tcp_delack_enabled || (tp->t_flags & TF_NEEDSYN)))
/* Initialize TCP reassembly queue */
static void
tcp_reass_zone_change(void *tag)
{
tcp_reass_maxseg = nmbclusters / 16;
uma_zone_set_max(tcp_reass_zone, tcp_reass_maxseg);
}
uma_zone_t tcp_reass_zone;
void
tcp_reass_init()
@ -212,6 +220,8 @@ tcp_reass_init()
tcp_reass_zone = uma_zcreate("tcpreass", sizeof (struct tseg_qent),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uma_zone_set_max(tcp_reass_zone, tcp_reass_maxseg);
EVENTHANDLER_REGISTER(nmbclusters_change,
tcp_reass_zone_change, NULL, EVENTHANDLER_PRI_ANY);
}
static int

View File

@ -202,6 +202,14 @@ do { \
(tcp_delack_enabled || (tp->t_flags & TF_NEEDSYN)))
/* Initialize TCP reassembly queue */
static void
tcp_reass_zone_change(void *tag)
{
tcp_reass_maxseg = nmbclusters / 16;
uma_zone_set_max(tcp_reass_zone, tcp_reass_maxseg);
}
uma_zone_t tcp_reass_zone;
void
tcp_reass_init()
@ -212,6 +220,8 @@ tcp_reass_init()
tcp_reass_zone = uma_zcreate("tcpreass", sizeof (struct tseg_qent),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uma_zone_set_max(tcp_reass_zone, tcp_reass_maxseg);
EVENTHANDLER_REGISTER(nmbclusters_change,
tcp_reass_zone_change, NULL, EVENTHANDLER_PRI_ANY);
}
static int

View File

@ -248,6 +248,15 @@ struct callout isn_callout;
/*
* TCP initialization.
*/
static void
tcp_zone_change(void *tag)
{
uma_zone_set_max(tcbinfo.ipi_zone, maxsockets);
uma_zone_set_max(tcpcb_zone, maxsockets);
uma_zone_set_max(tcptw_zone, maxsockets / 5);
}
void
tcp_init(void)
{
@ -310,6 +319,8 @@ tcp_init(void)
SHUTDOWN_PRI_DEFAULT);
sack_hole_zone = uma_zcreate("sackhole", sizeof(struct sackhole),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
EVENTHANDLER_REGISTER(maxsockets_change, tcp_zone_change, NULL,
EVENTHANDLER_PRI_ANY);
}
void

View File

@ -248,6 +248,15 @@ struct callout isn_callout;
/*
* TCP initialization.
*/
static void
tcp_zone_change(void *tag)
{
uma_zone_set_max(tcbinfo.ipi_zone, maxsockets);
uma_zone_set_max(tcpcb_zone, maxsockets);
uma_zone_set_max(tcptw_zone, maxsockets / 5);
}
void
tcp_init(void)
{
@ -310,6 +319,8 @@ tcp_init(void)
SHUTDOWN_PRI_DEFAULT);
sack_hole_zone = uma_zcreate("sackhole", sizeof(struct sackhole),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
EVENTHANDLER_REGISTER(maxsockets_change, tcp_zone_change, NULL,
EVENTHANDLER_PRI_ANY);
}
void

View File

@ -38,6 +38,7 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/domain.h>
#include <sys/eventhandler.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/lock.h>
@ -129,6 +130,13 @@ static void udp_detach(struct socket *so);
static int udp_output(struct inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct thread *);
static void
udp_zone_change(void *tag)
{
uma_zone_set_max(udbinfo.ipi_zone, maxsockets);
}
void
udp_init()
{
@ -141,6 +149,8 @@ udp_init()
udbinfo.ipi_zone = uma_zcreate("udpcb", sizeof(struct inpcb), NULL,
NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uma_zone_set_max(udbinfo.ipi_zone, maxsockets);
EVENTHANDLER_REGISTER(maxsockets_change, udp_zone_change, NULL,
EVENTHANDLER_PRI_ANY);
}
void

View File

@ -87,12 +87,22 @@ static MALLOC_DEFINE(M_FTABLE, "fragment", "fragment reassembly header");
/*
* Initialise reassembly queue and fragment identifier.
*/
static void
frag6_change(void *tag)
{
ip6_maxfragpackets = nmbclusters / 4;
ip6_maxfrags = nmbclusters / 4;
}
void
frag6_init()
{
ip6_maxfragpackets = nmbclusters / 4;
ip6_maxfrags = nmbclusters / 4;
EVENTHANDLER_REGISTER(nmbclusters_change,
frag6_change, NULL, EVENTHANDLER_PRI_ANY);
IP6Q_LOCK_INIT();

View File

@ -171,4 +171,7 @@ EVENTHANDLER_DECLARE(process_exit, exitlist_fn);
EVENTHANDLER_DECLARE(process_fork, forklist_fn);
EVENTHANDLER_DECLARE(process_exec, execlist_fn);
typedef void (*uma_zone_chfn)(void *);
EVENTHANDLER_DECLARE(nmbclusters_change, uma_zone_chfn);
EVENTHANDLER_DECLARE(maxsockets_change, uma_zone_chfn);
#endif /* SYS_EVENTHANDLER_H */