[Devel] [PATCH RHEL8 COMMIT] ms/ksm: replace jhash2 with xxhash

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 1 20:29:52 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.34
------>
commit 7367770fd58886c4272c1635546f6898a7eb923d
Author: Timofey Titovets <nefelim4ag at gmail.com>
Date:   Tue Jun 1 20:29:52 2021 +0300

    ms/ksm: replace jhash2 with xxhash
    
    Replace jhash2 with xxhash.
    
    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
    
    Sioh Lee did some testing:
    
    crc32c_intel: 1084.10ns
    crc32c (no hardware acceleration): 7012.51ns
    xxhash32: 2227.75ns
    xxhash64: 1413.16ns
    jhash2: 5128.30ns
    
    As jhash2 always will be slower (for data size like PAGE_SIZE).  Don't use
    it in ksm at all.
    
    Use only xxhash for now, because for using crc32c, cryptoapi must be
    initialized first - that requires some tricky solution to work well in all
    situations.
    
    Link: http://lkml.kernel.org/r/20181023182554.23464-3-nefelim4ag@gmail.com
    Signed-off-by: Timofey Titovets <nefelim4ag at gmail.com>
    Signed-off-by: leesioh <solee at os.korea.ac.kr>
    Reviewed-by: Pavel Tatashin <pavel.tatashin at microsoft.com>
    Reviewed-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
    Reviewed-by: Andrew Morton <akpm at linux-foundation.org>
    Cc: Andrea Arcangeli <aarcange at redhat.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    ksm: Switch to xxhash hash algorithm
    
    xxhash shows better performance in comparison to currently
    used jhash2:
    
            ksm: xxh64 hash() 8770 MB/s
            ksm: xxh32 hash() 4529 MB/s
            ksm: jhash2 hash() 1569 MB/s
    
    Note, that algorithm module lib/xxhash.c is already in ms kernel [1/3],
    while [2-3/3] just make ksm to use it (but they also already in akpm tree).
    
    This should improve ksm performance in some way.
    
    Nick Terrell (1):
          lib: Add xxhash module
    
    Timofey Titovets (2):
          xxHash: create arch dependent 32/64-bit xxhash()
          ksm: replace jhash2 with xxhash
    
    https://jira.sw.ru/browse/PSBM-90044
    
    (cherry-picked from vz7 commit 5df8dc1eb691271b92562bcfc43b458f3996596a)
    ms commit: 59e1a2f4bf83 ("ksm: replace jhash2 with xxhash")
    
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 mm/Kconfig | 1 +
 mm/ksm.c   | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/Kconfig b/mm/Kconfig
index 963532b08006..b64929ad5661 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -292,6 +292,7 @@ config MMU_NOTIFIER
 config KSM
 	bool "Enable KSM for page merging"
 	depends on MMU
+	select XXHASH
 	help
 	  Enable Kernel Samepage Merging: KSM periodically scans those areas
 	  of an application's address space that an app has advised may be
diff --git a/mm/ksm.c b/mm/ksm.c
index 034e032e72e5..5fec98bee29a 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -25,7 +25,7 @@
 #include <linux/pagemap.h>
 #include <linux/rmap.h>
 #include <linux/spinlock.h>
-#include <linux/jhash.h>
+#include <linux/xxhash.h>
 #include <linux/delay.h>
 #include <linux/kthread.h>
 #include <linux/wait.h>
@@ -1009,7 +1009,7 @@ static u32 calc_checksum(struct page *page)
 {
 	u32 checksum;
 	void *addr = kmap_atomic(page);
-	checksum = jhash2(addr, PAGE_SIZE / 4, 17);
+	checksum = xxhash(addr, PAGE_SIZE, 0);
 	kunmap_atomic(addr);
 	return checksum;
 }


More information about the Devel mailing list