From nobody Fri Oct 31 03:48:30 2025 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1756298038; cv=none; d=zohomail.com; s=zohoarc; b=XegJF2szUogTG9aobj45LW+/f7QlVoTm+Uytd4mEmCBor59Itw8d2MXmsoz+Gb6MZqHP2DR7PCG6z5w4M47xXVlS6oX7u2EPW53iUr4UGMBN3uqzIfnA3dKcmlzkJDyusqMDKzEgRJcIJOqBPLJwq/5COL9mCExjs9xaKj7latA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756298038; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Rbux99ex3cU0nog0VEpdTqXoplhetdpwz/JQ8/H1D5I=; b=Upn5H9GpC7AYojVcXTvnIu+8Bw5jaPeFQA6kIOa3h/1NUZ557BBWzLQ9bj50eXiBP5UcA82oFSYT/LKIdKeIEHP6HzgKI7mlAcFBUB2Ptg2nsGsEBYjTdyf7WeRid8XeMmJma1FjGxKS+A9n8N0+AYRqyQcWvT38WAz8eDUelKw= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1756298038707389.4340487541434; Wed, 27 Aug 2025 05:33:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1096004.1450821 (Exim 4.92) (envelope-from ) id 1urFLS-0003mq-Sl; Wed, 27 Aug 2025 12:33:42 +0000 Received: by outflank-mailman (output) from mailman id 1096004.1450821; Wed, 27 Aug 2025 12:33:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1urFLS-0003mj-Pb; Wed, 27 Aug 2025 12:33:42 +0000 Received: by outflank-mailman (input) for mailman id 1096004; Wed, 27 Aug 2025 12:33:41 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1urFLR-0003md-Gp for xen-devel@lists.xenproject.org; Wed, 27 Aug 2025 12:33:41 +0000 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [2a00:1450:4864:20::336]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0fb2997a-8342-11f0-aeb2-fb57b961d000; Wed, 27 Aug 2025 14:33:40 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-45b49f7aaf5so41276295e9.2 for ; Wed, 27 Aug 2025 05:33:40 -0700 (PDT) Received: from localhost.localdomain ([87.114.69.104]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3cb901975adsm6589141f8f.8.2025.08.27.05.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Aug 2025 05:33:39 -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" X-Inumbo-ID: 0fb2997a-8342-11f0-aeb2-fb57b961d000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1756298019; x=1756902819; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Rbux99ex3cU0nog0VEpdTqXoplhetdpwz/JQ8/H1D5I=; b=edoSMQYD6mzRNUBBlYw67XkFNN+W8SfnI93x3iCmPXIPHeImCtJ+vxbEo6zq0NDzQc PukyLUJqFEo2tTP/dYQJxEDCQROCVvtL0tnIrbBpaxmgZ0yu0Zr7XF4CRZlrheQ0WPi3 nFY2a3lDCT+btob+cHzDL3obAe7PFqGI9qg0k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756298019; x=1756902819; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Rbux99ex3cU0nog0VEpdTqXoplhetdpwz/JQ8/H1D5I=; b=EFRSI92WUC2VNFyzkmsU96oLA3eziZqSVC9kKGjNuqm68YWhgMlAx6AzC5sZq6Bt5C nv4QDtoluxPbRZ2cI8UaoAheXtQwZscsn0YUDIGOZxbwsQv5NU0iXdAgTOIzIi8PrpkN TlWsgBVQQ/SVX6n3Mr82r1Y2LmTE+eliZ5HrZVnXp+U5gHPgAeMwtuEkzwLaXuknrfW0 yQ1wEI532vqyx9j7RLP7V1uc9w8YInkHit9HBQzC8wdPXA/yEq7Vbagk1fjCye29DKe7 9deza/cXu5QX/yNkYEIGBoCEL+fPYfMabXSW80GNBVQOaAtnG5FjLlEl5VRdlxbnyKO2 XUlg== X-Gm-Message-State: AOJu0YypGC5L1NO24hWd40Iax4nCuUL0Tr8qUNiIwc2hPOBjFtUqPNVn 9/fwQMzxpeBQTkh3bm3gOGnZGG9m8tgePcgh0mUVZu9LUswISg88Q8A+xa0JiK2Cdyyd3JF1q/d zroT4m+g= X-Gm-Gg: ASbGncsnrdFXSUrEBqluO0EXfWA0FfYYJN+Dcl7lE2YbB76qL8FNRvfrRuin5lCegDU wC2UfNAsLYVX5FpJJCO832Sb9hHwN/s6iCh6ws9SHpg8bkAeNpF2WwDjBSAhRTF2JujGbItJDYg eAbKISFENwR3mCn9M2gn8KiOxMhbZOF49p7j37mgsLm+AXvYjTnb5TuZQ0uK2mtQaGi09vYD/Ki xvtsZQSvFd5+b8NYGHO5bhh5EQOw3Pld+y8CK0H2474kUqoBmUme43Tnpt3lVdQC+fWJOs18PtR TTV8SViTiGvmXr6OuECuP1ovHrR0acP8skuoC4GT5KtBg6hbejQVsPaH8pc/pNnN4VOJw35Ddr8 2rBq3pKEndbcTawvF0Y+TQLgbqj5Kj1LlmVD4DyxM3Q== X-Google-Smtp-Source: AGHT+IHGM05F58JjSKkC38WkyurLdSdDS1PUL81n3ViyxrnjEy0FTMLXwETjGGL70b/siJ1Eu3jSyg== X-Received: by 2002:a05:600c:4348:b0:459:d616:25c5 with SMTP id 5b1f17b1804b1-45b5213bb88mr114852915e9.12.1756298019562; Wed, 27 Aug 2025 05:33:39 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Anthony PERARD , Juergen Gross , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Andrew Cooper Subject: [PATCH] Optimise restore memory allocation Date: Wed, 27 Aug 2025 13:33:04 +0100 Message-ID: <20250827123309.39699-1-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1756298040524116600 Content-Type: text/plain; charset="utf-8" Try to allocate larger order pages. With some test memory program stressing TLB (many small random memory accesses) you can get 15% performance improves. On the first memory iteration the sender is currently sending memory in 4mb aligned chunks which allows the receiver to allocate most pages as 2mb superpages instead of single 4kb pages. Signed-off-by: Frediano Ziglio --- tools/libs/guest/xg_sr_restore.c | 39 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 06231ca826..8dcb1b19c5 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -129,6 +129,8 @@ static int pfn_set_populated(struct xc_sr_context *ctx,= xen_pfn_t pfn) return 0; } =20 +#define IS_POWER_OF_2(n) (((n) & ((n) - 1)) =3D=3D 0) + /* * Given a set of pfns, obtain memory from Xen to fill the physmap for the * unpopulated subset. If types is NULL, no page type checking is perform= ed @@ -141,6 +143,7 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned i= nt count, xen_pfn_t *mfns =3D malloc(count * sizeof(*mfns)), *pfns =3D malloc(count * sizeof(*pfns)); unsigned int i, nr_pfns =3D 0; + bool contiguous =3D true; int rc =3D -1; =20 if ( !mfns || !pfns ) @@ -159,18 +162,46 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned= int count, if ( rc ) goto err; pfns[nr_pfns] =3D mfns[nr_pfns] =3D original_pfns[i]; + if ( pfns[nr_pfns] !=3D pfns[0] + nr_pfns ) + contiguous =3D false; ++nr_pfns; } } =20 if ( nr_pfns ) { - rc =3D xc_domain_populate_physmap_exact( - xch, ctx->domid, nr_pfns, 0, 0, mfns); + /* try optimizing using larger order */ + rc =3D -1; + /* + * The "nr_pfns <=3D (1 << 18)" check is mainly for paranoia, it s= hould + * never happen, the sender would have to send a really large pack= et. + */ + if ( contiguous && nr_pfns <=3D (1 << 18) && + IS_POWER_OF_2(nr_pfns) && (pfns[0] & (nr_pfns - 1)) =3D=3D 0 ) + { + const unsigned int extent_order =3D __builtin_ffs(nr_pfns) - 1; + + rc =3D xc_domain_populate_physmap_exact( + xch, ctx->domid, 1, extent_order, 0, mfns); + if ( rc ) + mfns[0] =3D pfns[0]; + else + { + for ( i =3D 1; i < nr_pfns; ++i ) + mfns[i] =3D mfns[0] + i; + } + } + + /* if using larger order fails fall back to single pages */ if ( rc ) { - PERROR("Failed to populate physmap"); - goto err; + rc =3D xc_domain_populate_physmap_exact( + xch, ctx->domid, nr_pfns, 0, 0, mfns); + if ( rc ) + { + PERROR("Failed to populate physmap"); + goto err; + } } =20 for ( i =3D 0; i < nr_pfns; ++i ) --=20 2.43.0