From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 7DFBD80031 for ; Wed, 25 Nov 2026 01:26:55 +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 6AP1PhGs002555; Wed, 25 Nov 2026 04:25:44 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP1PhGs002555 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1795569945; bh=5IG+vceuXWj6PazQExGkCBV8LTJesH2loBtWEBU19Cg=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=LmBvibVhBZ2+kcdsFz/ppPwQAdqlh6XwAwjsC8EKpHing4voBG83cj/WWWImJOjLB GuGtSAP/FxiRLUVBLeiaqTvw/+hlShV1/GqJ9jg3AB4gKPAjEzIhkVFpeteSdEmqf4 bPaANjkc76r602aeDiEA7tv9NlwV/+fZ68ypZ/vSKVUbAMPrSnP4bAyvLM2Hd3w9hi Mhgz+Cgno8YnvtI3M6RaOOYCr/ttHjZWE5hNf9oaRQNAS/InwGCBgZ35xgmbehM3Se Z9vz8MnBm/4U5N3AmaxaNabkWZznGamF8jlheQjHbaUo0Q2IXZfvV39QFnDIIZ3UIH Sn9D9OgcewXLw== Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AP1PZi5002487 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 25 Nov 2026 04:25:35 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AP1PZi5002487 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="iPnZJ0pX" Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4ba01393800so33775245e9.1 for ; Tue, 24 Nov 2026 17:25:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGfG5Ndjc6xzFii0+K4Xckn0dUgrUQHBOzsddvnp9zM+NRG38jsCmX9/td3M0bJ754v21D6/w==@openvz.org X-Gm-Message-State: APuU4Z9d0oyqr6QwfGWb1MNM5Z2/XEgbUeokvMkiuB7bLed2C9hHCTaT kYLFfutlWxbk7/tTFIyWxZa5COYizjU4i2YVg/5IDMMhXeow3Y1OkTvIVmhebbipwzYzUfFw+9F DfRQcJ5SU4tOB/PuIPoNJQDIq1MovJNe7GiQnQwE5zmaPNJm26Al2Iw== X-Gm-Gg: AZFdTZe9+RhTeCbK8lb77kwImQVBitzMJ52YRT2yJqgrAbBDiGqZMdu1n+e2vmqZvbq kqzAMgKpojzM/aIgPJQw2sohzhAppbVevuAkpjBK1SJFLwHtb/n7346Jd3knrtR/LNnd9/WHE85 jTGOwBEOSu7yYZRN/ZtuOgzm8yFJlmhIzjYyeDRJ69LMoWLLwvtn4qv2Rydwsh0V9MvQo0ByQo9 AnT9O1oJdtUfmmYjcRbi+leHkiZC+S3IIgjFkWYripv4tpYzh15YqF+kjBtiGe0+WsOjtE0nrju +3K/4ALzcg== X-Received: by 2002:a05:600c:530f:b0:4bb:68b9:f615 with SMTP id 5b1f17b1804b1-4bb88810b22mr326568795e9.17.1795569935244; Tue, 24 Nov 2026 17:25:35 -0800 (PST) X-Received: by 2002:a05:600c:530f:b0:4bb:68b9:f615 with SMTP id 5b1f17b1804b1-4bb88810b22mr326568715e9.17.1795569934847; Tue, 24 Nov 2026 17:25:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795569934; cv=none; d=google.com; s=arc-20260327; b=o4PxkxUDaNQhGME7iruUJQ6/0LWUTzmTToKnRbBzJUJhtjfKfSPIRAl/j/lh2jIaDr 4Dqoh80e/nOV75/Ql7xn7KiEqVrPnP9Y8pQ+cfAzc7tqBB9CHOkg6No656NBYDeF1kJu qSF3ag6KfMJnP27lRq/+0+0Cqg7Ci36H85WnKoOTXco3yxD3amJzLwkb6CuWde67YH7H Ouz79z7QTw7H3DybyWefqcZIhhtM5bBzIu924RNr89HD/TUvypHjdtY3IpmLO4sNQ0xC FyvdJhrUtcU/95f/4atfsKLISKBLutfFckMNuWxsr3hZDiKYf3A9T+QLSWCJgFXuqEzO pSCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=7hzt1eh/UmE1s6bRvYPJfAjZ22xG1FQWmy6VTuib/Rk=; fh=6TanhA6KeCxE63qx5FumzahU1hSFE2DWrSg7EkLOLtw=; b=ab+Uz7WyzKDp1+zngvK+fpch4zus73S/cYckfPLThQ3khSXDFOO3y7vAbn/8siR/92 0VG/4Fs+esrqpoc/yq+G1FK+Alp6AjD0ZoXlT9qbzjpkGmrj8byFarftzD+eU27gvKQh tXGpJE05lZtokNhY7yjbID53+ZZcf/WuKsm5ntdhAgAdvt9anIcOSZKY8oTubhyYIwdF EVbNraF84NrMo5mCMlx09k0x2yFNn+CNkYtjZ40N2FwqBGi5evQBnf/cCsLj0iEv7c0d OTsxj0eOIQEy15TIB2AoID9QLcrh8Dc7ovy+byVnBIbUG71PEpLkeXyaJslVSqlUiYRl Mnsg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=iPnZJ0pX; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:fc:665c:9984:4e97 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 5b1f17b1804b1-4bb886cebcdsor25494135e9.0.2026.11.24.17.25.34 for (Google Transport Security); Tue, 24 Nov 2026 17:25:34 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:fc:665c:9984:4e97 as permitted sender) client-ip=2a06:5b06:b600:300:fc:665c:9984:4e97; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=iPnZJ0pX; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:fc:665c:9984:4e97 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1795569934; x=1796174734; darn=openvz.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7hzt1eh/UmE1s6bRvYPJfAjZ22xG1FQWmy6VTuib/Rk=; b=iPnZJ0pXkw+27t72DJ7PC0jlPb4N1IRFJ2Jyxblg25i0yc1EbMFPzd+NYjZIVYEPma ml7OPfe9WpHxnIWH4IZkv2Mx1znvvkknPux+D2TS18LemA3OZq+9gHLGUsJRlJ4Xl+Jt ygBpMWY2GITJpkD3PzFeQ2vr7N7ch5aNLDKP+tBtHktY9IJoKMLHa8VxazBjUcaTwG55 mhmv0vdyDUmxwUjfuYIvdfXY2RC/npJtgReUPu1o56m65J7KvfCwbsZJ63IvpAhbMUSa IJmF04KWxrDpGwdnDQ32dlkq16+YizT9JyEVdkKnxHYLoGhx9mPu0o84RXnjnzI4cPQj +ZNQ== X-Forwarded-Encrypted: i=1; AL+hErFxw2c+9A9BOyzJgwzosfRwQm5qRt1mA8Yd47aO/rP/0HQczHClKaSIUOBtL+81rc4fo0p22w==@openvz.org X-Received: by 2002:a05:600c:3b9e:b0:4a1:cf60:dcc3 with SMTP id 5b1f17b1804b1-4bb88820687mr386622665e9.29.1795569934450; Tue, 24 Nov 2026 17:25:34 -0800 (PST) Received: from artemis.sw.ru ([2a06:5b06:b600:300:fc:665c:9984:4e97]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb8526cbd0sm623632195e9.0.2026.11.24.17.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2026 17:25:33 -0800 (PST) From: "Denis V. Lunev" To: andrey.zhadchenko@virtuozzo.com, alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Wed, 25 Nov 2026 02:25:20 +0100 Message-ID: <20261125012525.681662-5-den@openvz.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261125012525.681662-1-den@openvz.org> References: <20261125012525.681662-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 4/9] dm-qcow2: map fast path writes without md_pages_lock 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: Denis V. Lunev Fast path writes still take md_pages_lock in parse_metadata() to map the cluster and count themselves in the L2 page's active_writers. With reads off the lock it is the remaining global serialization point for an overwrite workload. Map plain writes of allocated clusters through parse_metadata_lockless() too, then count the write and recheck the L2 page's md->gen. A discard that unmaps the cluster locks its index, which bumps md->gen, long before it waits for writers in delay_discard_if_writers(). With a full barrier on both sides, either the write sees the new md->gen, uncounts itself and takes the locked path, or the discard sees the count and waits for the write to finish before the cluster can be reused. The barrier is taken on entry, so a discard that re-enters to recheck the generation it waits for is covered as well. The write reads md->writer_gen without the lock. If it reads the generation the discard has just switched to, the switch comes after the md->gen bump and the discard's barrier, so the write's recheck sees the bump and backs off. If it reads the old one, the discard waits for it as for any earlier write. Discards and write-zeroes keep the locked parse. https://virtuozzo.atlassian.net/browse/VSTOR-95494 Feature: dm-qcow2: block device over QCOW2 files driver Signed-off-by: Denis V. Lunev --- drivers/md/dm-qcow2-map.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index b22cb5c90918..9d68d713ec3b 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -621,7 +621,7 @@ static bool delay_if_has_wpc_readers(struct qcow2 *qcow2, struct md_page *md, static void inc_writers(struct md_page *md, struct qio *qio) { qio->writer_md = md; - qio->writer_gen = md->writer_gen; + qio->writer_gen = READ_ONCE(md->writer_gen); atomic_inc(&md->active_writers[qio->writer_gen]); } @@ -670,6 +670,14 @@ static bool delay_discard_if_writers(struct qcow2 *qcow2, struct md_page *md, u8 gen; spin_lock_irq(&qcow2->md_pages_lock); + /* + * md->active_writers checks are valid only if increases are from + * main kwork (as we are), under md_pages_lock, or from a lockless + * fast path write, which counts itself and then rechecks md->gen, + * bumped by md_index_set_locked() when this discard locked the index. + * Pairs with smp_mb__after_atomic() in parse_metadata_lockless(). + */ + smp_mb(); if (qio->flags & QIO_DISCARD_WAIT_FL) { if (atomic_read(&md->active_writers[qio->writer_gen])) goto delay; @@ -679,10 +687,6 @@ static bool delay_discard_if_writers(struct qcow2 *qcow2, struct md_page *md, goto unlock; } - /* - * md->active_writers checks are valid only if increases are - * from main kwork (as we are) or under md_pages_lock. - */ gen = md->writer_gen; if (md->discard_waiters) { /* @@ -2130,10 +2134,11 @@ static bool md_page_stable(struct md_page *md, unsigned int *gen) } /* - * Map a read of an allocated cluster without md_pages_lock. Both L1 and - * L2 pages must be cached and clean, and the cluster mapped exactly once, - * not compressed and not all-zeroes. A page change seen through md->gen, - * or any other case, returns false, and the caller parses under the lock. + * Map a read or write of an allocated cluster without md_pages_lock. Both + * L1 and L2 pages must be cached and clean, and the cluster mapped exactly + * once, not compressed and not all-zeroes. A page change seen through + * md->gen, or any other case, returns false, and the caller parses under + * the lock. */ static bool parse_metadata_lockless(struct qcow2 *qcow2, struct qio *qio, struct qcow2_map *map, u64 *ret_pos) @@ -2176,6 +2181,16 @@ static bool parse_metadata_lockless(struct qcow2 *qcow2, struct qio *qio, if (READ_ONCE(l1->gen) != l1_gen || READ_ONCE(l2->gen) != l2_gen) goto out; + if (op_is_write(qio->bi_op)) { + inc_writers(l2, qio); + /* Pairs with smp_mb() in delay_discard_if_writers() */ + smp_mb__after_atomic(); + if (READ_ONCE(l2->gen) != l2_gen) { + dec_writers(qio); + goto out; + } + } + map->l1.md = l1; map->l2.md = l2; map->level = L1_LEVEL | L2_LEVEL; @@ -2215,7 +2230,8 @@ static int parse_metadata(struct qcow2 *qcow2, struct qio **qio, WARN_ON_ONCE(map->data_clu_pos != 0); if (qcow2_calc_cluster_map(qcow2, *qio, map) < 0) return -EIO; - if (avoid_metadata_changes && !write && + if (avoid_metadata_changes && + (!write || (*qio)->bi_op == REQ_OP_WRITE) && parse_metadata_lockless(qcow2, *qio, map, &pos)) { map->data_clu_pos = pos; return 0; -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel