mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Jack Wang <xjtuwjp@gmail.com>
Cc: gregkh@linuxfoundation.org,
	florian-ewald.mueller@profitbricks.com,
	linux-kernel@vger.kernel.org,
	Jack Wang <jinpu.wang@profitbricks.com>
Subject: Re: [PATCH] lib: memcmp optimization
Date: Tue, 9 Oct 2018 16:13:36 -0700	[thread overview]
Message-ID: <20181009161336.1abf11d48a9adf40486c30eb@linux-foundation.org> (raw)
In-Reply-To: <1539095291-9926-1-git-send-email-jinpuwang@gmail.com>

On Tue,  9 Oct 2018 16:28:11 +0200 Jack Wang <xjtuwjp@gmail.com> wrote:

> From: Florian-Ewald Mueller <florian-ewald.mueller@profitbricks.com>
> 
> During testing, I have configured 128 md/raid1's and, while under
> heavy IO, I started a check on each of them
> (echo check > /sys/block/mdx/md/sync_action).
> 
> The CPU utilization went through the ceiling and when looking for
> the cause (with 'perf top'). I've discovered that ~50% of the time
> was spend in memcmp() called from process_checks().
> 
> With this patch applied, it drops to 4% - 10%.

Which CPU architecture?  Most important architectures appear to define
__HAVE_ARCH_MEMCMP.

> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -852,7 +852,7 @@ EXPORT_SYMBOL(memmove);
>   * @count: The size of the area.
>   */
>  #undef memcmp
> -__visible int memcmp(const void *cs, const void *ct, size_t count)
> +static inline int __memcmp(const void *cs, const void *ct, size_t count)

What the heck does __visible do?

>  {
>  	const unsigned char *su1, *su2;
>  	int res = 0;
> @@ -862,6 +862,20 @@ __visible int memcmp(const void *cs, const void *ct, size_t count)
>  			break;
>  	return res;
>  }
> +__visible int memcmp(const void *cs, const void *ct, size_t count)
> +{
> +	const uint64_t *l1p = cs;
> +	const uint64_t *l2p = ct;
> +
> +	while (count >= sizeof(*l1p)) {
> +		if (*l1p != *l2p)
> +			return __memcmp(l1p, l2p, sizeof(*l1p));
> +		count -= sizeof(*l1p);
> +		++l1p;
> +		++l2p;
> +	}
> +	return __memcmp(l1p, l2p, count);
> +}

This is going to do bad things if the incoming addresses aren't
suitably aligned.

Certainly, byte-at-a-time is a pretty lame implementation when the
addresses are suitably aligned.  A fallback to the lame version when
there is misalignment will be simple to do.  And presumably there will
be decent benefits to whoever is actually using this code.  But I'm
wondering who is actually using this code!


  reply	other threads:[~2018-10-09 23:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 14:28 Jack Wang
2018-10-09 23:13 ` Andrew Morton [this message]
2018-10-10  7:33   ` Jinpu Wang

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=20181009161336.1abf11d48a9adf40486c30eb@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=florian-ewald.mueller@profitbricks.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jinpu.wang@profitbricks.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xjtuwjp@gmail.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

Powered by JetHome