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

Re: [PATCH v2 3/3] xen/heap: pass order to free_heap_pages() in heap init


  • To: Julien Grall <julien@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Wei Chen <Wei.Chen@xxxxxxx>
  • Date: Mon, 18 Jul 2022 16:38:46 +0800
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=jSMW2xPomPgsPEXkhoXTJ54KGnxk4Wc+qdpif4iCmrc=; b=Imi1gYfbGRXnKJoKH8CyMCBup9Bkv5i/QzSaPEWVmEfiCo8xPacEN1MAhcI9VxoPIK8nBByv2fQvxDZB87i+GBLJ7Gmjop7BHCqEwAmN7srvHM1AMXpPjaJTq7nGqQdipsqTTvbCgfM2afmN9bmlJ2V5ZGcvxS2QVlNQ3JuIGI4SPG75vOocFAk+AlkTtF36eBvJhmP0AEE5gUS3qXR6ZDuKsr4M/+yQO9aqhOsP5v+ZwlYrV4XvO9QrN16oRIXZ9K9KSEkm26f3QSC4jDbIa3Tfu9W6JVHS+tfuJn1Dj/aCqSBDVVn8YUvxnFgFE/TuxFCRFsBIXSTKzKRwDdKihA==
  • 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=jSMW2xPomPgsPEXkhoXTJ54KGnxk4Wc+qdpif4iCmrc=; b=LaIw9six9hjanUQVki+Y4EM4F+9xUA6btdPj4qoRMeKMUZo9uo6dSxznad8T8kWeknuUmJEf/PS6IkR3cwPO9CJstdIMP/8bF866VdF3HWZrzfb1EyEeEiJq5+zKdMQPSQNLtHJqKVyUBk64pqBXPP6dDo9zFlTLefIgtqMAYbYk9XbYio7EzMSOViVHMApl3U3kcm/4LyZHSEnstouROXwbVsRlUZ+RzMRfv/knF0xRW9KHSUhwqgjCauEtH+rGytg/0eCRsxYbTNKTwikTat6dKU2hgKVHfRlehs23KJAr2af/BzNnKUNGFbxpcJnu7TOIBoP5ocuEwIB9gUzNiQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=gfuIO1/8/Da4JfFlGsu3YLUA8aOE7cxH9sC9h6wxuG+L+/OE8I/30vJiEocjK5aFXD19Ns59vyzGDhGY2nxpgcFxOCXyAZRok4KtMH5O4AkkAtTlKK71IkxD/+DMlz3QobC+k7L8hj4NufwJD4OFzNlOAyrFpdu0sFum8fHlImwluTnJIFA9/i8xmZ7Fa5iezLl2ZK1tI72NC0LVLvzOwpaau6ve7c+jNraDdeLqS6xKOwIL1KUL0fufG7StRRXLz+dxCIZgwbVp5frOaplkqah/sFyl5bp8/vrXy4QEzYnyjlbph+Qci+pJONUK1MXiV91JMZC1HTckCD07kCinPw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BbEOs+gJeK9zAM5KkvJVNLjxEc78Mfleh6eGFEE5czLd1uuzkF+OBihJjHMWZhR6QBuLTIRGunQ/LTRZkmYZAT1pOF/FmYs6AfrVX2O37kV15jovGpIL5iYObwMuRUePmhecBLg6oxr9q4eCy4TlbWspxfLvuD1DJ2MsMTf2A4dprfp7WtJKBImDy4andcqjdV+1rO49MQxoPGHRIyy1b4JUlYb/4Ish0UaHhU74nvxRkIs7mgcX33/F9GF2gNuc8DjqUDXny7MxNDhoc58m6vScugZWP85ILak18XYb+Dg23dhN/bCgAb3gcp22vz+j3/ej7LOYI9WcWrEyRGh5VA==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Hongyan Xia <hongyxia@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Julien Grall <jgrall@xxxxxxxxxx>
  • Delivery-date: Mon, 18 Jul 2022 08:39:11 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;

