linux-stable/Documentation/dev-tools
Marco Elver d5dd3b4448 kfence: default to dynamic branch instead of static keys mode
commit 4f612ed3f7 upstream.

We have observed that on very large machines with newer CPUs, the static
key/branch switching delay is on the order of milliseconds.  This is due
to the required broadcast IPIs, which simply does not scale well to
hundreds of CPUs (cores).  If done too frequently, this can adversely
affect tail latencies of various workloads.

One workaround is to increase the sample interval to several seconds,
while decreasing sampled allocation coverage, but the problem still
exists and could still increase tail latencies.

As already noted in the Kconfig help text, there are trade-offs: at
lower sample intervals the dynamic branch results in better performance;
however, at very large sample intervals, the static keys mode can result
in better performance -- careful benchmarking is recommended.

Our initial benchmarking showed that with large enough sample intervals
and workloads stressing the allocator, the static keys mode was slightly
better.  Evaluating and observing the possible system-wide side-effects
of the static-key-switching induced broadcast IPIs, however, was a blind
spot (in particular on large machines with 100s of cores).

Therefore, a major downside of the static keys mode is, unfortunately,
that it is hard to predict performance on new system architectures and
topologies, but also making conclusions about performance of new
workloads based on a limited set of benchmarks.

Most distributions will simply select the defaults, while targeting a
large variety of different workloads and system architectures.  As such,
the better default is CONFIG_KFENCE_STATIC_KEYS=n, and re-enabling it is
only recommended after careful evaluation.

For reference, on x86-64 the condition in kfence_alloc() generates
exactly
2 instructions in the kmem_cache_alloc() fast-path:

 | ...
 | cmpl   $0x0,0x1a8021c(%rip)  # ffffffff82d560d0 <kfence_allocation_gate>
 | je     ffffffff812d6003      <kmem_cache_alloc+0x243>
 | ...

which, given kfence_allocation_gate is infrequently modified, should be
well predicted by most CPUs.

Link: https://lkml.kernel.org/r/20211019102524.2807208-2-elver@google.com
Signed-off-by: Marco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Jann Horn <jannh@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-12 15:05:49 +01:00
..
kunit kunit: tool: make --raw_output support only showing kunit output 2021-08-13 13:32:01 -06:00
checkpatch.rst docs: checkpatch: Document and segregate more checkpatch message types 2021-06-14 15:37:12 -06:00
coccinelle.rst Documentation: Coccinelle: Improve command example for debugging patches 2020-12-03 15:45:18 -07:00
gcov.rst docs/gcov: Convert two tags to ref in dev-tools/gov.rst 2021-04-08 11:19:43 -06:00
gdb-kernel-debugging.rst scripts/gdb: add lx_current support for arm64 2021-05-07 00:26:33 -07:00
index.rst Documentation: dev-tools: Add Testing Overview 2021-04-15 14:53:02 -06:00
kasan.rst mm/kasan: move kasan.fault to mm/kasan/report.c 2021-09-03 09:58:14 -07:00
kcov.rst Documentation: fix typos found in process, dev-tools, and doc-guide subdirectories 2020-12-03 15:55:04 -07:00
kcsan.rst kcsan: Rework atomic.h into permissive.h 2021-07-20 13:49:43 -07:00
kfence.rst kfence: default to dynamic branch instead of static keys mode 2021-11-12 15:05:49 +01:00
kgdb.rst Documentation: kgdb: Fix a typo 2020-11-18 13:47:17 -07:00
kmemleak.rst mm,kmemleak-test.c: move kmemleak-test.c to samples dir 2020-10-13 18:38:27 -07:00
kselftest.rst Documentation: kselftest: fix path to test module files 2021-04-02 16:17:18 -06:00
sparse.rst doc: add link to sparse's home page/internal docs 2020-07-05 14:32:56 -06:00
testing-overview.rst docs: dev-tools: testing-overview.rst: avoid using ReST :doc:foo markup 2021-06-17 13:24:37 -06:00
ubsan.rst ubsan: remove UBSAN_MISC in favor of individual options 2020-12-15 22:46:19 -08:00