[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xl: relax freemem()'s retry calculation


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 8 Jul 2022 15:39:38 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cKdnm3XyVTt2oEDS8+TU2y+4wxHgZzHT82MYHpkWhDw=; b=bRfashimuCARo+a7ehsTuNV88bC5F3OaLXZXS7yn16fyIJfKllshDgmkdq8e7CppN2DFKE6pYNQCmnhhuk3/m0prfk5sIiIVqXdWH8TKcECUqmw/2kmJW6Kf3yYne72tSh1KOh6YKM291GKJmE43WAnGwpSuKg8yqtkFetbKvOU6+U3DkPoX6hPzwCxnvOPOC0WjCCKzVjFOBdZXtTl5im+hLfVxtmIeU6zSrcmVP+1JG2kxuaCaJxW+Gzd+Oa3k3CjQVvZrt4eub5cQ/4L1muB1tVeKl1fHcYXZo3Ni5B04wcp/VDGIwk6oNjcNrm/yTYU4u25pQdJB95kaghN/ZQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OOqvKzCdsJvLwRPXp3Gg2sZMlfOcUPZKh0lEuWEhq9ReLTcpURx3knkrKyMI4EJP+AxFYBMSzVccInZiqrJxwEYvYHCRrBoQtfEGlfeQVs3LhSLyXTNnAuiTLbYzeIOVI/Hds4XSO/CDkkyOuNFMw/ok7nKYGVg7eBEMgtmRPtIRrIscXRKx+nMsA7Cy1iBDtthUlHmi8WxJyiNAdE/8KOpWAdfjz7FuthZ8X1Ad1myytzpejfBPuSz4ZSOS4LD5PD0W0u9Yh/VREAwwyJNLZ0n3zkNIcvl8qRZeZL+bXBy3RmG5I4amNIM/mqDxlqPuhFdDHIKJdd1FNauXiSn/1Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Anthony Perard <anthony.perard@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 08 Jul 2022 13:39:51 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

While in principle possible also under other conditions as long as other
parallel operations potentially consuming memory aren't "locked out", in
particular with IOMMU large page mappings used in Dom0 (for PV when in
strict mode; for PVH when not sharing page tables with HAP) ballooning
out of individual pages can actually lead to less free memory available
afterwards. This is because to split a large page, one or more page
table pages are necessary (one per level that is split).

When rebooting a guest I've observed freemem() to fail: A single page
was required to be ballooned out (presumably because of heap
fragmentation in the hypervisor). This ballooning out of a single page
of course went fast, but freemem() then found that it would require to
balloon out another page. This repeating just another time leads to the
function to signal failure to the caller - without having come anywhere
near the designated 30s that the whole process is allowed to not make
any progress at all.

Convert from a simple retry count to actually calculating elapsed time,
subtracting from an initial credit of 30s. Don't go as far as limiting
the "wait_secs" value passed to libxl_wait_for_memory_target(), though.
While this leads to the overall process now possibly taking longer (if
the previous iteration ended very close to the intended 30s), this
compensates to some degree for the value passed really meaning "allowed
to run for this long without making progress".

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
see https://lists.xen.org/archives/html/xen-devel/2021-08/msg00781.html
---
I further wonder whether the "credit expired" loop exit wouldn't better
be moved to the middle of the loop, immediately after "return true".
That way having reached the goal on the last iteration would be reported
as success to the caller, rather than as "timed out".

--- a/tools/xl/xl_vmcontrol.c
+++ b/tools/xl/xl_vmcontrol.c
@@ -321,7 +321,8 @@ static int domain_wait_event(uint32_t do
  */
 static bool freemem(uint32_t domid, libxl_domain_config *d_config)
 {
-    int rc, retries = 3;
+    int rc;
+    double credit = 30;
     uint64_t need_memkb, free_memkb;
 
     if (!autoballoon)
@@ -332,6 +333,8 @@ static bool freemem(uint32_t domid, libx
         return false;
 
     do {
+        time_t start;
+
         rc = libxl_get_free_memory(ctx, &free_memkb);
         if (rc < 0)
             return false;
@@ -345,12 +348,13 @@ static bool freemem(uint32_t domid, libx
 
         /* wait until dom0 reaches its target, as long as we are making
          * progress */
+        start = time(NULL);
         rc = libxl_wait_for_memory_target(ctx, 0, 10);
         if (rc < 0)
             return false;
 
-        retries--;
-    } while (retries > 0);
+        credit -= difftime(time(NULL), start);
+    } while (credit > 0);
 
     return false;
 }



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.