linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
To: Andrea Arcangeli <aarcange@redhat.com>
Cc: leesioh <solee@os.korea.ac.kr>,
	akpm@linux-foundation.org, mingo@kernel.org,
	zhongjiang@huawei.com, minchan@kernel.org,
	arvind.yadav.cs@gmail.com, kirill.shutemov@linux.intel.com,
	linux-mm@kvack.org
Subject: Re: [PATCH] mm/ksm : Checksum calculation function change (jhash2 -> crc32)
Date: Wed, 2 Aug 2017 14:26:29 +0200	[thread overview]
Message-ID: <20170802142629.578064f7@p-imbrenda.boeblingen.de.ibm.com> (raw)
In-Reply-To: <20170801200550.GB24406@redhat.com>

On Tue, 1 Aug 2017 22:05:50 +0200
Andrea Arcangeli <aarcange@redhat.com> wrote:

> On Tue, Aug 01, 2017 at 09:07:35PM +0900, leesioh wrote:
> > In ksm, the checksum values are used to check changes in page
> > content and keep the unstable tree more stable. KSM implements
> > checksum calculation with jhash2 hash function. However, because
> > jhash2 is implemented in software, it consumes high CPU cycles
> > (about 26%, according to KSM thread profiling results)
> > 
> > To reduce CPU consumption, this commit applies the crc32 hash
> > function which is included in the SSE4.2 CPU instruction set.
> > This can significantly reduce the page checksum overhead as follows.
> > 
> > I measured checksum computation 300 times to see how fast crc32 is
> > compared to jhash2. With jhash2, the average checksum calculation
> > time is about 3460ns, and with crc32, the average checksum
> > calculation time is 888ns. This is about 74% less than jhash2.  
> 
> crc32 may create more false positives than jhash2. crc32 only
> guarantees a different value in return if fewer than N bit
> changes. False positives in crc32 comparison, would result in more
> unstable pages being added to the unstable tree, and if they're
> changing as result of false positives it may make the unstable tree
> more unstable leading to missed merges (in addition to the overhead of
> adding those to the unstable tree in the first place and in addition
> of risking an immediate cow post merge which would slowdown apps even
> more).
> 
> I think if somebody wants a crc instead of a more proper hash (that is
> less likely to generate false positives if a couple of bits changes)
> it should be an option in sysfs not enabled by default, but overall I
> think it's not worth this change for a downgrade to crc. There's the
> risk an admin thinks it's going to make things runs faster because KSM
> CPU utilization decreases, but missing the risk of increased CoWs in
> app context or missed merges because of higher instability in the
> unstable tree.

that's true, but it's possible that all the extra work due to
additional collisions could still be less than the time saved with a
faster checksum. Also, even within the same architecture, different
checksums can have different performances depending on CPU vendor and
model. I would still let the admin (or ksmtuned) choose.

> Still deploying hardware accelleration in the KSM hash is a
> interesting idea that I don't recall has been tried. Could you try to
> benchmark in userland (or kernel if you wish) software jhash2 vs
> CONFIG_CRYPTO_SHA1_SSSE3 or CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL instead
> of the accellerated crc?  (I don't know if GHASH API can fit our use
> case though, but accellerated SHA1 sure would fit).  I suppose they'll
> be slower than crc32, and probably slower than jhash2 too, however I
> can't be sure by just thinking about it.
>
> We've to also keep the floating point save and restore into account in
> the real world, where ksm schedules often and may run interleaved in
> the same CPU where an app uses the fpu a lot in userland (if the
> interleaved app doesn't use the fpu in userland it won't create
> overhead).

that is also true, although some CPUs have basic (and not-so-basic)
crypto functions baked in, so no need to save or restore FPU registers
in those cases. 


best regards

Claudio

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-08-02 12:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-01 12:07 leesioh
2017-08-01 13:29 ` Claudio Imbrenda
2017-08-01 20:05 ` Andrea Arcangeli
2017-08-02 12:26   ` Claudio Imbrenda [this message]
2017-08-03  5:26   ` sioh Lee
2017-08-03 13:23     ` Andrea Arcangeli
2017-08-09 13:17       ` sioh Lee
2017-08-24 19:14         ` Andrea Arcangeli
2017-08-29  6:35           ` sioh Lee
2017-08-29 16:05             ` Andrea Arcangeli
2017-10-11 15:49 Timofey Titovets

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170802142629.578064f7@p-imbrenda.boeblingen.de.ibm.com \
    --to=imbrenda@linux.vnet.ibm.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=arvind.yadav.cs@gmail.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=mingo@kernel.org \
    --cc=solee@os.korea.ac.kr \
    --cc=zhongjiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox