From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37FDCC433DB for ; Wed, 20 Jan 2021 07:56:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9EE4C23131 for ; Wed, 20 Jan 2021 07:56:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9EE4C23131 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D95966B0007; Wed, 20 Jan 2021 02:56:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D46A36B0008; Wed, 20 Jan 2021 02:56:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C84DA6B000A; Wed, 20 Jan 2021 02:56:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0142.hostedemail.com [216.40.44.142]) by kanga.kvack.org (Postfix) with ESMTP id B41FD6B0007 for ; Wed, 20 Jan 2021 02:56:04 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 85F903628 for ; Wed, 20 Jan 2021 07:56:04 +0000 (UTC) X-FDA: 77725395048.04.home39_500424727558 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 64A7E8002264 for ; Wed, 20 Jan 2021 07:56:04 +0000 (UTC) X-HE-Tag: home39_500424727558 X-Filterd-Recvd-Size: 5334 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 Jan 2021 07:56:03 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1611129362; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=10TNc64vcvmY4BmMGIrygVrVOvqidXtSKL+wsXLD8iQ=; b=H36PWmR8WR91rEaz+VyKGTRDpLTkbRJr0CVQ7gnv765XueOy9Nm3t9V1y2h1wqCtOzdgsH qAoDbaxhhuPPZ12iuQxQ6fw69nNx5Mp9mvfGQob0EOVki8MDaQFWdux8z9iDob5JNCla3r tuomjMw366uAvUFpYiUdSm4wQ4nAgIY= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 9FDE3ACAD; Wed, 20 Jan 2021 07:56:02 +0000 (UTC) Date: Wed, 20 Jan 2021 08:56:01 +0100 From: Michal Hocko To: Feng Tang Cc: Andrew Morton , Johannes Weiner , Roman Gushchin , Shakeel Butt , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: page_counter: relayout structure to reduce false sharing Message-ID: <20210120075601.GC9371@dhcp22.suse.cz> References: <1611040814-33449-1-git-send-email-feng.tang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1611040814-33449-1-git-send-email-feng.tang@intel.com> Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue 19-01-21 15:20:14, Feng Tang wrote: > When checking a memory cgroup related performance regression [1], > from the perf c2c profiling data, we found high false sharing for > accessing 'usage' and 'parent'. >=20 > On 64 bit system, the 'usage' and 'parent' are close to each other, > and easy to be in one cacheline (for cacheline size =3D=3D 64+ B). 'usa= ge' > is usally written, while 'parent' is usually read as the cgroup's > hierarchical counting nature. >=20 > So move the 'parent' to the end of the structure to make sure they > are in different cache lines. >=20 > Following are some performance data with the patch, against > v5.11-rc1. [ In the data, A means a platform with 2 sockets 48C/96T, > B is a platform of 4 sockests 72C/144T, and if a %stddev will be > shown bigger than 2%, P100/P50 means number of test tasks equals > to 100%/50% of nr_cpu] >=20 > will-it-scale/malloc1 > --------------------- > v5.11-rc1 v5.11-rc1+patch >=20 > A-P100 15782 =B1 2% -0.1% 15765 =B1 3% will-it-scale.= per_process_ops > A-P50 21511 +8.9% 23432 will-it-scale.per_p= rocess_ops > B-P100 9155 +2.2% 9357 will-it-scale.per_= process_ops > B-P50 10967 +7.1% 11751 =B1 2% will-it-scale.per= _process_ops >=20 > will-it-scale/pagefault2 > ------------------------ > v5.11-rc1 v5.11-rc1+patch >=20 > A-P100 79028 +3.0% 81411 will-it-scale.per_= process_ops > A-P50 183960 =B1 2% +4.4% 192078 =B1 2% will-it-scale.p= er_process_ops > B-P100 85966 +9.9% 94467 =B1 3% will-it-scale.pe= r_process_ops > B-P50 198195 +9.8% 217526 will-it-scale.per_p= rocess_ops >=20 > fio (4k/1M is block size) > ------------------------- > v5.11-rc1 v5.11-rc1+patch >=20 > A-P50-r-4k 16881 =B1 2% +1.2% 17081 =B1 2% fio.read_bw_M= Bps > A-P50-w-4k 3931 +4.5% 4111 =B1 2% fio.write_bw_MB= ps > A-P50-r-1M 15178 -0.2% 15154 fio.read_bw_MBps > A-P50-w-1M 3924 +0.1% 3929 fio.write_bw_MBps Thanks for making results easier to read and understand. > [1].https://lore.kernel.org/lkml/20201102091543.GM31092@shao2-debian/ > Signed-off-by: Feng Tang > Reviewed-by: Roman Gushchin > Cc: Johannes Weiner > Cc: Michal Hocko Acked-by: Michal Hocko Thanks! > --- > Changelogs: > =20 > v2: > * Adjust the format of performance data to be more readable, > as suggested by Michal Hocko >=20 > include/linux/page_counter.h | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) >=20 > diff --git a/include/linux/page_counter.h b/include/linux/page_counter.= h > index 85bd413..6795913 100644 > --- a/include/linux/page_counter.h > +++ b/include/linux/page_counter.h > @@ -12,7 +12,6 @@ struct page_counter { > unsigned long low; > unsigned long high; > unsigned long max; > - struct page_counter *parent; > =20 > /* effective memory.min and memory.min usage tracking */ > unsigned long emin; > @@ -27,6 +26,14 @@ struct page_counter { > /* legacy */ > unsigned long watermark; > unsigned long failcnt; > + > + /* > + * 'parent' is placed here to be far from 'usage' to reduce > + * cache false sharing, as 'usage' is written mostly while > + * parent is frequently read for cgroup's hierarchical > + * counting nature. > + */ > + struct page_counter *parent; > }; > =20 > #if BITS_PER_LONG =3D=3D 32 > --=20 > 2.7.4 >=20 --=20 Michal Hocko SUSE Labs