linux/drivers/md/bcache
Kuan-Wei Chiu 43a27836ac Revert "bcache: remove heap-related macros and switch to generic min_heap"
commit 48fd7ebe00 upstream.

This reverts commit 866898efbb.

The generic bottom-up min_heap implementation causes performance
regression in invalidate_buckets_lru(), a hot path in bcache.  Before the
cache is fully populated, new_bucket_prio() often returns zero, leading to
many equal comparisons.  In such cases, bottom-up sift_down performs up to
2 * log2(n) comparisons, while the original top-down approach completes
with just O() comparisons, resulting in a measurable performance gap.

The performance degradation is further worsened by the non-inlined
min_heap API functions introduced in commit 92a8b224b8 ("lib/min_heap:
introduce non-inline versions of min heap API functions"), adding function
call overhead to this critical path.

As reported by Robert, bcache now suffers from latency spikes, with P100
(max) latency increasing from 600 ms to 2.4 seconds every 5 minutes.
These regressions degrade bcache's effectiveness as a low-latency cache
layer and lead to frequent timeouts and application stalls in production
environments.

This revert aims to restore bcache's original low-latency behavior.

Link: https://lore.kernel.org/lkml/CAJhEC05+0S69z+3+FB2Cd0hD+pCRyWTKLEOsc8BOmH73p1m+KQ@mail.gmail.com
Link: https://lkml.kernel.org/r/20250614202353.1632957-3-visitorckw@gmail.com
Fixes: 866898efbb ("bcache: remove heap-related macros and switch to generic min_heap")
Fixes: 92a8b224b8 ("lib/min_heap: introduce non-inline versions of min heap API functions")
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reported-by: Robert Pang <robertpang@google.com>
Closes: https://lore.kernel.org/linux-bcache/CAJhEC06F_AtrPgw2-7CvCqZgeStgCtitbD-ryuPpXQA-JG5XXw@mail.gmail.com
Acked-by: Coly Li <colyli@kernel.org>
Cc: Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-08-15 12:14:10 +02:00
..
alloc.c Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
bcache.h Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
bcache_ondisk.h flexible-array transformations for 6.3-rc1 2023-02-25 12:53:42 -08:00
bset.c Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
bset.h Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
btree.c Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
btree.h Locking changes for v6.5: 2023-06-27 14:14:30 -07:00
debug.c block: turn bio_kmalloc into a simple kmalloc wrapper 2022-04-17 19:30:41 -06:00
debug.h bcache: add identifier names to arguments of function definitions 2018-08-11 15:46:41 -06:00
extents.c Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
extents.h bcache: add identifier names to arguments of function definitions 2018-08-11 15:46:41 -06:00
features.c bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
features.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
io.c block: pass a block_device and opf to bio_init 2022-02-02 07:49:59 -07:00
journal.c closures: CLOSURE_CALLBACK() to fix type punning 2023-11-24 00:29:58 -05:00
journal.h bcache: avoid journal no-space deadlock by reserving 1 journal bucket 2022-05-24 06:19:33 -06:00
Kconfig bcache: move closures to lib/ 2023-10-19 14:47:33 -04:00
Makefile bcache: move closures to lib/ 2023-10-19 14:47:33 -04:00
movinggc.c Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
request.c bcache: call force_wake_up_gc() if necessary in check_should_bypass() 2024-05-28 06:55:59 -06:00
request.h closures: CLOSURE_CALLBACK() to fix type punning 2023-11-24 00:29:58 -05:00
stats.c bcache: use default_groups in kobj_type 2022-01-26 15:56:18 +01:00
stats.h bcache: Remove dead references to cache_readaheads 2023-06-15 07:30:11 -06:00
super.c Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
sysfs.c Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
sysfs.h bcache: make kobj_type structures constant 2023-06-15 07:30:11 -06:00
trace.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
util.c bcache: fix typo 2024-06-24 22:24:56 -07:00
util.h Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
writeback.c Revert "bcache: remove heap-related macros and switch to generic min_heap" 2025-08-15 12:14:10 +02:00
writeback.h bcache: improve multithreaded bch_sectors_dirty_init() 2022-05-24 06:19:33 -06:00