linux-stable/Documentation
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
..
ABI Misc driver patches for 5.15-rc1, second round 2021-09-10 11:31:47 -07:00
accounting
admin-guide Merge branch 'for-5.15-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup 2021-10-11 17:16:41 -07:00
arm Documentation: arm: marvell: Add 88F6825 model into list 2021-08-24 13:26:32 -06:00
arm64 Merge remote-tracking branch 'tip/sched/arm64' into for-next/core 2021-08-31 09:10:00 +01:00
block Documentation: block: blk-mq: Fix small typo in multi-queue docs 2021-08-24 13:30:00 -06:00
bpf libbpf: Rename libbpf documentation index file 2021-08-18 08:45:25 -07:00
cdrom
core-api irqchip fixes for 5.15, take #1 2021-09-24 14:11:04 +02:00
cpu-freq cpufreq: Remove ready() callback 2021-09-02 18:04:17 +02:00
crypto
dev-tools kfence: default to dynamic branch instead of static keys mode 2021-11-12 15:05:49 +01:00
devicetree Pin control fixes for the v5.15 series: 2021-10-25 09:47:18 -07:00
doc-guide
driver-api cxl for v5.15 2021-09-09 11:48:27 -07:00
fault-injection Char / Misc driver changes for 5.15-rc1 2021-09-01 08:35:06 -07:00
fb
features RISC-V Patches for the 5.15 Merge Window, Part 2 2021-09-11 14:29:42 -07:00
filesystems Fixed xfstests generic/016 generic/021 generic/022 generic/041 generic/274 generic/423, 2021-10-15 09:58:11 -04:00
firmware-guide docs: firmware-guide: acpi: dsd: graph.rst: replace some characters 2021-07-25 14:35:46 -06:00
firmware_class
fpga
gpu Merge tag 'amd-drm-fixes-5.15-2021-10-06' of https://gitlab.freedesktop.org/agd5f/linux into drm-fixes 2021-10-08 11:40:21 +10:00
hid
hwmon hwmon: (k10temp) Remove residues of current and voltage 2021-09-12 17:56:36 -07:00
i2c Documentation: i2c: add i2c-sysfs into index 2021-08-10 22:58:32 +02:00
ia64
ide
iio
infiniband
input
isdn
kbuild Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
kernel-hacking docs: kernel-hacking: Remove inappropriate text 2021-09-03 15:56:45 -06:00
leds Documentation: leds: standartizing LED names 2021-08-20 10:26:24 +02:00
litmus-tests
livepatch
locking Documentation: locking: fix references 2021-08-24 13:20:39 -06:00
m68k
maintainer
mhi
mips
misc-devices
netlabel
networking mctp: unify sockaddr_mctp types 2021-10-18 13:47:09 +01:00
nios2
nvdimm
openrisc
parisc
PCI pci-v5.15-changes 2021-09-07 19:13:42 -07:00
pcmcia
power Documentation: power: include kernel-doc in Energy Model doc 2021-09-07 21:17:28 +02:00
powerpc powerpc/doc: Fix htmldocs errors 2021-08-27 00:56:34 +10:00
process Merge branch 'gcc-min-version-5.1' (make gcc-5.1 the minimum version) 2021-09-13 10:43:04 -07:00
RCU
riscv
s390
scheduler
scsi
security
sh
sound Yet another set of documentation changes: 2021-09-01 18:49:47 -07:00
sparc
sphinx docs: sphinx-requirements: Move sphinx_rtd_theme to top 2021-08-12 09:15:38 -06:00
sphinx-static
spi
staging
target
timers
trace Tracing updates for 5.15: 2021-09-05 11:50:41 -07:00
translations Merge branch 'gcc-min-version-5.1' (make gcc-5.1 the minimum version) 2021-09-13 10:43:04 -07:00
usb docs: usb: fix malformed table 2021-08-05 12:31:51 +02:00
userspace-api ptp: Document the PTP_CLK_MAGIC ioctl number 2021-10-27 17:02:51 -07:00
virt ARM: 2021-09-07 13:40:51 -07:00
vm Merge branch 'akpm' (patches from Andrew) 2021-09-08 12:55:35 -07:00
w1
watchdog
x86 Another collection of documentation patches, mostly fixes but also includes 2021-09-08 16:28:14 -07:00
xtensa
.gitignore
arch.rst
asm-annotations.rst
atomic_bitops.txt
atomic_t.txt Documentation/atomic_t: Document forward progress expectations 2021-08-04 15:16:47 +02:00
Changes
CodingStyle
conf.py docs: pdfdocs: Fix typo in CJK-language specific font settings 2021-09-06 16:53:39 -06:00
COPYING-logo
docutils.conf
dontdiff
index.rst
Kconfig
logo.gif
Makefile
memory-barriers.txt
SubmittingPatches
watch_queue.rst