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

[PATCH] Arm/P2M: reduce locking in p2m_{alloc,free}_page()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 29 Nov 2022 15:39:57 +0100
  • 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=yvAci0YWhtZSwDYtSxfg7I4sW/keT/nE9BZRusa5KkU=; b=njUcrXm5hq0TqWitTwzJrNAC2L8pImbCCQhoNIr51nilBXz24nTA2hWue301LvvDcHj01NUOwj0jvI30Q950JlPIqkslmBGQaAP0py6/XeDu30A5yM2AtQ/Csb5YDcGex468TQsVQfJx4/VZEx95mbQrUq3xLiojVzUunhCfuZau+R+oLT72OJ4vxzjLKya5GjayqutQSO10fo9gSKt0UJUNTIn6kcdA3Ei4lh5RQXNPkMDtRut4So0rE0aLL3N41UhyX6bVMUgOpiEf2yTyo3ueTvw9gB9WhpBQlC7LIG7PPeTtvx8S6ZNpVtYyn1ihPs+mEaX8TtgVFTzWnp6sgQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SiQcVvRSDxqo9ugkci0oD/o+iiOkZg6N9kAzZ/mhsN+9CapGpBFVXu38mtU3SR/NYT+ndm+QGCG5JLdCzsFiFUN5wk2nwkr6Z5uD+mbo6SaPfq2x1Ed/rA1lMylfR9WCr4X+VDYlxBE4AGycX1blvS8LC/dnXjl6zgSiTu9x6hWOZws9ydmyWD1/uCKem4aZXGGipZ+hNyElbSrUClXAL25Ix5viLviFm8kClWQv51SUpPrdjK05goz1kmMZlePBXSOVmTwYiXBy7P02u5NqXZTdxL10F+U9NeZ1Pvn7DSAByf66nX8W4YtTmijihhoZRsswjA1wGrhF+7daCBajAg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • Delivery-date: Tue, 29 Nov 2022 14:40:31 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

It is generally preferable to not hold locks around allocation
functions. And indeed in the hwdom case there's no point at all to hold
the paging lock. Reduce the locked regions to the non-hwdom case, while
at the same time arranging for p2m_alloc_page() to have just a single
return point.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -48,7 +48,6 @@ static struct page_info *p2m_alloc_page(
 {
     struct page_info *pg;
 
-    spin_lock(&d->arch.paging.lock);
     /*
      * For hardware domain, there should be no limit in the number of pages 
that
      * can be allocated, so that the kernel may take advantage of the extended
@@ -58,34 +57,28 @@ static struct page_info *p2m_alloc_page(
     {
         pg = alloc_domheap_page(NULL, 0);
         if ( pg == NULL )
-        {
             printk(XENLOG_G_ERR "Failed to allocate P2M pages for hwdom.\n");
-            spin_unlock(&d->arch.paging.lock);
-            return NULL;
-        }
     }
     else
     {
+        spin_lock(&d->arch.paging.lock);
         pg = page_list_remove_head(&d->arch.paging.p2m_freelist);
-        if ( unlikely(!pg) )
-        {
-            spin_unlock(&d->arch.paging.lock);
-            return NULL;
-        }
+        spin_unlock(&d->arch.paging.lock);
     }
-    spin_unlock(&d->arch.paging.lock);
 
     return pg;
 }
 
 static void p2m_free_page(struct domain *d, struct page_info *pg)
 {
-    spin_lock(&d->arch.paging.lock);
     if ( is_hardware_domain(d) )
         free_domheap_page(pg);
     else
+    {
+        spin_lock(&d->arch.paging.lock);
         page_list_add_tail(pg, &d->arch.paging.p2m_freelist);
-    spin_unlock(&d->arch.paging.lock);
+        spin_unlock(&d->arch.paging.lock);
+    }
 }
 
 /* Return the size of the pool, in bytes. */



 


Rackspace

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