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

[PATCH 08/11] x86/shadow: reduce effort of hash calculation


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 5 Jan 2023 17:05:59 +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=tp/xRy5VT94YqOsqdM3hhLWnXJKhH74obPOAkyaCA0Q=; b=clxZolyFyrRJJ2KxqPgWzTGcPFh0Ka8PidOk5WXeoMN+a3lbNJxVedKEhiMtnQTLzaVNXZbt+L/sXRhqvk5rAD00BJvW4k7n+aeUbwZ8nuqjHJcgbfcazVtxF0Gy2AcYkZF7btAfAsAiyu2+xM6kFVtHvPVjz6V3MZSDfOIcItJE+15VvOCeDYJzJqu8GF5BYLnb+RAcQ3EHydRgnlw4GaAtzgJEEmtZ4VkSWJ+tqL05jcRr4TDgrx8RfuNmBQROOe4CW5pd77vgdVerYIVJCAcQpfjWtF8H6MN3V3UmMOPJZ3zDx2Qg+khE6ioIXnA6jKJy8DuG4OGx5SOEETi0dQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JK0twxZG6alBtmSSizwcYEyh563fpdxnpgziu3kcb+CZZ8IDa3K+w4U1anaG+W5B10VvmEUVzSq2++WzJjigo0XK4vSOicrqj0v7/FMvfiD/mtB4i+4DroFTkkLtV6kwzHTpAg1q61qYzpZinpL1gKcmbwwq6Hfcn5fasTL+8vpHh3MfmK8DkW5E9LdCmFpbgcmPIJa0m5wFw5cWxwgfkR/fG+0Y+p+jAyzm3fngBE/6TGSnp24Z07B2mgE0DvT47/AbpyVEmyQYoJFFdR7fy3/V5EyLlbboWGEUM2LwcndOzE4oVF0zW4lmyV72gemtGWqdkNl/uYstkh85iSql1Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Tim Deegan <tim@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Thu, 05 Jan 2023 16:06:06 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The "n" input is a GFN value and hence bounded by the physical address
bits in use on a system. The hash quality won't improve by also
including the upper always-zero bits in the calculation. To keep things
as compile-time-constant as they were before, use PADDR_BITS (not
paddr_bits) for loop bounding. This reduces loop iterations from 8 to 5.

While there also drop the unnecessary cast to u32.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
I was tempted to also change the types of "p" (pointer to const) and "i"
(unsigned) right here (and perhaps even the "byte" in the comment ahead
of the function), but then thought this might be going too far ...

--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -1400,7 +1400,11 @@ static inline key_t sh_hash(unsigned lon
     unsigned char *p = (unsigned char *)&n;
     key_t k = t;
     int i;
-    for ( i = 0; i < sizeof(n) ; i++ ) k = (u32)p[i] + (k<<6) + (k<<16) - k;
+
+    BUILD_BUG_ON(PADDR_BITS > BITS_PER_LONG + PAGE_SHIFT);
+    for ( i = 0; i < (PADDR_BITS - PAGE_SHIFT + 7) / 8; i++ )
+        k = p[i] + (k << 6) + (k << 16) - k;
+
     return k % SHADOW_HASH_BUCKETS;
 }
 




 


Rackspace

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