From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788638; cv=none; d=zohomail.com; s=zohoarc; b=GZlDY2r47xenM0AgASVtbCBitQUlzH5azLWoSO8V8fjJA0r8O/TuYLoPsE4f/1ybjyAz/OsA5gdCO+IjgXe9PIumfSZugdH89cer8bdatmNO4s4Jk1gbp+vQ31pUc7rCtbAo95CjYMhaSc1T4lqCC/USzJuIszkXrTfyHoRmMeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788638; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CDSatSx8OrVXDk0o7wj5shH6txGUOWHFIUf5mWNv4L0=; b=gfX30LCD4r+0T0mK6jRU8577bJfcwvATPB/YqM4De9qnf5QATBjbKtW2S/ob6BBpnQAs6ko8Y0RbbqcdcsfRF9STHVkuM0+y+hA7Xao1zu0GosVXMepIBtop2yARs4PF7iZACqjgLm9Q+iH26gur3nxgw1i9T3QRF8zk5XoROgU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 177978863834950.73169574187591; Tue, 26 May 2026 02:43:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319666.1587130 (Exim 4.92) (envelope-from ) id 1wRoK7-0007NP-Qz; Tue, 26 May 2026 09:43:43 +0000 Received: by outflank-mailman (output) from mailman id 1319666.1587130; Tue, 26 May 2026 09:43:43 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoK7-0007NH-Ni; Tue, 26 May 2026 09:43:43 +0000 Received: by outflank-mailman (input) for mailman id 1319666; Tue, 26 May 2026 09:43:43 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoK6-0007D9-WF for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:43 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoK6-00C7fR-CA for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:42 +0200 Received: from [10.42.69.9] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b46-e002-0a2a0a5209dd-0a2a45098e94-30 for ; Tue, 26 May 2026 11:43:42 +0200 Received: from [209.85.221.46] (helo=mail-wr1-f46.google.com) by tlsNG-bad1c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b4e-2497-0a2a45090019-d155dd2ec0a5-3 for ; Tue, 26 May 2026 11:43:42 +0200 Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-4526a8170ceso5213617f8f.2 for ; Tue, 26 May 2026 02:43:42 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:41 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788622; x=1780393422; darn=lists.xenproject.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; bh=CDSatSx8OrVXDk0o7wj5shH6txGUOWHFIUf5mWNv4L0=; b=TWsILB3LAnnFrJSxgdWZhQEt9yL1tCRXbBKjBG2R8hou2/Enw3Pc0OKhRdVP9OV63u WIDJHHoCH9/FgErxAOztFshqbegT4SgRb5ayu5ar/J+zfqZqyBt8d2nSwT2d0o6uVmjc np9uJpkVth+r1RqlwAWVfo/5pNuNS8FdkMMrin6c3wt1OAgC5FHDsSmOQDkv2l2H8e6R QURKRF5r7BcMdqnz9IwhaFXjIPe0CrJCngnvHPDzojpGR2K2DuG0KMgnsfgBeRUJvyts UpTsWyEU7HK4T5as0oHr56SZAHVvQ6GlLd/eiVzspkDlBOkOznGKoxVk+94yraYNa1Cp ZKpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788622; x=1780393422; 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; bh=CDSatSx8OrVXDk0o7wj5shH6txGUOWHFIUf5mWNv4L0=; b=B6CmWA63zg18ER7m+Zc0SEOtoR45mkM6inte/PspvW36MskdaqcXsTQnzWR9MzP6m8 +n9oTR/chqZsUOsycrOBExom1BSLxWkyPMFWJegvJe1H7opjFTtKaeV5Mrw3KWhMuluy H50ihQJPzKVkczW166KZ7OlqBUMxrBC0q4OwJnhnLhyNWHt3UONeSkr6EAKG5Yq6A731 mo+B1V9ZO+yVk4CdG3+R72CKy6lK6mjNfjyOrXLZzrh6ekxEQMrM/lR+pqsaM9nT4M/g qR6pKaHnk02aq0wjk/QUURCgYvfN7UL/Lirh47cenHuqIAzmmyeEFJjwf75t4PF+eeWB 5xYA== X-Gm-Message-State: AOJu0YwHMVcmtFDJWP5ExGuReRmFMPR/I0g5iFCXnNJrcALmI02mP+G3 OEPQ7ijy5mc12W0AS3JKBSSuosyK9INBH4DYSmVy8i68FrlcnOF59mLQBmEUWpV2 X-Gm-Gg: Acq92OGgkWhytvi93pOHazqIJnz/fYY7wZ6ebDMNqSNUIVRX8RdPutEQ4vdbJkjFxMW rroW7eg8ru8zKdZi3pWWy80Eb4ZuIJQk61cMhG+58zKKC8DPi9rxm1un2AD1bEpg/yKUbEI4d4/ XL5TZtNeJDoYfN8+eVSEHJ/elaLysmNhF+t850RTYnD5Iiy/PKnofP+BCudTal5QWJUtf1BDZTm ZYejzZEv6bBsqCx/eawzK7NhhrDBxFNGChMh0mh1w3V+HV7F1RE29E7TK0qsZHrJhqPlTjqzwyY 1Fa5KW4Jn5D7eGfRRdAiPdiJOpud5gUDWrovvLMX5Nzu/+dmlBtfnwT4NhaXkL7jyUqNSCNzsxM XXcNTu6dPlpD8T8npaCd1x/fFx0K4l50WYrpgBNof1HZi8j2Twop4PQqk2PMix+4gcrKdluuWYQ aJyXvzMcVsxHF7K3xtqa72EZBcF6Ai39n2XfXpW3II6IZuo49Gulid5hImY4qZGCtW+aKOhbKBh O3xV3KcaQQXWMrza1tsX227sQ== X-Received: by 2002:a05:6000:41d2:b0:43d:242:b9bb with SMTP id ffacd0b85a97d-45eb36a7d34mr28920267f8f.18.1779788621742; Tue, 26 May 2026 02:43:41 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v3 1/9] libs/guest: Reduce number of parts in write_split_record Date: Tue, 26 May 2026 10:43:12 +0100 Message-ID: <20260526094324.12286-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-bad1c0/1779788622-89B7BA53-2F529E4D/0/0 X-purgate-type: clean X-purgate-size: 1632 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788640134158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Small optimization. There's no much sense to split the header in 2 pieces, it will just take more time and space to reassemble them in the final buffer. This also avoids truncating combined_length to 32 bit in case of 64 bit machines potentially avoiding following record_length check. The function become more coherent with following read_record function. Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/guest/xg_sr_common.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.c b/tools/libs/guest/xg_sr_commo= n.c index 7ccdc3b1f6aa..86c148c62f3e 100644 --- a/tools/libs/guest/xg_sr_common.c +++ b/tools/libs/guest/xg_sr_common.c @@ -59,11 +59,11 @@ int write_split_record(struct xc_sr_context *ctx, struc= t xc_sr_record *rec, static const char zeroes[(1u << REC_ALIGN_ORDER) - 1] =3D { 0 }; =20 xc_interface *xch =3D ctx->xch; - typeof(rec->length) combined_length =3D rec->length + sz; + size_t combined_length =3D rec->length + sz; size_t record_length =3D ROUNDUP(combined_length, REC_ALIGN_ORDER); + struct xc_sr_rhdr rhdr =3D { rec->type, combined_length }; struct iovec parts[] =3D { - { &rec->type, sizeof(rec->type) }, - { &combined_length, sizeof(combined_length) }, + { &rhdr, sizeof(rhdr) }, { rec->data, rec->length }, { buf, sz }, { (void *)zeroes, record_length - combined_length }, --=20 2.54.0 From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788668; cv=none; d=zohomail.com; s=zohoarc; b=SG26DHhQ52wGvQrRBk2SgESJW8n2TK4WQ25KWR5SgsmQf6BvTTpS67c1vnL5zNhyPt+6qowkZz06KvaV3SnwH42zlXDzcUzmhtIkpNH01LmVLRJ3oZuYyx79+c/g+NJU9Kk1IkybeTjypUqiwTEnWGfNbMnzdUVdqwbn1w311zg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788668; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hHsDpV0xKbf5s8BDyceiYE3WNS4vLthHrGXN9Aw5Zmw=; b=lSV7dnzB+P/qzO9w7fmaJ85Vrf1Xo/9NOkb78Whr2gVpKLDEKpM7phawyDIx1ElOVk1D/9Oxb+C7vk5yUJOv2F7r+1Wg9ctU7LdfFZ5g4CHQYds21qdOeZRPTrinqIVMhNdDPq8gu64WvzurN/8Xbg//xgR+0l/ZLjOirVdRF9U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1779788668580316.9907710751238; Tue, 26 May 2026 02:44:28 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319667.1587140 (Exim 4.92) (envelope-from ) id 1wRoK9-0007ba-42; Tue, 26 May 2026 09:43:45 +0000 Received: by outflank-mailman (output) from mailman id 1319667.1587140; Tue, 26 May 2026 09:43:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoK8-0007bP-VE; Tue, 26 May 2026 09:43:44 +0000 Received: by outflank-mailman (input) for mailman id 1319667; Tue, 26 May 2026 09:43:43 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoK7-0007NG-SI for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:43 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoK7-002r1O-86 for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:43 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b43-5cb7-0a2a0a5109dd-0a2a450ab138-42 for ; Tue, 26 May 2026 11:43:43 +0200 Received: from [209.85.128.52] (helo=mail-wm1-f52.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b4f-56b3-0a2a450a0019-d1558034e988-3 for ; Tue, 26 May 2026 11:43:43 +0200 Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4891d7164ddso49805485e9.3 for ; Tue, 26 May 2026 02:43:43 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:42 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788623; x=1780393423; darn=lists.xenproject.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; bh=hHsDpV0xKbf5s8BDyceiYE3WNS4vLthHrGXN9Aw5Zmw=; b=lKgZGTgVgvM0O4TdUfycV6I7gyFHE6W22dVPhdRRbDEuc71fAQAdPygqPBq3+5WRHt R7kLqwKnM2Nnwmj0zWdgRBpyJaJiDq6r7JmABEaTUaTqhx6tb4Xh3BIyAE3gWgPpm3lK IH4FGT+g+oQaQNJWEFFCBmD/CIGqA38Pg/wRASn1LCd0H2pXhVYVlxIKkYEt1CFcL4jw cRBZS4l51GPJzEL9flDSrfPmP87owp7A44swJYVi+1YZUz98WWTVmZN+CxTW3EPIhvSq JSMFD4FUaJMwKBXEirJE2u7cDFkK033DxrpfEOsmAMt6SaWx4Lny6FXbM7hBJTEV0q2N 1+ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788623; x=1780393423; 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; bh=hHsDpV0xKbf5s8BDyceiYE3WNS4vLthHrGXN9Aw5Zmw=; b=m2keRCLBNI2Fyd8Dmp+Pu0hdx2QT3qyxwPZFM+GAxOXsh+k0d9If9K0f++fx/kWkJ3 ukEwBzxFNmgJS8nL6xc3smj0KYCJwLKaNoehd+daPU4jXmpFR3WFYpkM5tFfmqfuSdy/ X69tqYp4hMnTuYRN7QYdTK2jH0Z5tdaHoZFzXTpHGp3JnFGfDWYC1V01ywAGCVJOIixd L15ZtXD13mNco9hzy5bOuEMZ4TBXHqFLd/RZCV/24bJj4FPvqUiYgit6L/SehD+EvvpN zLAIJhkcvXOM6iIcQDbmfrpiBK0EzpzEfCB3NWo5BtcdTlx4VqMYIBV+jQhumE6BKC/8 xKrw== X-Gm-Message-State: AOJu0Yyp3Zsc8GAQLohpyt8pDWrJB6fQGz4okB6DAebTvRlDcO2Vx7zr Jt5+PJYyNq21odzz191ddHtH/QQinGfmCxbJmMNMwjWHS54xs6tDMuTWrdKAEUpi X-Gm-Gg: Acq92OE6UtPMxZAUVK9dKpC7x2E8o3KHYoxFW2NFhRRvb6XtUpdFXnpd4FTRG86PYwI 8089gnABl1leUael9VgARsMX00tFVS6LeaRJGPkloJhF6cSBCXCaVzf4+diuw683WpFWsmOreQy fXNd/NmxhdSECw/5mjNedSmR8EV/9V3vG3ThJ5MAjwkxFuM150m5Kjz2kG2D/4g9b+1RL/hsPFn X7lHz96C6qVKc61+o1I/L87d2G1sEYJdbm8NPuO3zzq0e+qGh/lkOxslzEX6gAD7xwg3v86sM0m 1TevaeYVfBJmTpEyLvkdKK5g5vOVCXKjJG5fOOEmCIYS6NfGTmApW+SS0TFJUMhSdvyCmZHnqJ9 XUE3eWdCTLWL5PsyHQweouq9t7a/YWkQF6OBA7/1kG+SVxoijWwSb9Nxp7b/d4R04Dgal+QCFYd os/iH8sWtQPn11VkIPH2RONmn2FLxQQC74Hf2P5zULaYRTJENlD+LOe3/zZc255grySGzTLqH+9 YR0srPqTj0PuRNQ6clGw2jGyQ== X-Received: by 2002:a05:600c:4f52:b0:490:4f91:5519 with SMTP id 5b1f17b1804b1-4904f91568dmr278511135e9.18.1779788622601; Tue, 26 May 2026 02:43:42 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v3 2/9] libs/guest: Reduce number of I/O vectors in write_batch Date: Tue, 26 May 2026 10:43:13 +0100 Message-ID: <20260526094324.12286-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1779788623-7397E8B7-AAF07042/0/0 X-purgate-type: clean X-purgate-size: 2625 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788670065158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Small optimization. Reduce number of pieces passed to writev. Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/guest/xg_sr_save.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 3b2c5222e429..1700d819051a 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -97,9 +97,12 @@ static int write_batch(struct xc_sr_context *ctx) void *page, *orig_page; uint64_t *rec_pfns =3D NULL; struct iovec *iov =3D NULL; int iovcnt =3D 0; - struct xc_sr_rec_page_data_header hdr =3D { 0 }; - struct xc_sr_record rec =3D { - .type =3D REC_TYPE_PAGE_DATA, + struct { + struct xc_sr_rhdr rec; + struct xc_sr_rec_page_data_header page_data; + } hdrs =3D { + { .type =3D REC_TYPE_PAGE_DATA }, + { 0 }, }; =20 assert(nr_pfns !=3D 0); @@ -115,7 +118,7 @@ static int write_batch(struct xc_sr_context *ctx) /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); /* iovec[] for writev(). */ - iov =3D malloc((nr_pfns + 4) * sizeof(*iov)); + iov =3D malloc((nr_pfns + 2) * sizeof(*iov)); =20 if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov= ) { @@ -216,28 +219,22 @@ static int write_batch(struct xc_sr_context *ctx) goto err; } =20 - hdr.count =3D nr_pfns; + hdrs.rec.length =3D sizeof(hdrs.page_data); + hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); + hdrs.rec.length +=3D nr_pages * PAGE_SIZE; =20 - rec.length =3D sizeof(hdr); - rec.length +=3D nr_pfns * sizeof(*rec_pfns); - rec.length +=3D nr_pages * PAGE_SIZE; + hdrs.page_data.count =3D nr_pfns; =20 for ( i =3D 0; i < nr_pfns; ++i ) rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.batch_pfn= s[i]; =20 - iov[0].iov_base =3D &rec.type; - iov[0].iov_len =3D sizeof(rec.type); + iov[0].iov_base =3D &hdrs; + iov[0].iov_len =3D sizeof(hdrs); =20 - iov[1].iov_base =3D &rec.length; - iov[1].iov_len =3D sizeof(rec.length); + iov[1].iov_base =3D rec_pfns; + iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); =20 - iov[2].iov_base =3D &hdr; - iov[2].iov_len =3D sizeof(hdr); - - iov[3].iov_base =3D rec_pfns; - iov[3].iov_len =3D nr_pfns * sizeof(*rec_pfns); - - iovcnt =3D 4; + iovcnt =3D 2; =20 if ( nr_pages ) { --=20 2.54.0 From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788644; cv=none; d=zohomail.com; s=zohoarc; b=X+QJ+CMDZefzIzqLjivn02FglORSN5Wz4HVM/D4vwYz7eblaB1CLJYLKEUGo84wMZGXdmt4t4Yk8fcIT596e96sxqdHMTN2jzIB3SUH2QXqNFhTkoLZQxH0pPuuAiC5bOIpPYK+ydIH7ndxNV3Ya2T2LCzO3VBp53iTMoxrIAKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788644; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=syGgOjTw4c7Rut4emSk0LlZpDI5JJWx+QA9kfDo/79k=; b=hdp0pYtqK2FkBYWDlPzwxnyyF52uO/Wl8j4UYLxu6P9fvt02lVJMLR1ZibgJAghgZFh2RWNKZK/RMPV5z0z452hGaKoxaNf+h+BBk/iEpVaus1UQpGHPBNXoVykqZBgYnI6+E4S2Zodv4VUB/sAglBOjtWop9oK3giOMprpcr8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 17797886446071017.5190622690167; Tue, 26 May 2026 02:44:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319668.1587148 (Exim 4.92) (envelope-from ) id 1wRoKA-0007qA-C3; Tue, 26 May 2026 09:43:46 +0000 Received: by outflank-mailman (output) from mailman id 1319668.1587148; Tue, 26 May 2026 09:43:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKA-0007py-93; Tue, 26 May 2026 09:43:46 +0000 Received: by outflank-mailman (input) for mailman id 1319668; Tue, 26 May 2026 09:43:45 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoK8-0007ZZ-Vg for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:44 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoK8-002r0l-BN for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:44 +0200 Received: from [10.42.69.1] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b50-2eae-0a2a0a5409dd-0a2a45019012-0 for ; Tue, 26 May 2026 11:43:44 +0200 Received: from [209.85.128.43] (helo=mail-wm1-f43.google.com) by tlsNG-d62444.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b50-c1f2-0a2a45010019-d155802bed89-3 for ; Tue, 26 May 2026 11:43:44 +0200 Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4891e86fabeso4806235e9.1 for ; Tue, 26 May 2026 02:43:44 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:43 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788624; x=1780393424; darn=lists.xenproject.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; bh=syGgOjTw4c7Rut4emSk0LlZpDI5JJWx+QA9kfDo/79k=; b=eYSATg0MGpFfv+Ev2x3xDC1Utoz2RDAOsmxkt8onS9+57dnB7O0z/srcj2trvFioAU NYr7Wqddm8STbiVa7idDd5EGtVvG25v0pUScC0GIgQ8QESuI+GmDCr8nlaX2mWQFL1nV ZzSK8BWxBuoarRAaN88pop/skfcPI0fwyWqE/mzg8ljM7PBZ0mSylIm7tPqU+jUD6b6Z +rue7pMGIm1j0UNcNodldyqQDQw6vD9atK7HWyULPOgjD994Czrv8IyNL+7J9SeyN56/ lExmh/3+Z+wxJOspRqeaDCN9ke5KGCnjzsnNHpQdH2V+nVJaoOL4HWkzS7yVlReXG8sI 3Ssg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788624; x=1780393424; 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; bh=syGgOjTw4c7Rut4emSk0LlZpDI5JJWx+QA9kfDo/79k=; b=Hef6OdjQLXU9PrVBZTLh8Zs9ydyYO1aIS8rUMb1bCIa5jgmFbCAIiMiIY3QAyJ8k3T InJa4THEJA85dqW6x+BwDPp3lk/FXwVss6EAMH1EFvwkDQ6NZoJJXvObjt36GNGSQREy eZSdnZRJSI+vQSseanJExzHgKnFu1Xb5YmiQEXho93lDcDwGjtsxoc2j2QBtjxLii3E8 GHa1EnpsXpE8vmpQuha6HUa3dcfI59vUfakepFV+Sqjbt7ohVl/V8b7Vm6Ux9pniMCxa vJhd78CHgl2FOaU9GgGPj6VehhdTD/HWHfZx6XLRBZSITt9Y0/b62WAuGBDrMNEZH4+g ttUA== X-Gm-Message-State: AOJu0Yyb6shl9apVvNchA6qdzOJDKGE3HUXtp8yePnDdKBfmPvJPrTTg XKa5fPL3c7YsRfpPaOxCT2+VrRRJZwTdlrGhtrlQikkYCSvfTLa9uO1+4QLiwSxM X-Gm-Gg: Acq92OF8VdD7fKGfk+VEXLvJkVeJXCMCt4cIbGKzKSGg2hNdkF5bqc6xM+oFSOaFmxr EiW7eei12mQqF43GzCCP/LI4QI1U+SwCukjsveOcCzK1Mr4ImQbA4+mqSIUNt0rDTtUl4h2h7C+ q1wls+mSh2zyOu05CPIyQaX8BgJuGVbds5wpKzWftyt29ErpyRgvYLs2DN4NWf1wZy/GtRMb69a sfgBkjsF+M/0nWTcParFybdcVJBaONoUOxKEOZ3nqhdREN0kagwUKjILeJRERZBw1iTzRQppPtY Rk8wFxjtCdhNrG+ZkYf10i1AuCXSpWYWPFFFBJYba8WW8zJpyli3QXO3+Txxj4x08hmmxXKczRT N+CC3uwqBmZjVdJ9QmH44NL7yB295Hr1+NSdgiJ0T318KTwa24bQ0sZ/f0kFnvOFctmPfgRXo+Q nlvOmelPd51DlZbYojSOCc9k4U3rQTZ9xU4WwQRlqFdrhWnzRU+Na6rgXp5ew+5ECk1Bq8w/0BJ G1GvgMJF7FBC2AEtviHji2LAEx0G55AnT6h X-Received: by 2002:a05:600c:1f90:b0:490:5e2a:dbaf with SMTP id 5b1f17b1804b1-4905e2adc0dmr144697785e9.21.1779788623432; Tue, 26 May 2026 02:43:43 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v3 3/9] libs/guest: Reduce number of I/O vectors in write_batch Date: Tue, 26 May 2026 10:43:14 +0100 Message-ID: <20260526094324.12286-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d62444/1779788624-B5545FF4-92044BAA/0/0 X-purgate-type: clean X-purgate-size: 1328 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788646348154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Each page was sent using a different iovec item. This potentially exceed Linux maximum (1024). Also some implementation (MiniOS) emulate writev with multiple write calls. Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/guest/xg_sr_save.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 1700d819051a..62a39dfecc7a 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -240,13 +240,20 @@ static int write_batch(struct xc_sr_context *ctx) { for ( i =3D 0; i < nr_pfns; ++i ) { - if ( guest_data[i] ) + if ( !guest_data[i] ) + continue; + + if ( iov[iovcnt-1].iov_base + iov[iovcnt-1].iov_len !=3D guest= _data[i] ) { iov[iovcnt].iov_base =3D guest_data[i]; iov[iovcnt].iov_len =3D PAGE_SIZE; iovcnt++; - --nr_pages; } + else + { + iov[iovcnt-1].iov_len +=3D PAGE_SIZE; + } + --nr_pages; } } =20 --=20 2.54.0 From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788648; cv=none; d=zohomail.com; s=zohoarc; b=TvvCjRZCxecj4bKClnPe0RG3lR5uexSjyqJUJcz1s9Ui5uPy0NAYJf7gv6hrZl21xRN+RL3R4N43Ga4RqFUorkWJX0LKJeVG/Z8FgDWoLY151f9DNYm4m/QHqLHdya2llrDqqaw2WRxe3kLuBgXN8BHTyXH1US79RVVJiev5feM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788648; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LjNuNS+tEGweRY5UYIRJVJv/E+lf3Z5v+uA7RoSWlbs=; b=Hf/hw/W8nvwfe6M88TyXxk17j5Rc3i+xyDo5WS7AOmKEu6tTbQXbdCx/uONG2ET6aCoiSrFzR28n+bnTjyBvd+jDkchlCgi5t4Qnak2xl6PBEBmL7dKJFMhNJyG2DUdYX/6fU+TB2V7hwWTl4Dig3C9pCaVgolq1mEwe4F8hoxI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1779788648914738.1496512266957; Tue, 26 May 2026 02:44:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319669.1587158 (Exim 4.92) (envelope-from ) id 1wRoKB-00085B-KX; Tue, 26 May 2026 09:43:47 +0000 Received: by outflank-mailman (output) from mailman id 1319669.1587158; Tue, 26 May 2026 09:43:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKB-00084y-Ge; Tue, 26 May 2026 09:43:47 +0000 Received: by outflank-mailman (input) for mailman id 1319669; Tue, 26 May 2026 09:43:45 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoK9-0007iC-Md for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:45 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoK9-00C7jc-2g for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:45 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b4e-e002-0a2a0a5209dd-0a2a4502c48c-22 for ; Tue, 26 May 2026 11:43:45 +0200 Received: from [209.85.221.49] (helo=mail-wr1-f49.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b50-af86-0a2a45020019-d155dd31e5d7-3 for ; Tue, 26 May 2026 11:43:45 +0200 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-44a5174670eso5826141f8f.1 for ; Tue, 26 May 2026 02:43:44 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:43 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788624; x=1780393424; darn=lists.xenproject.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; bh=LjNuNS+tEGweRY5UYIRJVJv/E+lf3Z5v+uA7RoSWlbs=; b=hrh9wP11MCg828qnNiYc72rHGBH7f11cmnLvqPuYp8KRjA09eZv9Ua6jDwvmvLz6Sj hGOUqRrbMnNm/HmT4va+SPBVjFa+XnfMmyWbNue6iTax1pRBRsWFXrEWv4QYLXMDkiWS KB5bs03EUQn91WLrp3NlK0YdsvmuUnzt0m2ST9715OF1Yf6wSXqzTcmPw2yFcjTOBs9q nazRevj+Vl3t6rOhIncE6tT0E2mHF1sXwlPLjHXHl2eCXP4vFGyjL5SnwWWKy6/vyOMk FkoOeDjvQHQdwr4Ii//ju/RY25eWk6TuM+7lbkampg+S9NJk7xD9Y3cnOXNZ2Txqhrqw eWSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788624; x=1780393424; 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; bh=LjNuNS+tEGweRY5UYIRJVJv/E+lf3Z5v+uA7RoSWlbs=; b=U9oWJg907+BLfj5XuoG2F9sJERx8dzJivDBtsRAWjwx1spEuNO9/p3NhkgPgytWkHG I6UMLlSEmjM7ySsk7IEtAqGGatJNYvz9FGARH1WbAOGUcz0vOiCIVQVFwWs8VjoItCal zXNB9T+FoeQmTLmAvsm73ZNv9SgLudh7mqd0ZRaoMtuWk4cL7ldCJ4p0WcbSZTRvzUMb reWeF9DCD66+atEC31ksu+SMElsMDwY5gW1C1Ak/Hr5FpYA8nynPdGugAEWeG1zV94ON jbS2yjX1ITF2XJfoBmMLtHX7N4u5yfwUjERgqe7UormsKX+6VNt976Mog7hYuITwZQ4l 4ftg== X-Gm-Message-State: AOJu0YyJvCkJ2NApxq9E1FgyD3h/obBtpyIh8F5W8MW+MkdR2UyapaMA 1W2LnKsCUOnk/pDvKoIAAY42ccazFFVyJocWxiKC2qmbTma8lufSf3We/8mxFcZT X-Gm-Gg: Acq92OHQVcKBYOOsxt+sNzwr+WtTFk3tOyEivl7r6GK0gT4zc0nOoWTLaSBpAOKQFML Wo1lJ7ssX/GIQz21LVXuO/Awfv5ah3peIhOK5i3EXPXhyD3ZN+mpreX3HErda4mBC9/sUVbRWGl c6S29Pi/VFPRs1HxqvjtA86kIdRHgehasJPLu+emlerylAz5DKu68YpW1L7BaIGc5fW6MldpPX+ smvogHvlsaLekHuW9FXFAkehGiK2cQYSV8vYWiuG84kZXhJuuUJ5MpEfjJGdj8TTCrg55F1sh7o 38izswGi5L5CylRj56/zw0uAa7EF3WTr3TKCdrVfTt8roKxzqLjU9YpyJx2H1lYPpV5sN2F908w 5uWT9GNLIvJrzSUyFxLNAIXG516Sgvvg4GAN0Q6NVdf2NMggJY6z6kzWGQrfZa3kV0GT9YhxyWt ppzJTq2773clzSuVHSZy7LKTeN7pRaBeF9PQRzs2/w2LXOyAAoD0Pn/pp8L395gkZ2JSglMAwdp 2WEucfPwLOAuaR2UA41Ky/omPmLzLQkejTm X-Received: by 2002:a05:6000:2688:b0:45e:88f5:ccfb with SMTP id ffacd0b85a97d-45eb367320cmr33474548f8f.2.1779788624364; Tue, 26 May 2026 02:43:44 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v3 4/9] libs/guest: Use a single write_exact in write_headers Date: Tue, 26 May 2026 10:43:15 +0100 Message-ID: <20260526094324.12286-5-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1779788625-81772161-A7D1DB3C/0/0 X-purgate-type: clean X-purgate-size: 2254 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788649933158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Reduce number of syscalls. Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/guest/xg_sr_save.c | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 62a39dfecc7a..8c4e760f8d0a 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -10,17 +10,22 @@ static int write_headers(struct xc_sr_context *ctx, uin= t16_t guest_type) { xc_interface *xch =3D ctx->xch; int32_t xen_version =3D xc_version(xch, XENVER_version, NULL); - struct xc_sr_ihdr ihdr =3D { - .marker =3D IHDR_MARKER, - .id =3D htonl(IHDR_ID), - .version =3D htonl(3), - .options =3D htons(IHDR_OPT_LITTLE_ENDIAN), - }; - struct xc_sr_dhdr dhdr =3D { - .type =3D guest_type, - .page_shift =3D XC_PAGE_SHIFT, - .xen_major =3D (xen_version >> 16) & 0xffff, - .xen_minor =3D (xen_version) & 0xffff, + struct { + struct xc_sr_ihdr ihdr; + struct xc_sr_dhdr dhdr; + } hdrs =3D { + { + .marker =3D IHDR_MARKER, + .id =3D htonl(IHDR_ID), + .version =3D htonl(3), + .options =3D htons(IHDR_OPT_LITTLE_ENDIAN), + }, + { + .type =3D guest_type, + .page_shift =3D XC_PAGE_SHIFT, + .xen_major =3D (xen_version >> 16) & 0xffff, + .xen_minor =3D (xen_version) & 0xffff, + }, }; =20 if ( xen_version < 0 ) @@ -29,15 +34,9 @@ static int write_headers(struct xc_sr_context *ctx, uint= 16_t guest_type) return -1; } =20 - if ( write_exact(ctx->fd, &ihdr, sizeof(ihdr)) ) - { - PERROR("Unable to write Image Header to stream"); - return -1; - } - - if ( write_exact(ctx->fd, &dhdr, sizeof(dhdr)) ) + if ( write_exact(ctx->fd, &hdrs, sizeof(hdrs)) ) { - PERROR("Unable to write Domain Header to stream"); + PERROR("Unable to write Headers to stream"); return -1; } =20 --=20 2.54.0 From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788647; cv=none; d=zohomail.com; s=zohoarc; b=dmKktXcUMImqsmC1fy5U1anFg28gjSrfaAFlCo6cqew16AxIkQ+1FOL4vZICPyqIXHU9s7txZhV93gi24ZKt5ma+f86bNvnDTyqRBcn+iYDc/25PZCq0+EOuzBc9HX2euZqXNqZZqGAMVvPgbUTBPxBg1g86Gj6MwRwpucYaH3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788647; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=X41YOolTDeQXd+76PX/UtsluEUpbnvoPlDNitCDAkx0=; b=SVl89VQpHqWR/98cFcwzVbfkwcxLNeVNFX/jFhg9/sfKoqBTkynHnZSKdA5UYPeAydmA76bb3ET+YWTBfBdfLLRYjh57XFCMFpApkqwiQm5hIv2YDws0ogxA5fykUpzA6z3nJj1u4+7XoQlt4jIAy/zYe03JNtLJVWvLpXqZBPI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1779788647580605.5664030134266; Tue, 26 May 2026 02:44:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319670.1587163 (Exim 4.92) (envelope-from ) id 1wRoKC-0008Bw-55; Tue, 26 May 2026 09:43:48 +0000 Received: by outflank-mailman (output) from mailman id 1319670.1587163; Tue, 26 May 2026 09:43:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKC-00089h-0Y; Tue, 26 May 2026 09:43:48 +0000 Received: by outflank-mailman (input) for mailman id 1319670; Tue, 26 May 2026 09:43:47 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKB-0007xP-19 for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:47 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoKA-00C7jc-DD for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:46 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b50-e002-0a2a0a5209dd-0a2a450cb892-8 for ; Tue, 26 May 2026 11:43:46 +0200 Received: from [209.85.221.51] (helo=mail-wr1-f51.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b52-62f1-0a2a450c0019-d155dd33c9c3-3 for ; Tue, 26 May 2026 11:43:46 +0200 Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-44c350a5b87so6133174f8f.3 for ; Tue, 26 May 2026 02:43:46 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:44 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788626; x=1780393426; darn=lists.xenproject.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; bh=X41YOolTDeQXd+76PX/UtsluEUpbnvoPlDNitCDAkx0=; b=gB5xUYCE1HltW/j/zJjRQWw/KbUnrfEW7SqE9UnvP0LB1pAyeJrQqNizDPx8bs6x3W QJq4BlwaKmFCm/rzqMgzKoQMVoW5vxkJU9tWvho2KigtGjdPChzrzS6fT7yIzsCZ0mom a+VEspdI1+CrHYYFtE7zjMOsG+o2URQbasldJ+gI8GlvlNzp4i76jL3zM73fNohvWNru ZQzdqBJHP4qBDQ/zCRLce7zuW0cziKnl9hQGLe096BVht2RzJxd9BI4dKbgxMz4tIq4B HCrYY3bzi/gPCBtRVZnqLS7ntw6pdINdlMb9LIprqlWztuzHV5oJDYrC3XdQYoxXGM+0 zE1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788626; x=1780393426; 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; bh=X41YOolTDeQXd+76PX/UtsluEUpbnvoPlDNitCDAkx0=; b=eFBqBFTQsoxngARZJqH07Pr3TNX6hzq9hULN2qd0S5T9XBHHhrYPJFT1XRPP6YVMH7 9u+Pqtyi1OUjg4z0gtaPO0O3dPYA1smuBTasQPmMp/kAGAyyIN1i69CdsXa3S81hFjEw oXhWGEVyttKrxzCjsdWUhYnPMYbTdWxaMLUcQkocAxSB2dD7JMcUovSJvxijhDRjKEhj GICdIXf5qhxC8DpbbhkKoQoIVKhkh4EWTruJp8HJm8PmoCSFq4Q582bjIPpWpC4u1Abf b6/Oe957v96eHj1vw9HqaUo2lM+W9KeF9VwxjrRmQlg1OckrtIbBoAYOPsse/Y0bTtag R0ew== X-Gm-Message-State: AOJu0YxYw6nn1zpIu7FrXLqGGWTNBnt5t+jognP8jg2s0FJq18r3fhqn 641IqZLjSg9NJRmbknFZ2G5VD3D1yNUgrH/2ZkhEUk/hWQeyyxNp5T8jDmTDgPCF X-Gm-Gg: Acq92OGbksBBO6ypyVqy65gPZjbXKarDCAQH6MGhxhxI4fp+9b6qXz6Ni2mRxotObka v8A/nkPb1SlsV6Mdq9fYi2EHBLRq4AdNjFxP0IVNhdSkn5pzPHS41+7ltjHBOxyJgvvoRXyBfEW invP/oHWq9ZYF9c731bY+1433wOqdH+eMYMQUdhESc9JyKndlNdZMJ6kJVeY9mfizLBsA8ENpj+ mdVHhxpfExnyG9e9psMkB/2wdVEB3EwXhBUDt4/5Lx4rDD1Fu7eoYQpyltH3zNS+FNi4/FD1+ri XlCqNchcQbmeNMukQo333tUbBcLwpxTBPnOEVxrDP9O1HInN2Zk2RDBIgiTW7ofgWgRhbX/KRMp wJd1sfjOR0Mz9GqbNpYgxw3Mo6DbPbczU/fYrc66v5QV79TXHxw+qGir3PfPNe3Gq1UO0xnPKpr v7uJMY9JMP047BY3A1XChlGH6A6ExWFeT8ZYDJL/U9J8YNKzS/E85QIv4uuqSvOyMpkRzyUGX54 SNlM/VNlhBzTx/EOpI/FtFO+0LWvvUyaZgC X-Received: by 2002:a05:6000:25c2:b0:45d:b14b:23f8 with SMTP id ffacd0b85a97d-45eb369044bmr31282502f8f.18.1779788625655; Tue, 26 May 2026 02:43:45 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross , Frediano Ziglio Subject: [PATCH v3 5/9] libs/guest: allocate various migration arrays just once Date: Tue, 26 May 2026 10:43:16 +0100 Message-ID: <20260526094324.12286-6-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1779788626-F4A7ACF5-98C149B4/0/0 X-purgate-type: clean X-purgate-size: 6461 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788648508154100 From: Edwin T=C3=B6r=C3=B6k Allocate these array just once at the start of migration, using the maximum batch size, and free them at the end. Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/guest/xg_sr_common.h | 13 +++++++ tools/libs/guest/xg_sr_save.c | 66 +++++++++++++-------------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index f1573aefcbff..77312bae9cf5 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -209,6 +209,18 @@ static inline int update_blob(struct xc_sr_blob *blob, return 0; } =20 +struct xc_sr_context_save_buffers +{ + xen_pfn_t batch_pfns[MAX_BATCH_SIZE]; + xen_pfn_t mfns[MAX_BATCH_SIZE]; + xen_pfn_t types[MAX_BATCH_SIZE]; + int errors[MAX_BATCH_SIZE]; + void *guest_data[MAX_BATCH_SIZE]; + void *local_pages[MAX_BATCH_SIZE]; + struct iovec iov[MAX_BATCH_SIZE + 2]; /* headers + data */ + uint64_t rec_pfns[MAX_BATCH_SIZE]; +}; + struct xc_sr_context { xc_interface *xch; @@ -244,6 +256,7 @@ struct xc_sr_context unsigned long *deferred_pages; unsigned long nr_deferred_pages; xc_hypercall_buffer_t dirty_bitmap_hbuf; + struct xc_sr_context_save_buffers *buffers; } save; =20 struct /* Restore data. */ diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 8c4e760f8d0a..7d8055a3f9e8 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -86,16 +86,16 @@ static int write_checkpoint_record(struct xc_sr_context= *ctx) static int write_batch(struct xc_sr_context *ctx) { xc_interface *xch =3D ctx->xch; - xen_pfn_t *mfns =3D NULL, *types =3D NULL; + xen_pfn_t *mfns, *types; void *guest_mapping =3D NULL; - void **guest_data =3D NULL; - void **local_pages =3D NULL; - int *errors =3D NULL, rc =3D -1; + void **guest_data; + void **local_pages; + int *errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; unsigned int nr_pfns =3D ctx->save.nr_batch_pfns; void *page, *orig_page; - uint64_t *rec_pfns =3D NULL; - struct iovec *iov =3D NULL; int iovcnt =3D 0; + uint64_t *rec_pfns; + struct iovec *iov; int iovcnt =3D 0; struct { struct xc_sr_rhdr rec; struct xc_sr_rec_page_data_header page_data; @@ -105,26 +105,24 @@ static int write_batch(struct xc_sr_context *ctx) }; =20 assert(nr_pfns !=3D 0); + assert(nr_pfns <=3D MAX_BATCH_SIZE); + assert(ctx->save.buffers); =20 /* Mfns of the batch pfns. */ - mfns =3D malloc(nr_pfns * sizeof(*mfns)); + mfns =3D ctx->save.buffers->mfns; /* Types of the batch pfns. */ - types =3D malloc(nr_pfns * sizeof(*types)); + types =3D ctx->save.buffers->types; /* Errors from attempting to map the gfns. */ - errors =3D malloc(nr_pfns * sizeof(*errors)); + errors =3D ctx->save.buffers->errors; /* Pointers to page data to send. Mapped gfns or local allocations. */ - guest_data =3D calloc(nr_pfns, sizeof(*guest_data)); + guest_data =3D ctx->save.buffers->guest_data; + memset(guest_data, 0, sizeof(*guest_data) * nr_pfns); /* Pointers to locally allocated pages. Need freeing. */ - local_pages =3D calloc(nr_pfns, sizeof(*local_pages)); + local_pages =3D ctx->save.buffers->local_pages; + memset(local_pages, 0, sizeof(*local_pages) * nr_pfns); /* iovec[] for writev(). */ - iov =3D malloc((nr_pfns + 2) * sizeof(*iov)); - - if ( !mfns || !types || !errors || !guest_data || !local_pages || !iov= ) - { - ERROR("Unable to allocate arrays for a batch of %u pages", - nr_pfns); - goto err; - } + iov =3D ctx->save.buffers->iov; + rec_pfns =3D ctx->save.buffers->rec_pfns; =20 for ( i =3D 0; i < nr_pfns; ++i ) { @@ -210,14 +208,6 @@ static int write_batch(struct xc_sr_context *ctx) } } =20 - rec_pfns =3D malloc(nr_pfns * sizeof(*rec_pfns)); - if ( !rec_pfns ) - { - ERROR("Unable to allocate %zu bytes of memory for page data pfn li= st", - nr_pfns * sizeof(*rec_pfns)); - goto err; - } - hdrs.rec.length =3D sizeof(hdrs.page_data); hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); hdrs.rec.length +=3D nr_pages * PAGE_SIZE; @@ -267,17 +257,13 @@ static int write_batch(struct xc_sr_context *ctx) rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: - free(rec_pfns); if ( guest_mapping ) xenforeignmemory_unmap(xch->fmem, guest_mapping, nr_pages_mapped); for ( i =3D 0; local_pages && i < nr_pfns; ++i ) + { free(local_pages[i]); - free(iov); - free(local_pages); - free(guest_data); - free(errors); - free(types); - free(mfns); + local_pages[i] =3D NULL; + } =20 return rc; } @@ -805,18 +791,18 @@ static int setup(struct xc_sr_context *ctx) =20 dirty_bitmap =3D xc_hypercall_buffer_alloc_pages( xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size))); - ctx->save.batch_pfns =3D malloc(MAX_BATCH_SIZE * - sizeof(*ctx->save.batch_pfns)); ctx->save.deferred_pages =3D bitmap_alloc(ctx->save.p2m_size); + ctx->save.buffers =3D calloc(1, sizeof(*ctx->save.buffers)); =20 - if ( !ctx->save.batch_pfns || !dirty_bitmap || !ctx->save.deferred_pag= es ) + if ( !dirty_bitmap || !ctx->save.deferred_pages || !ctx->save.buffers) { - ERROR("Unable to allocate memory for dirty bitmaps, batch pfns and" - " deferred pages"); + ERROR("Unable to allocate memory for dirty bitmaps, deferred pages" + " and various batch buffers"); rc =3D -1; errno =3D ENOMEM; goto err; } + ctx->save.batch_pfns =3D ctx->save.buffers->batch_pfns; =20 rc =3D 0; =20 @@ -840,7 +826,7 @@ static void cleanup(struct xc_sr_context *ctx) xc_hypercall_buffer_free_pages(xch, dirty_bitmap, NRPAGES(bitmap_size(ctx->save.p2m_size)= )); free(ctx->save.deferred_pages); - free(ctx->save.batch_pfns); + free(ctx->save.buffers); } =20 /* --=20 2.54.0 From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788653; cv=none; d=zohomail.com; s=zohoarc; b=h2qoO2k/kw7oGl+8ByRS24k4HWV8bkRXRrrZuzW/gETeD/ke/EM6EDrL5rtX9nE9L1z6Zp1pQnOgr3Pr1WOQLE7zfxpILlyVGSRc4iwV7zT6GIOtLNCqLuJv0gG1/ic3qnYYxL/lTYSPo3Z0WLrtpMAMzIbc9y0e3GcyMCvps5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788653; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hbvSYSz9jX9dafFppGzkbKpTIPtHmNPQUeh/EgdczHs=; b=nosD+aryybCfFo7MYgWqAwhOQNdaFAx+eZ8AVntniDu0KGhSmAhR/8+51MaGAksH/Lsdzf5b/sS70J7yNvyP+JcfyqFzIlcwISXmr+Fet3AdqGuv1+4iIRwRl9Dz39a8FvOoyIAORoGBRYr+JtqhwQBIftUB4xHzqZLY/vnnxqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1779788653634756.58002726008; Tue, 26 May 2026 02:44:13 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319671.1587176 (Exim 4.92) (envelope-from ) id 1wRoKE-0000B3-Cp; Tue, 26 May 2026 09:43:50 +0000 Received: by outflank-mailman (output) from mailman id 1319671.1587176; Tue, 26 May 2026 09:43:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKE-0000Ah-8i; Tue, 26 May 2026 09:43:50 +0000 Received: by outflank-mailman (input) for mailman id 1319671; Tue, 26 May 2026 09:43:48 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKC-0008Is-LI for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:48 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoKC-00C7jc-16 for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:48 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b54-e002-0a2a0a5209dd-0a2a450396a4-0 for ; Tue, 26 May 2026 11:43:48 +0200 Received: from [209.85.221.49] (helo=mail-wr1-f49.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b53-672d-0a2a45030019-d155dd31d024-3 for ; Tue, 26 May 2026 11:43:47 +0200 Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-44ccbd3290aso9039456f8f.2 for ; Tue, 26 May 2026 02:43:47 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:46 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788627; x=1780393427; darn=lists.xenproject.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; bh=hbvSYSz9jX9dafFppGzkbKpTIPtHmNPQUeh/EgdczHs=; b=RZysriK+S4QhPT7Dx+KuXjr7lR9V1nMKldFtJs0+K3O/rSjCg9QxCarUyLPJP0+LEO ur0BErc3+pTYZbHSI86/40y1ZZju9/QQzfGEIqzqhVTdQM65MzgJkbN3FAy2VM8ues6O CBLqgOYAKS4/6M4IwB7hLgjgztHFZMeKMQbvOp0vlxdHKGdPr+snnzKrIbRLtdh7bR7A XgsdfQ922TuQ7Jagh6u760AUrrG7ijuaRBq6icF0HCToxb8GrDK0mmWBpNltbDY0w1JH l/jHUCVwk/6FBYHs/dJoQPINpBOzl1zwg/GZh0/ylX7ZGZia+gx1ZYjNmiTMqdko5qSP zWqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788627; x=1780393427; 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; bh=hbvSYSz9jX9dafFppGzkbKpTIPtHmNPQUeh/EgdczHs=; b=U+SKtbAYA0KZwggFAD5Lhg5PZLBRwjgXAKbE4an5mppRXHE1DN3qXxQ9kLQ818fgNC SI0h8fsauZbh031GxTqD5b0L0sIABj2OtZr7TchaPY+XfZQFBSlolYWdR95qtwxXyFOZ lDhl5BdDQFzt4JMQ27MJ50TIpKJ38IVZr8TddxK1WBUL93P+LVnWZDpnv4CbdJzfLqBG IwSmoAidYTU7PyhcScR+iwinbcEWjQdgxE4JOlgyWhyf1JTGZk0Cu+C1P9fbZDLnRnv8 t+lyuVXdTvXjL4EM3Dp2s4yNMXBFuIgNgrf/szwhvyoZRDN7z1cznju4AAFCrhFGhO6F rN2w== X-Gm-Message-State: AOJu0Yy49jd1gfl3gA9x+VoFyDHv+cvdmsbPX+P2oV14gnl05ltjMS1l QVgZIX6wLJpFeLuYBw/DrJukmK1R0Id/68nF1fI8HB3+gyxZa7bx3v11mDR1KU/m X-Gm-Gg: Acq92OH7IhAZMVeHQ8qec7zcAJB46HzVwsTXawAuURN0Z7ffF+l29OzPntj8ucU9g6C 8K58SfA0fiDOx2RSV+CNBKiz5Qy5im6P6e3Qv1t23reIyteJbdafH4Myc711ahGguhzPbxgCsgm wEbUeki5w+wii34XfbZ55fqdZJ1H9v5R/mszBFh54EwlOKpXgrnAfs158tkUi+EySIRpn9XbP4Q 63msboMyc1RvwjLp2rmmYikPG8iKkJOgepu2fQ/Od9y8yN9hEFZG40dlcVMDHDtkS2nt6YKe1Ok R1lP8vggd6BBE4V6ZHeubUPy3DQMo5FhoaiBJIpG7Xe0EhNP+YyAqY+UF7NuJzu+qiSHB07mSif /y3v1Coa7Ecokbwv5OFh2lJr/pGLFpSqO/TlxRBxTjXfFUA++s3ApUwCufzTl+LndUmxXXJPdSd pdRQmmsVKE3WAdRQwItpwiqRMDsvGT6yCqc+Cto5Dbe1na4uB6535uZyYTsW9xGkqDPukmhZuhd JYaYclLbHzzkothOCmlYmpIqJoDu68SUAmn X-Received: by 2002:a05:6000:2888:b0:44f:da26:cbb4 with SMTP id ffacd0b85a97d-45eb38bae90mr31288289f8f.21.1779788626944; Tue, 26 May 2026 02:43:46 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross , Frediano Ziglio Subject: [PATCH v3 6/9] libs/call: cache up to 4 pages in hypercall bounce buffers Date: Tue, 26 May 2026 10:43:17 +0100 Message-ID: <20260526094324.12286-7-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1779788627-41794938-6F500648/0/0 X-purgate-type: clean X-purgate-size: 4985 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788653980158500 From: Edwin T=C3=B6r=C3=B6k During migration there are a lot of mmap/munmap calls, because `xc_get_pfn_type_batch` exceeds the default hypercall bounce buffer cache size, and needs to allocate every time it is called. `munmap` is slow, especially in a PV Dom0 (takes an emulation fault), so is best avoided. Eventually it'd be good if the memory pool from xmalloc_tlsf.c was reused here, but for now make it handle the commonly encountered sizes (so far up to 4 pages). Signed-off-by: Edwin T=C3=B6r=C3=B6k Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/call/buffer.c | 28 +++++++++++++++++----------- tools/libs/call/core.c | 3 ++- tools/libs/call/private.h | 8 +++++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c index 2579b8c71986..15d2f98a6b71 100644 --- a/tools/libs/call/buffer.c +++ b/tools/libs/call/buffer.c @@ -56,13 +56,13 @@ static void *cache_alloc(xencall_handle *xcall, size_t = nr_pages) if ( xcall->buffer_current_allocations > xcall->buffer_maximum_allocat= ions ) xcall->buffer_maximum_allocations =3D xcall->buffer_current_alloca= tions; =20 - if ( nr_pages > 1 ) + if ( nr_pages > ARRAY_SIZE(xcall->buffer_cache) ) { xcall->buffer_cache_toobig++; } - else if ( xcall->buffer_cache_nr > 0 ) + else if ( xcall->buffer_cache_nr[nr_pages-1] > 0 ) { - p =3D xcall->buffer_cache[--xcall->buffer_cache_nr]; + p =3D xcall->buffer_cache[nr_pages-1][--xcall->buffer_cache_nr[nr_= pages-1]]; xcall->buffer_cache_hits++; } else @@ -84,10 +84,10 @@ static int cache_free(xencall_handle *xcall, void *p, s= ize_t nr_pages) xcall->buffer_total_releases++; xcall->buffer_current_allocations--; =20 - if ( nr_pages =3D=3D 1 && - xcall->buffer_cache_nr < BUFFER_CACHE_SIZE ) + if ( nr_pages && nr_pages < ARRAY_SIZE(xcall->buffer_cache) && + xcall->buffer_cache_nr[nr_pages-1] < BUFFER_CACHE_SIZE ) { - xcall->buffer_cache[xcall->buffer_cache_nr++] =3D p; + xcall->buffer_cache[nr_pages-1][xcall->buffer_cache_nr[nr_pages-1]= ++] =3D p; rc =3D 1; } =20 @@ -108,17 +108,23 @@ void buffer_release_cache(xencall_handle *xcall) DBGPRINTF("current allocations:%d maximum allocations:%d", xcall->buffer_current_allocations, xcall->buffer_maximum_allocations); - DBGPRINTF("cache current size:%d", - xcall->buffer_cache_nr); + for ( unsigned i =3D 0; i < ARRAY_SIZE(xcall->buffer_cache_nr); ++i ) + { + DBGPRINTF("cache current size[%u pages]:%d", i+1, + xcall->buffer_cache_nr[i]); + } DBGPRINTF("cache hits:%d misses:%d toobig:%d", xcall->buffer_cache_hits, xcall->buffer_cache_misses, xcall->buffer_cache_toobig); =20 - while ( xcall->buffer_cache_nr > 0 ) + for ( unsigned i =3D 0; i < ARRAY_SIZE(xcall->buffer_cache_nr); ++i ) { - p =3D xcall->buffer_cache[--xcall->buffer_cache_nr]; - osdep_free_pages(xcall, p, 1); + while ( xcall->buffer_cache_nr[i] > 0 ) + { + p =3D xcall->buffer_cache[i][--xcall->buffer_cache_nr[i]]; + osdep_free_pages(xcall, p, i + 1); + } } =20 cache_unlock(xcall); diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c index 02c4f8e1aefa..dd8877c1a0bd 100644 --- a/tools/libs/call/core.c +++ b/tools/libs/call/core.c @@ -14,6 +14,7 @@ */ =20 #include +#include =20 #include "private.h" =20 @@ -44,7 +45,7 @@ xencall_handle *xencall_open(xentoollog_logger *logger, u= nsigned open_flags) xentoolcore__register_active_handle(&xcall->tc_ah); =20 xcall->flags =3D open_flags; - xcall->buffer_cache_nr =3D 0; + memset(xcall->buffer_cache_nr, 0, sizeof(xcall->buffer_cache_nr)); =20 xcall->buffer_total_allocations =3D 0; xcall->buffer_total_releases =3D 0; diff --git a/tools/libs/call/private.h b/tools/libs/call/private.h index 9c3aa432efe2..8e6a20897534 100644 --- a/tools/libs/call/private.h +++ b/tools/libs/call/private.h @@ -31,13 +31,15 @@ struct xencall_handle { Xentoolcore__Active_Handle tc_ah; =20 /* - * A simple cache of unused, single page, hypercall buffers + * A simple cache of unused, small, hypercall buffers + * buffer_cache[i]'s size is (i+1) pages * * Protected by a global lock. */ #define BUFFER_CACHE_SIZE 4 - int buffer_cache_nr; - void *buffer_cache[BUFFER_CACHE_SIZE]; +#define BUFFER_CACHE_NRPAGES 4 + int buffer_cache_nr[BUFFER_CACHE_NRPAGES]; + void *buffer_cache[BUFFER_CACHE_NRPAGES][BUFFER_CACHE_SIZE]; =20 /* * Hypercall buffer statistics. All protected by the global --=20 2.54.0 From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788647; cv=none; d=zohomail.com; s=zohoarc; b=TQt0ov7Og18xXVnoShYwbpQkLzO8TPLlaLZ8OifPe4nHvPtvjoNBXr5gHoaw+j8qyQbALCYTVswZkVPRT+1SBSuUC1C4cl6z53nChn+L9DkPDwPCIPLXWBMn09HGpejd1PwbzjBn5F5YkdvRL4/NRzPRGzDxvVY9lkV7+8b9nG4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788647; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Xm0Iw65jO+uKrMUpvtXIdJI78r5gGuJ870elFUF+nDU=; b=l1DrAA94iyA6hQucFdRGXXDV3lbXrDJ3PmEl9ARh9Hh9uTJqW3NXXHuf64S6oer07IiUCyxdB5ElHevPEfchFfTJ87daiOSixFIZ87DPWqn5LHrIKOPq23cT68a6t5g6KQyZgUkb09PXOu3KXXPNUDP/Hg66ZoH/6gqnysW7/vo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1779788647275416.90141580288775; Tue, 26 May 2026 02:44:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319672.1587181 (Exim 4.92) (envelope-from ) id 1wRoKE-0000FJ-UN; Tue, 26 May 2026 09:43:50 +0000 Received: by outflank-mailman (output) from mailman id 1319672.1587181; Tue, 26 May 2026 09:43:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKE-0000Ey-KH; Tue, 26 May 2026 09:43:50 +0000 Received: by outflank-mailman (input) for mailman id 1319672; Tue, 26 May 2026 09:43:49 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKD-00005J-Dz for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:49 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoKC-002r8y-PT for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:48 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b51-5cb7-0a2a0a5109dd-0a2a450ad64c-10 for ; Tue, 26 May 2026 11:43:48 +0200 Received: from [209.85.221.48] (helo=mail-wr1-f48.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b54-56b3-0a2a450a0019-d155dd30e90f-3 for ; Tue, 26 May 2026 11:43:48 +0200 Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-44509921fbcso6603823f8f.3 for ; Tue, 26 May 2026 02:43:48 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:47 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788628; x=1780393428; darn=lists.xenproject.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; bh=Xm0Iw65jO+uKrMUpvtXIdJI78r5gGuJ870elFUF+nDU=; b=npKeDXmavQuZhgcKoefetGO/sP7Zk5ZEJpUSIvz8o7+hxIsCQuGwQoqpe4aj2w9Jbt /z3alHI1ijuNZglNbfU9TGopFyWzK/+q3zhipKNdLgU7OISsfwJ1AgvWjrU0rVV0WdH4 MI+UjXBffqHEZYvwny0mToxjUb6m1ahI5vT1R7Hvjrs4LqNKmYr+W6MrM4jttZo8eqMo sd20VrCtLUkgT7OTvpmGR+rSFxm9UfcdyF+RiXBgWQ4ff5uyoR11ac+6C+5YJmjvLLIY QhL38OuQflu2YRsBgkCFvT8W9gqycIOBXW6ICWRWBhYfFiSCtOdjOY75bWetMfC1FMrb ZLZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788628; x=1780393428; 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; bh=Xm0Iw65jO+uKrMUpvtXIdJI78r5gGuJ870elFUF+nDU=; b=cXiQ2/lUYpFlswwclt5MSnro6oSUHJ+neubSCpnvz0Wj5wntnkQCi2yvPOqdCZuari hRoTCx1Cwot1kq454yWIw+eopKxnykGZQ/fiEvyZpkh2l/0mY5XYcNErKyhc50p6Za4l GjTUjse/UNnFwM4ngFpMbn/TmlM+Jyevm2Acgtv6UVGlwLWLhqaXOyAhZFTBHmle0Hvm y63+gJD8qI3wqyT3zqaiS14oy8QZ0ggG2dOAUPjsm8fz/6d8O6WdFS9YZQl+qD1ZFq5V NMR7AEtCLBKpXyDcl864n8oudvWl+v1lfJTBlU1DmnoJWUJQ1L4GDuQ/kpZQPXqEP/Q5 4xIg== X-Gm-Message-State: AOJu0YyQ4gZGzK1GZR7kQEwruIjxD1NKLkfUp0sQyrGCh6EpNqxBZJbr NOSHyWmWqGdY10zSY9Q04aPEJMmE/c5NBfBSEww6jBMLNFB6pyBlCYwUVPsHUCG2 X-Gm-Gg: Acq92OHXuoKpEq1kQwHvFupbApnNrF26s0hL8ZFeKgtN6pgvJOaEb7GGqQBDWwLHT3m zB3t12dT8D2FBeuhVRwdzpNiB3SoRGwS1RsfXRmpIHAsf42b5K3vmfdli/1RZZH3B067CDY12qG qVo5wdo+JZScs+V82TU5zQ9ZXfqf/RPQRI8Su6X7RVm0u8DTY3y4zeZysuud9qTbKSzEfyUVuvM FdLycfEVAyFvyqnOZFlkllIdhN54KuxQjM2AK5nGVJ0QOluZHQBjrZdaSvuX4X96jdf6/Cgo3zE DTdi3OZmrOfFqUtq9eDxaoLqmIKf6ecOATr5JO7q/QboiCs2cQQLBE/iHzR7zUGgfIUpPCaV1yI JPerwcOiY20pWGVRc1Gr5z78JiHVeZzQyeUATJZfXLd9yWidmdtkaNENtW4+y0cMNuXXpyfM2Xh LZdCS265AE/vmKdRf418mWJkcIq7YWWOVV3BNRr1vPlRwE6NyNy5A7+sGvBjCBCYeimNaNqzbkm Mz4K6Igw19puCGORnKZq302rA== X-Received: by 2002:a5d:59c5:0:b0:43c:ffee:ee94 with SMTP id ffacd0b85a97d-45eb368124fmr28746571f8f.11.1779788628043; Tue, 26 May 2026 02:43:48 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v3 7/9] libs/guest: avoids using 2 indexes Date: Tue, 26 May 2026 10:43:18 +0100 Message-ID: <20260526094324.12286-8-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1779788628-7D5868B7-F1F96C12/0/0 X-purgate-type: clean X-purgate-size: 2688 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788647932158500 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Simplify code, after the first scan of the various arrays we don't need to keep original types and PFNs but only the ones having data. Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_restore.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index e148fc594a73..fb46142d8729 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -260,9 +260,7 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, int *map_errs =3D malloc(count * sizeof(*map_errs)); int rc; void *mapping =3D NULL, *guest_page =3D NULL; - unsigned int i, /* i indexes the pfns from the record. */ - j, /* j indexes the subset of pfns we decide to map. */ - nr_pages =3D 0; + unsigned nr_pages; =20 if ( !mfns || !map_errs ) { @@ -279,12 +277,18 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, goto err; } =20 - for ( i =3D 0; i < count; ++i ) + nr_pages =3D 0; + for ( unsigned i =3D 0; i < count; ++i ) { ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); =20 - if ( page_type_has_stream_data(types[i]) ) - mfns[nr_pages++] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); + if ( !page_type_has_stream_data(types[i]) ) + continue; + + mfns[nr_pages] =3D ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); + pfns[nr_pages] =3D pfns[i]; + types[nr_pages] =3D types[i]; + nr_pages++; } =20 /* Nothing to do? */ @@ -302,16 +306,13 @@ static int process_page_data(struct xc_sr_context *ct= x, unsigned int count, goto err; } =20 - for ( i =3D 0, j =3D 0; i < count; ++i ) + for ( unsigned i =3D 0; i < nr_pages; ++i ) { - if ( !page_type_has_stream_data(types[i]) ) - continue; - - if ( map_errs[j] ) + if ( map_errs[i] ) { rc =3D -1; ERROR("Mapping pfn %#"PRIpfn" (mfn %#"PRIpfn", type %#"PRIx32"= ) failed with %d", - pfns[i], mfns[j], types[i], map_errs[j]); + pfns[i], mfns[i], types[i], map_errs[i]); goto err; } =20 @@ -337,7 +338,6 @@ static int process_page_data(struct xc_sr_context *ctx,= unsigned int count, memcpy(guest_page, page_data, PAGE_SIZE); } =20 - ++j; guest_page +=3D PAGE_SIZE; page_data +=3D PAGE_SIZE; } --=20 2.54.0 From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788659; cv=none; d=zohomail.com; s=zohoarc; b=MaX33EUQvuDT32ZmDTYd3C1jh4Pi8ukI1t+YNqxsq/bD5En9mzrM6sMaFF8366c0RqyRotnvNl00MiG/d3EfRLVAXbCy6cx0QN9hhz7yIrQw6T+V2sde1jxYrCPW6n8lyxj8wMsumX7ifTFQRTjzIuPEIPr0kodRPIC5iCvYSjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788659; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BYgK6iR894mAqSXBIRezXknZ0unnX59SBgdgZD/Yaro=; b=dCIvQ/fts3W9J/CHu4um1plY3q2WijtEZpgJyYW6wREYCIlg67tutejfOfUKIoQW7zJVi2KzrwENB8xiyPZdanBsLH1POghEK13+knZs86q4IgEOLdOi+eRiEPQRdjA/p5KSqLAQyqg45lHEM9t4DxevaXSQDPb4XfH7al2cn1k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 177978865980088.84192722423688; Tue, 26 May 2026 02:44:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319674.1587194 (Exim 4.92) (envelope-from ) id 1wRoKH-0000jw-1r; Tue, 26 May 2026 09:43:53 +0000 Received: by outflank-mailman (output) from mailman id 1319674.1587194; Tue, 26 May 2026 09:43:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKG-0000jU-Tv; Tue, 26 May 2026 09:43:52 +0000 Received: by outflank-mailman (input) for mailman id 1319674; Tue, 26 May 2026 09:43:50 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKE-0000B5-H6 for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:50 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoKD-002r8y-TG for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:49 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b51-5cb7-0a2a0a5109dd-0a2a450ad64c-20 for ; Tue, 26 May 2026 11:43:49 +0200 Received: from [209.85.128.41] (helo=mail-wm1-f41.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b55-56b3-0a2a450a0019-d1558029c583-3 for ; Tue, 26 May 2026 11:43:49 +0200 Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-49048e043e5so28146625e9.1 for ; Tue, 26 May 2026 02:43:49 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:48 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788629; x=1780393429; darn=lists.xenproject.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; bh=BYgK6iR894mAqSXBIRezXknZ0unnX59SBgdgZD/Yaro=; b=Ytk/LwkWOnfwfd6J3cyH5tWUfbV9ck4QJJ4s3x1gVeaIZTGYN8QJTnGz0fF8hOa79b 902y+Oia6tMDqid2HBa6VbIyQZoQRHIgEFOwLs83BgwvNmR83mb17xKlEPBgmlythuiX NFD6fTEMyVQPXuOEpMy8LQZsBn3AwuGJ8ZVTJQeAgfgfJR1Q6oUw1AkFHSJmTed7OH0+ ZGJk2GDIWdrqIrESycHNoDLEBQ5zOAR7BAZlg8qQImc+SEgFz5xwOekYIiAfeZCmBXcm Ne/CxYpZIOQ59QpidtRJdnlVz1DFIUj4YzqcqvznWiwkdZYoYGqKE5bkCHF6C+S+NpVw atsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788629; x=1780393429; 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; bh=BYgK6iR894mAqSXBIRezXknZ0unnX59SBgdgZD/Yaro=; b=gbSpOo6I4NMOCnYGOEFCwzb4+OGRX7/Y8yG0rYt4soGHzsUdebc8bjrbWJqpgTjSMI VKkWg4M4YDyLY3MRxdYgYWTajzwdroLyYK6F5Jf+NxSRxUFgCyHJSSp4cO/GzlZ8K3f7 Zzd8I9D/aPcowZT4AAi0k36bgYyHluADgtXhqn5AvinvkMiGb2fFJ3LeCzQsZ45W8vKn 7p+yQRfecW4Sk3e58GSomn3sfRhz/g/9vrl6aVn4mNzN0IEaUBnkAWESuk8mfLaYvT/W 5ID0H643jL6EgiJHHldqfchCNcHK2K42UaMir10GRoGhnnNqtDgEZydsv0LqBsa0+lI6 6abg== X-Gm-Message-State: AOJu0Yyo+Tpp/dIlHydbBgOO8mGxv9rygyirOhC7CBN+0P2kZ9t1HDdk RDRWj5WGV8YuPCneLn7RAqJkwWxkuOcog/lk+mLLJn8/LYLs9FWE3wqqIT+eC+6d X-Gm-Gg: Acq92OECe+USF50uO2hfrt/QzWMeuakTol0p4vxXpV6QYXfoFcQaJv+m7YGLSVbZl5P 14LSan85EocKN8d2NURULWVFQRwTnHLxO+P+zVrEXysfnPrqUIQyujmjjZDLmdYIL2/xk11m6tu RLEzbUujC9npR1Fx88BlFQzefy5c7SMYzN8nT+/en/RaRZwolC58fOAQ+WoUQhwzgoT5Go7r3jp CaN249xH175zbOL796rN8Pwo5lrkfhUR5XPa/Lsubpbl7uqI0+4M87Hv0K1mVledoelHgmoM8h+ 71TuUZYJuO2cgqsDuxahyDi8RYKt66Bb7D95Om44cKdGcPFB/dASwyXLAdSCa146RUNUdtLy1T5 bw71ESaI3paKGtATs24wnCnaodZFFvDmsdLo50F90P1cr2R2z9rfXVBkfr7HEZI5IJzE6S8Ilru BD2Kn3ZDfz+rJ14BQoDqbCT9jmgIufLqF+qQHNuh+BkC4s6E9rncEaWw676abZNtG5J9yObFBz0 rMeQ6YxfnZIgRWmDMJkH5kubw== X-Received: by 2002:a05:6000:40cf:b0:452:273:5cd6 with SMTP id ffacd0b85a97d-45eb367fe78mr31935951f8f.1.1779788629128; Tue, 26 May 2026 02:43:49 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v3 8/9] libs/guest: fill directly iov structure Date: Tue, 26 May 2026 10:43:19 +0100 Message-ID: <20260526094324.12286-9-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1779788629-71F698B7-2100B5B3/0/0 X-purgate-type: clean X-purgate-size: 4540 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788660628154101 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Instead of storing page pointers into an array and lately adding to iov vector add the pages directly to iov to avoid "guest_data" array. Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_common.h | 1 - tools/libs/guest/xg_sr_save.c | 62 ++++++++++++--------------------- 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 77312bae9cf5..797b4d1a7da1 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -215,7 +215,6 @@ struct xc_sr_context_save_buffers xen_pfn_t mfns[MAX_BATCH_SIZE]; xen_pfn_t types[MAX_BATCH_SIZE]; int errors[MAX_BATCH_SIZE]; - void *guest_data[MAX_BATCH_SIZE]; void *local_pages[MAX_BATCH_SIZE]; struct iovec iov[MAX_BATCH_SIZE + 2]; /* headers + data */ uint64_t rec_pfns[MAX_BATCH_SIZE]; diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 7d8055a3f9e8..593268f176a6 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -88,7 +88,6 @@ static int write_batch(struct xc_sr_context *ctx) xc_interface *xch =3D ctx->xch; xen_pfn_t *mfns, *types; void *guest_mapping =3D NULL; - void **guest_data; void **local_pages; int *errors, rc =3D -1; unsigned int i, p, nr_pages =3D 0, nr_pages_mapped =3D 0; @@ -114,9 +113,6 @@ static int write_batch(struct xc_sr_context *ctx) types =3D ctx->save.buffers->types; /* Errors from attempting to map the gfns. */ errors =3D ctx->save.buffers->errors; - /* Pointers to page data to send. Mapped gfns or local allocations. */ - guest_data =3D ctx->save.buffers->guest_data; - memset(guest_data, 0, sizeof(*guest_data) * nr_pfns); /* Pointers to locally allocated pages. Need freeing. */ local_pages =3D ctx->save.buffers->local_pages; memset(local_pages, 0, sizeof(*local_pages) * nr_pfns); @@ -159,6 +155,19 @@ static int write_batch(struct xc_sr_context *ctx) mfns[nr_pages++] =3D mfns[i]; } =20 + hdrs.rec.length =3D sizeof(hdrs.page_data); + hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); + + hdrs.page_data.count =3D nr_pfns; + + iov[0].iov_base =3D &hdrs; + iov[0].iov_len =3D sizeof(hdrs); + + iov[1].iov_base =3D rec_pfns; + iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); + + iovcnt =3D 2; + if ( nr_pages > 0 ) { guest_mapping =3D xenforeignmemory_map( @@ -200,60 +209,33 @@ static int write_batch(struct xc_sr_context *ctx) else goto err; } + else if ( iov[iovcnt-1].iov_base + iov[iovcnt-1].iov_len !=3D = page ) + { + iov[iovcnt].iov_base =3D page; + iov[iovcnt].iov_len =3D PAGE_SIZE; + iovcnt++; + } else - guest_data[i] =3D page; + { + iov[iovcnt-1].iov_len +=3D PAGE_SIZE; + } =20 rc =3D -1; ++p; } } =20 - hdrs.rec.length =3D sizeof(hdrs.page_data); - hdrs.rec.length +=3D nr_pfns * sizeof(*rec_pfns); hdrs.rec.length +=3D nr_pages * PAGE_SIZE; =20 - hdrs.page_data.count =3D nr_pfns; - for ( i =3D 0; i < nr_pfns; ++i ) rec_pfns[i] =3D ((uint64_t)(types[i]) << 32) | ctx->save.batch_pfn= s[i]; =20 - iov[0].iov_base =3D &hdrs; - iov[0].iov_len =3D sizeof(hdrs); - - iov[1].iov_base =3D rec_pfns; - iov[1].iov_len =3D nr_pfns * sizeof(*rec_pfns); - - iovcnt =3D 2; - - if ( nr_pages ) - { - for ( i =3D 0; i < nr_pfns; ++i ) - { - if ( !guest_data[i] ) - continue; - - if ( iov[iovcnt-1].iov_base + iov[iovcnt-1].iov_len !=3D guest= _data[i] ) - { - iov[iovcnt].iov_base =3D guest_data[i]; - iov[iovcnt].iov_len =3D PAGE_SIZE; - iovcnt++; - } - else - { - iov[iovcnt-1].iov_len +=3D PAGE_SIZE; - } - --nr_pages; - } - } - if ( writev_exact(ctx->fd, iov, iovcnt) ) { PERROR("Failed to write page data to stream"); goto err; } =20 - /* Sanity check we have sent all the pages we expected to. */ - assert(nr_pages =3D=3D 0); rc =3D ctx->save.nr_batch_pfns =3D 0; =20 err: --=20 2.54.0 From nobody Sat May 30 11:15:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1779788646; cv=none; d=zohomail.com; s=zohoarc; b=n02tJgMFCBHHUU5ZCowbgBE+akd8fI4Y7YoL31IEgfyvaD/6G0j6Myc64x0QksdhKpCei12KESQmXGg4fkD2zSGuvdj5Jh1AvFvZc0C/BS7rNx/biBl8XNAW/URKnWUA2vOX0Wzg/F5eFyHWdc9IES+NjppBqCZID1Mr1rhBGOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779788646; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=54F7jVLbDw17JTD+SKyHXt9Aa2Yn2dAnayA0OhhrPec=; b=AcqutAvlmDTQ+5Lj7VFREQGyj2ISfyUpRn4Avy9rbWRfZwY95V2BI7UPTERlMXurw7+RL9D55srubTNmuyxSuZfnymlx9Q5IxEpFbc5WSOptKIxC7j2/hogxxV8KKCNR6/tQjnB0OKfB40yr1ykoYVHgxeXIsOzoAkralYZFyyI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1779788646645372.20353243926604; Tue, 26 May 2026 02:44:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1319675.1587199 (Exim 4.92) (envelope-from ) id 1wRoKH-0000om-JU; Tue, 26 May 2026 09:43:53 +0000 Received: by outflank-mailman (output) from mailman id 1319675.1587199; Tue, 26 May 2026 09:43:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKH-0000oA-Cd; Tue, 26 May 2026 09:43:53 +0000 Received: by outflank-mailman (input) for mailman id 1319675; Tue, 26 May 2026 09:43:51 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wRoKF-0000JN-99 for xen-devel@lists.xenproject.org; Tue, 26 May 2026 09:43:51 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wRoKE-00C7nY-LC for xen-devel@lists.xenproject.org; Tue, 26 May 2026 11:43:50 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6a156b54-e002-0a2a0a5209dd-0a2a450396a4-32 for ; Tue, 26 May 2026 11:43:50 +0200 Received: from [209.85.221.54] (helo=mail-wr1-f54.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 6a156b56-672d-0a2a45030019-d155dd36d93b-3 for ; Tue, 26 May 2026 11:43:50 +0200 Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-43fe62837baso6040774f8f.3 for ; Tue, 26 May 2026 02:43:50 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6d70c51sm36522744f8f.36.2026.05.26.02.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 02:43:49 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779788630; x=1780393430; darn=lists.xenproject.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; bh=54F7jVLbDw17JTD+SKyHXt9Aa2Yn2dAnayA0OhhrPec=; b=V2KmXBFYoKq/VlpbqIx8zJ+WaLngZzzW75yTPjnrod4EoC/guQLFSp0jjl7JPiyTrg Vh4ZCKL346SKRzDv8jTxWNyj03yh2O+1K+hi5lLDU5s5ju89ee4qu6V3XSoNpl/ZoH1y 81WukOOiCp5MKh+4bZjsW5WIZo3SwjIHaq6cuArioHsKVo4wtYZ6i3fVBgRyqbyNMsCF QTzIP6eNvko78ZAsdBUZ+Sbdo03QJHLsCWqgAgGXRo6mMQmls8jTLkoLiaeQBpOJ1FKL ETY3Uf+HZZ/hIfjfDLt/wyVT1ykAgpf8GKsDtCRWHFT9OtiqeK8Ra/+O8LnuoUxZcOVv QLfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779788630; x=1780393430; 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; bh=54F7jVLbDw17JTD+SKyHXt9Aa2Yn2dAnayA0OhhrPec=; b=D7EeYBTQfuvArcRzQ6zRHwSL8yY/44hdsuuXe1wS99Efpg4mKYOampcrCwLcWtHdjB amPI0Y31Ypt0tgAV6BwyO6vkKsDMChPPelhIqpZUddKsxyEeBa7YxiReaqnX1OcsKvY9 KC4MCgoe3npTCHOaxu13FPozgUwUTinlMt8durV0FhkUdMCl4sZFKUUrNhO3wVc3ArkY qFtaPXbf8yUslIC9plQ9t6zc2Q8wg/ORzdrgU0GIAfj3/nn/VZKaiGBQ9P9DZhLdewYM KWeN68ngTbE3KfYmHzK2T7UbDIK06TXd7fYsSs4KFe690YcMjIicOqq9FAJE+lVzYEJo /2Gw== X-Gm-Message-State: AOJu0YxVHhD/elu53+y0F/XD4Mx2vPZhcA4kPUmMXm9clViVG8iE0JTf SQZNdvbVnKB2SjlyHE3CNRpiE3uGfLG9hmvpwNcLgaKo9dyekm4GpgypNCrh2i6v X-Gm-Gg: Acq92OFqD+aCOLJ+mH+SLmiKELiQHykVyCIRNdXdRUGo8fTUlV5wjCwTSAKupdcvZVC nGCM7Ij+s3IBnqjH45rPRBVpI5nHJR9UEOy8DOFu4wLqahqOgVBOHH+RjosePk7DH05ojb1+nLi XWNOVmpstRYLHNF3rZmlgFcNxvsbcLuoqSK7Wa8jzviPG7lB2NqWdKesltD177Td+QaXsnScSyG EubSTlf3l0IIkPdVoiV4+3aZb+6Tj723D+ePdgx4fbKljuVkyC4cDDiikjL9EuLqIz9EaHGiM4y OPud70ThLzqA6v2l9cek6r0JBGBZz5jdgkh5wUDdc4hwk9OZtlcPgn22FlfoErqgLh1e86Mgr0d zXBRnYoPLOKs7fWhlEfINvkAU58IPdyuezqQKSbjx+nkZulApktrvTnLxxq4gEriOIwBhGOyLMI 3psZiZZ3bxS9qxZECcDwaXkUXmjXRZUssckPOsNWz8GS/70u11f/te83Kx0DrJ95SG1D/U2x8Fo kPIYhXeMhlrPc/ZdvMl+xZsXoEVU4bz2kfmU8WQq4ZkCzk= X-Received: by 2002:a05:6000:2508:b0:45e:65a3:badf with SMTP id ffacd0b85a97d-45eb39e1f43mr31281958f8f.21.1779788629960; Tue, 26 May 2026 02:43:49 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Teddy Astie , Anthony PERARD , Juergen Gross Subject: [PATCH v3 9/9] libs/ctrl: Allows writev_exact to change iov array Date: Tue, 26 May 2026 10:43:20 +0100 Message-ID: <20260526094324.12286-10-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526094324.12286-1-frediano.ziglio@cloud.com> References: <20260526094324.12286-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-33051d/1779788630-41D91938-12F8B3E5/0/0 X-purgate-type: clean X-purgate-size: 3234 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1779788648459154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Avoid having to allocate and copy the array if a partial write happens. The implementation in tools/libs/store/xs.c already use this signature and method. Signed-off-by: Frediano Ziglio -- Changes since v2: - change prefix in subject. --- tools/libs/ctrl/xc_private.c | 26 +++++--------------------- tools/libs/ctrl/xc_private.h | 2 +- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c index bb0f81d6f389..946fc307aabd 100644 --- a/tools/libs/ctrl/xc_private.c +++ b/tools/libs/ctrl/xc_private.c @@ -635,7 +635,7 @@ int write_exact(int fd, const void *data, size_t size) /* * MiniOS's libc doesn't know about writev(). Implement it as multiple wri= te()s. */ -int writev_exact(int fd, const struct iovec *iov, int iovcnt) +int writev_exact(int fd, struct iovec *iov, int iovcnt) { int rc, i; =20 @@ -649,9 +649,8 @@ int writev_exact(int fd, const struct iovec *iov, int i= ovcnt) return 0; } #else -int writev_exact(int fd, const struct iovec *iov, int iovcnt) +int writev_exact(int fd, struct iovec *iov, int iovcnt) { - struct iovec *local_iov =3D NULL; int rc =3D 0, iov_idx =3D 0, saved_errno =3D 0; ssize_t len; =20 @@ -686,23 +685,9 @@ int writev_exact(int fd, const struct iovec *iov, int = iovcnt) len -=3D iov[iov_idx++].iov_len; else { - /* Partial write of iov[iov_idx]. Copy iov so we can adjust - * element iov_idx and resubmit the rest. */ - if ( !local_iov ) - { - local_iov =3D malloc(iovcnt * sizeof(*iov)); - if ( !local_iov ) - { - saved_errno =3D ENOMEM; - rc =3D -1; - goto out; - } - - iov =3D memcpy(local_iov, iov, iovcnt * sizeof(*iov)); - } - - local_iov[iov_idx].iov_base +=3D len; - local_iov[iov_idx].iov_len -=3D len; + /* Partial write of iov[iov_idx]. */ + iov[iov_idx].iov_base +=3D len; + iov[iov_idx].iov_len -=3D len; break; } } @@ -711,7 +696,6 @@ int writev_exact(int fd, const struct iovec *iov, int i= ovcnt) saved_errno =3D 0; =20 out: - free(local_iov); errno =3D saved_errno; return rc; } diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h index b5892ae8dc1e..3af996e9002e 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -383,7 +383,7 @@ int xc_flush_mmu_updates(xc_interface *xch, struct xc_m= mu *mmu); /* Return 0 on success; -1 on error setting errno. */ int read_exact(int fd, void *data, size_t size); /* EOF =3D> -1, errno=3D0= */ int write_exact(int fd, const void *data, size_t size); -int writev_exact(int fd, const struct iovec *iov, int iovcnt); +int writev_exact(int fd, struct iovec *iov, int iovcnt); =20 int xc_ffs8(uint8_t x); int xc_ffs16(uint16_t x); --=20 2.54.0