* [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one
@ 2026-09-22 13:27 Konstantin Khorenko
2026-09-22 13:27 ` [Devel] [PATCH hci-8.1 1/2] Revert "fs/ext4: do not run test_and_set_bit on every prefetch scan" Konstantin Khorenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-09-22 13:27 UTC (permalink / raw)
To: Alexey Kuznetsov, devel, Konstantin Khorenko
The vz patch 3fff8724d1f89 ("fs/ext4: do not run test_and_set_bit on
every prefetch scan") went in for VSTOR-137147 to stop
ext4_mb_prefetch() from doing a locked test_and_set_bit on bb_state of
every group it walks. The bit is set-only, yet the atomic RMW took the
ext4_group_info cache line exclusive on every pass and bounced it
between allocating threads.
Mainstream fixed the same thing before us: v7.3-rc1 carries
0e364a030229b ("ext4: avoid RWM atomic in EXT4_MB_GRP_TEST_AND_SET_READ")
by Bohdan Trach. The logic is identical, test_bit first and the atomic
only while the bit is still clear. The only difference is where the
check lives: the vz patch adds a second macro and tests it at the call
site, the mainstream one folds the test into
EXT4_MB_GRP_TEST_AND_SET_READ() itself. ext4_mb_prefetch() is the only
user of the macro, so the resulting code is the same either way.
Revert the vz patch and cherry-pick the mainstream commit, so that the
tree matches what the rebase to 7.3 brings anyway and this spot does
not turn into a conflict there.
https://virtuozzo.atlassian.net/browse/VSTOR-137147
https://virtuozzo.atlassian.net/browse/VSTOR-145663
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
Bohdan Trach (1):
ext4: avoid RWM atomic in EXT4_MB_GRP_TEST_AND_SET_READ
Konstantin Khorenko (1):
Revert "fs/ext4: do not run test_and_set_bit on every prefetch scan"
fs/ext4/ext4.h | 10 +++++++---
fs/ext4/mballoc.c | 4 +---
2 files changed, 8 insertions(+), 6 deletions(-)
---
base-commit: 60a71f6c543ed4d4815774d57241370aa6475041
change-id: 20260922-pr-khorenko-vstor-145663-ext4-ms-2c3cdcb3a7fb
Best regards,
--
Konstantin Khorenko <khorenko@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread* [Devel] [PATCH hci-8.1 1/2] Revert "fs/ext4: do not run test_and_set_bit on every prefetch scan"
2026-09-22 13:27 [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one Konstantin Khorenko
@ 2026-09-22 13:27 ` Konstantin Khorenko
2026-09-22 13:27 ` [Devel] [PATCH hci-8.1 2/2] ext4: avoid RWM atomic in EXT4_MB_GRP_TEST_AND_SET_READ Konstantin Khorenko
2026-09-22 13:31 ` [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one Konstantin Khorenko
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-09-22 13:27 UTC (permalink / raw)
To: Alexey Kuznetsov, devel, Konstantin Khorenko
This reverts commit 3fff8724d1f894459c1477990fe086c0c2573410.
Mainstream has already fixed this issue the same way, only with the
test_bit check folded into the macro instead of the call site, so drop
our patch and take the mainstream version:
0e364a030229b ("ext4: avoid RWM atomic in EXT4_MB_GRP_TEST_AND_SET_READ")
https://virtuozzo.atlassian.net/browse/VSTOR-137147
https://virtuozzo.atlassian.net/browse/VSTOR-145663
Feature: fix ms/ext4
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
fs/ext4/ext4.h | 2 --
fs/ext4/mballoc.c | 4 +---
2 files changed, 1 insertion(+), 5 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index ca6498609e2e1..bf7637785e073 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3514,8 +3514,6 @@ struct ext4_group_info {
(clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
#define EXT4_MB_GRP_TEST_AND_SET_READ(grp) \
(test_and_set_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &((grp)->bb_state)))
-#define EXT4_MB_GRP_TEST_READ(grp) \
- (test_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &((grp)->bb_state)))
#define EXT4_MAX_CONTENTION 8
#define EXT4_CONTENTION_THRESHOLD 2
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index b50aa34057967..aaf2c24c514c6 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2836,9 +2836,7 @@ ext4_group_t ext4_mb_prefetch(struct super_block *sb, ext4_group_t group,
* prefetch once, so we avoid getblk() call, which can
* be expensive.
*/
- if (gdp && grp &&
- !EXT4_MB_GRP_TEST_READ(grp) &&
- !EXT4_MB_GRP_TEST_AND_SET_READ(grp) &&
+ if (gdp && grp && !EXT4_MB_GRP_TEST_AND_SET_READ(grp) &&
EXT4_MB_GRP_NEED_INIT(grp) &&
ext4_free_group_clusters(sb, gdp) > 0 ) {
bh = ext4_read_block_bitmap_nowait(sb, group, true);
--
2.43.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread* [Devel] [PATCH hci-8.1 2/2] ext4: avoid RWM atomic in EXT4_MB_GRP_TEST_AND_SET_READ
2026-09-22 13:27 [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one Konstantin Khorenko
2026-09-22 13:27 ` [Devel] [PATCH hci-8.1 1/2] Revert "fs/ext4: do not run test_and_set_bit on every prefetch scan" Konstantin Khorenko
@ 2026-09-22 13:27 ` Konstantin Khorenko
2026-09-22 13:31 ` [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one Konstantin Khorenko
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-09-22 13:27 UTC (permalink / raw)
To: Alexey Kuznetsov, devel, Konstantin Khorenko
From: Bohdan Trach <bohdan.trach@huaweicloud.com>
EXT4_MB_GRP_TEST_AND_SET_READ uses test_and_set_bit function which
issues an atomic write. This can cause high overhead due to cache
contention when multiple threads iterate over groups in a tight loop,
as is the case for ext4_mb_prefetch(). We have seen this to be a
problem for Kunpeng 920b CPUs which uses a single ARM LSE instruction
for this purpose.
Avoid this unconditional atomic write by testing the bit first without
changing its value. This is OK for this use case as this bit is never
unset.
This change significantly reduces costs of fallocate() operations which
trigger linear group scans on large multicore machines where
test_and_set_bit issues an atomic write operation unconditionally.
Signed-off-by: Bohdan Trach <bohdan.trach@huaweicloud.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://patch.msgid.link/20260615100331.163997-2-bohdan.trach@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
(cherry picked from commit 0e364a030229b3b06b858dbe4b7412d87d9d86ce)
https://virtuozzo.atlassian.net/browse/VSTOR-137147
https://virtuozzo.atlassian.net/browse/VSTOR-145663
Feature: fix ms/ext4
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
fs/ext4/ext4.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index bf7637785e073..3fe70a19e2a79 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3513,7 +3513,13 @@ struct ext4_group_info {
#define EXT4_MB_GRP_CLEAR_TRIMMED(grp) \
(clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state)))
#define EXT4_MB_GRP_TEST_AND_SET_READ(grp) \
- (test_and_set_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &((grp)->bb_state)))
+ (ext4_mb_grp_test_and_set_read((grp)))
+
+static inline int ext4_mb_grp_test_and_set_read(struct ext4_group_info *grp)
+{
+ return (test_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &grp->bb_state) ||
+ test_and_set_bit(EXT4_GROUP_INFO_BBITMAP_READ_BIT, &grp->bb_state));
+}
#define EXT4_MAX_CONTENTION 8
#define EXT4_CONTENTION_THRESHOLD 2
--
2.43.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one
2026-09-22 13:27 [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one Konstantin Khorenko
2026-09-22 13:27 ` [Devel] [PATCH hci-8.1 1/2] Revert "fs/ext4: do not run test_and_set_bit on every prefetch scan" Konstantin Khorenko
2026-09-22 13:27 ` [Devel] [PATCH hci-8.1 2/2] ext4: avoid RWM atomic in EXT4_MB_GRP_TEST_AND_SET_READ Konstantin Khorenko
@ 2026-09-22 13:31 ` Konstantin Khorenko
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-09-22 13:31 UTC (permalink / raw)
To: Alexey Kuznetsov, devel, Konstantin Khorenko
On Tue, 22 Sep 2026 15:27:46 +0200, Konstantin Khorenko wrote:
> ext4: replace the vz prefetch test_bit patch with the mainstream one
>
> The vz patch 3fff8724d1f89 ("fs/ext4: do not run test_and_set_bit on
> every prefetch scan") went in for VSTOR-137147 to stop
> ext4_mb_prefetch() from doing a locked test_and_set_bit on bb_state of
> every group it walks. The bit is set-only, yet the atomic RMW took the
> ext4_group_info cache line exclusive on every pass and bounced it
> between allocating threads.
>
> [...]
Applied to branch-rh10-6.12.0-211.52.1.22.x.vz10-ovz, will be released in rh10-6.12.0-211.52.1.22.2.vz10, thanks!
[1/2] Revert "fs/ext4: do not run test_and_set_bit on every prefetch scan"
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/52ea9a9ab754
[2/2] ext4: avoid RWM atomic in EXT4_MB_GRP_TEST_AND_SET_READ
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/7ecb7901c306
--
Konstantin Khorenko <khorenko@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-22 13:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-22 13:27 [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one Konstantin Khorenko
2026-09-22 13:27 ` [Devel] [PATCH hci-8.1 1/2] Revert "fs/ext4: do not run test_and_set_bit on every prefetch scan" Konstantin Khorenko
2026-09-22 13:27 ` [Devel] [PATCH hci-8.1 2/2] ext4: avoid RWM atomic in EXT4_MB_GRP_TEST_AND_SET_READ Konstantin Khorenko
2026-09-22 13:31 ` [Devel] [PATCH hci-8.1 0/2] ext4: replace the vz prefetch test_bit patch with the mainstream one Konstantin Khorenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox