Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp190550imm; Tue, 9 Oct 2018 16:15:57 -0700 (PDT) X-Google-Smtp-Source: ACcGV622HUZa6/yEl4MEuSromlay9vGXVBg0fJ/dU3BClhxkUEM2m7aWMWa6ReQkTfEcEITQ7NRK X-Received: by 2002:a63:1148:: with SMTP id 8-v6mr27872163pgr.172.1539126957908; Tue, 09 Oct 2018 16:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539126957; cv=none; d=google.com; s=arc-20160816; b=WZxXTmRfJBldSszLVFIzfE/kHAt/V9vjuGsrosQNjwwgYnX+3xXG6JTscmhOq67hwf 6r7hTdA4AWxyutraVJZFUy4VXdgBKKjnD94ofJ5dGtvTuUpbQYxDpiNPvITt/c8tUwcv 9vkLJTjbDJwcjsBwKu3mMGKq2sqeLkYJtyRnhqgrtLvtI9pH+3AcNHZdJyatC+bS8ilr UZfDF5GHV4dCcd99iGYZza+YRAsEmItlQcp4L5R8HcssieauTP0MKwjqWDXCZ4T7gMVc 7F2tdKcbbh90fSAGiYRdluCfr7rCDEqGHZTUEPc4HVEfEkEbeVGWDk4u2Uf/yHYeqEUg W9GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=LawPj4BDTNfXaup49X3W+X43YSmatXy+PUrcAj7whTU=; b=lPRfRnSvShgGVZG1QkWdCU21NnNi5hQgjq+t4v3liyN+tRcsMzJY8lp57Yg4N+89ir 0fi3ZHIw8g9nVk6p/vLAeiqIcP6iHcfETzern57ZdgAq9jMfoZkcJHa+Ack8HuavKzAK WOa7aLEPuY4hwqlXh16bLDM6tFXghgkh3Q8T4LIi8YVM33kIc5Cw4Z23wT7YYa7PBQtN ijjfG/xVb7FUoYozhSqyXGMGSyKWp+GcL3P2C6d3jRR638BMjGYBiI1Q0URSjXkBAGZf I/GtouKUURBkw532fOOFJj8928XY34LKTl7DY5XtJcddStNQUUZ0cyr5YZHpy2vpR4qI iddA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h184-v6si25931361pfb.146.2018.10.09.16.15.43; Tue, 09 Oct 2018 16:15:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726925AbeJJGcy (ORCPT + 99 others); Wed, 10 Oct 2018 02:32:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45870 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725750AbeJJGcy (ORCPT ); Wed, 10 Oct 2018 02:32:54 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.8.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id CCF4A7AA; Tue, 9 Oct 2018 23:13:37 +0000 (UTC) Date: Tue, 9 Oct 2018 16:13:36 -0700 From: Andrew Morton To: Jack Wang Cc: gregkh@linuxfoundation.org, florian-ewald.mueller@profitbricks.com, linux-kernel@vger.kernel.org, Jack Wang Subject: Re: [PATCH] lib: memcmp optimization Message-Id: <20181009161336.1abf11d48a9adf40486c30eb@linux-foundation.org> In-Reply-To: <1539095291-9926-1-git-send-email-jinpuwang@gmail.com> References: <1539095291-9926-1-git-send-email-jinpuwang@gmail.com> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 9 Oct 2018 16:28:11 +0200 Jack Wang wrote: > From: Florian-Ewald Mueller > > 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!