diff mbox series

[RESEND,V8,1/2] xxHash: create arch dependent 32/64-bit xxhash()

Message ID 20181023182554.23464-2-nefelim4ag@gmail.com (mailing list archive)
State New, archived
Headers show
Series Currently used jhash are slow enough and replace it allow as to make KSM | expand

Commit Message

Timofey Titovets Oct. 23, 2018, 6:25 p.m. UTC
xxh32() - fast on both 32/64-bit platforms
xxh64() - fast only on 64-bit platform

Create xxhash() which will pickup fastest version
on compile time.

As result depends on cpu word size,
the main proporse of that - in memory hashing.

Changes:
  v2:
    - Create that patch
  v3 -> v8:
    - Nothing, whole patchset version bump

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
Reviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>
Reviewed-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

CC: Andrea Arcangeli <aarcange@redhat.com>
CC: linux-mm@kvack.org
CC: kvm@vger.kernel.org
CC: leesioh <solee@os.korea.ac.kr>
---
 include/linux/xxhash.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Pavel Tatashin Nov. 8, 2018, 6:31 p.m. UTC | #1
Hi Andrew,

Can you please accept these patches? They are simple yet provide a good
performance improvement. Timofey has been resending them for a while.

Thank you,
Pasha

On 18-10-23 21:25:53, Timofey Titovets wrote:
> xxh32() - fast on both 32/64-bit platforms
> xxh64() - fast only on 64-bit platform
> 
> Create xxhash() which will pickup fastest version
> on compile time.
> 
> As result depends on cpu word size,
> the main proporse of that - in memory hashing.
> 
> Changes:
>   v2:
>     - Create that patch
>   v3 -> v8:
>     - Nothing, whole patchset version bump
> 
> Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
> Reviewed-by: Pavel Tatashin <pavel.tatashin@microsoft.com>
> Reviewed-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> 
> CC: Andrea Arcangeli <aarcange@redhat.com>
> CC: linux-mm@kvack.org
> CC: kvm@vger.kernel.org
> CC: leesioh <solee@os.korea.ac.kr>
> ---
>  include/linux/xxhash.h | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/include/linux/xxhash.h b/include/linux/xxhash.h
> index 9e1f42cb57e9..52b073fea17f 100644
> --- a/include/linux/xxhash.h
> +++ b/include/linux/xxhash.h
> @@ -107,6 +107,29 @@ uint32_t xxh32(const void *input, size_t length, uint32_t seed);
>   */
>  uint64_t xxh64(const void *input, size_t length, uint64_t seed);
>  
> +/**
> + * xxhash() - calculate wordsize hash of the input with a given seed
> + * @input:  The data to hash.
> + * @length: The length of the data to hash.
> + * @seed:   The seed can be used to alter the result predictably.
> + *
> + * If the hash does not need to be comparable between machines with
> + * different word sizes, this function will call whichever of xxh32()
> + * or xxh64() is faster.
> + *
> + * Return:  wordsize hash of the data.
> + */
> +
> +static inline unsigned long xxhash(const void *input, size_t length,
> +				   uint64_t seed)
> +{
> +#if BITS_PER_LONG == 64
> +       return xxh64(input, length, seed);
> +#else
> +       return xxh32(input, length, seed);
> +#endif
> +}
> +
>  /*-****************************
>   * Streaming Hash Functions
>   *****************************/
> -- 
> 2.19.0
>
diff mbox series

Patch

diff --git a/include/linux/xxhash.h b/include/linux/xxhash.h
index 9e1f42cb57e9..52b073fea17f 100644
--- a/include/linux/xxhash.h
+++ b/include/linux/xxhash.h
@@ -107,6 +107,29 @@  uint32_t xxh32(const void *input, size_t length, uint32_t seed);
  */
 uint64_t xxh64(const void *input, size_t length, uint64_t seed);
 
+/**
+ * xxhash() - calculate wordsize hash of the input with a given seed
+ * @input:  The data to hash.
+ * @length: The length of the data to hash.
+ * @seed:   The seed can be used to alter the result predictably.
+ *
+ * If the hash does not need to be comparable between machines with
+ * different word sizes, this function will call whichever of xxh32()
+ * or xxh64() is faster.
+ *
+ * Return:  wordsize hash of the data.
+ */
+
+static inline unsigned long xxhash(const void *input, size_t length,
+				   uint64_t seed)
+{
+#if BITS_PER_LONG == 64
+       return xxh64(input, length, seed);
+#else
+       return xxh32(input, length, seed);
+#endif
+}
+
 /*-****************************
  * Streaming Hash Functions
  *****************************/