WSL2-Linux-Kernel/include
Linus Torvalds 7c6333411a fs: only do a memory barrier for the first set_buffer_uptodate()
commit 2f79cdfe58 upstream.

Commit d4252071b9 ("add barriers to buffer_uptodate and
set_buffer_uptodate") added proper memory barriers to the buffer head
BH_Uptodate bit, so that anybody who tests a buffer for being up-to-date
will be guaranteed to actually see initialized state.

However, that commit didn't _just_ add the memory barrier, it also ended
up dropping the "was it already set" logic that the BUFFER_FNS() macro
had.

That's conceptually the right thing for a generic "this is a memory
barrier" operation, but in the case of the buffer contents, we really
only care about the memory barrier for the _first_ time we set the bit,
in that the only memory ordering protection we need is to avoid anybody
seeing uninitialized memory contents.

Any other access ordering wouldn't be about the BH_Uptodate bit anyway,
and would require some other proper lock (typically BH_Lock or the folio
lock).  A reader that races with somebody invalidating the buffer head
isn't an issue wrt the memory ordering, it's a serialization issue.

Now, you'd think that the buffer head operations don't matter in this
day and age (and I certainly thought so), but apparently some loads
still end up being heavy users of buffer heads.  In particular, the
kernel test robot reported that not having this bit access optimization
in place caused a noticeable direct IO performance regression on ext4:

  fxmark.ssd_ext4_no_jnl_DWTL_54_directio.works/sec -26.5% regression

although you presumably need a fast disk and a lot of cores to actually
notice.

Link: https://lore.kernel.org/all/Yw8L7HTZ%2FdE2%2Fo9C@xsang-OptiPlex-9020/
Reported-by: kernel test robot <oliver.sang@intel.com>
Tested-by: Fengwei Yin <fengwei.yin@intel.com>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-09-15 11:30:00 +02:00
..
acpi ACPI: CPPC: Do not prevent CPPC from working in the future 2022-08-17 14:24:25 +02:00
asm-generic asm-generic: sections: refactor memory_intersects 2022-08-31 17:16:47 +02:00
clocksource
crypto crypto: blake2s - remove shash module 2022-08-17 14:24:19 +02:00
drm drm/bridge: Add stubs for devm_drm_of_get_bridge when OF is disabled 2022-09-05 10:30:03 +02:00
dt-bindings clk: qcom: gcc-msm8939: Add missing SYSTEM_MM_NOC_BFDCD_CLK_SRC 2022-08-17 14:23:45 +02:00
keys
kunit
kvm
linux fs: only do a memory barrier for the first set_buffer_uptodate() 2022-09-15 11:30:00 +02:00
math-emu
media
memory
misc
net net: fix refcount bug in sk_psock_get (2) 2022-09-05 10:30:07 +02:00
pcmcia
ras Revert "mm/memory-failure.c: fix race with changing page compound again" 2022-07-12 16:35:17 +02:00
rdma
scsi scsi: iscsi: Fix session removal on shutdown 2022-08-17 14:23:45 +02:00
soc
sound ALSA: control: Use deferred fasync helper 2022-08-25 11:40:44 +02:00
target
trace tracing/perf: Avoid -Warray-bounds warning for __rel_loc macro 2022-08-17 14:24:30 +02:00
uapi btrfs: remove no longer needed logic for replaying directory deletes 2022-09-05 10:30:09 +02:00
vdso
video video: of_display_timing.h: include errno.h 2022-07-12 16:35:10 +02:00
xen