linux-stable/drivers
Carlos Llamas 7710e2cca3 binder: switch alloc->mutex to spinlock_t
The alloc->mutex is a highly contended lock that causes performance
issues on Android devices. When a low-priority task is given this lock
and it sleeps, it becomes difficult for the task to wake up and complete
its work. This delays other tasks that are also waiting on the mutex.

The problem gets worse when there is memory pressure in the system,
because this increases the contention on the alloc->mutex while the
shrinker reclaims binder pages.

Switching to a spinlock helps to keep the waiters running and avoids the
overhead of waking up tasks. This significantly improves the transaction
latency when the problematic scenario occurs.

The performance impact of this patchset was measured by stress-testing
the binder alloc contention. In this test, several clients of different
priorities send thousands of transactions of different sizes to a single
server. In parallel, pages get reclaimed using the shinker's debugfs.

The test was run on a Pixel 8, Pixel 6 and qemu machine. The results
were similar on all three devices:

after:
  | sched  | prio | average | max       | min     |
  |--------+------+---------+-----------+---------|
  | fifo   |   99 | 0.135ms |   1.197ms | 0.022ms |
  | fifo   |   01 | 0.136ms |   5.232ms | 0.018ms |
  | other  |  -20 | 0.180ms |   7.403ms | 0.019ms |
  | other  |   19 | 0.241ms |  58.094ms | 0.018ms |

before:
  | sched  | prio | average | max       | min     |
  |--------+------+---------+-----------+---------|
  | fifo   |   99 | 0.350ms | 248.730ms | 0.020ms |
  | fifo   |   01 | 0.357ms | 248.817ms | 0.024ms |
  | other  |  -20 | 0.399ms | 249.906ms | 0.020ms |
  | other  |   19 | 0.477ms | 297.756ms | 0.022ms |

The key metrics above are the average and max latencies (wall time).
These improvements should roughly translate to p95-p99 latencies on real
workloads. The response time is up to 200x faster in these scenarios and
there is no penalty in the regular path.

Note that it is only possible to convert this lock after a series of
changes made by previous patches. These mainly include refactoring the
sections that might_sleep() and changing the locking order with the
mmap_lock amongst others.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Carlos Llamas <cmllamas@google.com>
Link: https://lore.kernel.org/r/20231201172212.1813387-29-cmllamas@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-12-05 09:23:41 +09:00
..
accel accel/ivpu/37xx: Fix hangs related to MMIO reset 2023-11-21 09:20:25 +01:00
accessibility
acpi Merge branches 'acpi-video' and 'acpi-processor' into acpi 2023-11-24 19:16:22 +01:00
amba
android binder: switch alloc->mutex to spinlock_t 2023-12-05 09:23:41 +09:00
ata ata: pata_isapnp: Add missing error check for devm_ioport_map() 2023-11-20 09:22:26 +09:00
atm
auxdisplay
base
bcma
block nbd: pass nbd_sock to nbd_read_reply() instead of index 2023-11-21 07:42:04 -07:00
bluetooth
bus
cache
cdrom
cdx
char
clk
clocksource RISC-V Patches for the 6.7 Merge Window, Part 2 2023-11-10 09:23:17 -08:00
comedi
connector
counter
cpufreq
cpuidle
crypto
cxl
dax
dca
devfreq
dio
dma
dma-buf
dpll dpll: Fix potential msg memleak when genlmsg_put_reply failed 2023-11-21 17:41:20 -08:00
edac
eisa
extcon
firewire
firmware vhost,virtio,vdpa,firmware: bugfixes 2023-11-16 07:39:37 -05:00
fpga
fsi
gnss
gpio
gpu Merge tag 'drm-intel-fixes-2023-11-23' of git://anongit.freedesktop.org/drm/drm-intel into drm-fixes 2023-11-24 11:18:29 +10:00
greybus
hid for-linus-2023112301 2023-11-23 17:31:53 -08:00
hsi
hte
hv
hwmon
hwspinlock
hwtracing
i2c i2c: ocores: Move system PM hooks to the NOIRQ phase 2023-11-13 12:43:42 -05:00
i3c
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip - Flush the translation service tables to prevent unpredictable behavior 2023-11-19 13:49:32 -08:00
isdn
leds
macintosh
mailbox
mcb
md block-6.7-2023-11-23 2023-11-23 17:40:15 -08:00
media
memory
memstick
message
mfd
misc misc: Add Nitro Secure Module driver 2023-11-28 19:05:16 +00:00
mmc
most
mtd - removed AR7 platform support 2023-11-10 09:19:46 -08:00
mux
net net: ipa: fix one GSI register field width 2023-11-23 08:52:00 -08:00
nfc nfc: virtual_ncidev: Add variable to check if ndev is running 2023-11-22 10:55:48 +00:00
ntb
nubus
nvdimm
nvme nvme: tcp: fix compile-time checks for TLS mode 2023-11-22 18:41:14 -07:00
nvmem
of RISC-V Patches for the 6.7 Merge Window, Part 2 2023-11-10 09:23:17 -08:00
opp
parisc parisc/power: Fix power soft-off when running on qemu 2023-11-18 18:59:30 +01:00
parport
pci
pcmcia
peci
perf arm64 fixes: 2023-11-10 12:22:14 -08:00
phy
pinctrl
platform platform/goldfish: goldfish_pipe: Convert to platform remove callback returning void 2023-11-28 19:03:24 +00:00
pmdomain
pnp
power
powercap
pps
ps3
ptp ptp: annotate data-race around q->head and q->tail 2023-11-13 20:51:37 -08:00
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390 block-6.7-2023-11-23 2023-11-23 17:40:15 -08:00
sbus
scsi Merge branch '6.7/scsi-staging' into 6.7/scsi-fixes 2023-11-14 11:40:40 -05:00
sh
siox
slimbus
soc
soundwire
spi spi: Fixes for v6.7 2023-11-10 11:44:38 -08:00
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt thunderbolt: Only add device router DP IN to the head of the DP resource list 2023-11-17 13:05:57 +02:00
tty - removed AR7 platform support 2023-11-10 09:19:46 -08:00
ufs Merge branch '6.7/scsi-staging' into 6.7/scsi-fixes 2023-11-14 11:40:40 -05:00
uio
usb USB-serial fixes for 6.7-rc3 2023-11-24 16:30:38 +00:00
vdpa
vfio
vhost vhost,virtio,vdpa,firmware: bugfixes 2023-11-16 07:39:37 -05:00
video vgacon: drop IA64 reference in VGA_CONSOLE dependency list 2023-11-28 19:04:20 +00:00
virt vmgenid: emit uevent when VMGENID updates 2023-11-30 10:52:00 +00:00
virtio vhost,virtio,vdpa,firmware: bugfixes 2023-11-16 07:39:37 -05:00
w1
watchdog - removed AR7 platform support 2023-11-10 09:19:46 -08:00
xen xen: privcmd: Replace zero-length array with flex-array member and use __counted_by 2023-11-17 10:47:19 +01:00
zorro
Kconfig - removed AR7 platform support 2023-11-10 09:19:46 -08:00
Makefile - removed AR7 platform support 2023-11-10 09:19:46 -08:00