diff options
author | Niels Provos <provos@cvs.openbsd.org> | 2001-11-27 22:53:21 +0000 |
---|---|---|
committer | Niels Provos <provos@cvs.openbsd.org> | 2001-11-27 22:53:21 +0000 |
commit | 70b56742cf82dfc14c2cddce7d760f0ef720291e (patch) | |
tree | 743df86ba0d4278b2e776940adc1087e02ba62fc /sys/kern | |
parent | de8a6b54fc1b9cc6e96a16bfcb7b264bc528de2c (diff) |
change socket allocation to pool allocator; from netbsd; okay niklas@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/init_main.c | 6 | ||||
-rw-r--r-- | sys/kern/uipc_socket.c | 30 | ||||
-rw-r--r-- | sys/kern/uipc_socket2.c | 8 |
3 files changed, 34 insertions, 10 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index f807a181062..800eb96aa08 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.85 2001/11/27 05:27:11 art Exp $ */ +/* $OpenBSD: init_main.c,v 1.86 2001/11/27 22:53:19 provos Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -61,6 +61,7 @@ #include <sys/conf.h> #include <sys/buf.h> #include <sys/device.h> +#include <sys/socketvar.h> #include <sys/protosw.h> #include <sys/reboot.h> #include <sys/user.h> @@ -210,6 +211,9 @@ main(framep) */ mbinit(); + /* Initalize sockets. */ + soinit(); + /* * Initialize timeouts. */ diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index c7ff2b6ae35..8b3c6dea96e 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.37 2001/11/27 17:55:39 provos Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.38 2001/11/27 22:53:19 provos Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -50,6 +50,7 @@ #include <sys/socketvar.h> #include <sys/signalvar.h> #include <sys/resourcevar.h> +#include <sys/pool.h> void filt_sordetach(struct knote *kn); int filt_soread(struct knote *kn, long hint); @@ -72,6 +73,16 @@ struct filterops sowrite_filtops = int somaxconn = SOMAXCONN; int sominconn = SOMINCONN; +struct pool socket_pool; + +void +soinit(void) +{ + + pool_init(&socket_pool, sizeof(struct socket), 0, 0, 0, + "sockpl", 0, NULL, NULL, M_SOCKET); +} + /* * Socket operation routines. * These routines are called by the routines in @@ -88,9 +99,9 @@ socreate(dom, aso, type, proto) int proto; { struct proc *p = curproc; /* XXX */ - register struct protosw *prp; - register struct socket *so; - register int error; + struct protosw *prp; + struct socket *so; + int error, s; if (proto) prp = pffindproto(dom, proto, type); @@ -100,7 +111,8 @@ socreate(dom, aso, type, proto) return (EPROTONOSUPPORT); if (prp->pr_type != type) return (EPROTOTYPE); - MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT); + s = splsoftnet(); + so = pool_get(&socket_pool, PR_WAITOK); bzero((caddr_t)so, sizeof(*so)); TAILQ_INIT(&so->so_q0); TAILQ_INIT(&so->so_q); @@ -115,6 +127,7 @@ socreate(dom, aso, type, proto) if (error) { so->so_state |= SS_NOFDREF; sofree(so); + splx(s); return (error); } #ifdef COMPAT_SUNOS @@ -124,6 +137,7 @@ socreate(dom, aso, type, proto) so->so_options |= SO_BROADCAST; } #endif + splx(s); *aso = so; return (0); } @@ -164,6 +178,10 @@ solisten(so, backlog) return (0); } +/* + * Must be called at splsoftnet() + */ + void sofree(so) register struct socket *so; @@ -182,7 +200,7 @@ sofree(so) } sbrelease(&so->so_snd); sorflush(so); - FREE(so, M_SOCKET); + pool_put(&socket_pool, so); } /* diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index 5b8d6e19efc..5ea887dfbca 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket2.c,v 1.21 2001/11/27 15:51:36 provos Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.22 2001/11/27 22:53:19 provos Exp $ */ /* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* @@ -149,6 +149,8 @@ soisdisconnected(so) * then we allocate a new structure, properly linked into the * data structure of the original socket, and return this. * Connstatus may be 0, or SS_ISCONFIRMING, or SS_ISCONNECTED. + * + * Must be called at splsoftnet() */ struct socket * sonewconn(head, connstatus) @@ -160,7 +162,7 @@ sonewconn(head, connstatus) if (head->so_qlen + head->so_q0len > head->so_qlimit * 3) return ((struct socket *)0); - MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_DONTWAIT); + so = pool_get(&socket_pool, PR_NOWAIT); if (so == NULL) return ((struct socket *)0); bzero((caddr_t)so, sizeof(*so)); @@ -180,7 +182,7 @@ sonewconn(head, connstatus) if ((*so->so_proto->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0)) { (void) soqremque(so, soqueue); - (void) free((caddr_t)so, M_SOCKET); + pool_put(&socket_pool, so); return ((struct socket *)0); } if (connstatus) { |