From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11020105.outbound.protection.outlook.com [52.101.84.105]) by lore.virtuozzo.com (Postfix) with ESMTPS id 0F7A1802A5 for ; Wed, 30 Sep 2026 11:17:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wilNSgTyYFUqkQwEcXj8RhATWH4S1V4pORnhckNU/Ay+gkYqLfWUkFQVkRmn18qtmX0tddJlRr16Z439vLkRycbzjobjVW6EdOliWHyTSzDoug34O5xwAijAwNZdY3F2QfDW/jv9BfL+mkeTCxpUkhPOWQ0AI/J8nScZYgLgZrOFyCDuaYMXx1jL0wjyatkdTWhM7ikDPUDH/ErJ/N5pRFaIq3v0T9XqPjfj1IWQ652sw4R7waidUd1uN2XNT68kKK5XrTH/aiK2/qhH6INIGndHCa1oyLXHLopGRaphcdfT5ebGlVqYgKPb9ALRF9ubmiAgxK8b7enQzIiOb6W10Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eMrpYX0Ipq7fwHjah5Zn/PzXxGFg6zzkpabj+dylzsE=; b=QJoWldwWgUkAlxhkjpN0YlpGRAYCuZR9M0dqeFXulx9TSFJkiApWImjR+BmsmNxObmCeZ5rsvzNBCoGOkx8z5I9oKs6bkpvCfhGJK5Hme1IEVuBmclNeM9QEgFK0uUBpHarDeFjK/kg3ThN0jomIr7qpkOrSMJ33i9jw0/Ia8piOnP07mjJhKf1KVkbRZkbf9n/am28aJb6aD9VLNeedK8km9tEk9CrQk5CRHdlSo9kypAqzfLH6FATa5ctkyTJHoc0XDIHdY9gcN7Zz78ME7lH6cEckcFPwTHQARWsYlztO39pc5B83ydh21ndujYcKR5YOc/lmVysxS+oMNAIRxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 2a00:1450:4864:31::11) smtp.rcpttodomain=virtuozzo.com smtp.mailfrom=openvz.org; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=openvz.org; dkim=pass (signature was verified) header.d=openvz.org; arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.onmicrosoft.com; s=selector2-virtuozzo-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eMrpYX0Ipq7fwHjah5Zn/PzXxGFg6zzkpabj+dylzsE=; b=eXn7Ci58csUU/dFSMKkqyMudomvw6ZtBK9QAA5WjJaF897fWTRuqvYc91gTALncR3+cw2pP/vqAIfyhcoDHkZ0mFwVMQiCVaZ7ZF251nxZAPQN45YlPLes2azwis6IiVthBgQ0GkieqTvY/tYM1fA3NLN2mKVDL2JTTw/OQ7QIw= Received: from DUZPR01CA0331.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b8::24) by PAWPR08MB11511.eurprd08.prod.outlook.com (2603:10a6:102:50b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.472.15; Wed, 30 Sep 2026 11:17:51 +0000 Received: from DB1PEPF000509E6.eurprd03.prod.outlook.com (2603:10a6:10:4b8:cafe::1f) by DUZPR01CA0331.outlook.office365.com (2603:10a6:10:4b8::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.472.16 via Frontend Transport; Wed, 30 Sep 2026 11:17:50 +0000 Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 2a00:1450:4864:31::11) smtp.mailfrom=openvz.org; dkim=pass (signature was verified) header.d=openvz.org;dmarc=pass action=none header.from=openvz.org; Received-SPF: Pass (protection.outlook.com: domain of openvz.org designates 2a00:1450:4864:31::11 as permitted sender) receiver=protection.outlook.com; client-ip=2a00:1450:4864:31::11; helo=mail-wm2-x11.google.com; pr=C Received: from mail-wm2-x11.google.com (2a00:1450:4864:31::11) by DB1PEPF000509E6.mail.protection.outlook.com (2603:10a6:18:3::618) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.472.14 via Frontend Transport; Wed, 30 Sep 2026 11:17:50 +0000 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49ffe817151so22068665e9.0 for ; Wed, 30 Sep 2026 04:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1790767070; x=1791371870; darn=virtuozzo.com; 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=eMrpYX0Ipq7fwHjah5Zn/PzXxGFg6zzkpabj+dylzsE=; b=nOuRwSagCN2BdEVTAJQrwxCwEIHcGhZHdsv2+WKJAEEmnD134dQE9XsTjyp8OFm894 GPMWwKdW6vndtZdYi8NuQtui5NyJrw52NgTcfJuGQBCuSFI8mQLOQF3aXjPp/jhOx0qX 8L7cf41LocP8KXSNXAn2Zq/aLRsTDxONXa/3QC0BbWeaCSHJ2QZBdFTWvohUX24OT6Ig 5ZG9juiP3E0GovGsrGxF8DfHcdeVUJZ+NohCadJEtSMM/acZAO+w3XdTa57odclwlnnc W+GnAGhRm2ALELOpdCefiZSSk+HXIqoj+c+/Ya3NBaVHXnPjxMaeS/GWtPXZeq5HpRqM voDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790767070; x=1791371870; 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=eMrpYX0Ipq7fwHjah5Zn/PzXxGFg6zzkpabj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id 5b1f17b1804b1-4a01b015403mr14666545e9.24.1790767070149; Wed, 30 Sep 2026 04:17:50 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c6b8:98e2:93f0:2de6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a01cd002bcsm3092365e9.4.2026.09.30.04.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 04:17:49 -0700 (PDT) From: "Denis V. Lunev" To: svt-core@virtuozzo.com Cc: andrey.drobyshev@virtuozzo.com, den@virtuozzo.com Subject: [PATCH hci-8.0 3/9] block/commit: batch block-status queries #VSTOR-134085 Date: Wed, 30 Sep 2026 13:17:33 +0200 Message-ID: <20260930111739.3866427-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260930111739.3866427-1-den@openvz.org> References: <20260930111739.3866427-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-EOPTenantAttributedMessage: 0bc7f26d-0264-416e-a6fc-8352af79c58f:0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB1PEPF000509E6:EE_|PAWPR08MB11511:EE_ X-MS-Office365-Filtering-Correlation-Id: 8679a920-d0ae-495c-56b8-08df1ee47707 X-LD-Processed: 0bc7f26d-0264-416e-a6fc-8352af79c58f,ExtAddr X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 0 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|9140799003|6059299003|43022699015|61400799027|48200799018|376014|10067099003|6133799003|56012099006|5063699009|55112099003|22082099003|18002099003|16102099003; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9cVgf9fWFsuBL8BlCoI8ONlqk8wwrYPzeoZqjBY6uopT2oXHBb38reqmJIn/?= =?us-ascii?Q?WsQ3kUZLjK9T7e8jB3lD8gjHXrWw29QO7FQ9pAFcv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qOKNNKP2Q=3D=3D?= X-Forefront-Antispam-Report: CIP:2a00:1450:4864:31::11;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail-wm2-x11.google.com;PTR:mail-wm2-x11.google.com;CAT:NONE;SFS:(13230040)(82310400026)(9140799003)(6059299003)(43022699015)(61400799027)(48200799018)(376014)(10067099003)(6133799003)(56012099006)(5063699009)(55112099003)(22082099003)(18002099003)(16102099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HeX/teiQDdakZs2r9OaPCu7spO0grxlLjmGlRQZ2tvloNPZdl3zOEFVSzsxh2ws6tsl+dyvOLkkkS6VPkJ+KzjHZQyIqLwELzmGKrVC7n1VoKB2sfRTus8WKYcL9rKRAUXdo+XQUZ7JeG10Md5HlgksDhAJpVgH8uAtqWBNaVmzSR0Fb/UyFwJuOmjmKKNtQZKkOqdkkFZlc3+Tgg1ZOW0roblHoOk0vVRJEgtO4scSlKwOCa1DfyLVt8I0AhWOU3TurWJS44NXW0RILGD1ArmOmr4TcvZ2wB6wUMdC3yIqBUu6yVKTvcxv95+LP39uFAUl80i3+ovj+gkN+X9AJVkJp8niJDI5OVOZ01oMse3PomVplnuKbFHX5eFH76MkXGFzibkEKPywhz+ZSZhnbgTsgeTHr/uUF4HyFVAnisYbkJRStva2yhS9XwJqEdJOQ X-ExternalRecipientOutboundConnectors: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-Auto-Response-Suppress: DR, OOF, AutoReply X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2026 11:17:50.7666 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8679a920-d0ae-495c-56b8-08df1ee47707 X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-AuthSource: DB1PEPF000509E6.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB11511 List-Id: 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 --- block/commit.c | 59 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/block/commit.c b/block/commit.c index a2e807288b2..80b89e6269d 100644 --- a/block/commit.c +++ b/block/commit.c @@ -31,8 +31,23 @@ enum { * contiguous regions of the image is efficient. */ COMMIT_BUFFER_SIZE = 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 = 256 * 1024 * 1024, /* in bytes */ }; +/* 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; @@ -129,26 +144,46 @@ static void commit_clean(Job *job) } static int 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 = *requested_bytes; + int64_t bytes; int ret = 0; bool error_in_source = true; - /* Copy if allocated above the base */ - WITH_GRAPH_RDLOCK_GUARD() { - ret = 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 >= st->offset); + + if (offset >= st->end) { + /* Copy if allocated above the base */ + WITH_GRAPH_RDLOCK_GUARD() { + ret = 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 = offset; + st->end = offset + bytes; + st->ret = ret; } - trace_commit_one_iteration(s, offset, bytes, ret); + ret = st->ret; + bytes = st->end - offset; - 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 = MIN(bytes, COMMIT_ZERO_CHUNK); + } else if (ret & BDRV_BLOCK_ALLOCATED) { + bytes = MIN(bytes, COMMIT_BUFFER_SIZE); } + trace_commit_one_iteration(s, offset, bytes, ret); + if (ret & BDRV_BLOCK_ALLOCATED) { if (ret & BDRV_BLOCK_ZERO) { /* @@ -214,6 +249,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp) int64_t n = 0; /* bytes */ QEMU_AUTO_VFREE void *buf = NULL; int64_t len, base_len; + CommitStatus st = { 0 }; len = blk_co_getlength(s->top); if (len < 0) { @@ -234,6 +270,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp) } buf = blk_blockalign(s->top, COMMIT_BUFFER_SIZE); + st.len = len; for (offset = 0; offset < len; offset += n) { /* Note that even when no rate limit is applied we need to yield @@ -244,7 +281,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp) break; } - ret = commit_iteration(s, offset, &n, buf); + ret = commit_iteration(s, offset, &n, buf, &st); if (ret < 0) { return ret; -- 2.53.0