]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: splice: assume by default that splice is working correctly
authorWilly Tarreau <w@1wt.eu>
Mon, 7 Jan 2013 15:57:09 +0000 (16:57 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 7 Jan 2013 15:57:09 +0000 (16:57 +0100)
Versions of splice between 2.6.25 and 2.6.27.12 were bogus and would return EAGAIN
on incoming shutdowns. On these versions, we have to call recv() after such a return
in order to find whether splice is OK or not. Since 2.6.27.13 we don't need to do
this anymore, saving one useless recv() call after each splice() returning EAGAIN,
and we can avoid this logic by defining ASSUME_SPLICE_WORKS.

Building with linux2628 automatically enables splice and the flag above since the
kernel is safe. People enabling splice for custom kernels will be able to disable
this logic by hand too.

Makefile
src/raw_sock.c

index fb6ce986a76b73e10962b49b5fd7e35f8425be48..f1eed55e5a95e0e209ab1a4d5ae7d85f388167d0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -243,6 +243,7 @@ ifeq ($(TARGET),linux2628)
   USE_ACCEPT4     = implicit
   USE_FUTEX       = implicit
   USE_CPU_AFFINITY= implicit
+  ASSUME_SPLICE_WORKS= implicit
 else
 ifeq ($(TARGET),solaris)
   # This is for Solaris 8
@@ -449,6 +450,11 @@ OPTIONS_CFLAGS += -DUSE_MY_SPLICE
 BUILD_OPTIONS  += $(call ignore_implicit,USE_MY_SPLICE)
 endif
 
+ifneq ($(ASSUME_SPLICE_WORKS),)
+OPTIONS_CFLAGS += -DASSUME_SPLICE_WORKS
+BUILD_OPTIONS  += $(call ignore_implicit,ASSUME_SPLICE_WORKS)
+endif
+
 ifneq ($(USE_ACCEPT4),)
 OPTIONS_CFLAGS += -DUSE_ACCEPT4
 BUILD_OPTIONS  += $(call ignore_implicit,USE_ACCEPT4)
index 952891133deda4d003f4117106e9347ee4a1df66..ad4a0aafa49eec54cd8cdb2b5f56e4b7aa9e955a 100644 (file)
  * infinite forwarding */
 #define MAX_SPLICE_AT_ONCE     (1<<30)
 
+/* Versions of splice between 2.6.25 and 2.6.27.12 were bogus and would return EAGAIN
+ * on incoming shutdowns. On these versions, we have to call recv() after such a return
+ * in order to find whether splice is OK or not. Since 2.6.27.13 we don't need to do
+ * this anymore, and we can avoid this logic by defining ASSUME_SPLICE_WORKS.
+ */
+
 /* Returns :
  *   -1 if splice() is not supported
  *   >= 0 to report the amount of spliced bytes.
@@ -62,7 +68,9 @@
  */
 int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int count)
 {
+#ifndef ASSUME_SPLICE_WORKS
        static int splice_detects_close;
+#endif
        int ret;
        int retval = 0;
 
@@ -95,7 +103,9 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co
                                 * recent kernels (>= 2.6.27.13). If we notice
                                 * it works, we store the info for later use.
                                 */
+#ifndef ASSUME_SPLICE_WORKS
                                splice_detects_close = 1;
+#endif
                                goto out_read0;
                        }
 
@@ -125,7 +135,9 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co
                                 * try to fall back to the normal recv scheme
                                 * which will be able to deal with the situation.
                                 */
+#ifndef ASSUME_SPLICE_WORKS
                                if (splice_detects_close)
+#endif
                                        __conn_data_poll_recv(conn); /* we know for sure that it's EAGAIN */
                                break;
                        }