]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cache: Add global option to enable/disable zero-copy forwarding
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 4 Dec 2023 15:06:24 +0000 (16:06 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 6 Dec 2023 09:24:41 +0000 (10:24 +0100)
tune.cache.zero-copy-forwarding parameter can now be used to enable or
disable the zero-copy fast-forwarding for the cache applet only. It is
enabled ('on') by default. It can be disabled by setting the parameter to
'off'.

doc/configuration.txt
include/haproxy/global-t.h
src/cache.c

index cada9f1aa3ef24e3307f1eea21bb581975f3ab4c..23136bc02396a326d6a436f69371283fa9deb283 100644 (file)
@@ -1323,6 +1323,7 @@ The following keywords are supported in the "global" section :
    - tune.buffers.limit
    - tune.buffers.reserve
    - tune.bufsize
+   - tune.cache.zero-copy-forwarding
    - tune.comp.maxlevel
    - tune.disable-fast-forward
    - tune.disable-zero-copy-forwarding
@@ -3051,6 +3052,13 @@ tune.bufsize <number>
   value set using this parameter will automatically be rounded up to the next
   multiple of 8 on 32-bit machines and 16 on 64-bit machines.
 
+tune.cache.zero-copy-forwarding { on | off }
+  Enables ('on') of disabled ('off') the zero-copy forwarding of data for the
+  cache applet, when objects are served from the cache to clients. It is
+  enabled by default.
+
+  See also: tune.disable-zero-copy-forwarding.
+
 tune.comp.maxlevel <number>
   Sets the maximum compression level. The compression level affects CPU
   usage during compression. This value affects CPU usage during compression.
@@ -3074,7 +3082,7 @@ tune.disable-zero-copy-forwarding
   Thanks to this directive, it is possible to disable this optimization. Note
   it also disable any kernel tcp splicing.
 
-  See also: tune.pt.zero-copy-forwarding,
+  See also: tune.pt.zero-copy-forwarding, tune.cache.zero-copy-forwarding,
             tune.h1.zero-copy-fwd-recv, tune.h1.zero-copy-fwd-send,
             tune.h2.zero-copy-fwd-send, tune.quic.zero-copy-fwd-send
 
index bb39baffce99fb790ca14cae445ab6aa6611541b..5fd118995c149f5cb55abec1508ac33bd83e00a1 100644 (file)
@@ -95,6 +95,7 @@
 #define NO_ZERO_COPY_FWD_QUIC_SND    0x0080 /* disable zero-copy FF for QUIC on send */
 #define NO_ZERO_COPY_FWD_FCGI_RCV    0x0100 /* disable zero-copy FF for FCGI on received */
 #define NO_ZERO_COPY_FWD_FCGI_SND    0x0200 /* disable zero-copy FF for FCGI on send */
+#define NO_ZERO_COPY_FWD_CACHE       0x0400 /* disable zero-copy FF for cache applet */
 
 
 extern int cluster_secret_isset; /* non zero means a cluster secret was initialized */
index 8e809f3ac9407e64cad7190ee46c974d7f2e1e70..616c8b2d3e45122b9df4106d43acbc181d2503eb 100644 (file)
@@ -1797,7 +1797,7 @@ static void http_cache_io_handler(struct appctx *appctx)
 
        applet_have_more_data(appctx);
 
-       if (!(global.tune.no_zero_copy_fwd & NO_ZERO_COPY_FWD) &&
+       if (!(global.tune.no_zero_copy_fwd & (NO_ZERO_COPY_FWD|NO_ZERO_COPY_FWD_CACHE)) &&
            sc_ep_test(sc, SE_FL_MAY_FASTFWD) &&
            res->to_forward &&
            ctx->data_sent != cache_ptr->body_size) {
@@ -3028,6 +3028,26 @@ parse_cache_flt(char **args, int *cur_arg, struct proxy *px,
        return -1;
 }
 
+/* config parser for global "tune.cache.zero-copy-forwarding" */
+static int cfg_parse_cache_zero_copy_fwd(char **args, int section_type, struct proxy *curpx,
+                                     const struct proxy *defpx, const char *file, int line,
+                                     char **err)
+{
+       if (too_many_args(1, args, err, NULL))
+               return -1;
+
+       if (strcmp(args[1], "on") == 0)
+               global.tune.no_zero_copy_fwd &= ~NO_ZERO_COPY_FWD_CACHE;
+       else if (strcmp(args[1], "off") == 0)
+               global.tune.no_zero_copy_fwd |= NO_ZERO_COPY_FWD_CACHE;
+       else {
+               memprintf(err, "'%s' expects 'on' or 'off'.", args[0]);
+               return -1;
+       }
+       return 0;
+}
+
+
 /* It reserves a struct show_cache_ctx for the local variables */
 static int cli_parse_show_cache(char **args, char *payload, struct appctx *appctx, void *private)
 {
@@ -3215,6 +3235,15 @@ struct applet http_cache_applet = {
        .release = http_cache_applet_release,
 };
 
+/* config keyword parsers */
+static struct cfg_kw_list cfg_kws = {ILH, {
+       { CFG_GLOBAL, "tune.cache.zero-copy-forwarding", cfg_parse_cache_zero_copy_fwd },
+       { 0, NULL, NULL }
+}};
+
+INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
+
+
 /* config parsers for this section */
 REGISTER_CONFIG_SECTION("cache", cfg_parse_cache, cfg_post_parse_section_cache);
 REGISTER_POST_CHECK(post_check_cache);