Hi Julien,

On 2022/7/16 1:03, Julien Grall wrote:
From: Hongyan Xia <hongyxia@xxxxxxxxxx>

The idea is to split the range into multiple aligned power-of-2 regions
which only needs to call free_heap_pages() once each. We check the least
significant set bit of the start address and use its bit index as the
order of this increment. This makes sure that each increment is both
power-of-2 and properly aligned, which can be safely passed to
free_heap_pages(). Of course, the order also needs to be sanity checked
against the upper bound and MAX_ORDER.

Tested on a nested environment on c5.metal with various amount
of RAM and CONFIG_DEBUG=n. Time for end_boot_allocator() to complete:
             Before         After
     - 90GB: 1445 ms         96 ms
     -  8GB:  126 ms          8 ms
     -  4GB:   62 ms          4 ms

Signed-off-by: Hongyan Xia <hongyxia@xxxxxxxxxx>
Signed-off-by: Julien Grall <jgrall@xxxxxxxxxx>

---

Changes in v2:
     - Update comment
     - Update the numbers. They are slightly better as is_contig_page()
       has been folded in init_heap_pages().
---
  xen/common/page_alloc.c | 35 ++++++++++++++++++++++++++++++++---
  1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index eedb2fed77c3..2b99801d2ea3 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -1779,7 +1779,7 @@ int query_page_offline(mfn_t mfn, uint32_t *status)
/*
   * This function should only be called with valid pages from the same NUMA
- * node.
+ * node and zone.
   */
  static void _init_heap_pages(const struct page_info *pg,
                               unsigned long nr_pages,
@@ -1806,8 +1806,22 @@ static void _init_heap_pages(const struct page_info *pg,
while ( s < e )
      {
-        free_heap_pages(mfn_to_page(_mfn(s)), 0, need_scrub);
-        s += 1UL;
+        /*
+         * For s == 0, we simply use the largest increment by checking the
+         * MSB of the region size. For s != 0, we also need to ensure that the
+         * chunk is properly sized to end at power-of-two alignment. We do this
+         * by checking the LSB of the start address and use its index as
+         * the increment. Both cases need to be guarded by MAX_ORDER.
+         *
+         * Note that the value of ffsl() and flsl() starts from 1 so we need
+         * to decrement it by 1.
+         */
+        int inc_order = min(MAX_ORDER, flsl(e - s) - 1);
+
+        if ( s )
+            inc_order = min(inc_order, ffsl(s) - 1);
+        free_heap_pages(mfn_to_page(_mfn(s)), inc_order, need_scrub);
+        s += (1UL << inc_order);
      }
  }
@@ -1844,6 +1858,9 @@ static void init_heap_pages( for ( i = 0; i < nr_pages; )
      {
+#ifdef CONFIG_SEPARATE_XENHEAP
+        unsigned int zone = page_to_zone(pg);
+#endif
          unsigned int nid = phys_to_nid(page_to_maddr(pg));
          unsigned long left = nr_pages - i;
          unsigned long contig_pages;
@@ -1856,6 +1873,18 @@ static void init_heap_pages(
           */
          for ( contig_pages = 1; contig_pages < left; contig_pages++ )
          {
+            /*
+             * No need to check for the zone when !CONFIG_SEPARATE_XENHEAP
+             * because free_heap_pages() can only take power-of-two ranges
+             * which never cross zone boundaries. But for separate xenheap
+             * which is manually defined, it is possible for power-of-two
+             * range to cross zones.
+             */
+#ifdef CONFIG_SEPARATE_XENHEAP
+            if ( zone != page_to_zone(pg) )
+                break;
+#endif
+
              if ( nid != (phys_to_nid(page_to_maddr(pg))) )
                  break;
          }

Reviewed-by: Wei Chen <Wei.Chen@xxxxxxx>




 


Rackspace

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