From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id ED19B8015C for ; Wed, 16 Sep 2026 11:01:20 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68GAxvZY014473; Wed, 16 Sep 2026 13:59:59 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68GAxvZY014473 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="il/T3n4w" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68GAxtJI014469 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 16 Sep 2026 13:59:55 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68GAxtJI014469 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4870af30a85so745907f8f.1 for ; Wed, 16 Sep 2026 03:59:55 -0700 (PDT) X-Gm-Message-State: AFuF++lOsW3ge0q24W/MWB1240a9+o+NPMU/Lu5aNIj8hDgf77snFIiF RzNNqrkSVyIzowpzlRkJizgpHElaevipw+6CxTIKSTgM28iyAs7PndJkWeEJ1BA2HjkZGf/t5WI McD9Hh3ib3F01xVKIF/LZoVaCK26vOzqNVbq19rlFafEo+uzrqawmqA== X-Gm-Gg: AYBFou1OtsS831I1qeE5elc1as3dNaJoNkaiBbofVyoLTXq5Z2VHBCrpdjFUDAxLrkQ H/L5A2PmFfNKZnfMgiRnwzutl2Bk4qBEFbN2RxXaorzqpQEpvJThsY5edAPt52xNzpVqCYUom3k wAVCe20dj8M6jY5QwiVePiExzhOUMl6drLjfpe5ETQkYBMxS0hwo7oJ++uTkb9IMwQ6CC5C4y4V 7rMIzS511GtbxXLA9Jwy7iBF0eINYmGfjYfu/49xoZ+ETodqGHgiffYNZo6jY1NkN4hCV+imCMM rHg3WwZhmRWdDc5nkBcZjU7NHMDn1gmXHExVusy83FwgFtdfvg3D8um6Qw2W9YSjmC2fZPQ7jdd E9mTw3E0BDw79Y1co X-Received: by 2002:a05:6000:4382:b0:485:8226:c696 with SMTP id ffacd0b85a97d-48705b9c8c7mr10496972f8f.21.1789556395191; Wed, 16 Sep 2026 03:59:55 -0700 (PDT) X-Received: by 2002:a05:6000:4382:b0:485:8226:c696 with SMTP id ffacd0b85a97d-48705b9c8c7mr10496927f8f.21.1789556394637; Wed, 16 Sep 2026 03:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1789556394; cv=none; d=google.com; s=arc-20260327; b=jeLsyeBgdadIgBIvVAwOhzQKTWB4RIdIrAkwQppA5Vpk2Q3eISAqWQSVWQqMEVxBC0 7zN05PUJkfIpYdq0rYxH1iJcHX7itM9WlucsFlCLeTspG2wZXlNNXy2aoxsxGrsStyr3 uk48gJTK3cXUo+1x41xNdAIf8pZDIbLEYBtEdNvwO45+4i3DJN6tSbUqX1ZRJWZqXwKy zpj/02ffmoPf2x06VK7q7bYS+NMdU04452c6IBTqwuSW36e/5kggKx6ixRKqMn+gRfQR HDrMy1mYgJ1jH/UwNgO6Y2S9Xhj7SoHqtEs/f4/a9voIwdZe3T9M0/3b3+E+qZupUUqZ CZVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:dkim-signature; bh=b0DPL4wa0MPyUNfZYmX/fO9CU6c4sAUWw/9D0tm0k/4=; fh=0SOuIgRUy6Mq/Mzh2F18C4k72YXUIlGP7n6LSzdqO+w=; b=QMlByDcZ+y/PEDOWAjFb0jy7fkDfU4uq8VWM+ExLr4PVQna/NNasCPjnhmd3SxPI9T GkR72m1znlFDcjIxqeRAtuEtZWZwZBn3zY5P8/npXpCKoo1Q3XH9ieykR4p/M83Zym57 hLcxfQVJDcZzgrsGb9Q7QVqFgKkcSWCKlO/ztHdFTX2uXwBjLHc/+yXxIzURNBHTsucb K38uzrbiSKQGiLXAxKWj+SuGakg/MBJzgulvkN6MUIzKzrowfMZrg8cetfFAWa+UbUIo svhWW2/TORx0sc0UirwfbIeDoC5L0oY/vmsi/xaOtwjeTir9Ef1Ys1xyMc267+jL2oHT TdkQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="il/T3n4w"; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4870bf52db9si4186157f8f.268.2026.09.16.03.59.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2026 03:59:54 -0700 (PDT) Received-SPF: pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="il/T3n4w"; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=b0DPL4wa0MPyUNfZYmX/fO9CU6c4sAUWw/9D0tm0k/4=; b=il/T3n4wmcK0TAo0vvh d7pD8mUQXzCdSSZPvIbu27D50qs7wZUVzoHibjSEV12WLJK81bLxdQhogP9eYtO/CZi5yXS8hCmkK 9YGLqhsctSD9XrXz0N8Wm3ITjpeyXI33JtAhlnSiHK5s4v+EjDuywzAuXKdUTvLBVcYjBUyK+rVo0 8MvHflar7yqgpzJ5v+j7toKMD6TVm1d2NQCCMAFvwnK6nwCKaNsDrIKp5lKiJDSXUlpJJqD4khmva nNXenlT3aSqJrJevb8i+thKlintadoWtw2yxkYbTjHuUq6Ss/GWCm2nL6hvoScKPXZz2PirHUoHUJ BivnjdXRzpp/yLA==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1x6nK3-001TSU-2g; Wed, 16 Sep 2026 12:59:53 +0200 From: Konstantin Khorenko Date: Wed, 16 Sep 2026 12:59:39 +0200 MIME-Version: 1.0 Message-Id: <20260916-ext4-prefetch-test-bit-v2-1-0fc2b95ab452@virtuozzo.com> X-B4-Tracking: v=1; b=H4sIAJp2qmoC/yWMQQ6CMBBFr0Jm7SSlQVK8inFRylfGBZrOSIiEu 1N0+X7+eyspskDpUq2UMYvKayrgTxWlMU4PsAyFyTvfuq5uGYs1/M64w9LIBjXuxTiG7hzi4AN SoCIfD1l+4SvN39rR7b/qp38i2dGkbdsBW28DRIAAAAA= X-Change-ID: 20260916-ext4-prefetch-test-bit-a8958ad28ec8 To: devel@openvz.org, Konstantin Khorenko X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3359; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=a8yjOB9h9CbnV8jn99zxclQPDcwjyD7+WoHqmijI1BM=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBqqnapjjgotRzdS83kOeEj3bksIVl3VMw+dsRwb sfquP+JW3aJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCaqp2qQAKCRBRlgpH+WFc KlC0EACcHhZjGxU3quTaidW5A0Hhn4DayaO7m/98c+SeewiHycRbw88Duvq/Wy3gxfnmikxuZN5 chQ80b6VogV+gyTWNiEyj8Cz481E/IVuzXF62BqtXgvg2sAFeZV0Y/3l9lCdLaByAEavSf8WzhV egqf751wGonVpq1P/EBbAegvT0pj4vQixRvoyZLCzkiyCSq6mz3VLqcaAeO00zkhFfMA6QMZIYa xFsjuEKQffjw3Gf1jQVdGOdU0KUcMY/O3XhNvhHoY5+SIsTEw8zDeMP44Blr9UJAlQOwdu1oZJh h9JC1A3JL8CrdXrz0G65Ltp5nhteizXm86qF3B7LZImhYdOdp3f4HCyXN/8gwZcWBwTJEQWWTaG tngFDLO51HyOOt9j0xU0pRY0AWLWeMCWPzDtlKQj3W0LWg23wFKtplhUDcN0Y37hP1OCOoaLw2V 5GvAgDPVggp+EUTCOod4oT48pm0QUz8iMWv89RvjJHljg+XpdmaoFPdIwZg9qi5kprdCqL5c80s rV5n0I932D21s1i1dDZ5svEvCjNMwbBHqqlTWweH+WIOpLLushhfxKI7Wx3yr4pORaGSImM3okn j6d+vaiCvePkwNMk0046dB6iVLUk94T8bELOmyx8WKoVp5NjhwFRQEbBjw84GnjWt8IB5XbyKpe Va+8AE87+BGg+DQ== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Subject: [Devel] [PATCH vz10 v2] fs/ext4: do not run test_and_set_bit on every prefetch scan X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Alexey Kuznetsov ext4_mb_prefetch() marks every group it scans with EXT4_MB_GRP_TEST_AND_SET_READ(), so that a block bitmap is prefetched only once. The bit is never cleared, yet the atomic test_and_set_bit is executed on every pass over every group. A locked read-modify-write takes the bb_state cache line exclusive, so each allocating thread invalidates it for all the others, and that same line carries the rest of the hot read-mostly fields of struct ext4_group_info. The prefetch loop walks s_mb_prefetch groups per allocation, so the ping-pong scales with the number of allocating threads: even on just 4 allocating threads ext4 wastes 50% of cpu time on this test_and_set, none with the patch. Test the bit first and fall through to the atomic only while it is still clear. The bit is set-only, so a stale test_bit can only miss a set bit, and then the atomic decides the race as before. Nothing is published through the bit, so its full barrier is not needed. The atomic stays ahead of the EXT4_MB_GRP_NEED_INIT() and free clusters checks, so a group that turns out not to be worth prefetching is still marked and not looked at again. Testing: the change has been in production use as a private patch. https://virtuozzo.atlassian.net/browse/VSTOR-137147 Feature: ext4 fixes Signed-off-by: Alexey Kuznetsov Reviewed-by: Konstantin Khorenko --- Alexey's patch, resent with the commit message rewritten. The diff is the same as in v1. Changes in v2: - commit message rewritten: what the atomic actually costs and why a plain test_bit is safe, plus a note that the atomic has to stay ahead of the EXT4_MB_GRP_NEED_INIT() check - Jira reference in the form used in the tree, Feature tag added - no code changes - Link to v1: http://lore.virtuozzo.com/aqlr6A+cDUoielHy@mops2 --- fs/ext4/ext4.h | 2 ++ fs/ext4/mballoc.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index bf7637785e073..ca6498609e2e1 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3514,6 +3514,8 @@ 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 aaf2c24c514c6..b50aa34057967 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -2836,7 +2836,9 @@ 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_AND_SET_READ(grp) && + if (gdp && grp && + !EXT4_MB_GRP_TEST_READ(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); --- base-commit: c385dabedddacd691cfe0b21a599567c3b72314c change-id: 20260916-ext4-prefetch-test-bit-a8958ad28ec8 Best regards, -- Konstantin Khorenko _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel