engines/net: add TCP_MAXSEG setting (mss)
authorJens Axboe <axboe@fb.com>
Thu, 9 Oct 2014 18:05:44 +0000 (12:05 -0600)
committerJens Axboe <axboe@fb.com>
Thu, 9 Oct 2014 18:05:44 +0000 (12:05 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
HOWTO
configure
engines/net.c
fio.1

diff --git a/HOWTO b/HOWTO
index f78e47c1f0d6523332a42f10862e98a6139e2ee8..d2ce4d8eb9bf76af9d360286967ebc26eeab649e 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1687,6 +1687,8 @@ that defines them is selected.
 
 [net] window_size      Set the desired socket buffer size for the connection.
 
+[net] mss      Set the TCP maximum segment size (TCP_MAXSEG).
+
 [e4defrag] donorname=str
                File will be used as a block donor(swap extents between files)
 [e4defrag] inplace=int
index 3e3c9785e889cc9ae97dadac32cae1b9e718a886..81b16a3551ac8b32bd1e36c4738d6064b8c4e158 100755 (executable)
--- a/configure
+++ b/configure
@@ -1093,6 +1093,26 @@ if compile_prog "" "" "SO_SNDBUF"; then
 fi
 echo "Net engine window_size        $window_size"
 
+##########################################
+# Check whether we have TCP_MAXSEG
+mss="no"
+cat > $TMPC << EOF
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
+int main(int argc, char **argv)
+{
+  return setsockopt(0, IPPROTO_TCP, TCP_MAXSEG, NULL, 0);
+}
+EOF
+if compile_prog "" "" "TCP_MAXSEG"; then
+  mss="yes"
+fi
+echo "TCP_MAXSEG                    $mss"
+
 ##########################################
 # Check whether we have RLIMIT_MEMLOCK
 rlimit_memlock="no"
@@ -1451,6 +1471,9 @@ fi
 if test "$window_size" = "yes" ; then
   output_sym "CONFIG_NET_WINDOWSIZE"
 fi
+if test "$mss" = "yes" ; then
+  output_sym "CONFIG_NET_MSS"
+fi
 if test "$rlimit_memlock" = "yes" ; then
   output_sym "CONFIG_RLIMIT_MEMLOCK"
 fi
index ac5a93c8309b7bd275461cc599ff18f8389947a0..9a327da8a442659f1098711671227102c27126da 100644 (file)
@@ -40,6 +40,7 @@ struct netio_options {
        unsigned int nodelay;
        unsigned int ttl;
        unsigned int window_size;
+       unsigned int mss;
        char *intfc;
 };
 
@@ -177,6 +178,18 @@ static struct fio_option options[] = {
                .category = FIO_OPT_C_ENGINE,
                .group  = FIO_OPT_G_NETIO,
        },
+#endif
+#ifdef CONFIG_NET_MSS
+       {
+               .name   = "mss",
+               .lname  = "Maximum segment size",
+               .type   = FIO_OPT_INT,
+               .off1   = offsetof(struct netio_options, mss),
+               .minval = 0,
+               .help   = "Set TCP maximum segment size",
+               .category = FIO_OPT_C_ENGINE,
+               .group  = FIO_OPT_G_NETIO,
+       },
 #endif
        {
                .name   = NULL,
@@ -233,6 +246,30 @@ static int set_window_size(struct thread_data *td, int fd)
 #endif
 }
 
+static int set_mss(struct thread_data *td, int fd)
+{
+#ifdef CONFIG_NET_MSS
+       struct netio_options *o = td->eo;
+       unsigned int mss;
+       int ret;
+
+       if (!o->mss || !is_tcp(o))
+               return 0;
+
+       mss = o->mss;
+       ret = setsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, (void *) &mss,
+                               sizeof(mss));
+       if (ret < 0)
+               td_verror(td, errno, "setsockopt TCP_MAXSEG");
+
+       return ret;
+#else
+       td_verror(td, -EINVAL, "setsockopt TCP_MAXSEG");
+       return -1;
+#endif
+}
+
+
 /*
  * Return -1 for error and 'nr events' for a positive number
  * of events
@@ -655,6 +692,10 @@ static int fio_netio_connect(struct thread_data *td, struct fio_file *f)
                close(f->fd);
                return 1;
        }
+       if (set_mss(td, f->fd)) {
+               close(f->fd);
+               return 1;
+       }
 
        if (is_udp(o)) {
                if (!fio_netio_is_multicast(td->o.filename))
@@ -1101,6 +1142,10 @@ static int fio_netio_setup_listen_inet(struct thread_data *td, short port)
                close(fd);
                return 1;
        }
+       if (set_mss(td, fd)) {
+               close(fd);
+               return 1;
+       }
 
        if (td->o.filename) {
                if (!is_udp(o) || !fio_netio_is_multicast(td->o.filename)) {
diff --git a/fio.1 b/fio.1
index dc727d36553ff12f34497e4c5f0df75c0e50b074..9ddf101abd6d92faa9b2e3f2769e586b4f72fcf3 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -1528,6 +1528,9 @@ reader when multiple readers are listening to the same address.
 .BI (net, window_size) \fR=\fPint
 Set the desired socket buffer size for the connection.
 .TP
+.BI (net, mss) \fR=\fPint
+Set the TCP maximum segment size (TCP_MAXSEG).
+.TP
 .BI (e4defrag,donorname) \fR=\fPstr
 File will be used as a block donor (swap extents between files)
 .TP