From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697138; cv=none; d=zohomail.com; s=zohoarc; b=BUiGTD8+8WWV3+KVj4nvyIep3lahbYOyVam/sIE5q7mhcuIeVqW5wzFK2rB6n4wRlrsZZPSppodFzOYw/FaLjWAFrb8erqggKBovW4bv3xe6bSl5bi9ugMENLOYkgKWRcu1VYu6+3cC+9RRtdfuQTTw5eZmgzL/yK81BCNzif/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697138; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nRgsZGjFcRabgUhVMnu6mZsS+vJhVWDRtCtPb6hG3D4=; b=nIHomgshsQBPtW+7RZs7kvpFb5ItdGCluoUDtTwwAG1SFKP7hsuXCrMtz4tmpow1EPzqNYUHFKwL7+1Rof1FqCjGD9kvnqiRDXrP+wKT4QA3bKUtzuIJxCFVHKFP3PIERLJwd4vtbTIu5H+gNZC9ajPbC3udkZlZENvFGXrCzEI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179069713853329.769755500772476; Tue, 29 Sep 2026 08:52:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7X-0005ws-Ca; Tue, 29 Sep 2026 11:51:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7E-0005kt-44 for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:36 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7C-0001Qg-0i for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:35 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49b912d3931so33215185e9.3 for ; Tue, 29 Sep 2026 08:51:33 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697092; x=1791301892; darn=nongnu.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=nRgsZGjFcRabgUhVMnu6mZsS+vJhVWDRtCtPb6hG3D4=; b=IyP2BB8/PJezG8YgTAMepURdV7g1VdNa68BluF8c0wb/qbmc41S48Xi7KXS5ZUKiiz Nl4ufjannb+6vA3KKvsmHwCP4MmkMWHOQimXhvlUdgPnxnWad7K1n2P6+4CgAsKB65l5 YHXhPfOVzWITLwVa+4FV6yoriN+6YKnNDvqT13lB54NC2QldL3W+Ee+wKONdlVsbnNWM qcYSlUAm6GjBWcZIn6nlpesMHIOaCvyeQJJnR9m7+Gbo/gDmYJiN/DyxAbNQdVBGmLG2 xDu4u8H5xefTvfFUB5QFRlez0z7rPb8QNQehHSUYF4gr2ENW94sEzPC3jSQloJm5Xl83 g9qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697092; x=1791301892; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=nRgsZGjFcRabgUhVMnu6mZsS+vJhVWDRtCtPb6hG3D4=; b=anj848SW6Q+omtrGRVJcj+62l8KYwYIi3Dv26TlCdrUMEtlTX/Jdp6CifouHisuehv lqbOn1flUljxcfdOS/ddwzWHhN+H8RB3Xax2D4TG/VWdk9OyqCDp/jHYTJc8SjKIfYce XfB4VBkKTsKvsh4hsUebSJ3Ys8Qg4bggs3uFX/XdPTn0REBymXGJeLsNSIOctBf0T0Nu 5PTtZRzl9bJMDW/VtKC9fbbjZ90IW9kiFqdeYKliF3rtSvz8lAtozudaUl51kS8ilL0B nz6H4Z5UQC2EPVKqZjZJzrupiyFLMHbr2AiCtz8Atg3Ahg0poq2UeWVZzwB0l9EgRgNM cucw== X-Gm-Message-State: AFuF++lS8lykB8FAHC3iLGqffZOFzJUHPHWAEBqdG2Uu1sKiLeJXzHY/ hTH7EJ3pC4p2f4vhVYSUT4DhICzWwB/SwgSsOH8Z1ARXLgZKub/dbuaNQiMJ1XDko62Rrb0k9CL WvHL/ X-Gm-Gg: AYBFou1QvMqNq2xyc/TUWX73vKWBTbohEZqLXd6XAa1Az6xSkCvfzwc5Q99qqH9ewdU z/JJYkXmfiw+SZ2ozewy+QaOASb9lUd3UEJa/jBKCdttompuFdT5GFTdulQpkFk3ED3+peb+zFc 9j1gJk+iZM4O844dU/Fb3YbKdioG9WGp0U0VM3X+h3PeyVnKSW20309CUYNTvQ9Fm3zncREYuTf B95grtkwLrgRd18NEDrZ8TGwP8cCFJG5Xp5Uj+8rSxtaoAvLFf9ePda+l7m4Hl9XyBtwRIaMMeP keORkp414yo4qcQOFfABnYdH+s0TDWHXutEybWriZ7bTeZZ5pSNcVsbhp+7ftOx4HczqwazWP8e WLdIYmnRMHVixD/1Nj4pXYCSj5KSc0aghKU2cQuuCZLHpXVH8188jsgmPy+ETNlIt0S6CHvaOZX IzxuKppCY+2cAOrXU7F5kfv4rwQ85s2aILHJ2enh0gM0g0HAjhUGtJ8vvUEQ== X-Received: by 2002:a05:600c:83c4:b0:49f:c331:39e4 with SMTP id 5b1f17b1804b1-49fe66ca101mr283651795e9.7.1790697092261; Tue, 29 Sep 2026 08:51:32 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow , Eric Blake Subject: [PATCH v3 1/9] block/commit: pass BDRV_WANT_PRECISE to block-status Date: Tue, 29 Sep 2026 17:51:17 +0200 Message-ID: <20260929155125.3151111-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697138861158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev c33159dec790 replaced the want_zero bool with a bitmask of BDRV_WANT_* flags. block/commit.c was missed and still passes "true", which is BDRV_BLOCK_DATA, not BDRV_WANT_PRECISE. Convert it like the other callers. Fixes: c33159dec790 ("block: Expand block status mode from bool to flags") Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev CC: Eric Blake Reviewed-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/commit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/commit.c b/block/commit.c index 2d52c39594..4e0b0f9029 100644 --- a/block/commit.c +++ b/block/commit.c @@ -140,8 +140,8 @@ commit_iteration(CommitBlockJob *s, int64_t offset, /* Copy if allocated above the base */ WITH_GRAPH_RDLOCK_GUARD() { ret =3D bdrv_co_common_block_status_above(blk_bs(s->top), - s->base_overlay, true, true, offset, COMMIT_BUFFER_SIZE, - &bytes, NULL, NULL, NULL); + s->base_overlay, true, BDRV_WANT_PRECISE, offset, + COMMIT_BUFFER_SIZE, &bytes, NULL, NULL, NULL); } =20 trace_commit_one_iteration(s, offset, bytes, ret); --=20 2.53.0 From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697135; cv=none; d=zohomail.com; s=zohoarc; b=H6yMWtrWGhtXO/Y3uhshFVjqbgtbtU9snwehC8j/4jIt7hJ99HApLI9be1zvHZa6zxM0oRES1QyfsL7+FA5Vtvrcn7bqiuA2ILkSf+0fmVlnCKiBTp2VCJRYRw0wwwn2w35hhPMQ8ZSQBEVlGBkVQ10kwTdr6AviaU7UXDN0Arc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697135; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mo2H2454pgzwXQizQ9mmVpilIP+aDCvsipICKA+Bkms=; b=RzjSf2MtfT4dbjlN6IixhQ9Fbe67GYQF091xbUqQQ+6xm0G+nTeSHBYxn6Wm1mwDse10n4qeTUWUYNmlWQ9qWZ7cqHkaBbn7LB6ASkwG0AhIPKy8zsC64ff1rWEeIWnTsIPGP6cVRRezTurWvByY1HiSWjInO+tz1Ko0O2+Nvto= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790697135246756.2565782047546; Tue, 29 Sep 2026 08:52:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7T-0005s5-50; Tue, 29 Sep 2026 11:51:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7F-0005lp-UQ for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:38 -0400 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7D-0001Qp-BY for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:37 -0400 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-48439feca17so3271197f8f.1 for ; Tue, 29 Sep 2026 08:51:34 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697093; x=1791301893; darn=nongnu.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=mo2H2454pgzwXQizQ9mmVpilIP+aDCvsipICKA+Bkms=; b=t2J+6yfAgeuOcF1bWFH5cNShtrEjha+EenzxeijjdFD6p04zkubogwByu8gzkOP1Wa 9+519rdoS1rdUF2fq4zHjjLAwVssaqvaZFHPKIupxjJKYnMomKPaBZ1Xv2I++u9gr82O LRL2RvUG76qOrKlDUPeSNCiTisBdhAu1W3PZte29ftYR1Ko0EMJHB/Xc07HZuFKwuMaO z/zGzbqDM/JCy8WRV4+lT0Wpn0cDPLYV/oOueGoZewQMCPPxYmBMGWtQyRGy1ejhSnOO m7qHhOruA1fAd4JiSO8zXUjgvyCpJkQMphJjSdMp8A9sbG44kAxr38NHo2aSI4rmeqf/ vcRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697093; x=1791301893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=mo2H2454pgzwXQizQ9mmVpilIP+aDCvsipICKA+Bkms=; b=jKNfWG17R1WIVyNHx6zl6nhXChjldTPiIFRi/15WZeoTexGD2OnOmmuxcH3ob+FAt/ 1p7kOIuqXty1jN+/PhNNDrBt7O0uY1wP1NUXdLl3yEiErXZzWaW9vPx0ZUsnqWn7gS6q yXAaNZfd+pytKJa6wIEaUBj51XdBrArpyOZZQQRT0ycxaX+ARP9raZLzQPcDt0x4ipK1 kX4mP7gsFcOwGCP/5NX174FL2alDMTOrYGAfox01qBezPgsR0fsPMxtwCofxXnPrFJhc RRt+n2jDINj3K5nR5XO+EVPXrg5+fN0/ICIg4ikFx2c7xP1HdNdEjWRougBdGqqAbjsP 4/sA== X-Gm-Message-State: AFq9FYL2Vbw95U5lI7aY36ICVx22PRkj3/+aXs+9mI0rT7y/7pHYxzs3 Sz5IxfwCZXKlO6gr8yh7juANrhUyXuKbeD6Z0Sl6RMK0jJ3eG4qdruBO+cpenhlKHSvEcHG06nq AgTHR X-Gm-Gg: AYBFou1xIe+1bpDIL0U2+9HiZ/BlKVUpmhs1SVeWSH07cVuDvtOAsWi14etK85z5WTm zjgVlRkLWOZlZ3K6z6ev7/G2eJ4ZoPkMFWvSw2fwyj5HK1xAC743uBFBaBoV/49G/knTECMNtHj ISur7je2CrlpyoCumkKbgGudIwD/e69cO/5kPeJEUZX8+knowfgNZTiV+OuQDdTJmcNwr4SAVfk xxX2KQTDicoZPRJS9+NommCPttO8iUnsRVlV9jGrPQFxv79szV1mN8uWvsMMucGyW5Cqd7JJwD2 ykJn4yHnDthtI8dUdJP4jjPd0SqqKYr6SH8WBRw8Wme48OLyuw3cPzbU0Y5LIlqD8md4w4l9qs0 vmwKfIRXyqZKsty7u6E+mI173IKQ17tl8gg2sAC8bUSVWH3lURXbMFFxeKFoLdJe2PZkm7M0KOL Kr4H2L1x3hg0uW0QbaGYiDe2Emuwl7fkWlqqOTzJ7xgJ25a05VwXO13NHH/g== X-Received: by 2002:a05:6000:2c0b:b0:48a:fdb2:f2f4 with SMTP id ffacd0b85a97d-48afdb2f312mr74331f8f.57.1790697093501; Tue, 29 Sep 2026 08:51:33 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v3 2/9] iotests/040: cover large and fragmented commit runs Date: Tue, 29 Sep 2026 17:51:18 +0200 Message-ID: <20260929155125.3151111-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::10; envelope-from=den@openvz.org; helo=mail-wr2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697137719158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev 040 never commits runs long enough to span more than one block-status query, so the answer that commit_iteration() is about to start caching goes untested. Add two cases on a base <- mid <- active chain, committing mid so the job takes the regular commit path rather than active commit, and compare base against a snapshot of mid taken before the commit. One case mixes multi-megabyte data, zero and hole runs, the other fragments them down to single clusters with every transition off the 512K boundary. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/040 | 102 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/040.out | 4 +- 2 files changed, 103 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index 5c18e413ec..e01c9385ba 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -25,13 +25,14 @@ import time import os import iotests -from iotests import qemu_img, qemu_io +from iotests import qemu_img, qemu_img_create, qemu_io, compare_images import struct import errno =20 backing_img =3D os.path.join(iotests.test_dir, 'backing.img') mid_img =3D os.path.join(iotests.test_dir, 'mid.img') test_img =3D os.path.join(iotests.test_dir, 'test.img') +reference_img =3D os.path.join(iotests.test_dir, 'reference.img') =20 class ImageCommitTestCase(iotests.QMPTestCase): '''Abstract base class for image commit test cases''' @@ -951,6 +952,105 @@ class TestCommitWithOverriddenBacking(iotests.QMPTest= Case): self.vm.qmp('block-job-complete', device=3D'commit') self.vm.event_wait('BLOCK_JOB_COMPLETED') =20 +class TestCommitLargeRuns(iotests.QMPTestCase): + """Commit runs long enough to cross commit_iteration()'s cached span."= "" + + MB =3D 1024 * 1024 + CLUSTER =3D 64 * 1024 + + # Runs several COMMIT_BUFFER_SIZE (512K) chunks long, of every kind. + SIZE =3D 32 * MB + LAYOUT =3D [ + (0, 4 * MB, 'data'), + (4 * MB, 6 * MB, 'hole'), + (10 * MB, 4 * MB, 'data'), + (14 * MB, 6 * MB, 'zero'), + (20 * MB, 4 * MB, 'data'), + (24 * MB, 8 * MB, 'hole'), + ] + + # The same, with every transition off the 512K boundary. + SIZE_FRAGMENTED =3D 384 * CLUSTER # 24M + LAYOUT_FRAGMENTED =3D [ + (0, 45 * CLUSTER, 'data'), + (45 * CLUSTER, 55 * CLUSTER, 'hole'), + (100 * CLUSTER, CLUSTER, 'data'), + (101 * CLUSTER, 49 * CLUSTER, 'zero'), + (150 * CLUSTER, 80 * CLUSTER, 'data'), + (230 * CLUSTER, CLUSTER, 'hole'), + (231 * CLUSTER, 69 * CLUSTER, 'data'), + (300 * CLUSTER, 83 * CLUSTER, 'zero'), + (383 * CLUSTER, CLUSTER, 'hole'), + ] + + def setUp(self): + self.vm =3D iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + for img in (backing_img, mid_img, test_img, reference_img): + if os.path.exists(img): + os.remove(img) + + def build_images(self, layout, size): + # A pattern of its own in base, so a misplaced cluster shows up. + qemu_img_create('-f', iotests.imgfmt, backing_img, str(size)) + qemu_io('-c', f'write -P 0x11 0 {size}', backing_img) + + qemu_img_create('-f', iotests.imgfmt, '-b', backing_img, '-F', + iotests.imgfmt, mid_img, str(size)) + for offset, length, kind in layout: + if kind =3D=3D 'data': + qemu_io('-c', f'write -P 0x22 {offset} {length}', mid_img) + elif kind =3D=3D 'zero': + qemu_io('-c', f'write -z {offset} {length}', mid_img) + + # What base must equal once mid is committed into it. + qemu_img('convert', '-f', iotests.imgfmt, '-O', iotests.imgfmt, + mid_img, reference_img) + + # An empty layer above mid, so top_node=3Dmid is not the active on= e. + qemu_img_create('-f', iotests.imgfmt, '-b', mid_img, '-F', + iotests.imgfmt, test_img, str(size)) + + self.vm.cmd('blockdev-add', { + 'node-name': 'base', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': backing_img}, + }) + self.vm.cmd('blockdev-add', { + 'node-name': 'mid', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': mid_img}, + 'backing': 'base', + }) + self.vm.cmd('blockdev-add', { + 'node-name': 'active', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': test_img}, + 'backing': 'mid', + }) + + def commit_and_verify(self): + self.vm.cmd('block-commit', job_id=3D'commit0', device=3D'active', + top_node=3D'mid', base_node=3D'base') + self.wait_until_completed(drive=3D'commit0') + + self.vm.cmd('blockdev-del', node_name=3D'active') + self.vm.cmd('blockdev-del', node_name=3D'mid') + self.vm.cmd('blockdev-del', node_name=3D'base') + self.assertTrue(compare_images(reference_img, backing_img)) + + def test_commit_large_runs(self): + self.build_images(self.LAYOUT, self.SIZE) + self.commit_and_verify() + + def test_commit_fragmented_runs(self): + self.build_images(self.LAYOUT_FRAGMENTED, self.SIZE_FRAGMENTED) + self.commit_and_verify() + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index 1bb1dc5f0e..d2e2a2d98f 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -................................................................. +................................................................... ---------------------------------------------------------------------- -Ran 65 tests +Ran 67 tests =20 OK --=20 2.53.0 From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697135; cv=none; d=zohomail.com; s=zohoarc; b=gA+QPOpHPrAT8GfpR76h5ihqLRZB8GBhSaIcwTAkCGyRRkGMfHy32hOKRjQfebNCqxOuLANK16pQs37/F6BEZLHDKuqd1fB4qOy3A7A+zMlx/Oi6YedYWMBpxHHpPIeqINtoB+4b/r/Dmw5cNjKrzPQQuqyckEWp7a8om3zxHLw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697135; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lFAcWnrWi60JYEjwn6l8H/drw/Jr0F8dV3g2fTSKPqM=; b=a0yAYekCdYekYYeSJFXGq5GxQsXOVs2+KhP4gnDTLC+4+4UjpbdWkgbwttJelvSj3n7eZ8r+S4rng4pkZ8oGmG5537QyPaUmGHbouLFgQJITGPX/euKVqKV95MxeQ2QrBVJ3/9X0aQNwOcDCo6WFtnl7EyrUhEp0WIZ8pe9denQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17906971354671017.6935218490477; Tue, 29 Sep 2026 08:52:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7P-0005rK-BK; Tue, 29 Sep 2026 11:51:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7H-0005mT-JE for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:40 -0400 Received: from mail-wr2-x0f.google.com ([2a00:1450:4864:30::f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7F-0001RF-0h for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:38 -0400 Received: by mail-wr2-x0f.google.com with SMTP id ffacd0b85a97d-4887f6cf16bso2751109f8f.0 for ; Tue, 29 Sep 2026 08:51:36 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697095; x=1791301895; darn=nongnu.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=lFAcWnrWi60JYEjwn6l8H/drw/Jr0F8dV3g2fTSKPqM=; b=hIc6WSSC8x6U2V/ozGyjq8NHrca3JSiuM/FutMg2EXrVMTovfbrrDl1/JBmGejHEnt u9LfEgJojLiD6dmKr4q0YhRq4siY5G39MeJOZQDGrfdEKjl6GSToKS9Ugbv9mBsJOQZX hFWibaawN4KBIW51ioo+GczDfZXoF8PUpXA6ZYmvqNDJLbcqJhlyjCao4EProim4hFX+ ms4F+5tLvDnouvGT5m4DeNU20u2j9SEnxv/8LKUza3DPTXInN0XouASb60ofoPcDAM5l NpEQa2wrPqYMQrKVAUEhH467r6Yuxo3fVXUGK/ka7D/P9Ytv2JB52m6ZhEmXqEEci48G vJMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697095; x=1791301895; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=lFAcWnrWi60JYEjwn6l8H/drw/Jr0F8dV3g2fTSKPqM=; b=y8i9Ac7+mSgd4CgATFXpHqDZUsun3PRAXrAkMO5R/AsDYwatFALdLLTLlVdO3/vcwV E8VCY3+uVQ6IhdJaEw385sUJq9yF4mtnx3uQhaEmsmVsHQ4UgyxXPelUXDNU8+WlwREs pXLgRVXGP4qipPkU/AHD/WNblCCB0tW3Y9VdZsVz2/Fj2xuDQAZWDZ9NjfuDAENnZCG8 KeglzxL+cOKd2llNIjvLSK/KcI/p+gtS69kDaDOYfVXjqcloyOb7oGaKUxYfqj2I4y0L YzotGQZDL6GMC0601yMhCqdE9oB1D1dBkX9KfTanVWopBmhvaAesIDyF0g6A+594dN8W Jrdw== X-Gm-Message-State: AFq9FYLru+r+FgZW5bamQunyTCtxNnyxPCP/s4TN/CW95bRKvSWXDumv cL+9wc1vEQx9zvmLlJDkr8SR+/UIY8VMjZcBqxt/59pSiQhjyZtagRcv1x6U3YjSPFNfS9M9cKf kzOHE X-Gm-Gg: AYBFou2JFOkQHk//Ap/QBGhoCfuwV/r+PxrNI/rn2uM3cddQMQqn31PnM0YJkNbZUs4 /mbTxjnsjQ0qB4Sn9IgzLlScsLoZe40kEMWrAL6BzXIZN4yqU7ddUmie8Mz0iNyp5sPD+YEQhbd EeLp6KNk8861D/eaEreu8CKsP0OrOxTKZPMcVceF4Rcm3dmq0NPkwyVFQULhme/ff7n7Eql5Rg/ /31byMA5tBzSPlVLIggWS5ipaR9KGBjquCmRRAlLTpmqIe0YttpHevTm2jhEpxZKVUYa6M1OZ6g M7iW+JR2c0vTf16Eiyu4FElQYv5jk5niJn0zoxhOx8kuW89YLRsOcoCE09Z+Q/MyRE+sznqKvrR gQkk4+9qbWgDb3cTN3ctvX8/SPdUeKObFkUcAKfPwoIgaPcr5SLAYe9Eo6sSEjE1ZQ3Nt3dxx/q Z7RMTiyM7GcWnPF2fH/drixxXaPpJqmQ0MvJdectcPui+Bt3KUAf9LeZZWXw== X-Received: by 2002:a05:6000:4a04:b0:487:aa6:c90d with SMTP id ffacd0b85a97d-4887d9fa6e6mr23686461f8f.1.1790697095528; Tue, 29 Sep 2026 08:51:35 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v3 3/9] block/commit: batch block-status queries Date: Tue, 29 Sep 2026 17:51:19 +0200 Message-ID: <20260929155125.3151111-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::f; envelope-from=den@openvz.org; helo=mail-wr2-x0f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697137705158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev commit_iteration() asks for block status COMMIT_BUFFER_SIZE (512K) at a time, so a long run above base pays one query per 512K for an answer the whole run shares. Query the remainder of the image instead and keep the answer in a CommitStatus owned by commit_run(). No device or export writes top above base_overlay while the job runs: they ask for BLK_PERM_CONSISTENT_READ along with BLK_PERM_WRITE, and the job withholds CONSISTENT_READ there, having to share WRITE or it would block its own writes to base through the backing chain. A job target asks for WRITE alone and is refused by the op blocker instead. From filtered_base downwards CONSISTENT_READ is shared again, and there only the job writes. Copying is still bounded by the read buffer. Zeroes need no buffer, so COMMIT_ZERO_CHUNK bounds them, keeping a cancel from waiting on a huge write-zeroes, and an unallocated span is crossed in one step. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/commit.c | 58 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/block/commit.c b/block/commit.c index 4e0b0f9029..e8ddd46053 100644 --- a/block/commit.c +++ b/block/commit.c @@ -31,8 +31,23 @@ enum { * contiguous regions of the image is efficient. */ COMMIT_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ + + /* + * Zeroes need no buffer, so they are bounded by this instead. It stays + * well under BDRV_REQUEST_MAX_BYTES and keeps a cancel from waiting on + * a multi-gigabyte write. + */ + COMMIT_ZERO_CHUNK =3D 256 * 1024 * 1024, /* in bytes */ }; =20 +/* Last block-status answer, covering [offset, end). Empty when equal. */ +typedef struct CommitStatus { + int64_t len; + int64_t offset; + int64_t end; + int ret; +} CommitStatus; + typedef struct CommitBlockJob { BlockJob common; BlockDriverState *commit_top_bs; @@ -130,26 +145,45 @@ static void commit_clean(Job *job) =20 static int coroutine_fn commit_iteration(CommitBlockJob *s, int64_t offset, - int64_t *requested_bytes, void *buf) + int64_t *requested_bytes, void *buf, CommitStatus *st) { BlockErrorAction action; - int64_t bytes =3D *requested_bytes; + int64_t bytes; int ret =3D 0; bool error_in_source =3D true; =20 - /* Copy if allocated above the base */ - WITH_GRAPH_RDLOCK_GUARD() { - ret =3D bdrv_co_common_block_status_above(blk_bs(s->top), - s->base_overlay, true, BDRV_WANT_PRECISE, offset, - COMMIT_BUFFER_SIZE, &bytes, NULL, NULL, NULL); + assert(offset >=3D st->offset); + + if (offset >=3D st->end) { + /* Copy if allocated above the base */ + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_co_common_block_status_above(blk_bs(s->top), + s->base_overlay, true, BDRV_WANT_PRECISE, offset, + st->len - offset, &bytes, NULL, NULL, NULL); + } + + if (ret < 0) { + trace_commit_one_iteration(s, offset, 0, ret); + goto fail; + } + + st->offset =3D offset; + st->end =3D offset + bytes; + st->ret =3D ret; } =20 - trace_commit_one_iteration(s, offset, bytes, ret); + ret =3D st->ret; + bytes =3D st->end - offset; =20 - if (ret < 0) { - goto fail; + /* An unallocated span costs no I/O, so it is crossed in one step. */ + if (ret & BDRV_BLOCK_ZERO) { + bytes =3D MIN(bytes, COMMIT_ZERO_CHUNK); + } else if (ret & BDRV_BLOCK_ALLOCATED) { + bytes =3D MIN(bytes, COMMIT_BUFFER_SIZE); } =20 + trace_commit_one_iteration(s, offset, bytes, ret); + if (ret & BDRV_BLOCK_ALLOCATED) { if (ret & BDRV_BLOCK_ZERO) { /* @@ -215,6 +249,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) int64_t n =3D 0; /* bytes */ QEMU_AUTO_VFREE void *buf =3D NULL; int64_t len, base_len; + CommitStatus st =3D { 0 }; =20 len =3D blk_co_getlength(s->top); if (len < 0) { @@ -235,6 +270,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) } =20 buf =3D blk_blockalign(s->top, COMMIT_BUFFER_SIZE); + st.len =3D len; =20 for (offset =3D 0; offset < len; offset +=3D n) { /* Note that even when no rate limit is applied we need to yield @@ -245,7 +281,7 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) break; } =20 - ret =3D commit_iteration(s, offset, &n, buf); + ret =3D commit_iteration(s, offset, &n, buf, &st); =20 if (ret < 0) { return ret; --=20 2.53.0 From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697179; cv=none; d=zohomail.com; s=zohoarc; b=Pb49lF/NfGh9LMZSGbC9BTEbbY4fy7Ptc9aWbAjEIKR8yC/LEV2BiM5EM3b+9Yy0/7jNGR1yAUT/kBJWPU7bhmrPvSGL9jyx1XwamTbKk9C5YOU0/7b3/JA+oyk9lB+FqfaZgMC/P8oRp8ERvzzCsz5DoZ+eY9Qc//GD9dJoDak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697179; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9e5vUSJlpSMtdxLo9965mEtIMUDEOzT4vCZhI+GxTyo=; b=KHXFc1zFPEx9f3bGkngxNCp9P4hkWDBxsTQ8GjG2Ldaub/Re5ftMglpt/1pvE7TcxHsEBC7EsqwnnJm8iMW0nZsW9s8Ogg9D/JnKpzp6k+qu2mHKF6oAB1qOyxoY4TsIlm/3q673QoIzHqYY25zMw+TStIQfJ/eNSXZqvQr2ymE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790697179519692.0432195079934; Tue, 29 Sep 2026 08:52:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7Z-0005yP-58; Tue, 29 Sep 2026 11:51:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7J-0005nq-QB for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:43 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7H-0001RV-Bt for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:41 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ffbd83a92so25504545e9.0 for ; Tue, 29 Sep 2026 08:51:38 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697097; x=1791301897; darn=nongnu.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=9e5vUSJlpSMtdxLo9965mEtIMUDEOzT4vCZhI+GxTyo=; b=bzWQjjU3u7HAcpTsyx1uKzZfuz26Fbk0EviExjWhQSfrd/tQTJiLCiWAxwqtu83uqm eauzajKAOWa561ik07vJmaYSYV2NA2Mbyd9gnVG6KptQ5Wu2Qz+P+RqLgdAEKWvqHsTo FISclFuqxXK5UOPbsx2Me+jdrs9Az95M2IfF9SYL17jKzFCxcfW6e6tIJ5yDHgmsp4nx alHpJ+b+z98ztkddod9U1BD+vTP+TMqwQ8jiL9T7Xam+qWTPagRRcWf3TmLxlbaDatT4 ns42d5Cmx63krQzhQe2pnex6+eb8kVY9TaO2sq6bV1i7wOWFgj20myvgx5hAncWMPOYS +Z3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697097; x=1791301897; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9e5vUSJlpSMtdxLo9965mEtIMUDEOzT4vCZhI+GxTyo=; b=lbAOMagpVrjuPWCNcaQTMEoDZgJdLXLICp+PNfqi+Ykt64L4ek5z29dhZgtfONqW+m Y8J9cgCxs9qSmXS+Pv0ELCnMGrSMEudc0hdRF4dZXnct32az6890i/lOBNQ5RDx8+8jX +r1XXb03YkZXioOHuD3eY9t3heCvsHIAxmVVQwow+YxpdvGUO0UT1uoNaeDpreQRlxUA bwPOEYVE/7GDqfJRYslXAy31R6t9WxuSFsnUM62ekdOovXwgzDSnPIWfz8VqD3Dt7K0E YardOFQEKECTau01FSV2FYmopSJgLXiRZ8lx0Id8ZRlMTT8AxEEQaXFjXeLfo9mzlqGS u4Yg== X-Gm-Message-State: AFuF++kVkJSxDc0YkPKkqQ3PxnS+ONsHnsRRr4dtiZSKWkQR+JU6uJid z/JcQkP9KKOyNa8PTEPoSrB1dfiZElzLYGOplOhK5zUl8wsyOeUVjjX8PnQKHkzjty+Q9HprXIW tXLfk X-Gm-Gg: AYBFou21Rj1jxJn6SAAcwukvMrNLcgYfpKzY2+O49uEO+oh8KdZ3eOPUMMQgv4tWCbZ a+xcfUkndRRtA59cL4K2RZrKaCXpvwFubEI0Yu1WKAzg/9t7BxxrLbfX7G6I8SE6WDeRghzwaV2 XWQt+QR5DHqySICkWIALRbiOdCkcGILB+nREOrUA5FJYjZDGnrNBl60hDtPxnLhvig4UDNTH3Eo +l5qaze72lLj4+i0f7yOwkXnz7KnQdu/adyhxjV/DQxBHfg8o8gNA6lGga1HPaqFPnZzq/1lJXX O/TVJl9Zc0K/A98untIwtsTqL5ZJrD0m72XXIOkErwaqj52kMF4ZFZDp6+SSM4gLmGiHVXjx621 gKFxtU6ODG6LwyYrm3SvYyugf0fCw5j2iA3nCveGxB2W9GShFVWIhm6MXuqeIVDMLWsEHgFcoAi 73CWbSNZ8GCPfpceH5P3TzyO/KMArlS2/uuBwjgF5fhizNSaAvaisEqWtYfQ== X-Received: by 2002:a05:600d:8482:20b0:49f:c451:b4ab with SMTP id 5b1f17b1804b1-49fe67bc264mr220286175e9.29.1790697096976; Tue, 29 Sep 2026 08:51:36 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v3 4/9] iotests/124: cover backup of zero clusters and holes Date: Tue, 29 Sep 2026 17:51:20 +0200 Message-ID: <20260929155125.3151111-5-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697181480158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev The backup tests compare content only, and their sources hold data alone, so nothing pins how backup treats zero clusters and holes. Back up a source mixing data, write-zero and holes with sync=3Dfull, sync=3Dtop and sync=3Dbitmap, and check the target with qemu-img map, which tells a copied cluster apart from a write-zero and from an untouched one. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/124 | 347 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/124.out | 4 +- 2 files changed, 348 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/124 b/tests/qemu-iotests/124 index ab9ea4d8b5..7afcf61324 100755 --- a/tests/qemu-iotests/124 +++ b/tests/qemu-iotests/124 @@ -22,8 +22,11 @@ # =20 import os +from collections import namedtuple + import iotests -from iotests import try_remove +from iotests import (compare_images, qemu_img_create, qemu_img_map, qemu_i= o, + try_remove) from qemu.qmp.qmp_client import ExecuteError =20 =20 @@ -748,6 +751,348 @@ class TestIncrementalBackupBlkdebug(TestIncrementalBa= ckupBase): self.check_backups() =20 =20 +# Backup of sources mixing data, zero clusters and holes. + +Extent =3D namedtuple('Extent', ['start', 'length', 'kind']) +Case =3D namedtuple('Case', ['size', 'layout', 'expected'], defaults=3D[No= ne]) + +source_img =3D os.path.join(iotests.test_dir, 'source') +base_img =3D os.path.join(iotests.test_dir, 'base') +target_img =3D os.path.join(iotests.test_dir, 'target') + +SIZE =3D 64 * 1024 * 1024 +MB =3D 1024 * 1024 +CLUSTER =3D 64 * 1024 + +# Data, write-zero and holes, every combination at a cluster boundary. +MIXED =3D Case(SIZE, [ + (0, MB, 'data'), + (2 * MB, MB, 'zero'), + (5 * MB, 2 * MB, 'data'), + (8 * MB, MB, 'zero'), + (10 * MB, MB // 2, 'data'), + (20 * MB, 4 * MB, 'zero'), + (30 * MB, MB, 'data'), +]) + +# Single-cluster runs, and a zero run ending exactly at EOF. +BOUNDARY_SIZE =3D 16 * MB +BOUNDARY =3D Case(BOUNDARY_SIZE, [ + (0, CLUSTER, 'zero'), + (CLUSTER, CLUSTER, 'data'), + (2 * CLUSTER, CLUSTER, 'zero'), + (3 * CLUSTER, CLUSTER, 'data'), + (4 * CLUSTER, 8 * MB, 'zero'), + (4 * CLUSTER + 8 * MB, CLUSTER, 'data'), + (BOUNDARY_SIZE - CLUSTER, CLUSTER, 'zero'), +]) + +# A zero run past the old block_copy_chunk_size() 16M cap. +LARGE_ZERO =3D Case(48 * MB, [ + (0, MB, 'data'), + (4 * MB, 32 * MB, 'zero'), + (40 * MB, MB, 'data'), +]) + +# Image size not a multiple of the cluster size: a partial tail cluster. +TAIL_SIZE =3D 4 * MB + 4096 +TAIL_CLUSTER =3D (TAIL_SIZE // CLUSTER) * CLUSTER +TAIL_DATA =3D Case(TAIL_SIZE, [ + (0, MB, 'data'), + (2 * MB, MB, 'zero'), + (4 * MB, TAIL_SIZE - 4 * MB, 'data'), +]) +# The partial tail cluster falls out of zero_bitmap, so it copies as data. +TAIL_ZERO =3D Case(TAIL_SIZE, [ + (0, MB, 'data'), + (2 * MB, TAIL_SIZE - 2 * MB, 'zero'), +], [ + (0, MB, 'data'), + (2 * MB, TAIL_CLUSTER - 2 * MB, 'zero'), + (TAIL_CLUSTER, TAIL_SIZE - TAIL_CLUSTER, 'data'), +]) + + +def coalesce(extents): + out =3D [] + for e in extents: + prev =3D out[-1] if out else None + adjacent =3D prev is not None and prev.start + prev.length =3D=3D = e.start + if adjacent and prev.kind =3D=3D e.kind: + out[-1] =3D prev._replace(length=3Dprev.length + e.length) + else: + out.append(e) + return out + + +def layout_to_extents(layout, size, gap=3D'hole'): + extents =3D [] + pos =3D 0 + for offset, length, kind in layout: + if offset > pos: + extents.append(Extent(pos, offset - pos, gap)) + extents.append(Extent(offset, length, kind)) + pos =3D offset + length + if pos < size: + extents.append(Extent(pos, size - pos, gap)) + return coalesce(extents) + + +def create_image(path, size, backing=3DNone, opts=3DNone): + args =3D ['-f', iotests.imgfmt] + if opts: + args +=3D ['-o', opts] + if backing: + args +=3D ['-b', backing, '-F', iotests.imgfmt] + qemu_img_create(*args, path, str(size)) + + +class TestBackupZeroClusters(iotests.QMPTestCase): + def setUp(self): + self.vm =3D iotests.VM() + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + for img in (source_img, base_img, target_img): + if os.path.exists(img): + os.remove(img) + + def hmp_write(self, drive, cmd): + res =3D self.vm.hmp_qemu_io(drive, cmd) + self.assertNotIn('error', res['return'].lower()) + + def write_layout(self, layout): + for offset, length, kind in layout: + opt =3D '-z' if kind =3D=3D 'zero' else '-P 0x5a' + self.hmp_write('src', f'write {opt} {offset} {length}') + + def assert_map(self, case, backing=3DFalse, gap=3D'hole'): + # Content is not enough, pin the data/zero/hole split as well. + def classify(e): + is_hole =3D e['depth'] > 0 if backing else not e['present'] + return 'hole' if is_hole else ('zero' if e['zero'] else 'data') + + actual =3D coalesce([Extent(e['start'], e['length'], classify(e)) + for e in qemu_img_map(target_img)]) + layout =3D case.expected if case.expected else case.layout + + self.assertEqual(actual, layout_to_extents(layout, case.size, gap)) + + def add_source(self, case=3DMIXED, backing=3DNone, opts=3DNone): + create_image(source_img, case.size, backing, opts) + + self.vm.cmd('blockdev-add', { + 'node-name': 'src', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': source_img}, + }) + + # Write through the node, so an attached bitmap sees it. + self.write_layout(case.layout) + + def dirty_layout(self, case): + # A new bitmap tracks nothing yet: dirty all, then re-apply. + self.vm.cmd('block-dirty-bitmap-add', node=3D'src', name=3D'bm0') + self.hmp_write('src', f'write -z 0 {case.size}') + self.write_layout(case.layout) + + def do_backup(self, sync, case, target_backing=3DNone, prefill=3DNone, + **kwargs): + create_image(target_img, case.size, target_backing) + + if prefill is not None: + # Not zero, so a skipped cluster is provably untouched. + qemu_io('-c', f'write -P {prefill} 0 {case.size}', target_img) + + self.vm.cmd('blockdev-add', { + 'node-name': 'target', + 'driver': iotests.imgfmt, + 'file': {'driver': 'file', 'filename': target_img}, + }) + + self.vm.cmd('blockdev-backup', device=3D'src', target=3D'target', + job_id=3D'bk0', sync=3Dsync, **kwargs) + self.wait_until_completed(drive=3D'bk0') + + self.vm.cmd('blockdev-del', node_name=3D'target') + self.vm.cmd('blockdev-del', node_name=3D'src') + + def backup_and_check(self, sync, case, gap=3D'zero', backing=3DFalse, + **kwargs): + self.do_backup(sync, case, **kwargs) + self.assertTrue(compare_images(source_img, target_img)) + self.assert_map(case, backing=3Dbacking, gap=3Dgap) + + def test_full(self): + self.add_source() + self.backup_and_check('full', MIXED) + + def test_full_zero_overwrite(self): + # full skips holes, so only check that zero overwrites prefill. + case =3D Case(SIZE, [(2 * MB, MB, 'zero')]) + self.add_source(case) + self.do_backup('full', case, prefill=3D0xcc) + qemu_io('-c', f'read -P 0 {2 * MB} {MB}', target_img) + + def test_bitmap(self): + self.add_source() + self.dirty_layout(MIXED) + self.backup_and_check('bitmap', MIXED, bitmap=3D'bm0', + bitmap_mode=3D'never') + + def test_top(self): + # Non-zero backing data, so a hole and an explicit zero differ. + create_image(base_img, SIZE) + qemu_io('-c', f'write -P 0x33 0 {SIZE}', base_img) + + self.add_source(backing=3Dbase_img) + self.backup_and_check('top', MIXED, gap=3D'hole', backing=3DTrue, + target_backing=3Dbase_img) + + def test_boundary_full(self): + self.add_source(BOUNDARY) + self.backup_and_check('full', BOUNDARY) + + def test_boundary_bitmap(self): + self.add_source(BOUNDARY) + self.dirty_layout(BOUNDARY) + self.backup_and_check('bitmap', BOUNDARY, bitmap=3D'bm0', + bitmap_mode=3D'never') + + def test_large_zero_full(self): + self.add_source(LARGE_ZERO) + self.backup_and_check('full', LARGE_ZERO) + + def test_large_zero_bitmap(self): + self.add_source(LARGE_ZERO) + self.dirty_layout(LARGE_ZERO) + self.backup_and_check('bitmap', LARGE_ZERO, bitmap=3D'bm0', + bitmap_mode=3D'never') + + def test_huge_zero(self): + # A zero run past the cap on a single write-zeroes request, so it + # has to be split. qemu-io caps one write at 2G, hence three. + case =3D Case(2560 * MB, [(0, 1024 * MB, 'zero'), + (1024 * MB, 1024 * MB, 'zero'), + (2048 * MB, 512 * MB, 'zero')]) + self.add_source(case) + self.backup_and_check('full', case) + + def test_tail_data(self): + self.add_source(TAIL_DATA) + self.backup_and_check('full', TAIL_DATA) + + def test_tail_zero(self): + self.add_source(TAIL_ZERO) + self.backup_and_check('full', TAIL_ZERO) + + def test_tail_zero_bitmap(self): + # Same tail rounding as test_tail_zero, via the bitmap scan. + self.add_source(TAIL_ZERO) + self.dirty_layout(TAIL_ZERO) + self.backup_and_check('bitmap', TAIL_ZERO, bitmap=3D'bm0', + bitmap_mode=3D'never') + + def test_mixed_cluster(self): + # 4K source clusters, so content varies inside one 64K cluster. + case =3D Case(2 * CLUSTER, [ + (0, 8 * 1024, 'zero'), + (8 * 1024, 8 * 1024, 'data'), + (CLUSTER, CLUSTER, 'zero'), + ], [ + # A mixed cluster must be data, or the data at [8k, 16k) is lo= st. + (0, CLUSTER, 'data'), + (CLUSTER, CLUSTER, 'zero'), + ]) + self.add_source(case, opts=3D'cluster_size=3D4k') + self.backup_and_check('full', case) + + def test_top_zero_broken(self): + # An overlay hole before an explicit-zero run: the zero prefix + # must stop at the hole, or the backing data under it is lost. + size =3D 2 * CLUSTER + create_image(base_img, size, opts=3D'cluster_size=3D4k') + qemu_io('-c', f'write -P 0x33 0 {size}', base_img) + + # [0, 4k) stays a hole, the zero run spills into cluster 1. + case =3D Case(size, [(4096, CLUSTER, 'zero')]) + self.add_source(case, backing=3Dbase_img, opts=3D'cluster_size=3D4= k') + + self.do_backup('top', case, target_backing=3Dbase_img) + self.assertTrue(compare_images(source_img, target_img)) + + def test_bitmap_straddle(self): + # One dirty run straddling a zero/data transition, both ways. + case =3D Case(SIZE, []) + self.add_source(case) + self.vm.cmd('block-dirty-bitmap-add', node=3D'src', name=3D'bm0') + + # One contiguous dirty run each: [7M, 9M) zero to data, and + # [15M, 17M) data to zero. + layout =3D [ + (7 * MB, MB, 'zero'), + (8 * MB, MB, 'data'), + (15 * MB, MB, 'data'), + (16 * MB, MB, 'zero'), + ] + self.write_layout(layout) + + self.do_backup('bitmap', case, bitmap=3D'bm0', bitmap_mode=3D'neve= r') + self.assertTrue(compare_images(source_img, target_img)) + # Nothing outside the two dirty runs may reach the target. + self.assert_map(case._replace(layout=3Dlayout)) + + def test_bitmap_fragmented(self): + # Isolated single-cluster dirty spots: nothing outside them + # may reach the target. + case =3D Case(SIZE, []) + self.add_source(case) + + # Written before the bitmap exists, so untracked. + self.hmp_write('src', f'write -P 0x5a 0 {16 * MB}') + + self.vm.cmd('block-dirty-bitmap-add', node=3D'src', name=3D'bm0') + + # The only dirty bit in the data region, with a pattern of its own. + data_island =3D 4 * MB + self.hmp_write('src', f'write -P 0x7b {data_island} {CLUSTER}') + + # The only dirty bit in the hole region. + zero_island =3D 24 * MB + self.hmp_write('src', f'write -z {zero_island} {CLUSTER}') + + self.do_backup('bitmap', case, bitmap=3D'bm0', bitmap_mode=3D'neve= r', + prefill=3D0xcc) + + # Only the two isolated spots should have reached target ... + qemu_io('-c', f'read -P 0x7b {data_island} {CLUSTER}', target_img) + qemu_io('-c', f'read -P 0 {zero_island} {CLUSTER}', target_img) + + # ... everything else must still hold the prefill pattern. + qemu_io('-c', f'read -P 0xcc 0 {CLUSTER}', target_img) + qemu_io('-c', f'read -P 0xcc {8 * MB} {CLUSTER}', target_img) + + def test_bitmap_clean_zero_gap(self): + # A clean zero run between two dirty ones must stay prefilled. + case =3D Case(16 * MB, []) + self.add_source(case) + self.hmp_write('src', f'write -z 0 {16 * MB}') + + self.vm.cmd('block-dirty-bitmap-add', node=3D'src', name=3D'bm0') + self.write_layout([(2 * MB, MB, 'zero'), (6 * MB, MB, 'zero')]) + + self.do_backup('bitmap', case, bitmap=3D'bm0', bitmap_mode=3D'neve= r', + prefill=3D0xcc) + + qemu_io('-c', f'read -P 0 {2 * MB} {MB}', target_img) + qemu_io('-c', f'read -P 0 {6 * MB} {MB}', target_img) + + qemu_io('-c', f'read -P 0xcc 0 {2 * MB}', target_img) + qemu_io('-c', f'read -P 0xcc {3 * MB} {3 * MB}', target_img) + qemu_io('-c', f'read -P 0xcc {7 * MB} {9 * MB}', target_img) + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2'], supported_protocols=3D['file'], diff --git a/tests/qemu-iotests/124.out b/tests/qemu-iotests/124.out index fa16b5ccef..5ce2f9a2ed 100644 --- a/tests/qemu-iotests/124.out +++ b/tests/qemu-iotests/124.out @@ -1,5 +1,5 @@ -............. +.............................. ---------------------------------------------------------------------- -Ran 13 tests +Ran 30 tests =20 OK --=20 2.53.0 From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697182; cv=none; d=zohomail.com; s=zohoarc; b=m4gdW8f3rB1+4GnP7MfjaL8/LN8qotlNVUtSW48fb2BMu3n4VBuNXg9dbCUEuupL+IIdzhY7qRfarZ/kyduhNM1Jr246X1pQci1X57vOz3lT4WAOMiLFAJkN0Nfnwqu7rimnMiRhA8P9WUcGapWCaZ0te11XSWmTz+vedCpUGRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697182; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SJFEI1lQ8SXWXqcCjUVxKX69y0HMHBq5YIZK1wiDeeQ=; b=F/jIiz0fU3OhMica+oAjlsAO7idvPN8ctzO+ccBn54F/S4nyW0s5JRuNq0D75n3hJcu15mJvmrY7Y0NXJDD3RdYn6+s8Pl5jbHUPCpEK17k0Heqfdkv7dQU2B0UPFdhHoy/hogWcb2tXLjCcYbQz158gZmDtL6Gt6rTcrntcN4k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790697182741161.2941478915185; Tue, 29 Sep 2026 08:53:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7V-0005uY-RJ; Tue, 29 Sep 2026 11:51:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7L-0005o0-0W for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:43 -0400 Received: from mail-wr2-x0f.google.com ([2a00:1450:4864:30::f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7H-0001Rr-N2 for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:42 -0400 Received: by mail-wr2-x0f.google.com with SMTP id ffacd0b85a97d-488811c9ebaso2136553f8f.2 for ; Tue, 29 Sep 2026 08:51:39 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697098; x=1791301898; darn=nongnu.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=SJFEI1lQ8SXWXqcCjUVxKX69y0HMHBq5YIZK1wiDeeQ=; b=hZwXKynwgCmIsIhPXvqlNsFlAZjUQEGq4DDgMjpJFCiZ6lsX30FTy+OzHpGi6v/TDe +3FWmMFXogSRU/MsWlV/DWtPtjbbcHbt1dF58nkY2PcaGwhnmhUkjy3SZBDHcWZVoWJ/ RPPUNGM/eTxXDUPtE0aQXNucQ3uoZZ1sKLUkwFil8D17RGOpqxzLW3AST5PQSYAliBxw wI5FsErzaWhtJ1+ZJTQ93wcISUAN8FqZ66ouvPXtLDRfw0G1pjBVNrhGYAZDzMVUcu3P N1tajbUr6nHzlL30Bvd3h5qwOCupqqMAk7lH+h2pdDEG4HqIcdH7D3lYgwnKJ8dJcfw6 72eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697098; x=1791301898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SJFEI1lQ8SXWXqcCjUVxKX69y0HMHBq5YIZK1wiDeeQ=; b=2NV0HfbGdbApeAcgsRzFqh2brlaYXn5DD+dXDWf+7IsA0DjaPY/81cQ2OK4YzGSvZb qIsyDzLcvDuYo5NGVgCmT7XxvyV3BXxJcaJjNWdmGvkr63FK5ymipMqvIjXI9WyRwAwk dVZaz3hcHFKw7I96B9BauBkyS9TfXZVhrZxPzSXHBY+BSccFClsXEWmo7NsQ1SV/JFkI ENX7PchFbgiSu336tm4DwDcqKMZwiWoZ/6szJDGEdnjQoWbXKr9KX03t5wsIMTZW1XOY 0dzEf0pCx4x7XuYQ9s+Nb/CsBR4lysbJSQcHZJ39HnJZsXtU+ugKbW1MX3G4SC1egxxC BR0w== X-Gm-Message-State: AFq9FYIh9v2YRGpG68h64Dz32OvY8qtPOX+huqH7CPW9T0atFHZcsw3D LFxpYc+vVK47X2RcNGTLq8r4svDmv57ptMWc6hketfEQ6tAM6GxZH/Z4M1aUZC9HxogAx6v888N xrsd8 X-Gm-Gg: AYBFou0SX1H4MniBuiunu1obpRUgB9sofqpN3VvePEO3wO3UEmtYI0uxxSU7hMG+GyS 1TcXh6DaesNAbzIFsf1inr8LfrSSnROJ/wJ6kZR9t2OS/b3S7DaA9t729Ux0Qdmy3VQJJOOGYCx GxGJPIO2XM4vJyX3Y6uG+aiZjWEMx2yyLW3FAUFWFv8j+9k+eUHGCVTgl2ttE4zPqY9Gczpimx0 rQXo1q5biwiugPsWq4LhCeKngE42US1ae7SxHEySZw5pz/7gh49phr7kEisq+MbBB0j3hNSogJM m3C9Cl+Ul85QAHU78EOOhQQV6weIHy+7UJSPwI/+nFywJVHyrHzyDVHR/k4x8cz7DD+dfrKpW5G kvgLIA+2FObCdWo6IFmqF2MIE1+0f8ICXumjvFJbCaxJ1eBCqSPppLIXndsea6xDnuo8HLBPUGZ 3JGlBKX6PIeZduKxNxiFff6U4IAfHfLHfiE9GS4HYxZnYHzK4WnqxlGOsekMY= X-Received: by 2002:a5d:5d0c:0:b0:487:1f7:f506 with SMTP id ffacd0b85a97d-488835f2adamr25347759f8f.11.1790697098360; Tue, 29 Sep 2026 08:51:38 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v3 5/9] block/block-copy: don't reserve memory for zero tasks Date: Tue, 29 Sep 2026 17:51:21 +0200 Message-ID: <20260929155125.3151111-6-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::f; envelope-from=den@openvz.org; helo=mail-wr2-x0f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697183282158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev block_copy_dirty_clusters() charges task->req.bytes to the shared memory pool for every task, but a COPY_WRITE_ZEROES task allocates no bounce buffer, so there is nothing to account for. Add block_copy_task_shres_bytes() and use it at all three call sites. Zero tasks lose the throttling the pool gave them incidentally and are bounded only by BLOCK_COPY_MAX_WORKERS (64). Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/block-copy.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 1826c2e1c7..21ebe8aec2 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -453,6 +453,11 @@ void block_copy_set_progress_meter(BlockCopyState *s, = ProgressMeter *pm) s->progress =3D pm; } =20 +static uint64_t block_copy_task_shres_bytes(BlockCopyTask *task) +{ + return task->method =3D=3D COPY_WRITE_ZEROES ? 0 : task->req.bytes; +} + /* * Takes ownership of @task * @@ -474,7 +479,7 @@ static coroutine_fn int block_copy_task_run(AioTaskPool= *pool, =20 aio_task_pool_wait_slot(pool); if (aio_task_pool_status(pool) < 0) { - co_put_to_shres(task->s->mem, task->req.bytes); + co_put_to_shres(task->s->mem, block_copy_task_shres_bytes(task)); block_copy_task_end(task, -ECANCELED); g_free(task); return -ECANCELED; @@ -605,7 +610,7 @@ static coroutine_fn int block_copy_task_entry(AioTask *= task) progress_work_done(s->progress, t->req.bytes); } } - co_put_to_shres(s->mem, t->req.bytes); + co_put_to_shres(s->mem, block_copy_task_shres_bytes(t)); block_copy_task_end(t, ret); =20 if (s->discard_source && ret =3D=3D 0) { @@ -816,7 +821,7 @@ block_copy_dirty_clusters(BlockCopyCallState *call_stat= e) =20 trace_block_copy_process(s, task->req.offset); =20 - co_get_from_shres(s->mem, task->req.bytes); + co_get_from_shres(s->mem, block_copy_task_shres_bytes(task)); =20 offset =3D task_end(task); bytes =3D end - offset; --=20 2.53.0 From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697216; cv=none; d=zohomail.com; s=zohoarc; b=PkGJMEWjMieCZ/HG/zrtcp7Ns0dnrHJ52J+S3WhHTUS8p8GwWcaNNSPIijyul+bao5S8YKpDlzJJ8nW+7bkX2BgbFDmFV0VLDANAzg8bn98bUlTfqgP6tUGUJR/1xNN5iT4RDH/ti+KO7o7Pb7K1jDi6LdOZ+XrQTPB6x43z+n4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697216; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=K0kBd+JRwRmYuSzj9Gu1odey8tK1kya/yjE5FN2wYZ8=; b=Injopsf2InAna1nsGmyInow5gbyFqDLqneCEMO5U/YjTFv8oHUw5usev4Gf9byn9jfGflJcYSBIuuAJSeqjMdl3a+F0H7mDrEohh6bdHRZxd1Z1IW2tGJUme6AJvF1F67Q7NtM/chhWkuFw1V8Oxt1jABgRnXVihligHb6OVJBs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790697216820486.1479436213698; Tue, 29 Sep 2026 08:53:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7W-0005wX-LY; Tue, 29 Sep 2026 11:51:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7L-0005o1-6A for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:43 -0400 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7J-0001S9-1L for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:42 -0400 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-485933b24c3so2707932f8f.0 for ; Tue, 29 Sep 2026 08:51:40 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697099; x=1791301899; darn=nongnu.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=K0kBd+JRwRmYuSzj9Gu1odey8tK1kya/yjE5FN2wYZ8=; b=C5P6sCfyqR4wgql5NBy3AFaT90De2tp2yB3kZlelu8hSXtA8K+XVp4PHmZMVUayxLq 9j0HN9qJtns1ppUUWWg/K8kSRdCvPBA3j2or406rd96vDAdaxHyzcIDWkCpqwjoNrHoq B0wt4rUhbxFAlGtd+W4ARj4f7sHQt0Pt5G7TSYEdIpEMXAjfRDdcuQ9LzDpaR+n3vC2h oRt8SrWlyWk2Jpt5rkoC19hJQGbW8081bl4UhqL/RCWHqcR5PGOLSsR3mOxzsakl8KOz yQs2WzM6DuGK02k6zoBhdh8rXak2WtxS8pBFMs2aBpd5MJCXAKJDsGk7pmglZ7bWPKWn 7hcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697099; x=1791301899; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=K0kBd+JRwRmYuSzj9Gu1odey8tK1kya/yjE5FN2wYZ8=; b=dAMYuJbx0fGN2LkNI/99Pzjo64J0UxgcvtBc0jHuBMPQu3YKgA6wLM13L7NAtrnZxX 9+Awh7v/rCpkmRYD2fX/l1GSgP05bmyQfHpJxMOHJSfUj9fjJhKUE/KwLHvpcW2Ecsow eF8fdAp1tfA4DOrkKQsMl5bf44qwk1pWcdllbVJ+780AfsLgHBM6Y0KP+GhwGUYz3t5f K26K+HXyIH/1fjUCKYcq9gBsBNRDPwb2kcvlybpAJ6zovXlwPaOPzwc41bvb+7NzeSly GRlXSkXGVXiH3bFBNJPoADOkhvXzDsXoNWVo0Ja8ZERAPALMngKiGj+CJlBBMo75BPkl +Bag== X-Gm-Message-State: AFq9FYJiwXJ5FU88IMRe2m9sprqWBjwMybuDWi8Id9TBksDgkzximKFx fGTR7X2GR3CBjwyKZVz12a/0R2TDCFtGWN7TkIfFwE3XsaO+M+BeqyTnJwCn2E5D49buZBjjqvq xPk23 X-Gm-Gg: AYBFou2It4MHVSTfjkf83SE3qvVSKAbu91O+nKA9P2adoW5S/VXwdGEE4usd9x7y5fw AiqrwQPcOFqE4K2LgIuI5LScAoPyOkMTySGol+hWjW4cvhSxcUE5vrGXGBTxzUpo83NLCZfK/XB N/Fb3qT7yfkPqaBaQdGayj0u9hME/xZBwnxhTwIdxF+TJcpSbcGJmyNUSqZBqvZsZf4779xwFDK BmQAgQFiC8lUg9LSXnccBCm63FSEfC4aqw4R80mn9L5hp+YbRFx46xBoloMd7BCKx1Q7lykL11A fwC5eQCTv7CUXM9lM95u/fDSqyf3/G3XMpyAFPb6CEblv9Yh1GTA5YIr15TEeRDPfohjQXB3ooI 8bZZKqdR/4gC7Ywjm0sLWgVWMjb/HRjrsMN/8GmSQ5aHYA099SLy6ZTp7tBnzZI95Q2luckIiJ4 6rHAer7QiDGeYX87IncE3+bc7RgzEEy15S2vyj8FeG4kpzPkgs4RbwK580Rw== X-Received: by 2002:a05:6000:2885:b0:48a:f073:336b with SMTP id ffacd0b85a97d-48af0733452mr5980594f8f.23.1790697099594; Tue, 29 Sep 2026 08:51:39 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v3 6/9] block/block-copy: extract block_copy_set_task_method() Date: Tue, 29 Sep 2026 17:51:22 +0200 Message-ID: <20260929155125.3151111-7-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::10; envelope-from=den@openvz.org; helo=mail-wr2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697217539158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev Move the per-task block-status query and its skip_unallocated and BDRV_BLOCK_ZERO handling out of block_copy_dirty_clusters() into block_copy_set_task_method(). No behavior change. The next patch changes that decision, and having it in one place keeps that change to just the new logic. The block-status result no longer lands in the caller's @ret, so drop the note saying @ret may be positive at the out: label. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/block-copy.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 21ebe8aec2..d71d070dbd 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -741,6 +741,35 @@ int64_t coroutine_fn block_copy_reset_unallocated(Bloc= kCopyState *s, return ret; } =20 +/* + * Decide how @task is copied: COPY_WRITE_ZEROES if it reads as zero. May + * shrink @task. Returns false if @task is to be skipped (already ended, + * not freed). + */ +static bool coroutine_fn GRAPH_RDLOCK +block_copy_set_task_method(BlockCopyState *s, BlockCopyTask *task) +{ + int ret; + int64_t status_bytes; + + ret =3D block_copy_block_status(s, task->req.offset, task->req.bytes, + &status_bytes); + assert(ret >=3D 0); /* never fail */ + if (status_bytes < task->req.bytes) { + block_copy_task_shrink(task, status_bytes); + } + if (qatomic_read(&s->skip_unallocated) && !(ret & BDRV_BLOCK_ALLOCATED= )) { + block_copy_task_end(task, 0); + trace_block_copy_skip_range(s, task->req.offset, task->req.bytes); + return false; + } + if (ret & BDRV_BLOCK_ZERO) { + task->method =3D COPY_WRITE_ZEROES; + } + + return true; +} + /* * block_copy_dirty_clusters * @@ -773,7 +802,6 @@ block_copy_dirty_clusters(BlockCopyCallState *call_stat= e) while (bytes && aio_task_pool_status(aio) =3D=3D 0 && !qatomic_read(&call_state->cancelled)) { BlockCopyTask *task; - int64_t status_bytes; =20 task =3D block_copy_task_create(s, call_state, offset, bytes); if (!task) { @@ -787,24 +815,12 @@ block_copy_dirty_clusters(BlockCopyCallState *call_st= ate) =20 found_dirty =3D true; =20 - ret =3D block_copy_block_status(s, task->req.offset, task->req.byt= es, - &status_bytes); - assert(ret >=3D 0); /* never fail */ - if (status_bytes < task->req.bytes) { - block_copy_task_shrink(task, status_bytes); - } - if (qatomic_read(&s->skip_unallocated) && - !(ret & BDRV_BLOCK_ALLOCATED)) { - block_copy_task_end(task, 0); - trace_block_copy_skip_range(s, task->req.offset, task->req.byt= es); + if (!block_copy_set_task_method(s, task)) { offset =3D task_end(task); bytes =3D end - offset; g_free(task); continue; } - if (ret & BDRV_BLOCK_ZERO) { - task->method =3D COPY_WRITE_ZEROES; - } =20 if (!call_state->ignore_ratelimit) { uint64_t ns =3D ratelimit_calculate_delay(&s->rate_limit, 0); @@ -845,8 +861,6 @@ out: * block_copy_task_run. If it fails, it means some task already fa= iled * for real reason, let's return first failure. * Still, assert that we don't rewrite failure by success. - * - * Note: ret may be positive here because of block-status result. */ assert(ret >=3D 0 || aio_task_pool_status(aio) < 0); ret =3D aio_task_pool_status(aio); --=20 2.53.0 From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697202; cv=none; d=zohomail.com; s=zohoarc; b=BqU9xO2pFKYTosu8nNHSmtVZCqk2uckXr4XaaycDkP65THRx1jIaMTcDpTibtu5Gs/LZZ+XSZHDBT4KzV7oGW2MPdotOjSkSh4CJrUCyhBLmXnaO/rxUZ7JhQ+q519xqBG0idmq1pPPqyLZpptFrBV3RZUiRQd3PnevbZ1WUz88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697202; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gauZhWunVSnOWagdnaQx1CJFfB6UJ8th/qE2ie82hjc=; b=dBqR7NJ9+yzWCx4Hv3u459rf7GhkUQJu5yw/JSvSLWWc17jyhL8P1bT3sfehy58RQqXgwnv2O7t4J0Y0OWWvuv5G+vCyduDyIdNKiXBlR5cx8SrooZOO56uKvz+q2kEr3QAljiu1tCOUdWtUszH5niCABzdWNTncGrU7sP56hM8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1790697202837397.28964108483274; Tue, 29 Sep 2026 08:53:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7Y-0005xP-4F; Tue, 29 Sep 2026 11:51:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7N-0005qN-FL for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:46 -0400 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7K-0001ST-IH for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:44 -0400 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-4843cedd129so2493780f8f.0 for ; Tue, 29 Sep 2026 08:51:42 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697101; x=1791301901; darn=nongnu.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=gauZhWunVSnOWagdnaQx1CJFfB6UJ8th/qE2ie82hjc=; b=IReDZkh7iL0XBZWPMAupsDVuK4Kd0l8Tfd/OYkJgaFKWoOYL06C83w59Ao7NCdk3Yt nvY3SJFqYLJTC8mc9yE1ji+FYlj7bSo2eRTAt/ADD5IdR/+cv8OwMZGnIqODfcQWjbGi WS8rUTX1lXNf39+iUSbVF0WwL9QTZ5cU5Do6t1il+N1voGV+WoZUWlAWVcYUrygkZ9cJ Otiz2r2CcSemwV031Pb/9enDpelmtcldnNhG5aHcdWAbTTubSbpXLKYGEu+ZZVjqKHMN zA0iMPuAeGA4q7o6bDKYBPxG1+3sth4/rkiv9bkkv8pXPei/XDQ0teiG4VfKJRx0DuUE UyAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697101; x=1791301901; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=gauZhWunVSnOWagdnaQx1CJFfB6UJ8th/qE2ie82hjc=; b=PxMz1EEIQ6QM4dapIYC31lh3yAwmQamA2ixteN5kEGkRhN+gvNKunshQwm7t/VutAF gAmohsKcUyo/mskCy4ZRGo+5HhPl8hoG7AR4hFvw0De43FcRxSINg9IVEdmO5Yg1xAtK 64WyngBG+x9LtgQEZFux8eGco2r7+0mNScNatw29x+TPkrNULx1EoV9PlS7ZL4DZidVz IoM0OIziT1cst2d8jH7wWnpoyQ7cX8Mdusz9ifBfXKAEEeRoiS6NeY0zTDhpEpoxHv7d XkIQCXeS5Bq3HCkjvCu+d4NE3ngQXAufus8iUVOj7BTLcutuoX6HaICifruAtCpLSzVn vJRA== X-Gm-Message-State: AFq9FYISPBFuHqXW2uxt6UhNepTgsDudCkMGzuIIe7x04pHav77HfdKO jyA72H9Krwz9bsOuHqEg/oslIHnGU2rJHjcZBUf/RvMaG0sGbfZdgwB9FaJVUlZjX8hlGQZW+eY c1cFv X-Gm-Gg: AYBFou2MZHZFVawByMeiWKLnbLm3g4Vt2+B5yyTgMs27/OjSb0sNDlqGWSllZpStlrd bnsBBCF9DpkiU2aRrZiUiya92PJhfqNnW9g8/NSb000KrYpU/Sumj/TAVfV36kpPIrMFx9s2O0i 8rqwNQF5zMAShD1zEvWJdO/sX2w7n4swN8QHWrojKKu4rsSX9jXqt33OntEFAlWcFvE/ih+REpJ LIZCOq0wwz3ew9qdxleuz17dT0DrbdWYdPiMjsfNiFQlcn6Q/mNZUBwC4vos4bzJXvbNEZ8LpwY WWZMvSMM58k/w8cZVT+vUjmjQef7cNKxrAP+GlRaaCA8q5b+xPW0RvkIk1mD7Sc9YD0r/2t3NPn O1R4n0c4nsdF/NW+NXvIGQpfBsY/O07Z6T1ucxrqs/5OY2qlUaKTIHwriqmnLnU4TUGZi9bcpfS 2GGaV3ew9LlOAeaL/q9M5EPnWDJsuyv6NaVsmIAHNjK1NZYRu25wtgi7TLrg== X-Received: by 2002:a05:6000:71d:b0:487:21a4:f617 with SMTP id ffacd0b85a97d-48871681179mr27935377f8f.19.1790697101222; Tue, 29 Sep 2026 08:51:41 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v3 7/9] block/block-copy: track known-zero source clusters Date: Tue, 29 Sep 2026 17:51:23 +0200 Message-ID: <20260929155125.3151111-8-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::10; envelope-from=den@openvz.org; helo=mail-wr2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697203465158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev block_copy_reset_unallocated()'s up-front scan already queries the source, and the same query reports zero-ness. The copy loop re-queries per task and, having no answer up front, can only size a task by the copy buffer, so a mostly-zero image is cut into thousands of pieces that each turn out to read as zero. Cache the answer in zero_bitmap, published by zero_bitmap_valid once the scan is done. block_copy_task_create() then picks the method from the bitmap and ends the task where the answer changes, so a zero task never reaches into data and a copy task never swallows a zero run. The per-task query stays as the fallback until the flag is set, since CBW intercepts guest writes while the scan is still running. The scan and the query it replaces must resolve BDRV_BLOCK_ZERO against the same part of the chain, so the scan moves from bdrv_co_is_allocated() to bdrv_co_block_status_above() and the base selection is factored out into block_copy_status_base(). zero_bitmap is a plain HBitmap, not a BdrvDirtyBitmap: an internal cache has no business in query-named-block-nodes. One writer and readers gated by the flag need no mutex, but the publish needs ordering, hence store-release and load-acquire. It is allocated on demand, so sync=3Dnone and a standalone copy-before-write filter do not pay for it. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev --- block/backup.c | 1 + block/block-copy.c | 108 ++++++++++++++++++++++++++++++++----- include/block/block-copy.h | 1 + 3 files changed, 98 insertions(+), 12 deletions(-) diff --git a/block/backup.c b/block/backup.c index d4713fa1cd..11d70243e2 100644 --- a/block/backup.c +++ b/block/backup.c @@ -280,6 +280,7 @@ static int coroutine_fn backup_run(Job *job, Error **er= rp) offset +=3D count; } block_copy_set_skip_unallocated(s->bcs, false); + block_copy_set_zero_bitmap_valid(s->bcs); } =20 if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE) { diff --git a/block/block-copy.c b/block/block-copy.c index d71d070dbd..94d4f3dd69 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -20,6 +20,8 @@ #include "block/block_int-io.h" #include "block/dirty-bitmap.h" #include "block/reqlist.h" +#include "qemu/hbitmap.h" +#include "qemu/host-utils.h" #include "system/block-backend.h" #include "qemu/units.h" #include "qemu/co-shared-resource.h" @@ -157,6 +159,10 @@ typedef struct BlockCopyState { bool skip_unallocated; /* atomic */ /* State fields that use a thread-safe API */ BdrvDirtyBitmap *copy_bitmap; + /* Clusters reading as zero; allocated on demand, frozen once valid. */ + HBitmap *zero_bitmap; + /* Published only after the scan, with skip_unallocated already false.= */ + bool zero_bitmap_valid; /* atomic, store-release/load-acquire */ ProgressMeter *progress; SharedResource *mem; RateLimit rate_limit; @@ -190,6 +196,7 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCall= State *call_state, int64_t offset, int64_t bytes) { BlockCopyTask *task; + BlockCopyMethod method; int64_t max_chunk; =20 QEMU_LOCK_GUARD(&s->lock); @@ -201,6 +208,27 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCal= lState *call_state, return NULL; } =20 + method =3D s->method; + + /* + * The scan already knows how this range reads: pick the method here a= nd + * stop the task where the answer changes. + */ + if (qatomic_load_acquire(&s->zero_bitmap_valid)) { + int64_t boundary; + + if (hbitmap_get(s->zero_bitmap, offset)) { + method =3D COPY_WRITE_ZEROES; + boundary =3D hbitmap_next_zero(s->zero_bitmap, offset, bytes); + } else { + boundary =3D hbitmap_next_dirty(s->zero_bitmap, offset, bytes); + } + + if (boundary >=3D 0) { + bytes =3D boundary - offset; + } + } + assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); bytes =3D QEMU_ALIGN_UP(bytes, s->cluster_size); =20 @@ -215,7 +243,7 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCall= State *call_state, .task.func =3D block_copy_task_entry, .s =3D s, .call_state =3D call_state, - .method =3D s->method, + .method =3D method, }; reqlist_init_req(&s->reqs, &task->req, offset, bytes); =20 @@ -271,6 +299,9 @@ void block_copy_state_free(BlockCopyState *s) =20 ratelimit_destroy(&s->rate_limit); bdrv_release_dirty_bitmap(s->copy_bitmap); + if (s->zero_bitmap) { + hbitmap_free(s->zero_bitmap); + } shres_destroy(s->mem); g_free(s); } @@ -624,20 +655,24 @@ static coroutine_fn int block_copy_task_entry(AioTask= *task) return ret; } =20 +/* The scan and the per-task query must resolve BDRV_BLOCK_ZERO alike. */ +static GRAPH_RDLOCK BlockDriverState *block_copy_status_base(BlockCopyStat= e *s) +{ + if (qatomic_read(&s->skip_unallocated)) { + return bdrv_backing_chain_next(s->source->bs); + } + + return NULL; +} + static coroutine_fn GRAPH_RDLOCK int block_copy_block_status(BlockCopyState *s, int64_t offset, int64_t byt= es, int64_t *pnum) { int64_t num; - BlockDriverState *base; + BlockDriverState *base =3D block_copy_status_base(s); int ret; =20 - if (qatomic_read(&s->skip_unallocated)) { - base =3D bdrv_backing_chain_next(s->source->bs); - } else { - base =3D NULL; - } - ret =3D bdrv_co_block_status_above(s->source->bs, base, offset, bytes,= &num, NULL, NULL); if (ret < 0 || num < s->cluster_size) { @@ -657,16 +692,41 @@ int block_copy_block_status(BlockCopyState *s, int64_= t offset, int64_t bytes, return ret; } =20 +/* Only the scan allocates, and it runs before zero_bitmap_valid. */ +static HBitmap *block_copy_zero_bitmap(BlockCopyState *s) +{ + if (!s->zero_bitmap) { + s->zero_bitmap =3D hbitmap_alloc(s->len, ctz32(s->cluster_size)); + } + + return s->zero_bitmap; +} + +static void block_copy_mark_zero_prefix(BlockCopyState *s, int64_t offset, + int64_t zero_count) +{ + int64_t zero_bytes =3D QEMU_ALIGN_DOWN(zero_count, s->cluster_size); + + if (zero_bytes > 0) { + hbitmap_set(block_copy_zero_bitmap(s), offset, zero_bytes); + } +} + /* * Check if the cluster starting at offset is allocated or not. * return via pnum the number of contiguous clusters sharing this allocati= on. + * Also marks the zero prefix of the range in zero_bitmap. */ static int coroutine_fn GRAPH_RDLOCK block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, int64_t *pnum) { BlockDriverState *bs =3D s->source->bs; + BlockDriverState *base =3D block_copy_status_base(s); + int64_t orig_offset =3D offset; int64_t count, total_count =3D 0; + int64_t zero_count =3D 0; + bool zero_broken =3D false; int64_t bytes =3D s->len - offset; int ret; =20 @@ -674,25 +734,37 @@ block_copy_is_cluster_allocated(BlockCopyState *s, in= t64_t offset, =20 while (true) { /* protected in backup_run() */ - ret =3D bdrv_co_is_allocated(bs, offset, bytes, &count); + ret =3D bdrv_co_block_status_above(bs, base, offset, bytes, &count, + NULL, NULL); if (ret < 0) { return ret; } =20 + if (!zero_broken) { + if (ret & BDRV_BLOCK_ZERO) { + zero_count +=3D count; + } else { + zero_broken =3D true; + } + } + total_count +=3D count; =20 - if (ret || count =3D=3D 0) { + if ((ret & BDRV_BLOCK_ALLOCATED) || count =3D=3D 0) { /* - * ret: partial segment(s) are considered allocated. + * BDRV_BLOCK_ALLOCATED: partial segment(s) are considered + * allocated. * otherwise: unallocated tail is treated as an entire segment. */ *pnum =3D DIV_ROUND_UP(total_count, s->cluster_size); - return ret; + block_copy_mark_zero_prefix(s, orig_offset, zero_count); + return !!(ret & BDRV_BLOCK_ALLOCATED); } =20 /* Unallocated segment(s) with uncertain following segment(s) */ if (total_count >=3D s->cluster_size) { *pnum =3D total_count / s->cluster_size; + block_copy_mark_zero_prefix(s, orig_offset, zero_count); return 0; } =20 @@ -752,6 +824,12 @@ block_copy_set_task_method(BlockCopyState *s, BlockCop= yTask *task) int ret; int64_t status_bytes; =20 + /* block_copy_task_create() already decided, from zero_bitmap. */ + if (qatomic_load_acquire(&s->zero_bitmap_valid)) { + return true; + } + + /* CBW filter could call this early. */ ret =3D block_copy_block_status(s, task->req.offset, task->req.bytes, &status_bytes); assert(ret >=3D 0); /* never fail */ @@ -1081,6 +1159,12 @@ void block_copy_set_skip_unallocated(BlockCopyState = *s, bool skip) qatomic_set(&s->skip_unallocated, skip); } =20 +void block_copy_set_zero_bitmap_valid(BlockCopyState *s) +{ + block_copy_zero_bitmap(s); + qatomic_store_release(&s->zero_bitmap_valid, true); +} + void block_copy_set_speed(BlockCopyState *s, uint64_t speed) { ratelimit_set_speed(&s->rate_limit, speed, BLOCK_COPY_SLICE_TIME); diff --git a/include/block/block-copy.h b/include/block/block-copy.h index 0df2771181..e4e5b56753 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -101,5 +101,6 @@ void block_copy_call_cancel(BlockCopyCallState *call_st= ate); BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s); int64_t block_copy_cluster_size(BlockCopyState *s); void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip); +void block_copy_set_zero_bitmap_valid(BlockCopyState *s); =20 #endif /* BLOCK_COPY_H */ --=20 2.53.0 From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697156; cv=none; d=zohomail.com; s=zohoarc; b=NGaoAltHbRGkQcAevIzsnaGyySNtpxANcxetm2a9aqQCkcTzUb6tZ3rAc5/bIXkxAw+RdgUwZaajBwHUbuo7TveFK8PWm/J+KXGuyJaAmI4+VUeWqSoZLUn+WvR/gaJ+j7Pqt7Z5RbYBEErrhIE11qZf25EgVRDaKc/OsFE/W6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697156; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=thMNzpR9hfmP2UrqepCGOnSZLkYfUI9v4LXa+JCQASs=; b=k2xmj3RL000sItHJkcZAqf6XcAEh0UV1H9GNbTvRWfDRkIPoYQSg98iSG/yadVoTJdeXX4abOdVsUDZsCramnY1uNC5n4vLPr4oltyCoJ8ft7ZLSChi/E/wiuwYfxnI/BmWa6NAmtaSFDKvqzOFAs/RzRNtONRcAmwVOH9c+RNc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179069715651471.02676192701801; Tue, 29 Sep 2026 08:52:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7b-0005zU-Qn; Tue, 29 Sep 2026 11:52:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7P-0005rk-9T for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:47 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7L-0001Sq-Nt for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:46 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ffb83bf7aso26859695e9.2 for ; Tue, 29 Sep 2026 08:51:43 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697102; x=1791301902; darn=nongnu.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=thMNzpR9hfmP2UrqepCGOnSZLkYfUI9v4LXa+JCQASs=; b=Z7o/kaXfRVDtVTHp9uI6wc2e9+OXCfnR+6ClFTHQeuC1kO+KRrd2cJHLFm6OS5Umnc W4vHnGs53WeRFi7t8byVdB5kqvXGGqHu2jqAmdp9c/fxPQzfrnS00jjanMfnGXR95sc7 Qs9rrp1Cd15+/M58AO0tUZo9EixSFXzr5JVkjINYz907GJWgVcfXYEvnCCsjuB7K4jAY IYXUiFXuXvIRSGHdBjiWOY9AlXQaIZ0ofPUe2pDQIFuod9WN9S3iAUeitLQXTYfwPfV5 HvpTmA4yUURcTlnML8lAdY9yydMhfeg+JGSUhFRoT5ERQ08uV7QgcacwpJdK/WQV26x8 jxlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697102; x=1791301902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=thMNzpR9hfmP2UrqepCGOnSZLkYfUI9v4LXa+JCQASs=; b=IektVC8OCcGrA3hGLp+3dYVYvZsd/QzP+/1/7NQZh/8AyHw3dbIpubta2py6uumwJB 1uXDV4HQJIOJSjhMKyCjy4BjnV9tJ3ujk1CqMUc6pYNS0a58blxhDHImgmbYAKHqAV8l Hc3+iKF9wyiVc3qK3sBDiYhD1KhUSovBglKygabWmhGN/Vif4YaD6ZWkvrKRj/ijwb1V BRvNE9mQ2M7zsQPvidYku6AjkVyQSp6TrHe/bJy1Z9HOzOxMrIwn9GiNGWaJT6Sbj85s i0NVXsPhaC+BaiZO54kJ3aYLkcKGK1P7A4WF3P/+BnVWzDf+cWJBfZtGUvNggaO3MVY+ Um+Q== X-Gm-Message-State: AFuF++merkWsXqPcFluJ3cbL02dHzQMLY+bwPyoCNl1pI+nICRZPYYGb 0JlaQ/f1bKyn2T8h5lVu3J1goZIRJ1MIptlQJepWCOEWm3+adUQrvLcO2AT4XLVGaaJtPeSunE2 JP9OK X-Gm-Gg: AYBFou1P+R+ki6p0POYYmbLFytP0RQkI5xA5rQWzxw6z5m6mTygdVrS/n29/A/b2ZlO HYPNKD+4/tBDsu+sbEHQ/ZUm7c4d41WknPgswGMWShTdhKbzM6QVEla/o3Xg7I26a4leEtyQyML ooDTfrUN86ncSPWWGa1/+ldKsmYvOOjRTd7I1BbyVyo/XpglzawyqNwDZkhHiN8siF8gG0pV9l+ xXVkjVXntk2MsR9UcyDeYk+jESIPnFCV2gPknQiIgjBfGc+/6zXn0gbv5xXXY0K6k8/JDyjd/XJ fvkaoNNH6a7gE6300W4N6XQyTtRnlQ1SbsUh6/9bxa2G+fSfHlXOSSgvyn7Z/DPnh5+3M1DG7yg 26A3WdztvK5nji7Dv58+gP79g2h53oejcPLUaFvD/1LW3phOduFAEZ39TxcvZJB3RiolFgdEms/ S5VwLuw8Ko/3ZcfHVMg7Qh9g4He/0zhecv3vfiqpEb0XrV8gLHUJorr5lCBH+ppNEyKeDC X-Received: by 2002:a05:600c:4f42:b0:49f:bd3c:bc1b with SMTP id 5b1f17b1804b1-49fe66f5ddemr369021675e9.22.1790697102317; Tue, 29 Sep 2026 08:51:42 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Andrey Drobyshev , Vladimir Sementsov-Ogievskiy , John Snow Subject: [PATCH v3 8/9] block/backup: pre-fill zero_bitmap for full/bitmap Date: Tue, 29 Sep 2026 17:51:24 +0200 Message-ID: <20260929155125.3151111-9-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=den@openvz.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697157174158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev Only sync=3Dtop runs an up-front scan, so the previous patch did nothing for the other modes. FULL and BITMAP know their complete copy_bitmap before copying starts, and the same copy-before-write guarantee holds: a cluster still dirty when the copy loop reaches it has not been written since the scan. Add block_copy_calculate_zero_bitmap(), driven one query at a time from backup_scan_source() so the graph rdlock and the pause point are taken per query, and query each confirmed span once however many dirty areas it covers. The scan only fills zero_bitmap and never clears copy_bitmap, so sync=3Dfull still writes zeroes for clusters the source never allocated; it just stops re-querying to find that out. Unlike the per-task queries it replaces the scan is serial, so a sparsely dirtied job against a slow source may spend more time here than it saves. The sync=3Dtop loop had the same shape, so both fold into backup_scan_source(). sync=3Dnone keeps the per-task query. Its bitmap says "anything may be copied", not "this will be copied", and it only ever copies what the guest writes during the fleecing window, so scanning the whole image at attach is the wrong trade. Reviewed-by: Andrey Drobyshev Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev --- block/backup.c | 94 ++++++++++++++++++++++++-------------- block/block-copy.c | 41 +++++++++++++++++ include/block/block-copy.h | 4 ++ 3 files changed, 105 insertions(+), 34 deletions(-) diff --git a/block/backup.c b/block/backup.c index 11d70243e2..38b0838d69 100644 --- a/block/backup.c +++ b/block/backup.c @@ -247,59 +247,85 @@ static void backup_init_bcs_bitmap(BackupBlockJob *jo= b) job_progress_set_remaining(&job->common.job, estimate); } =20 -static int coroutine_fn backup_run(Job *job, Error **errp) +/* + * Walk the source before copying starts: fill zero_bitmap and, for sync= =3Dtop, + * drop the clusters that are not allocated above the backing. + */ +static int coroutine_fn backup_scan_source(BackupBlockJob *s) { - BackupBlockJob *s =3D container_of(job, BackupBlockJob, common.job); - int ret; - - backup_init_bcs_bitmap(s); - - if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP) { - int64_t offset =3D 0; - int64_t count; + Job *job =3D &s->common.job; + bool top =3D s->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP; + int64_t offset, cached_end =3D 0, count; + int ret =3D 0; =20 - for (offset =3D 0; offset < s->len; ) { - if (job_is_cancelled(job)) { - return -ECANCELED; - } + for (offset =3D 0; offset < s->len; offset +=3D count) { + if (job_is_cancelled(job)) { + return -ECANCELED; + } =20 - job_pause_point(job); + job_pause_point(job); =20 - if (job_is_cancelled(job)) { - return -ECANCELED; - } + if (job_is_cancelled(job)) { + return -ECANCELED; + } =20 - /* rdlock protects the subsequent call to bdrv_is_allocated() = */ - bdrv_graph_co_rdlock(); + /* rdlock protects the block-status queries below */ + bdrv_graph_co_rdlock(); + if (top) { ret =3D block_copy_reset_unallocated(s->bcs, offset, &count); - bdrv_graph_co_rdunlock(); - if (ret < 0) { - return ret; - } + } else { + block_copy_calculate_zero_bitmap(s->bcs, offset, &cached_end, + &count); + } + bdrv_graph_co_rdunlock(); =20 - offset +=3D count; + if (ret < 0) { + return ret; } + } + + if (top) { block_copy_set_skip_unallocated(s->bcs, false); - block_copy_set_zero_bitmap_valid(s->bcs); } + block_copy_set_zero_bitmap_valid(s->bcs); =20 - if (s->sync_mode =3D=3D MIRROR_SYNC_MODE_NONE) { + return 0; +} + +static int coroutine_fn backup_run(Job *job, Error **errp) +{ + BackupBlockJob *s =3D container_of(job, BackupBlockJob, common.job); + int ret; + + backup_init_bcs_bitmap(s); + + switch (s->sync_mode) { + case MIRROR_SYNC_MODE_TOP: + case MIRROR_SYNC_MODE_FULL: + case MIRROR_SYNC_MODE_BITMAP: + ret =3D backup_scan_source(s); + if (ret < 0) { + return ret; + } + break; + + case MIRROR_SYNC_MODE_NONE: /* * All bits are set in bcs bitmap to allow any cluster to be copie= d. - * This does not actually require them to be copied. + * This does not actually require them to be copied. Yield until t= he + * job is cancelled and let the before_write notify callback servi= ce + * CoW requests. */ while (!job_is_cancelled(job)) { - /* - * Yield until the job is cancelled. We just let our before_w= rite - * notify callback service CoW requests. - */ job_yield(job); } - } else { - return backup_loop(s); + return 0; + + default: + g_assert_not_reached(); } =20 - return 0; + return backup_loop(s); } =20 static void coroutine_fn backup_pause(Job *job) diff --git a/block/block-copy.c b/block/block-copy.c index 94d4f3dd69..c0a3359938 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -813,6 +813,47 @@ int64_t coroutine_fn block_copy_reset_unallocated(Bloc= kCopyState *s, return ret; } =20 +/* + * One scan step, like block_copy_reset_unallocated(); @cached_end + * tracks progress across calls, @count how far @offset should move. + */ +void coroutine_fn GRAPH_RDLOCK +block_copy_calculate_zero_bitmap(BlockCopyState *s, int64_t offset, + int64_t *cached_end, int64_t *count) +{ + int64_t dirty_offset, dirty_bytes, dirty_end; + bool found; + + /* CBW mutates copy_bitmap from its own AioContext meanwhile. */ + WITH_QEMU_LOCK_GUARD(&s->lock) { + found =3D bdrv_dirty_bitmap_next_dirty_area(s->copy_bitmap, offset, + s->len, INT64_MAX, + &dirty_offset, &dirty_by= tes); + } + + if (!found) { + *count =3D s->len - offset; + return; + } + dirty_end =3D dirty_offset + dirty_bytes; + + if (*cached_end < dirty_end) { + int64_t clusters; + int64_t query_offset =3D MAX(dirty_offset, *cached_end); + int ret =3D block_copy_is_cluster_allocated(s, query_offset, &clus= ters); + + if (ret >=3D 0) { + *cached_end =3D query_offset + clusters * s->cluster_size; + } else { + /* Best-effort: leave this area unmarked; it copies as data. */ + *cached_end =3D dirty_end; + } + } + + /* 0 if the query above didn't yet reach dirty_end: try again next cal= l. */ + *count =3D *cached_end >=3D dirty_end ? dirty_end - offset : 0; +} + /* * Decide how @task is copied: COPY_WRITE_ZEROES if it reads as zero. May * shrink @task. Returns false if @task is to be skipped (already ended, diff --git a/include/block/block-copy.h b/include/block/block-copy.h index e4e5b56753..3a61066b55 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -44,6 +44,10 @@ void block_copy_reset(BlockCopyState *s, int64_t offset,= int64_t bytes); int64_t coroutine_fn GRAPH_RDLOCK block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *c= ount); =20 +void coroutine_fn GRAPH_RDLOCK +block_copy_calculate_zero_bitmap(BlockCopyState *s, int64_t offset, + int64_t *cached_end, int64_t *count); + int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool ignore_ratelimit, uint64_t timeout_ns, BlockCopyAsyncCallbackFunc cb, --=20 2.53.0 From nobody Mon Nov 23 05:10:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1790697191; cv=none; d=zohomail.com; s=zohoarc; b=DAKwZ1CTLwOmak+bZde44kh9jDZORZuzi9+v1pLuXAASepd/ILCffNQve1Gjsa3Zif4zZUpWcLeOsE5fbqPq0lDryjF5SLco0GJBph4g8ZqpZjGU+UgxbuKULNTgPcgj/67yQNVzISXU0XFzDNeTDGAMQAaQrrklWk4qOgOeYqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1790697191; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uSYCU2wY83TuX28IyI/gF41SHzkxKRLllFlKhgVPhn8=; b=Vqsxw9mUjJ4YC+PnKaquiBZEuRsbK35rD1MR3v346Q4lhuD2cUt2EoOlgskA2LXEBnZmo3y/4KktX+Ru4RNygpEE6gjkRCjzElSmOfcTHWP3AfcVGoFIyVQdP0TV+6K+kNEZcNU4BeGXibr+z8yNPbCIAOiKcD2lJ9bYev4BEEo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179069719143492.22061925651121; Tue, 29 Sep 2026 08:53:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xBa7f-00063s-7L; Tue, 29 Sep 2026 11:52:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xBa7S-0005sO-VT for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:51 -0400 Received: from mail-wr2-x10.google.com ([2a00:1450:4864:30::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xBa7N-0001TG-7Y for qemu-devel@nongnu.org; Tue, 29 Sep 2026 11:51:48 -0400 Received: by mail-wr2-x10.google.com with SMTP id ffacd0b85a97d-485984ebf5cso3510346f8f.0 for ; Tue, 29 Sep 2026 08:51:44 -0700 (PDT) Received: from athena ([2a06:5b06:b600:300:37e8:6d0c:7fb:398c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48af508b13fsm4416852f8f.27.2026.09.29.08.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2026 08:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790697104; x=1791301904; darn=nongnu.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=uSYCU2wY83TuX28IyI/gF41SHzkxKRLllFlKhgVPhn8=; b=Sk1oV/KI0bZIRrkz/KR/VqeuheaofJcsoQQ3N0k1uUfxD83bxC4sOmexKQ4jO+MW/b WJYMHHhZZ6ePI+0cIr5x+SiFCj25Ntl45U6ocVRufB4a+ANM6Rk9U2bV1y60zFdVqqgD Z1WnsiL81/tl3KtN8R1rB+U1Y/LN/yo9r2mMM7Dn3mJWlcrYHmpjHDQiBiS6/dtnD2bE 09nIMvjMgyetlT1X/qSfcAPg3Sjn9YJx5mcemc0Z+YHJ6nSaa2kh+/xYsVCZaXnQjUfb 0PFXZb1c1XZDiShEvaE0MJxyT2zujB6FTjglTuvudKc8+TyDZrvF9+FALDZ4U+UksPrY KPhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790697104; x=1791301904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=uSYCU2wY83TuX28IyI/gF41SHzkxKRLllFlKhgVPhn8=; b=UExxudwn9Rl8eHKc4olRqEunDGsL2yeN8oIO1Xekm/xxP3cU4iUt69IFHvbZL0Bgum VLmb76BMTRqu4NtBS/TQ4G7bwnVBJBJ3TjEoH4EjF85PPM/6LYN9JR+Xc44CEv/TvqvZ C3ScklqsBWw3quJVJFNfq4SDOuBePxzjkTuHswUGxmV/SD1iLPuiq/a9NTrO1c7NtnGU 9aNdbzy/RVvvgNYNudWCTw6AnyXxKowQvTGDUP3Q6EruN2OyLPUZJwXtRZyaXee3ukRw U+5Xp/K8ZkwAK5heuwUSo9bVriv7iReT3vuZ3eAPoQklrk6RAqX1XA9qn9UI6R1NZX1D DUgg== X-Gm-Message-State: AFq9FYIBQ3KS8cx62KR+CGirKsQNMCxLqRG180AA2jeLSKPt93MTeo5w XUtrtwiubtSz7zJOO51FTRhhF5hTn5TflKT9jFqszF35nyYrFDClV/LdfH7nH1YTKU+1fgMsIBI uMIHu X-Gm-Gg: AYBFou3mc25SkRZVNhkxXO0vUBcY+w+fy3DRQ6/XU9QWIwSnb9vxfxPRWAOp2/VrpOA oJd6Syj/GtuIV0xUELCxTLorRH6NI7kgR7+0Z0R05XKLsl/YD2DUhNDa1DM1oba6FIN8JyllgfA SxB3sYXNrhAvd+pgas7d+BPuxDsea7KAl6q496cv8RMGj3bTSWA4gilit6em6VqoUd5SCskIN3g QTZhoO+puQodf4jTWxq/WwjHHEPsdWonlBCZxMUbOi9CXyMvJQRB4/mhGTO3emJdvXzgZT8ccWq 8te8Qmot88iS5pZnB6maqYCdZKoOjnvNMv/0bvKNrQEbdJrbIMvRputrcNL5zCmUyhfmndc9f6y Idji6FH2zufOtk8zaJOvaf0OGSLek97n4Dt+SDmWWWdeIRyAq6WJLd8ltmwzHTZ8cZ3G+z4MGr2 bTSyi/7nlWPrrkrdWazpEvvmIKZmyD7HqJomx2Nl5BIp/M4ovSa/vdoEdqew== X-Received: by 2002:a05:6000:386:b0:488:8c99:fbc8 with SMTP id ffacd0b85a97d-4888c99fcccmr14354971f8f.50.1790697103751; Tue, 29 Sep 2026 08:51:43 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Vladimir Sementsov-Ogievskiy , John Snow , Andrey Drobyshev Subject: [PATCH v3 9/9] block/block-copy: coalesce write-zeroes tasks Date: Tue, 29 Sep 2026 17:51:25 +0200 Message-ID: <20260929155125.3151111-10-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260929155125.3151111-1-den@openvz.org> References: <20260929155125.3151111-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:30::10; envelope-from=den@openvz.org; helo=mail-wr2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1790697193753158500 Content-Type: text/plain; charset="utf-8" From: Denis V. Lunev Task size was capped to block_copy_chunk_size() regardless of method, which sizes a task by the copy buffer. A write-zeroes task carries no buffer, so that cap only splits one long known-zero run into a crowd of small COPY_WRITE_ZEROES tasks, each with its own request against the target. block_copy_task_create() already decides from zero_bitmap how far a task may run, so add block_copy_widen_zero_area() to that decision: for a write-zeroes task, re-search the dirty area under BDRV_REQUEST_MAX_BYTES instead of the buffer chunk size, and let the existing clamp cut it back to where the zero run ends. That bound is INT_MAX rounded down to a sector, so nothing has aligned it to cluster_size and it is aligned down at the use site. Widening is safe: an overlapping caller waits on the task's BlockReq via reqlist_wait_one() rather than observing it mid-flight. A request that large is only cheap where the target zeroes by metadata. BDRV_REQ_NO_FALLBACK in supported_zero_flags rules out the targets which cannot, qcow2 v2 and iscsi among them, but it is optimistic for the rest: file-posix advertises it at open and only learns from a failing fallocate. So a write-zeroes request asks for it while the target is believed to oblige, which costs nothing when it does. A refusal ends the widening, and the range is written in buffer-sized chunks, as is any task widened before the refusal came. -ENOTSUP says the fast path is unavailable, not that the target wrote nothing, so the range is rewritten whole: zeroes over zeroes change nothing. Signed-off-by: Denis V. Lunev CC: Vladimir Sementsov-Ogievskiy CC: John Snow CC: Andrey Drobyshev Reviewed-by: Andrey Drobyshev --- block/block-copy.c | 94 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 7 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index c0a3359938..94ca2a10ed 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -159,6 +159,8 @@ typedef struct BlockCopyState { bool skip_unallocated; /* atomic */ /* State fields that use a thread-safe API */ BdrvDirtyBitmap *copy_bitmap; + /* Whether a write-zeroes task may widen; see block_copy_write_zeroes(= ). */ + bool zero_widen; /* atomic */ /* Clusters reading as zero; allocated on demand, frozen once valid. */ HBitmap *zero_bitmap; /* Published only after the scan, with skip_unallocated already false.= */ @@ -187,6 +189,34 @@ static int64_t block_copy_chunk_size(BlockCopyState *s) } } =20 +/* + * A write-zeroes task carries no buffer, so it may cover far more than + * block_copy_chunk_size(). Return how far it may run; the caller clamps it + * to where the zero run ends. + */ +static int64_t block_copy_widen_zero_area(BlockCopyState *s, + BlockCopyCallState *call_state, + int64_t offset, int64_t search_e= nd, + int64_t bytes) +{ + int64_t aligned =3D QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES, + s->cluster_size); + int64_t zero_chunk =3D MIN_NON_ZERO(MAX(aligned, s->cluster_size), + call_state->max_chunk); + int64_t wide_offset, wide_bytes; + + if (!bdrv_dirty_bitmap_next_dirty_area(s->copy_bitmap, offset, search_= end, + zero_chunk, &wide_offset, + &wide_bytes)) { + return bytes; + } + + /* @offset is dirty, so the search cannot have moved past it. */ + assert(wide_offset =3D=3D offset); + + return wide_bytes; +} + /* * Search for the first dirty area in offset/bytes range and create task at * the beginning of it. @@ -198,6 +228,7 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCall= State *call_state, BlockCopyTask *task; BlockCopyMethod method; int64_t max_chunk; + int64_t search_end =3D offset + bytes; =20 QEMU_LOCK_GUARD(&s->lock); max_chunk =3D MIN_NON_ZERO(block_copy_chunk_size(s), call_state->max_c= hunk); @@ -219,6 +250,10 @@ block_copy_task_create(BlockCopyState *s, BlockCopyCal= lState *call_state, =20 if (hbitmap_get(s->zero_bitmap, offset)) { method =3D COPY_WRITE_ZEROES; + if (qatomic_read(&s->zero_widen)) { + bytes =3D block_copy_widen_zero_area(s, call_state, offset, + search_end, bytes); + } boundary =3D hbitmap_next_zero(s->zero_bitmap, offset, bytes); } else { boundary =3D hbitmap_next_dirty(s->zero_bitmap, offset, bytes); @@ -465,6 +500,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source,= BdrvChild *target, .max_transfer =3D QEMU_ALIGN_DOWN( block_copy_max_transfer(source, target= ), cluster_size), + .zero_widen =3D target->bs->supported_zero_flags & BDRV_REQ_NO_FAL= LBACK, }; =20 s->discard_source =3D discard_source; @@ -521,6 +557,56 @@ static coroutine_fn int block_copy_task_run(AioTaskPoo= l *pool, return 0; } =20 +/* + * Widening a write-zeroes request only pays off where the target zeroes by + * metadata, so while the target is believed to oblige, a request asks to = fail + * instead of falling back to writing the zeroes out. That costs nothing w= hen + * it does oblige, and a refusal ends the widening for the rest of the run. + */ +static int coroutine_fn GRAPH_RDLOCK +block_copy_write_zeroes(BlockCopyState *s, int64_t offset, int64_t bytes, + bool *error_is_read) +{ + BdrvRequestFlags flags =3D s->write_flags & ~BDRV_REQ_WRITE_COMPRESSED; + int64_t chunk; + int ret =3D 0; + + if (qatomic_read(&s->zero_widen)) { + ret =3D bdrv_co_pwrite_zeroes(s->target, offset, bytes, + flags | BDRV_REQ_NO_FALLBACK); + if (ret !=3D -ENOTSUP) { + goto out; + } + + /* Redoing the range is safe: zeroes over zeroes change nothing. */ + qatomic_set(&s->zero_widen, false); + } + + WITH_QEMU_LOCK_GUARD(&s->lock) { + chunk =3D block_copy_chunk_size(s); + } + + while (bytes) { + int64_t n =3D MIN(bytes, chunk); + + ret =3D bdrv_co_pwrite_zeroes(s->target, offset, n, flags); + if (ret < 0) { + break; + } + + offset +=3D n; + bytes -=3D n; + } + +out: + if (ret < 0) { + trace_block_copy_write_zeroes_fail(s, offset, ret); + *error_is_read =3D false; + } + + return ret; +} + /* * block_copy_do_copy * @@ -552,13 +638,7 @@ block_copy_do_copy(BlockCopyState *s, int64_t offset, = int64_t bytes, =20 switch (*method) { case COPY_WRITE_ZEROES: - ret =3D bdrv_co_pwrite_zeroes(s->target, offset, nbytes, s->write_= flags & - ~BDRV_REQ_WRITE_COMPRESSED); - if (ret < 0) { - trace_block_copy_write_zeroes_fail(s, offset, ret); - *error_is_read =3D false; - } - return ret; + return block_copy_write_zeroes(s, offset, nbytes, error_is_read); =20 case COPY_RANGE_SMALL: case COPY_RANGE_FULL: --=20 2.53.0