From nobody Sun May 3 14:20:52 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=1777287281; cv=none; d=zohomail.com; s=zohoarc; b=O/zX4M953ePOmvLCw4rYrWEnKy6p2rTzksDTFBl67lTLR3K49bPhYWTkKVepEKFelRJf0IQJBDnlFm897fTpYZOf0xfXQv5kHW/4z4/JEULE1PU1biFUyn0LiFL7jQNJJidTmpF+TpxFLyjStT9GZJxrcZ5HmN0UYCpPXQWCWtg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777287281; 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=mQuJg18CTxOpb+CiZpRsAxRqnG2FkStLAfpVtU9HpvE=; b=m42n+ISnqY6xc0ifovn8XpQv5JKbsB0YJzeb5z33qBs11QAHS9rT9hKWvcgFZrEbPVB6vYw1hJBCpHjS8iaZ0fvZggyopul3mN7PG2brTCsn3ukSaptOPuBCow79G1NfsspyGZCXHd7YQUkUOXrCW9WasCWmPtcp9/dvX11ZcUo= 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 1777287281591511.6885202514744; Mon, 27 Apr 2026 03:54:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1294777.1571476 (Exim 4.92) (envelope-from ) id 1wHJbI-0005ju-CO; Mon, 27 Apr 2026 10:54:04 +0000 Received: by outflank-mailman (output) from mailman id 1294777.1571476; Mon, 27 Apr 2026 10:54:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbI-0005jn-9h; Mon, 27 Apr 2026 10:54:04 +0000 Received: by outflank-mailman (input) for mailman id 1294777; Mon, 27 Apr 2026 10:54:03 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbH-0005d1-M0 for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 10:54:03 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wHJbH-004Inu-2U for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 12:54:03 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ef4047-5cb7-0a2a0a5109dd-0a2a4506ab9a-28 for ; Mon, 27 Apr 2026 12:54:03 +0200 Received: from [209.85.128.49] (helo=mail-wm1-f49.google.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ef404a-7371-0a2a45060019-d1558031b8af-3 for ; Mon, 27 Apr 2026 12:54:02 +0200 Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-488a88aeec9so125694715e9.2 for ; Mon, 27 Apr 2026 03:54:02 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a5c4b9e8dsm116133355e9.7.2026.04.27.03.54.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:54:00 -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=1777287242; x=1777892042; 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=mQuJg18CTxOpb+CiZpRsAxRqnG2FkStLAfpVtU9HpvE=; b=kTtT7Lziv85cvWbNwlixmOigtONfppaa1mm/AKF+AG+GL55f6ynqmHqxwbQZKgPPEn hxHdO2TRN5RveSyh5dKd5GVRRcCU1wruTL+PuVmt1UkSdAZ/6NweaSzT86LnFH0tQ3O5 cc0aBuq4Spx6hwLNlVnXxLiek55WgnV8lsuB4GoeBkKrhvy1lBn4LpvBjqt1Zb6Eh+Sk fSJeoVy6tFn9RIEmDnblQ3h7iFEE54UZzl/wRdl1xp2QIjmTFv3XUFjiyU+p5S7ZCnKc R+aaR4r5flfGbNHc3Z1qbIVWVmVaUcIS50z9lt/QiUGSLedQqbDAM6ODfXhqnGy27GNX VfuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777287242; x=1777892042; 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=mQuJg18CTxOpb+CiZpRsAxRqnG2FkStLAfpVtU9HpvE=; b=qlYkYtHn5lu5Oyrze2xg2ztKtz87hKoykO8CHl5sOXFIgNuoGpWbibUwPKv3qSAkU2 CT+whEmAmNlmDnEBq+wXqVNrqnCYLpKcjEYvmXTS+fULl3BwXm200ZD3v/IefYxKj5vB dWxaYkHmeRwiAElBJ3Exehfmrlw5zGIKO9/qFEaUEyBlUb3NXToEnp9e3g43HjIajGVo F3MWLiP9EWG77GStGWVIcb2OC5oxuCPqiDjYYOKu8AlyHAvkKvYrM1mrtEQ4yfnjRNNi B32UYk3Huzs/uKPwRd73tdbdtViA+dYdbnisNgmtsLN635/hiuG2Max5F1ugsr0QJ+xb BRoQ== X-Gm-Message-State: AOJu0Yyqj4aVPx1FUqR0lUVgCo1T4ixuXxQZ9f3NuLIPJjMDK7u5dDXE 00ynYx7y2N0e9lu4CgjNgfvbGbQYqaMiZ65I15Bz1RAmE8dwgaWIBkImCsUP+z+8 X-Gm-Gg: AeBDiev+4w/pBX0HJuSst1DXOBkmxzKmxY10IDq9u5ebBnohw6uXyeePDJvM8mxoC/D YooHiYfS0D3GoWHUrlsjI+kPaMgW1/W08Zem1Uct3GlIuNSCI4tQfo7dFKJVLw+c2cuMp3AyY1m xomX7mgczv7wl6iyeid4arQEEWbewIcR9SjvhuAdpyH3Z216KiX8zDbx2RECFQbJp5b12RFr+6a EUhBcnHK/aWs8EAjpW1KgDyrkc5luWs7XB5YmiLWNt1nwRaTdnI4rv3sUWLvB6wUKDDDOub64kH arNA0KzwyNxYIiD0NrBj4xZm1lehiLUVTH6eC7sr+fZUGd9CqEwwwTT+ygSQk124zkIoFD8dr3d t3JII9in5q6S1M3rT5PlNs3Sn/zwy3zkVw2y+fVR6HakZDjaEiYkn82J4/rE///v/G5+gC+9Y1a EY1wCvh66v2xJV5f9qaXzTUMbg3OnkhSTmkW3J6YYGOarNOuL2+C1AqQxWEKBNP9A//YYwSEXWD M6o X-Received: by 2002:a05:600c:a086:b0:48a:568f:ae82 with SMTP id 5b1f17b1804b1-48a568fb009mr371461725e9.10.1777287241913; Mon, 27 Apr 2026 03:54:01 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross Subject: [PATCH v2 1/7] xenguest: Reduce number of parts in write_split_record Date: Mon, 27 Apr 2026 11:53:26 +0100 Message-ID: <20260427105338.99792-2-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427105338.99792-1-frediano.ziglio@cloud.com> References: <20260427105338.99792-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-16d1c6/1777287242-CFB7DD75-FEAE29A2/0/0 X-purgate-type: clean X-purgate-size: 1580 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1777287282805158500 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 --- 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.53.0 From nobody Sun May 3 14:20:52 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=1777287272; cv=none; d=zohomail.com; s=zohoarc; b=PPyfiXx14NHwDxTURL3E5WZltrSfEBes06JmZsJ9VXCM8lo8CDws7BnMKHcONWI45OLfVfkYtEKaY9xyk2BFgXcZP7FzsLyDbdwWI+ejQn75rzmOwxnVZjFDSY+eRveRCiVA0a/SM3giC9QJ0ucM0deDr31fgRlqbiFGa4Gy88g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777287272; 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=A5ou0MaWeF1QaqgGjfxneV8ESfLfmJPSRFjrAyNPQHE=; b=S4kyj/q298BeVFPC0L+BI1pqXo9imXTY0HwGWG/fmGBbtuqVI5dFeGc0qYJ24XQij9uUY65rJvDIuZYM1nPCtXJB9uPDQZkGz1cvcyEVYzqcxXXMQWDeudZev2CCfpThPV3so6Ma19xii1lEBguN2rBHO08VCUNGiawYpCU4G8U= 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 1777287272263840.9984893037723; Mon, 27 Apr 2026 03:54:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1294778.1571486 (Exim 4.92) (envelope-from ) id 1wHJbK-0005xG-Id; Mon, 27 Apr 2026 10:54:06 +0000 Received: by outflank-mailman (output) from mailman id 1294778.1571486; Mon, 27 Apr 2026 10:54:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbK-0005x7-Fv; Mon, 27 Apr 2026 10:54:06 +0000 Received: by outflank-mailman (input) for mailman id 1294778; Mon, 27 Apr 2026 10:54:05 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbJ-0005sG-28 for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 10:54:05 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wHJbI-00FJ4k-FM for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 12:54:04 +0200 Received: from [10.42.69.4] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ef4034-2eae-0a2a0a5409dd-0a2a4504918c-46 for ; Mon, 27 Apr 2026 12:54:04 +0200 Received: from [209.85.128.45] (helo=mail-wm1-f45.google.com) by tlsNG-ebf023.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ef404c-1dec-0a2a45040019-d155802dd452-3 for ; Mon, 27 Apr 2026 12:54:04 +0200 Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4852a9c6309so92918585e9.0 for ; Mon, 27 Apr 2026 03:54:04 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a5c4b9e8dsm116133355e9.7.2026.04.27.03.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:54:03 -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=1777287244; x=1777892044; 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=A5ou0MaWeF1QaqgGjfxneV8ESfLfmJPSRFjrAyNPQHE=; b=IeEE8Pr3Xk3o/Aca+3DeBcJAuoa4/UJRsw+hETocJYULKwT5EH5uCUhgcf7XYIF/rk 06OlGSusuJ3gv4eeQJzfUaCR8vqra+3Yt4GDHgvS3A1cSaaK4b5D8hAtjmEOj2josjsI VDemOfwPZ3YJ3KaNEY6Csiv0ls3tJGhZPlm3TEdLIj/lQJQucaazFOLUkmL6cjhki+Qi r01DFfchQeFcGdsS2iTqMb2oY+X2z0dBIftEaIkVrxBpFgcpJz2AFpOwcrO7Ij9PA2pW Cn94CroDBx76kenrGWHXIe1WL4T7zqJ3NX/7UMqhcydAU6ZoGLEBW+qRO8+Z6IYeuLHx QWWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777287244; x=1777892044; 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=A5ou0MaWeF1QaqgGjfxneV8ESfLfmJPSRFjrAyNPQHE=; b=apbm9Wa5dFyno7UZtxk8ttgLuH67MJzNJE2irTf4klLpuOWQiRQ948gD2XLzrog1/z iEnYWdd2+ZiIqmIw25/xLXGZj+xL1Cu8kncsv+Z6DlESwYUDp2EzHdTtzaOI54j6fhCg 1tbetqTFoN6WuOJlgZFHW1rBqX0Su4kzr6OgfCqZpe455CWZoriLwt8lQAJh10NpnJW0 yxIYn0jNxhu2mviWLEhTprc/Tdpt4hsaMi17rN41BZn/dJrV48xeYqKy8tYLKZ4sjYUv Z/niJU04dkSwaIA4UVAl59lfcxoacSdPqIJpcvbfL3+8pO+f8ZQhavdTakYb9mpKg182 iZbA== X-Gm-Message-State: AOJu0Yxe49nnvK9hIyMNMQ1xHceCvoD+MmGArQeTgGthJ3j5zI7OJ010 4VoqaWjAwRyXVYxhGAbfN7dmDCnirWSMk+3eYtcDM0oGFNR+gJWNFz99uNURe8A8 X-Gm-Gg: AeBDies3GIORC4W/kxz9WWFbafpNZIQNbjrlKK0rMfPnRAsNC2DytECcX6YOILbbO8X ZVkKBROkVlvBCGBpnExqeBi9HVuAE46ndqxRydb7vScHLFHF2M0ESJiwfEu5FXFbpj42oMKSIgl ZHTfHqc6Y+S6PEwF1kD0E+M5S9CJkeMrOZoCXQ+4fb0IX30KW5ck+5uX9F5D2qrRVk04vkU3EQ0 lHfN3VR43iPvBBwXm01omuLz/IU1tuaPaxPhDF2/Hv62cJCBDANgVQXLDKS4iADFfuTqnq/qIWA XWQn7ajjydBkj0ITYXup0hC46irPhvtfdQQ27Qo3u9vHdBzjZ3P4tiSgOeZIfAxIsa0I6sD0GIF lB76QxG56vUnQHcl18bsx7NqKubu+ZKXwENPGSCL+Z3V9Iawjt6spEf1EN2juSvEoBIcYko4imw 6Khy3TLj9tNwaWOjy1xFjzilsLyDP9ym/jvPaDjTT3w/DUuq5Vg96G7Jn2eYgMOcKZRImi+dAFq d6U X-Received: by 2002:a05:600c:46cb:b0:488:a723:ea53 with SMTP id 5b1f17b1804b1-488fb744fbemr610461055e9.7.1777287243489; Mon, 27 Apr 2026 03:54:03 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross Subject: [PATCH v2 2/7] xenguest: Reduce number of I/O vectors in write_batch Date: Mon, 27 Apr 2026 11:53:27 +0100 Message-ID: <20260427105338.99792-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427105338.99792-1-frediano.ziglio@cloud.com> References: <20260427105338.99792-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-ebf023/1777287244-32E743FF-D0655396/0/0 X-purgate-type: clean X-purgate-size: 2573 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1777287274284154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Small optimization. Reduce number of pieces passed to writev. Signed-off-by: Frediano Ziglio --- 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.53.0 From nobody Sun May 3 14:20:52 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=1777287275; cv=none; d=zohomail.com; s=zohoarc; b=A57+oLf8YrYRB4gjoSQeD/DIJNcGFDZBKC5pe0Yzv+7V66UOu1aW1VZcBf3BZ9HsJbGOkjQGp7YcI4OpKhYIWJuVSekYr1wfzQvbU10IdVAGRDRJ8cIOKnBxkOHbeXhdkiKulITttkGQQlk/cVCf4e9ZGLJ1TtJr7PhAw6JnxPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777287275; 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=bvJdGnq8cUcIRKsRqa+Ot2JNRA4/ZQKz59vK5GFR3u4=; b=Kt54cZswWG18VFTURdrSS+pCFkqJKYywN9BnnkHbA/EWtNHFESL2a1BdKZPauYj7HovYcRktQueuN4g2nUNpyxN4reheDNn740J1Dfc0btVJZ1zXOu14QEzoJNLRk3bWOADsz8u7itSOlg83WOhI5hkCSbzNjL4618mt2P9S4Kg= 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 1777287275429658.6751755593617; Mon, 27 Apr 2026 03:54:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1294779.1571491 (Exim 4.92) (envelope-from ) id 1wHJbK-000609-SA; Mon, 27 Apr 2026 10:54:06 +0000 Received: by outflank-mailman (output) from mailman id 1294779.1571491; Mon, 27 Apr 2026 10:54:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbK-0005zD-ND; Mon, 27 Apr 2026 10:54:06 +0000 Received: by outflank-mailman (input) for mailman id 1294779; Mon, 27 Apr 2026 10:54:05 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbJ-0005wq-QX for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 10:54:05 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wHJbJ-00C4TO-7F for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 12:54:05 +0200 Received: from [10.42.69.12] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ef404b-bab6-0a2a0a5309dd-0a2a450c96ba-12 for ; Mon, 27 Apr 2026 12:54:05 +0200 Received: from [209.85.128.48] (helo=mail-wm1-f48.google.com) by tlsNG-d25034.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ef404d-62f1-0a2a450c0019-d1558030a430-3 for ; Mon, 27 Apr 2026 12:54:05 +0200 Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4891f625344so90080665e9.0 for ; Mon, 27 Apr 2026 03:54:05 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a5c4b9e8dsm116133355e9.7.2026.04.27.03.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:54:03 -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=1777287244; x=1777892044; 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=bvJdGnq8cUcIRKsRqa+Ot2JNRA4/ZQKz59vK5GFR3u4=; b=fEyvEUkJ3Ov/tyWaEjHQQQ/u9TSJ/kZ1W6ToR1i4kCXT9rWkgeenmDOVik2dxjE3js rcJ0+latap+jmHQLajsbFcxQFCaHHumVBgmYVO2b0q0mXHMjmtvFwyfdv1vLLmXtbXJv IbLvaE1Fl82/fygodiqZMjZ551oaeQlxrbc3QLv1JNaoOdt16vUhfacJzv3OUkbeDLBb pZwOiWKrpAHnygPqKsesTMH4h6pgVxPXaCna1N+yYOOd4WOW8HsKQvPYqck5wGAncQTl xmwlHrgSEMoLMbnS1NBZbYCRPe7mperAbQzSGLrgyGz6ZSAQrm6n4LS1xyKLHb9UeCwJ OfFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777287244; x=1777892044; 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=bvJdGnq8cUcIRKsRqa+Ot2JNRA4/ZQKz59vK5GFR3u4=; b=DdavYh2khl4qwl6YB5aiNeFNQRxOhlB0l1HQw2sW9zkQl7EFeba9A2gDmCDTKxYhPn d3OqR2IQ6gAxOKxzKhW10SLnZcPMpaMsudM8zWQExuFkDbyiQXT2kFBgUwWjzgx5OEw6 pO3Hjk1wxxqmqqf+OCcRbhYcakt96hMpnzmk8DN92Wf7WUu14XCup15/2ikHpR9g/Xio hgmB7zcWnEgg1s6OGFfXaERMBJIKSdQ4ZSjmgiqqKNpSV++o4vhfwHaSKdA7wG55QYcc 5cUyWTnJGnIDCyuOjvMI9jc6Yi38u9kTyU19WCKyC1rXPKmieRANqdLVzufcpihVVcCh Qv3g== X-Gm-Message-State: AOJu0Yy3m8tTwTR06DyuzSEurUe9+SX+E26zkSQmAqGjR0FVI9lfDpw8 P4XXMhSoxYoF2/rjZ3cl1FZqejPWImn6yE/k1qxjfqvBKWEPt4m7NpzjknWYZ+3T X-Gm-Gg: AeBDietfPO5XVrmUqeatZxynPiTGhJRkXHgeLTvMnyTR4fc6cpLai+xTspRZDQDWSCh FX2IPcY3g2ku3U1VGjGoBE2v2mQ+UD9Xfrs4fAgjB8Rxyba00plA0P+ioK+I0CZHCZwC0PZGArN ZFLcmI6M8tHLBwNQIZbFDHywmj1nq92wTS+7yYnzmZ9Abbp3RgmrzzyTz8W4moHUHpiBMysTHzP S2TaTfT4jUAfO/nVWcLaQwC37KAHxp48OM3CYlHVB5IAg2Vsxif6NHHMjKF0t6sxdfOLgTZ2cdy m1ixylK62C+Wb/khCZ6jB0V170eR3f6SGrUSkD57EobYwZ0ryDkH6dXyba4SM8KO/VR83NvcIor ib6N33Iysx4tVdJd0hmcUQTpBNESyAH+LsHDYpMDxuRLMt4I0LNBpNCM/N1Mkzwq7mQ7G6Va/qJ zlvG9sZrjLGogKjttQA3jm/UUUVYx7m8h7ts3MJu9Qn5QVsahKaVBAAtJawd0r3qJZw4PX7B1NS YZT X-Received: by 2002:a05:600c:870e:b0:488:aa33:dc8f with SMTP id 5b1f17b1804b1-488fb84ffb8mr571290555e9.0.1777287244170; Mon, 27 Apr 2026 03:54:04 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross Subject: [PATCH v2 3/7] xenguest: Allows writev_exact to change iov array Date: Mon, 27 Apr 2026 11:53:28 +0100 Message-ID: <20260427105338.99792-4-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427105338.99792-1-frediano.ziglio@cloud.com> References: <20260427105338.99792-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-d25034/1777287245-6F57FCF5-7DF79E61/0/0 X-purgate-type: clean X-purgate-size: 3182 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1777287276866158501 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 --- 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.53.0 From nobody Sun May 3 14:20:52 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=1777287278; cv=none; d=zohomail.com; s=zohoarc; b=AgjYk/vY9F69ZniU+d0UQDPnAK4Y9fCvftKg18exTdbdsok6VAUTleI8G03RpQJ6C2zlnI1kJJVsylbR2N42FDIxknvrA0g1NZRjkra8uojCu3YzAowiajbkofFg3OGu4qiqFfQ3G0vFEbhWko2KKW/VtYPth3VXm1uzXfLlIy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777287278; 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=HGSrCjw2s0wYO4IMNzZTZ7EkL1Z+q5fAlbsu5KPJu08=; b=lWHFTW4d/ItNyMS+htgmrQlpF/bC6amA9T8Y8D5192jZyUl4h6w0+nVc1ONDGAMKE7CCIB2Q4qufnZ5pMdoaPhs3t0/hzLDjNI1kbVKLSYtMJHeyg+9UfdsIC6UpjCcnes6JfMPeSQwiOCq7SRerEMphnvPBw13ZP9cU/Gs+LLI= 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 177728727884752.45503761760165; Mon, 27 Apr 2026 03:54:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1294780.1571503 (Exim 4.92) (envelope-from ) id 1wHJbM-0006P0-83; Mon, 27 Apr 2026 10:54:08 +0000 Received: by outflank-mailman (output) from mailman id 1294780.1571503; Mon, 27 Apr 2026 10:54:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbM-0006Or-2o; Mon, 27 Apr 2026 10:54:08 +0000 Received: by outflank-mailman (input) for mailman id 1294780; Mon, 27 Apr 2026 10:54:06 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbK-0005x2-GK for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 10:54:06 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wHJbJ-00FSse-TO for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 12:54:05 +0200 Received: from [10.42.69.10] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ef404a-e002-0a2a0a5209dd-0a2a450a8756-12 for ; Mon, 27 Apr 2026 12:54:05 +0200 Received: from [209.85.128.53] (helo=mail-wm1-f53.google.com) by tlsNG-4011c0.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ef404d-56b3-0a2a450a0019-d1558035e4fe-3 for ; Mon, 27 Apr 2026 12:54:05 +0200 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-488ad135063so92238245e9.0 for ; Mon, 27 Apr 2026 03:54:05 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a5c4b9e8dsm116133355e9.7.2026.04.27.03.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:54:04 -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=1777287245; x=1777892045; 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=HGSrCjw2s0wYO4IMNzZTZ7EkL1Z+q5fAlbsu5KPJu08=; b=rnGb9HCBGyIo9p1Rx+UbHkcBoRIOdoyddDbPxWzSqUhpmF/ApRNOfgJ07Fog3KLVR7 kj7vLZ1KHXLeRdRhHQPEFZpGUQl0x2ay55H95p2O+5LFTvbEU+IaFtZxBTq5goSKWKM6 z3y4PzD+JRg1zKqu5XeZMsbBKJencerw62SkuDR+cLI309fHKYjuFwK9nGz1+uomleq+ LogEIV3aQ9GwKo2ejf4N9kll6XVGCQyUSu2HZsGeivoP8mtYgtJbOEVHs+mmtAhaRGH+ mlddz8Xi63JwFN32qqipvWhh3F7wdzdHh2ZpYlWe1tLQBSiFpp+gol7ETOGLhBIidpLt 2MKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777287245; x=1777892045; 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=HGSrCjw2s0wYO4IMNzZTZ7EkL1Z+q5fAlbsu5KPJu08=; b=rjueFz9yxUW42AOKAg6U+BDgixNtlSYtG1FDRzr9qDoVGxThqy2GdlwCeTzTwGRZic nsC1RPy1++zjrS1+79rsINDl9q3zwPaWmsEZRUtUGFxhlhY6TQoFXwC0KeIV/EbFrm23 68YSdb210x0adNR4LO7dMNx+DLwUwnziBKoxNQwlxpgZIwkwrTtrHTrAIZ8uie0DKv2E VUpc71+z9quT2cOed2Get5Lu+pbF+f1kpjYr93PWjoksGqZVHRPhQxx3qxd+nTP0op++ a+vKPY7i3sZWDEyneSOLepYZtWTtHwYDHspiIgmEzFGkTyyX+Kih/EENngUXSDL8D4Lx 9RLA== X-Gm-Message-State: AOJu0Yz3HRt4kZZ7Srsqt8kIZ32tgI9NNb5OJkNQwnRk2M/cMT1mlAxx BqoUQZE3Qon20Y64l8EAYKft7753wVPtje83TbvPSxrnFWs2zcNzxpDZda2Xs0yF X-Gm-Gg: AeBDieuv4Hpc9slJeI3qtsfOhXrPX8Oox9uot1P7yK6lRYkTADl2holvJosoXPwF1mZ TvaSi/JcGLX29ueTl/KLfBUZPFRO56wgDy/+EHK/6YSS3FAodtIEVN+M/PkKqufdxkRxNsh6s/X a/5u+rE86EvVo24txzNodhGYcL/ICfKUq7zxBn5JLuXeyf54ZET/4JRugnEUOqbbvKNIVNfgVIF H+nt95lExpvJ6ZLP29C58GVrpZmLpSCcSUtNSNB9G1YoYDfcDwwsGyEh7ZZIRVlOrObxtsbe9cj iAvHdGDz9+d5ygfwX1n6laMG7y95KqT7RRiE++LGUHdtKV8VVfXdCssLCY4nYZiSq8Vi6gkmBZ8 Hg//BhFm5tPzVuJL0QCqEpHJ14Gfg8U7GMtZG3HLC2p5gXZjAnQrw6W3C03qnNqrL3vR07G8THC lQfXY8qpSqHbswa3HRtiCgM9vMldIM4UUEDzot1jKUx2Ngikidqr57t0g+BFU2V8WuXa06NMeKo Tqt X-Received: by 2002:a05:600c:a108:b0:480:69b6:dfed with SMTP id 5b1f17b1804b1-488fb78ba6fmr501796635e9.24.1777287244934; Mon, 27 Apr 2026 03:54:04 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross Subject: [PATCH v2 4/7] xenguest: Reduce number of I/O vectors in write_batch Date: Mon, 27 Apr 2026 11:53:29 +0100 Message-ID: <20260427105338.99792-5-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427105338.99792-1-frediano.ziglio@cloud.com> References: <20260427105338.99792-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-4011c0/1777287245-CDF698B7-73142FAC/0/0 X-purgate-type: clean X-purgate-size: 1276 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1777287280286154100 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 --- 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.53.0 From nobody Sun May 3 14:20:52 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=1777287271; cv=none; d=zohomail.com; s=zohoarc; b=huGDFGfPoztWVKiNU5lwluJHDUPuMQFnrvyDz8QpAlOvAB6UdTdotAZPzocMMEZjqcBOikjM7/EDUCYrxRJP7rbsM5pjFoWvdNzKE0XFA8WihwRw75ZHwqQeqN3TzWaGK+CHIA3NiUYExnGgKLPZV8YYsaY4XyXHAFHfOb3CbpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777287271; 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=p4AU8wNCg4sNfAG0KEAAxVIbQZGrr/jQDed1Iwzn940=; b=nZ8zJAFpMiwqrUkXVU9V8BJfxe+PZT19ZwKJknRiTllRUsEC+T+Mg7fS+gjNakpb2O58atyehP6aJSKlnA7XJcEuYwSqaW9mlo7YVE7kn3X+g2A64T/+qa/oJcKva2nUlIADJ9UBNsaFZGpHG0hU/qrHYePcHbml5GYqdQSA8+0= 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 1777287271858538.5878672523376; Mon, 27 Apr 2026 03:54:31 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1294781.1571509 (Exim 4.92) (envelope-from ) id 1wHJbM-0006SW-Kt; Mon, 27 Apr 2026 10:54:08 +0000 Received: by outflank-mailman (output) from mailman id 1294781.1571509; Mon, 27 Apr 2026 10:54:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbM-0006S6-Cq; Mon, 27 Apr 2026 10:54:08 +0000 Received: by outflank-mailman (input) for mailman id 1294781; Mon, 27 Apr 2026 10:54:07 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbL-0006HQ-OI for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 10:54:07 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wHJbL-004Ir6-5F for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 12:54:07 +0200 Received: from [10.42.69.2] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ef404f-5cb7-0a2a0a5109dd-0a2a4502c732-0 for ; Mon, 27 Apr 2026 12:54:07 +0200 Received: from [209.85.128.46] (helo=mail-wm1-f46.google.com) by tlsNG-720697.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ef404e-af86-0a2a45020019-d155802eb0af-3 for ; Mon, 27 Apr 2026 12:54:07 +0200 Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-483487335c2so98602365e9.2 for ; Mon, 27 Apr 2026 03:54:07 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a5c4b9e8dsm116133355e9.7.2026.04.27.03.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:54:05 -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=1777287246; x=1777892046; 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=p4AU8wNCg4sNfAG0KEAAxVIbQZGrr/jQDed1Iwzn940=; b=LaqaedwaC8kPp/+SJUGO//T/3kYevf1jawMYsUTozvz8hsdITx9KeITmNR6d5LNnvs +fM7H5EnjNsBCZRmKYSaW8SnH6foHEY9RpU7lwv5n+Xi2FI8jrZU6wmVleI3Q2fquxau 6IVkpZgAAdbTzR0oEBaCu923DoNw/66UsurVvfSo8FCubdC0cOKGrmpLblaR3bQc8tcR BVLO8+EH2Us38OpZ/QpxTZcAD7Ri3Eq5khxCo3L65v+vB4/wzjR3UJeU0p6744ZvQ9I8 5LwVRQB0LODWrYeqVz5IMgRErYisn/Ju+FDvy/LUHapPywys0d5MIysAG25i94Ubm3Ja jDrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777287246; x=1777892046; 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=p4AU8wNCg4sNfAG0KEAAxVIbQZGrr/jQDed1Iwzn940=; b=f+6/D2eMjOh2sIIoJnkdW+YkUrsnJP0eUqPhILQsvNSceeexUUWmBpBZKJ1DWeMcG0 gLRRSNcDJ7pWWGTCI7HUnAOlwEoKkcB+nzVA5/HnFHFMAbsMRpbBeOLlZtth7sgEXWJb OoGXEku52subUpadVt78xzi4CQVYV3OdlXng+qoPSA7TP8fP9vaAqrZ4CaBPc1RhkFn+ p6qq6fiH070KUjfjaTlsZmKwa8+TgaB+8oo+X3ANipcF9K+SgBtB6lTnssGgo/DlACYY 6RZYwIzHPRE0PGJ/EcQgkcEeWU5CkO2rRj5+Cpe9c6gilflWj5cP6NemM0weV5wt/8kX AEnQ== X-Gm-Message-State: AOJu0YwAfkhH3Xs1m8/TeGReVpHTJZAU/YqgzYYhb6KUjI2HoxqEDQNr OB4GsDf5NGAV0avWtMWf/ROH9vyVp+q3nYvDnnPNb3bP3E8X0uSCh712mvwLPirf X-Gm-Gg: AeBDieufWazTMn05yMAQrnMjJqxyTMBWQSZoDwl2ISMuosyN4A3sl9l2fChvwbLGxBF 8w5Ue3PVaX6kaadhA9TQZ8BWuMPaKHl1VQuRd16pBR5FPZEymBYxma6wW9mr5394t4QIzb+Ij7Z R+a+Vnm27/mA6pWZFzUjYFnbF9lbjBPINBnCQmN3VpDatr2WjvBoTgILH76CKY8oVU3El8Q4/bb R3qnFcZFb6phf7NWvSHGIlWI4R8G4NCE39lxSikBjm3NZxpY3Bh3ThfUUsQRzwXXO3BhLRmfqj0 LPH6lkesGwB6FY+Oqspw99GGUq0i8cyNwDXLnTMKdttpUbijVQLFV+dQsDT3Pn3oh/frsVRfJQY r3RuisUkqrUsRns74dv7JUnagikai3FcLaPgxwBKeZ2buVGx3pgUmQpyQQFts/tEPsQimcYfMAc SXwfF5KeeuN2AMXCS1aeoRVIVFTJJQIx2fFTUiu6fDpAsRS2RcZ/rLtIaxBRcnh+7b4ZWXc2wO9 BjA X-Received: by 2002:a05:600c:3b9b:b0:489:fec9:a17e with SMTP id 5b1f17b1804b1-489fec9a322mr440855345e9.12.1777287245938; Mon, 27 Apr 2026 03:54:05 -0700 (PDT) From: Frediano Ziglio X-Google-Original-From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross Subject: [PATCH v2 5/7] xenguest: Use a single write_exact in write_headers Date: Mon, 27 Apr 2026 11:53:30 +0100 Message-ID: <20260427105338.99792-6-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427105338.99792-1-frediano.ziglio@cloud.com> References: <20260427105338.99792-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-purgate-ID: tlsNG-720697/1777287247-88CC9161-6415FC08/0/0 X-purgate-type: clean X-purgate-size: 2202 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1777287274339154100 Content-Type: text/plain; charset="utf-8" From: Frediano Ziglio Reduce number of syscalls. Signed-off-by: Frediano Ziglio --- 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.53.0 From nobody Sun May 3 14:20:52 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=1777287280; cv=none; d=zohomail.com; s=zohoarc; b=UeWIrELbRbUZSQ7pPt8/zvaC1yZo2/wReVvN4RO1tG/2pL6j1lcuaxAS8UDoVBLM+84hwLEz+xm9CBKp+IAykgt8ZNHjLC9uEdTTqj6X1U86vkzdYsYuGVm4mPsbsDPZnwBCoB5y/cgFoQ/U+iSAjkfLgGlag7Bvl93+vkAt+VY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777287280; 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=R7dVoM67UHYTIleORpVUCsCVE7I/cjwGpwM6+OI25+A=; b=aPlAEVsMetqxMwohdHIHejkn0uAlX/VC4na5TNaT2mtNHKQ337HuDUi1NfzxTA6WHcVb0+K+a09Yikhr9R4vqAJUDt14CYuBwn4AWPYT9PEU2e4JCwZzzGTqhI7R1RHJEdRGt8LHYvpDwilAxKjPdqmMMBY5yA6ASY++NS1w8NU= 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 1777287280562380.1743986006463; Mon, 27 Apr 2026 03:54:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1294782.1571521 (Exim 4.92) (envelope-from ) id 1wHJbN-0006qz-Qf; Mon, 27 Apr 2026 10:54:09 +0000 Received: by outflank-mailman (output) from mailman id 1294782.1571521; Mon, 27 Apr 2026 10:54:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbN-0006qH-NL; Mon, 27 Apr 2026 10:54:09 +0000 Received: by outflank-mailman (input) for mailman id 1294782; Mon, 27 Apr 2026 10:54:08 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbM-0006Ur-QL for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 10:54:08 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wHJbM-00FJ4k-6s for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 12:54:08 +0200 Received: from [10.42.69.6] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ef404d-2eae-0a2a0a5409dd-0a2a4506aba4-14 for ; Mon, 27 Apr 2026 12:54:08 +0200 Received: from [209.85.128.47] (helo=mail-wm1-f47.google.com) by tlsNG-16d1c6.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ef404f-7371-0a2a45060019-d155802fe164-3 for ; Mon, 27 Apr 2026 12:54:08 +0200 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-488a8ca4aadso140739775e9.3 for ; Mon, 27 Apr 2026 03:54:08 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a5c4b9e8dsm116133355e9.7.2026.04.27.03.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:54:06 -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=1777287247; x=1777892047; 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=R7dVoM67UHYTIleORpVUCsCVE7I/cjwGpwM6+OI25+A=; b=O2rnqAWdKbFKwIeA8WjhUKDFjzkRxAGGse/kuXy5huC4XLI8xHYXYA5A68Ylf5pmXC Txi2k4hxkfUjZpp7T8gT02vZ9FRQWEYyEVjHw83MVZOxNnIHXp0k8Fe3gsA0cJG0UrfQ vn8mmfUWZ+aAZy3PCpdYCLg7okOLvONpE9RF/tB2pQ2RQT9XlWjjUxMAMEkMwqNGlqZe S0894gZhsPJe039MSdvws8LV4mm7ECwn0m9+DosLx9p1V+/WOZJYGIghYAS9yv6viF/w QShD2cWB7LLn1UatQG646lV4iCnmwLOm/595CrRLVvsuaWWLo0hs/JJHAO+hwiiO1lDQ zwXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777287247; x=1777892047; 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=R7dVoM67UHYTIleORpVUCsCVE7I/cjwGpwM6+OI25+A=; b=OUKthnCNA7f4qsJVdjz5l3Y4HS0Zyq0lu6gKzONAaK6Cuf+rWi9FnNPGlfA7nx9pnU Qs5lg1l0KNeJycxYxfByFp22fXn4kBsE1pj0VJgY0vmj/7oeasVeGDMVAr4NFL14NrII zEWqIBUOA6GLVde5H3NK65KVnZRpewTfPsw8n6cEm2PccAhxJGSIBvMrgTzx/fzNo+Q5 RuPl9UO5QYdzTatUVKx/9hhFVINkfMRmZghhesHn3huEsFL4McEv3p5hSB0Yt0WAmitu j/dos2T8AIpGXb5RaFHwClkbh93MBPAwYno4J5l+HgqDROKZMFrBGJcwsbOMiHDdFb20 RmsA== X-Gm-Message-State: AOJu0YxmC0heCEzdG/dd3xc7JN1bLWLtDm0QxVRpviVajll2eiSYkEUO qhxSzZxJ+Tnqbg+nIaHqQFCZRuRBEsjdVUV5BVYfy4WirycyNnaHeYDaGxXebf2/ X-Gm-Gg: AeBDiet4XLjgoFDbX/oGRUMvld+bzVFNlJdHH7bqxHppAHuOcVWCH1vjTQw9LZYpDEU x5x+Uu7ECK+53u4AYIojRKfSeYnQFWLtm+PjZZMn9Ch9IUacVue7jvJ9oSbiCpGAhoRHr8CHH5k PdAMl39ZvnFcCZr2Y6rT+r4HuSgyGbKqb8GS4vMpLF2BNgsnXDBrrKR3uQlwQAwX1/nG6GVg2Ej g1tcMKcxCnTmhkDDGuzA1iqjh5wHKr9GpP6myA2tJ136IGGCcCw9tY9+t+BEAmQGmUcqjuilUQ7 0VhBL4PrsYsRvOjieLGeWe9xsUzL/23T2fzPPnV7Zrz7i6xncwK35acMWZZEGeuBucew4E3gg+m lc1Ni/oOEzyY74sEkUP2yhjzivjS0r9P9dZuTlfKRJ3UR1Mrx2YEL6aN4JkSAhAlEAQtRW35CvK q+FO+08yvwnMNMSc+6ZJBGnn9g5Qi2QO15OB0K8bDI3X5YcxbPzauUiW+sUw6ZFylKVXZtTIVvG emQ X-Received: by 2002:a05:600c:1da1:b0:488:f453:b976 with SMTP id 5b1f17b1804b1-488fb7844c5mr648731355e9.27.1777287246992; Mon, 27 Apr 2026 03:54:06 -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?= , Anthony PERARD , Juergen Gross , Frediano Ziglio Subject: [PATCH v2 6/7] tools/libs/guest: allocate various migration arrays just once Date: Mon, 27 Apr 2026 11:53:31 +0100 Message-ID: <20260427105338.99792-7-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427105338.99792-1-frediano.ziglio@cloud.com> References: <20260427105338.99792-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-16d1c6/1777287248-52974D75-3D252544/0/0 X-purgate-type: clean X-purgate-size: 6409 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1777287282764158500 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 --- 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 ec42b4a9e535..f84c47800098 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -211,6 +211,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; @@ -246,6 +258,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.53.0 From nobody Sun May 3 14:20:52 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=1777287274; cv=none; d=zohomail.com; s=zohoarc; b=b2r4bJZmUtUJjMTNAi7LROxcV/vWB6GIihBP7XU6wfoPpbmzUgHc/cLEQVow4SNzVpmF1Ms4uRBb2ehMukofMnLCtNwNv/xXGnDy96uY0SrgVu2lEQvvMKmBk9zW0jI3UbBApgnU0bTw27cf9Cj8YSebIjvgq5FQoJxlkMsFbno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1777287274; 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=RVb1my+fIjS7vfPgLx5O5td6PHPVJPTF5pUCPqufxWI=; b=c8TPLyakWvOWbHtbatVFKLvqAU3QBYQX97QDFwQcPY4PE6T1Y8OzFnb40/HdVq8SdF2giWM8UG6qBhmB74Suq1nd0LYax1mniHA/8kQzZ7wpjwTUSEctxZLriQJ4FYQxFZnufdtWoNKed0Gi6b1tXFQB6US3/eTd7IFi+VWPadU= 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 1777287274215774.6726591755584; Mon, 27 Apr 2026 03:54:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1294783.1571531 (Exim 4.92) (envelope-from ) id 1wHJbP-00077p-8A; Mon, 27 Apr 2026 10:54:11 +0000 Received: by outflank-mailman (output) from mailman id 1294783.1571531; Mon, 27 Apr 2026 10:54:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbP-00077X-2u; Mon, 27 Apr 2026 10:54:11 +0000 Received: by outflank-mailman (input) for mailman id 1294783; Mon, 27 Apr 2026 10:54:10 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1wHJbN-0006pf-SB for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 10:54:09 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1wHJbN-004Ir6-8B for xen-devel@lists.xenproject.org; Mon, 27 Apr 2026 12:54:09 +0200 Received: from [10.42.69.3] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 69ef4051-5cb7-0a2a0a5109dd-0a2a4503c4b8-0 for ; Mon, 27 Apr 2026 12:54:09 +0200 Received: from [209.85.128.51] (helo=mail-wm1-f51.google.com) by tlsNG-33051d.mxtls.expurgate.net with ESMTPS (eXpurgate 4.56.1) (envelope-from ) id 69ef4051-672d-0a2a45030019-d1558033c86d-3 for ; Mon, 27 Apr 2026 12:54:09 +0200 Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4891e5b9c1fso84864145e9.2 for ; Mon, 27 Apr 2026 03:54:09 -0700 (PDT) Received: from localhost.localdomain (5.116.208.46.dyn.plus.net. [46.208.116.5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a5c4b9e8dsm116133355e9.7.2026.04.27.03.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 03:54:07 -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=1777287248; x=1777892048; 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=RVb1my+fIjS7vfPgLx5O5td6PHPVJPTF5pUCPqufxWI=; b=NXqJPzU1nN0S4FsDtr+l5Puecwi8NQKusSBbu2duK8M7zOcIU/mMc8+I912A5CJwpj kZxVIgXM4uC2clS4KEfQqshT3qpe06dEaBxcHjXogSNQscr2uBf1W6i2zEaEHXovzm1b ZdumLkUHaYJgivL3eiiTNkbsVE+y0de4BKEjlrn88IO1lnCchjUwn4Rh81AFQdIyXX+I zhKKFkC3sOpKxejAL1Xavj1rIWeJNaJ4ITypgTr5ksDg8gyni4X/EYXNtujdtTOFkpz7 KrxmyhZHQa+iY3SctOCkV9P5mcGH2mEdH+Z+eq+dhQ9B/b38hV03P9WU9VvHcniY6mqV a9RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777287248; x=1777892048; 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=RVb1my+fIjS7vfPgLx5O5td6PHPVJPTF5pUCPqufxWI=; b=K8JNr0BC/AOKJFx4fTrC+c5GYeGGXk7eK1qzucc5cm+uMFT1UEqevZPpcPMbdCo6Yi q41Z/nu9lp47PkbNwKN6HLzhl1q7vEZkSHIg8DBeay4EUDJdHC2LK8ytegFeFoLrO95h qlwVSvxyUCPezFt1+gunT6JlO9PV0c0EaJH4vMwomP6x6zKLAmvLSVFz9vBrE9YaArGH +42Gd59RXAe4M6iWR5ACawA3Xi5vNHcCIlPSXTy4ZJiTSmmRRdtmhE6atGzJ6MIYFl6z DlOXDWBT9K77n8vbwNyJjvtmTmJpRkwvKfkxr0faHsjCp1aFlZn3SLBpBp27ErnevzcJ KpKA== X-Gm-Message-State: AOJu0YyNwyYeWO6b+KvuaBjjjoBuaCaKxvYEmQ87gBotWUfiQPd12gj0 FAfj21V0lt9M7v0Nf3uUdymckW6+s+6Rf8bCZc61D2AElQ2raYvqTjYxKg4B1OzC X-Gm-Gg: AeBDieu76PgTa1ihBT9JAccAe1gSqLUxdnFdB84K7i/zW5Ak20vBo/adsRJWDZVEY4n 2mB/nFpLvqExrLszoE6YAURAqAPTIaXHKTLaJLSeNLArOmeSPDs4DtYqb1F+5cKh1AdU9c9NLsz hTNo9KDZs7jKpm06XE/RIOrMmcXdi9AjhYAihDpC2kU8SACjjN0ZRjFqQ4RI2+kNpQ603KzTe// 9f3N4dG71pVgdpqqojNbCN7RP0/TwTjXJtdKSRv1BMbs07BQnRN1WYcuDUSpx7EQzzbF8KDL62l a1hmNEIdPJFz6jHRzwhU7a5lPf1mqmgyi9dKo+DxR5wApRMUbtzrLYEghnMyk3jBOu/FISAylqU jvjTm5K9knIelw0QZAZf80lBffWYuquUrx/vQQpKbGmTD/8YCPdzcKXjvNmxJdmpBMFBWdtU0sx oo8prenD9UDGnEhIk/mMrqXR7VqyNZfEMRgB7r8TPaI2qGbDIPzRtqT4wZRcqwGRicLcH2sdvy0 686isdL50ftNQc= X-Received: by 2002:a05:600c:a08c:b0:48a:563c:c8c0 with SMTP id 5b1f17b1804b1-48a563cd176mr361650105e9.7.1777287248180; Mon, 27 Apr 2026 03:54:08 -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?= , Anthony PERARD , Juergen Gross , Frediano Ziglio Subject: [PATCH v2 7/7] tools/lib/call: cache up to 4 pages in hypercall bounce buffers Date: Mon, 27 Apr 2026 11:53:32 +0100 Message-ID: <20260427105338.99792-8-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260427105338.99792-1-frediano.ziglio@cloud.com> References: <20260427105338.99792-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/1777287249-2A378938-ABA77346/0/0 X-purgate-type: clean X-purgate-size: 4933 X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1777287274803158500 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 --- 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.53.0