[or-cvs] r10843: Tweaks on constrained socket buffers patch from coderman: Ad (in tor/trunk: . doc src/or)

nickm at seul.org nickm at seul.org
Mon Jul 16 16:23:38 UTC 2007


Author: nickm
Date: 2007-07-16 12:23:36 -0400 (Mon, 16 Jul 2007)
New Revision: 10843

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/doc/tor.1.in
   tor/trunk/src/or/config.c
   tor/trunk/src/or/connection.c
   tor/trunk/src/or/or.h
Log:
 r13774 at catbus:  nickm | 2007-07-16 12:23:28 -0400
 Tweaks on constrained socket buffers patch from coderman: Add a changelog; rename some variables; fix some long lines and whitespace; make ConstrainedSockSize a memunit; pass setsockopt a void.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r13774] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-07-16 16:23:34 UTC (rev 10842)
+++ tor/trunk/ChangeLog	2007-07-16 16:23:36 UTC (rev 10843)
@@ -5,6 +5,8 @@
       root, and have Tor bind those ports before it changes to another UID.
     - tor-gencert creates all files as readable to the file creator only, and
       write-protects the authority identity key.
+    - New ConstrainedSockets option to set SO_SNDBUF and SO_RCVBUF on TCP
+      sockets.  (Patch from coderman.)
 
   o Minor features (directory authority):
     - Fail quickly and (relatively) harmlessly if we generate a network

Modified: tor/trunk/doc/tor.1.in
===================================================================
--- tor/trunk/doc/tor.1.in	2007-07-16 16:23:34 UTC (rev 10842)
+++ tor/trunk/doc/tor.1.in	2007-07-16 16:23:36 UTC (rev 10843)
@@ -102,30 +102,32 @@
 .LP
 .TP
 \fBConstrainedSockets \fR\fB0\fR|\fB1\fR\fP
-If set, Tor will attempt to shrink the recv and xmit buffers for all 
+If set, Tor will tell the kernel to attempt to shrink the buffers for all 
 sockets to the size specified in \fBConstrainedSockSize\fP.  This is useful 
 for virtual servers and other environments where system level TCP
-buffers may be limited.  If you encounter the "Error creating network
-socket: No buffer space available" message you are likely experiencing
+buffers may be limited.  If you're on a virtual server, and you
+encounter the "Error creating network
+socket: No buffer space available" message, you are likely experiencing
 this problem.
 
 The preferred solution is to have the admin increase the buffer pool for
-the host itself via /proc/sys/net/ipv4/tcp_mem or equivalent facility. 
+the host itself via /proc/sys/net/ipv4/tcp_mem or equivalent facility; this
+configuration option is a second-resort.
 
 The DirPort option should also not be used if TCP buffers are scarce.  The
 cached directory requests consume additional sockets which exacerbates the
 problem.
 
-You should \fBnot\fP enable this feature unless you encounter the no buffer
-space available issue.  Reducing the TCP buffers affects window size for
+You should \fBnot\fP enable this feature unless you encounter the "no buffer
+space available" issue.  Reducing the TCP buffers affects window size for
 for the TCP stream and will reduce throughput in proportion to round trip
-time on long paths.
+time on long paths.  (Default: 0.)
 .LP
 .TP
-\fBConstrainedSockSize \fR\fINUM\fP
-When \fBConstrainedSockets\fP is enabled the recv and xmit buffers for
+\fBConstrainedSockSize \fR\fIN\fR \fBbytes\fR|\fBKB\fP
+When \fBConstrainedSockets\fP is enabled the receive and transmit buffers for
 all sockets will be set to this limit.  Must be a value between 2048
-and 262144 in 1024 byte increments.  Default of 8192 is recommended.
+and 262144, in 1024 byte increments.  Default of 8192 is recommended.
 .LP
 .TP
 \fBControlPort \fR\fIPort\fP

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2007-07-16 16:23:34 UTC (rev 10842)
+++ tor/trunk/src/or/config.c	2007-07-16 16:23:36 UTC (rev 10843)
@@ -147,7 +147,7 @@
   VAR("ClientOnly",          BOOL,     ClientOnly,           "0"),
   VAR("ConnLimit",           UINT,     ConnLimit,            "1000"),
   VAR("ConstrainedSockets",  BOOL,     ConstrainedSockets,   "0"),
-  VAR("ConstrainedSockSize", UINT,     ConstrainedSockSize,  "8192"),
+  VAR("ConstrainedSockSize", MEMUNIT,  ConstrainedSockSize,  "8192"),
   VAR("ContactInfo",         STRING,   ContactInfo,          NULL),
   VAR("ControlListenAddress",LINELIST, ControlListenAddress, NULL),
   VAR("ControlPort",         UINT,     ControlPort,          "0"),
