Author: andre
Date: Mon Jul  8 13:24:18 2013
New Revision: 253035
URL: http://svnweb.freebsd.org/changeset/base/253035

Log:
  MFC r241726:
  
   Move UMA socket zone initialization from uipc_domain.c to uipc_socket.c
   into one place next to its other related functions to avoid confusion.
  
  MFC r241729:
  
   Move socket UMA zone initialization functionality together into
   one place.
  
  MFC r241779:
  
   Tidy up somaxconn (accept queue limit) and related functions
   and move it together into one place.

Modified:
  stable/9/sys/kern/uipc_domain.c
  stable/9/sys/kern/uipc_socket.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/kern/uipc_domain.c
==============================================================================
--- stable/9/sys/kern/uipc_domain.c     Mon Jul  8 13:22:58 2013        
(r253034)
+++ stable/9/sys/kern/uipc_domain.c     Mon Jul  8 13:24:18 2013        
(r253035)
@@ -239,28 +239,11 @@ domain_add(void *data)
        mtx_unlock(&dom_mtx);
 }
 
-static void
-socket_zone_change(void *tag)
-{
-
-       uma_zone_set_max(socket_zone, maxsockets);
-}
-
 /* ARGSUSED*/
 static void
 domaininit(void *dummy)
 {
 
-       /*
-        * Before we do any setup, make sure to initialize the
-        * zone allocator we get struct sockets from.
-        */
-       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;
 

Modified: stable/9/sys/kern/uipc_socket.c
==============================================================================
--- stable/9/sys/kern/uipc_socket.c     Mon Jul  8 13:22:58 2013        
(r253034)
+++ stable/9/sys/kern/uipc_socket.c     Mon Jul  8 13:24:18 2013        
(r253035)
@@ -175,11 +175,8 @@ static struct filterops sowrite_filtops 
        .f_event = filt_sowrite,
 };
 
-uma_zone_t socket_zone;
 so_gen_t       so_gencnt;      /* generation count for sockets */
 
-int    maxsockets;
-
 MALLOC_DEFINE(M_SONAME, "soname", "socket name");
 MALLOC_DEFINE(M_PCB, "pcb", "protocol control block");
 
@@ -187,15 +184,37 @@ MALLOC_DEFINE(M_PCB, "pcb", "protocol co
        VNET_ASSERT(curvnet != NULL,                                    \
            ("%s:%d curvnet is NULL, so=%p", __func__, __LINE__, (so)));
 
+/*
+ * Limit on the number of connections in the listen queue waiting
+ * for accept(2).
+ */
 static int somaxconn = SOMAXCONN;
-static int sysctl_somaxconn(SYSCTL_HANDLER_ARGS);
-/* XXX: we dont have SYSCTL_USHORT */
+
+static int
+sysctl_somaxconn(SYSCTL_HANDLER_ARGS)
+{
+       int error;
+       int val;
+
+       val = somaxconn;
+       error = sysctl_handle_int(oidp, &val, 0, req);
+       if (error || !req->newptr )
+               return (error);
+
+       if (val < 1 || val > USHRT_MAX)
+               return (EINVAL);
+
+       somaxconn = val;
+       return (0);
+}
 SYSCTL_PROC(_kern_ipc, KIPC_SOMAXCONN, somaxconn, CTLTYPE_UINT | CTLFLAG_RW,
-    0, sizeof(int), sysctl_somaxconn, "I", "Maximum pending socket connection "
-    "queue size");
+    0, sizeof(int), sysctl_somaxconn, "I",
+    "Maximum listen socket pending connection accept queue size");
+
 static int numopensockets;
 SYSCTL_INT(_kern_ipc, OID_AUTO, numopensockets, CTLFLAG_RD,
     &numopensockets, 0, "Number of open sockets");
+
 #ifdef ZERO_COPY_SOCKETS
 /* These aren't static because they're used in other files. */
 int so_zero_copy_send = 1;
@@ -229,6 +248,45 @@ MTX_SYSINIT(so_global_mtx, &so_global_mt
 SYSCTL_NODE(_kern, KERN_IPC, ipc, CTLFLAG_RW, 0, "IPC");
 
 /*
+ * Initialize the socket subsystem and set up the socket
+ * memory allocator.
+ */
+uma_zone_t socket_zone;
+int    maxsockets;
+
+static void
+socket_zone_change(void *tag)
+{
+
+       uma_zone_set_max(socket_zone, maxsockets);
+}
+
+static void
+socket_init(void *tag)
+{
+
+        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);
+}
+SYSINIT(socket, SI_SUB_PROTO_DOMAININIT, SI_ORDER_ANY, socket_init, NULL);
+
+/*
+ * Initialise maxsockets.  This SYSINIT must be run after
+ * tunable_mbinit().
+ */
+static void
+init_maxsockets(void *ignored)
+{
+
+       TUNABLE_INT_FETCH("kern.ipc.maxsockets", &maxsockets);
+       maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters));
+}
+SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL);
+
+/*
  * Sysctl to get and set the maximum global sockets limit.  Notify protocols
  * of the change so that they can update their dependent limits as required.
  */
@@ -252,25 +310,11 @@ sysctl_maxsockets(SYSCTL_HANDLER_ARGS)
        }
        return (error);
 }
-
 SYSCTL_PROC(_kern_ipc, OID_AUTO, maxsockets, CTLTYPE_INT|CTLFLAG_RW,
     &maxsockets, 0, sysctl_maxsockets, "IU",
     "Maximum number of sockets avaliable");
 
 /*
- * Initialise maxsockets.  This SYSINIT must be run after
- * tunable_mbinit().
- */
-static void
-init_maxsockets(void *ignored)
-{
-
-       TUNABLE_INT_FETCH("kern.ipc.maxsockets", &maxsockets);
-       maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters));
-}
-SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL);
-
-/*
  * Socket operation routines.  These routines are called by the routines in
  * sys_socket.c or from a system process, and implement the semantics of
  * socket operations by switching out to the protocol specific routines.
@@ -3296,24 +3340,6 @@ socheckuid(struct socket *so, uid_t uid)
        return (0);
 }
 
-static int
-sysctl_somaxconn(SYSCTL_HANDLER_ARGS)
-{
-       int error;
-       int val;
-
-       val = somaxconn;
-       error = sysctl_handle_int(oidp, &val, 0, req);
-       if (error || !req->newptr )
-               return (error);
-
-       if (val < 1 || val > USHRT_MAX)
-               return (EINVAL);
-
-       somaxconn = val;
-       return (0);
-}
-
 /*
  * These functions are used by protocols to notify the socket layer (and its
  * consumers) of state changes in the sockets driven by protocol-side events.
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to