From: Willy Tarreau Date: Tue, 21 Mar 2023 08:24:53 +0000 (+0100) Subject: MINOR: pools: preset the allocation failure rate to 1% with -dMfail X-Git-Tag: v2.8-dev6~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c4348c982b73fa854de7c8cee5611cbfdd9db3c;p=thirdparty%2Fhaproxy.git MINOR: pools: preset the allocation failure rate to 1% with -dMfail Using -dMfail alone does nothing unless tune.fail-alloc is set, which renders it pretty useless as-is, and is not intuitive. Let's change this so that the filure rate is preset to 1% when the option is set on the command line. This allows to inject failures without having to edit the configuration. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 446d1a2d84..0c22b8265f 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -2865,7 +2865,9 @@ tune.fail-alloc If compiled with DEBUG_FAIL_ALLOC or started with "-dMfail", gives the percentage of chances an allocation attempt fails. Must be between 0 (no failure) and 100 (no success). This is useful to debug and make sure memory - failures are handled gracefully. + failures are handled gracefully. When not set, the ratio is 0. However the + command-line "-dMfail" option automatically sets it to 1% failure rate so that + it is not necessary to change the configuration for testing. tune.fd.edge-triggered { on | off } [ EXPERIMENTAL ] Enables ('on') or disables ('off') the edge-triggered polling mode for FDs diff --git a/doc/management.txt b/doc/management.txt index 94451b524e..96bd30c3d9 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -290,7 +290,8 @@ list of options is : - fail / no-fail: This enables randomly failing memory allocations, in conjunction with the global "tune.fail-alloc" setting. This is used to detect missing - error checks in the code. + error checks in the code. Setting the option presets the ratio to 1% + failure rate. - no-merge / merge: By default, pools of very similar sizes are merged, resulting in more diff --git a/src/pool.c b/src/pool.c index 4ea8d81270..345681a0c3 100644 --- a/src/pool.c +++ b/src/pool.c @@ -1080,10 +1080,16 @@ int pool_parse_debugging(const char *str, char **err) */ if (dbg_options[v].flg == POOL_DBG_UAF) new_dbg |= POOL_DBG_NO_CACHE; + /* fail should preset the tune.fail-alloc ratio to 1% */ + if (dbg_options[v].flg == POOL_DBG_FAIL_ALLOC) + mem_fail_rate = 1; break; } else if (isteq(feat, ist(dbg_options[v].clr))) { new_dbg &= ~dbg_options[v].flg; + /* no-fail should reset the tune.fail-alloc ratio */ + if (dbg_options[v].flg == POOL_DBG_FAIL_ALLOC) + mem_fail_rate = 0; break; } }