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=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 602A4C433E0 for ; Mon, 4 Jan 2021 13:05:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20CE121BE5 for ; Mon, 4 Jan 2021 13:05:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727012AbhADNEq (ORCPT ); Mon, 4 Jan 2021 08:04:46 -0500 Received: from mx2.suse.de ([195.135.220.15]:59702 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725840AbhADNEp (ORCPT ); Mon, 4 Jan 2021 08:04:45 -0500 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=1609765438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vibaRJ3VEeCNwuYRgupkbYHsXd/lrAoVedXx0JmGMyw=; b=AvzCZDX6SWN4RvUPRK1ZySQleecMLM8R6orz8os3JfH99EDKEGYuFkut7otZbLrf+jPlhr M9x7JEihGX91WZZsj4ZAYcdIky2i16bDwj8RxqoxyNCotXu8Cy9Bpwlyb9DtfAcolhRq6n hbe0hsgvtmCjOKCbkJWPilXMg8I/1ZA= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 84C07AD19; Mon, 4 Jan 2021 13:03:58 +0000 (UTC) Date: Mon, 4 Jan 2021 14:03:57 +0100 From: Michal Hocko To: Feng Tang Cc: Andrew Morton , Johannes Weiner , Vladimir Davydov , linux-mm@kvack.org, linux-kernel@vger.kernel.org, andi.kleen@intel.com, tim.c.chen@intel.com, dave.hansen@intel.com, ying.huang@intel.com, Roman Gushchin Subject: Re: [PATCH 1/2] mm: page_counter: relayout structure to reduce false sharing Message-ID: <20210104130357.GF13207@dhcp22.suse.cz> References: <1609252514-27795-1-git-send-email-feng.tang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1609252514-27795-1-git-send-email-feng.tang@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 29-12-20 22:35:13, 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'. > > On 64 bit system, the 'usage' and 'parent' are close to each other, > and easy to be in one cacheline (for cacheline size == 64+ B). 'usage' > is usally written, while 'parent' is usually read as the cgroup's > hierarchical counting nature. > > So move the 'parent' to the end of the structure to make sure they > are in different cache lines. Yes, parent is write-once field so having it away from other heavy RW fields makes sense to me. > Following are some performance data with the patch, against > v5.11-rc1, on several generations of Xeon platforms. Most of the > results are improvements, with only one malloc case on one platform > shows a -4.0% regression. Each category below has several subcases > run on different platform, and only the worst and best scores are > listed: > > fio: +1.8% ~ +8.3% > will-it-scale/malloc1: -4.0% ~ +8.9% > will-it-scale/page_fault1: no change > will-it-scale/page_fault2: +2.4% ~ +20.2% What is the second number? Std? > [1].https://lore.kernel.org/lkml/20201102091543.GM31092@shao2-debian/ > Signed-off-by: Feng Tang > Cc: Roman Gushchin > Cc: Johannes Weiner > --- > include/linux/page_counter.h | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > 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; > > /* 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; > }; > > #if BITS_PER_LONG == 32 > -- > 2.7.4 > -- Michal Hocko SUSE Labs