@@ -2935,13 +2935,13 @@
   if (options->ConstrainedSockets) {
     /* If the user wants to constrain socket buffer use, make sure the desired
      * limit is between MIN|MAX_TCPSOCK_BUFFER in k increments. */
-    if (options->ConstrainedSockSize < MIN_TCPSOCK_BUFFER ||
-        options->ConstrainedSockSize > MAX_TCPSOCK_BUFFER ||
-        options->ConstrainedSockSize % 1024 ) {
+    if (options->ConstrainedSockSize < MIN_CONSTRAINED_TCP_BUFFER ||
+        options->ConstrainedSockSize > MAX_CONSTRAINED_TCP_BUFFER ||
+        options->ConstrainedSockSize % 1024) {
       r = tor_snprintf(buf, sizeof(buf),
           "ConstrainedSockSize is invalid.  Must be a value between %d and %d "
           "in 1024 byte increments.",
-          MIN_TCPSOCK_BUFFER, MAX_TCPSOCK_BUFFER);
+          MIN_CONSTRAINED_TCP_BUFFER, MAX_CONSTRAINED_TCP_BUFFER);
       *msg = tor_strdup(r >= 0 ? buf : "internal error");
       return -1;
     }

Modified: tor/trunk/src/or/connection.c
===================================================================
--- tor/trunk/src/or/connection.c	2007-07-16 16:23:34 UTC (rev 10842)
+++ tor/trunk/src/or/connection.c	2007-07-16 16:23:36 UTC (rev 10843)
@@ -926,9 +926,8 @@
 
   set_socket_nonblocking(news);
 
-  if (options->ConstrainedSockets) {
-    set_constrained_socket_buffers (news, options->ConstrainedSockSize);
-  }
+  if (options->ConstrainedSockets)
+    set_constrained_socket_buffers(news, (int)options->ConstrainedSockSize);
 
   tor_assert(((struct sockaddr*)addrbuf)->sa_family == conn->socket_family);
 
@@ -1103,9 +1102,8 @@
 
   set_socket_nonblocking(s);
 
-  if (options->ConstrainedSockets) {
-    set_constrained_socket_buffers (s, options->ConstrainedSockSize);
-  }
+  if (options->ConstrainedSockets)
+    set_constrained_socket_buffers(s, (int)options->ConstrainedSockSize);
 
   memset(&dest_addr,0,sizeof(dest_addr));
   dest_addr.sin_family = AF_INET;
@@ -2561,17 +2559,17 @@
 static void
 set_constrained_socket_buffers(int sock, int size)
 {
-  if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (const char *)&size, sizeof(size)) < 0) {
+  void *sz = (void*)&size;
+  if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, sz, sizeof(size)) < 0) {
     int e = tor_socket_errno(sock);
-    log_warn(LD_NET, "setsockopt() to constrain send buffer to %d bytes failed: %s",
-             size, tor_socket_strerror(e));
+    log_warn(LD_NET, "setsockopt() to constrain send "
+             "buffer to %d bytes failed: %s", size, tor_socket_strerror(e));
   }
-  if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (const char *)&size, sizeof(size)) < 0) {
+  if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, sz, sizeof(size)) < 0) {
     int e = tor_socket_errno(sock);
-    log_warn(LD_NET, "setsockopt() to constrain recv buffer to %d bytes failed: %s",
-             size, tor_socket_strerror(e));
+    log_warn(LD_NET, "setsockopt() to constrain recv "
+             "buffer to %d bytes failed: %s", size, tor_socket_strerror(e));
   }
-  return;
 }
 
 /** Process new bytes that have arrived on conn-\>inbuf.

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-07-16 16:23:34 UTC (rev 10842)
+++ tor/trunk/src/or/or.h	2007-07-16 16:23:36 UTC (rev 10843)
@@ -1749,8 +1749,8 @@
 } exit_redirect_t;
 
 /* limits for TCP send and recv buffer size used for constrained sockets */
-#define MIN_TCPSOCK_BUFFER 2048
-#define MAX_TCPSOCK_BUFFER 262144  /* 256k */
+#define MIN_CONSTRAINED_TCP_BUFFER 2048
+#define MAX_CONSTRAINED_TCP_BUFFER 262144  /* 256k */
 
 /** A linked list of lines in a config file. */
 typedef struct config_line_t {
@@ -1894,7 +1894,7 @@
   config_line_t *ReachableDirAddresses; /**< IP:ports for Dir conns. */
 
   int ConstrainedSockets; /**< Shrink xmit and recv socket buffers. */
-  int ConstrainedSockSize; /**< Size of constrained buffers. */
+  uint64_t ConstrainedSockSize; /**< Size of constrained buffers. */
 
   /** Application ports that require all nodes in circ to have sufficient
    * uptime. */



More information about the tor-commits mailing list