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

[PATCH v2 7/9] x86/shadow: reduce effort of hash calculation


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 11 Jan 2023 14:56:30 +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=dOlBxwttZ7/+xseKnKOuiqz4kR/3+d88oza4XKWQx5c=; b=Q1F0GUfzbx8Z7UvU8AP+nNyj1rjYDxJ1ByQvE6awNcYfvdXADwXV1/RYwBNikqX8XWKMepjsSwsLiFqbPKOa+ulf5x5FLjtUjYC3gDHMSzCcmmAOSE1RwugoCnXY+pzcc1ekm1JZFeDYQMqHLCEgGaP2XheeW0HbSL0GfS4P7XmOzUVv6viabhuHXXtXQR+gW+8YmCLLB4lmW6lwGdLqxBrdopLfKRTW4DEonhELpNlONWyca/sU8ZJvHVkzUWjpWEK8GWQ8VCSNrg817ewABmRVY4ivcr6e2fI6JSgyqF+jT715XW8F/2sHT5eChtkneZu7tJXAUPi/qxbzW1D19g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z953bz3nFFFaQ8kRRDXismk0G7je/7A7feBoknxMk94W9dqBDDOXX4mEzejOYUSw3B7Gm2NMmgpZukW2t5lpVPYGUkCSlCelD7rN6bMJjHwC0llDL8OBOh1OQnYWbEJYX3kTM82iRHqLLv27sjzLtwosLtL7qO688g9QjzxwGDIgHN+uqUP6cJqF8Dr9iDGYliahGOBv/59fat9luHaLFVVhkqBiClnw5Nk+OmtbAfPTLo32/WmnTN02h8x/k6NUmfa1zGvMXUY3G2Q/hwdd8zYVJQS6pWwR5dq9jDVtYOJRPC98z9xfdZWiXLrAP4BJZLkQ8h8PAmtbxeylI0Gqaw==
  • 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: Wed, 11 Jan 2023 13:56:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The "n" input is a GFN/MFN 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 conversion to an array of unsigned
char, moving the value off the stack altogether (at least with
optimization enabled).

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
I was tempted to also change the type "i" (unsigned) right here, but
then thought this might be going too far ...
---
v2: Also eliminate the unsigned char * alias of "n".

--- a/xen/arch/x86/mm/shadow/common.c
+++ b/xen/arch/x86/mm/shadow/common.c
@@ -1397,10 +1397,13 @@ static unsigned int shadow_get_allocatio
 typedef u32 key_t;
 static inline key_t sh_hash(unsigned long n, unsigned int t)
 {
-    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++, n >>= 8 )
+        k = (uint8_t)n + (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®.