xxHash: create arch dependent 32/64-bit xxhash()
PATCH v5 1/2 xxHash: create arch dependent 32/64-bit xxhash()
xxh32() - fast on both 32/64-bit platformsxxh64() - 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 -> v5:
- Nothing, whole patchset version bump
--- include/linux/xxhash.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
include/linux/xxhash.h +23 -0
@@ -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 *****************************/
Signature · 7 lines
2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v5 2/2 ksm: replace jhash2 with faster hash
1. Pickup, Sioh Lee crc32 patch, after some long conversation
2. Merge with my work on xxhash
3. Add autoselect code to choice fastest hash helper.
Base idea are same, replace jhash2 with something faster.
Perf numbers:
Intel(R) Xeon(R) CPU E5-2420 v2 @ 2.20GHz
ksm: crc32c hash() 12081 MB/s
ksm: xxh64 hash() 8770 MB/s
ksm: xxh32 hash() 4529 MB/s
ksm: jhash2 hash() 1569 MB/s
As jhash2 always will be slower (For data size like PAGE_SIZE), just drop it from choice.
Add function to autoselect hash algo on boot,
based on hashing speed, like raid6 code does.
Move init of zero_checksum from init, to first call of fasthash():
1. KSM Init run on early kernel init,
run perf testing stuff on main kernel boot thread looks bad to me.
2. Crypto subsystem not avaliable at that early booting, so crc32c even, compiled in, not avaliable
Output after first try of KSM to hash page:
ksm: crc32c hash() 15218 MB/s
ksm: xxhash hash() 8640 MB/s
ksm: choise crc32c as hash function
Thanks.
Changes:
v1 -> v2:
- Move xxhash() to xxhash.h/c and separate patches
v2 -> v3:
- Move xxhash() xxhash.c -> xxhash.h
- replace xxhash_t with 'unsigned long'
- update kerneldoc above xxhash()
v3 -> v4:
- Merge xxhash/crc32 patches
- Replace crc32 with crc32c (crc32 have same as jhash2 speed)
- Add auto speed test and auto choice of fastest hash function
v4 -> v5:
- Pickup missed xxhash patch
- Update code with compile time choicen xxhash
- Add more macros to make code more readable
- As now that only possible use xxhash or crc32c,
on crc32c allocation error, skip speed test and fallback to xxhash
- For workaround too early init problem (crc32c not avaliable), move zero_checksum init to first call of fastcall()
- Don't alloc page for hash testing, use arch zero pages for that
--- mm/Kconfig | 4 +++ mm/ksm.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 109 insertions(+), 9 deletions(-)
mm/Kconfig +4 -0
@@ -305,6 +305,10 @@ config MMU_NOTIFIER config KSM bool "Enable KSM for page merging" depends on MMU + select XXHASH + select CRYPTO + select CRYPTO_HASH + select CONFIG_CRYPTO_CRC32C help Enable Kernel Samepage Merging: KSM periodically scans those areas of an application's address space that an app has advised may be
mm/ksm.c +105 -9
164 lines not on this page · raw message
Signature · 7 lines
2.15.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH V5 2/2] ksm: replace jhash2 with faster hash
JFYI performance on more fast/modern CPU:
Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
[ 172.651044] ksm: crc32c hash() 22633 MB/s [ 172.776060] ksm: xxhash hash() 10920 MB/s [ 172.776066] ksm: choice crc32c as hash function
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>