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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B860C00140 for ; Mon, 22 Aug 2022 00:24:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD2168E0001; Sun, 21 Aug 2022 20:24:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C5A0D6B0074; Sun, 21 Aug 2022 20:24:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AACC48E0001; Sun, 21 Aug 2022 20:24:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9632C6B0073 for ; Sun, 21 Aug 2022 20:24:42 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 672AB1C61C3 for ; Mon, 22 Aug 2022 00:24:42 +0000 (UTC) X-FDA: 79825332804.28.2EB40C3 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf25.hostedemail.com (Postfix) with ESMTP id 23C58A00AF for ; Mon, 22 Aug 2022 00:24:42 +0000 (UTC) Received: by mail-ej1-f41.google.com with SMTP id gt3so5851152ejb.12 for ; Sun, 21 Aug 2022 17:24:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=Eqv/19N5yEMgS5A7uMKIDvv+xbcnmfhfYxaJZgO8F20=; b=UicQpWpEmeF4kKoeqp/WmxAnf9tSyJSlCCvCKpoqea2kLCQ69aIPlMRNh8C+3XkGXM CKOhqFgao3DWFDsjsLNq8xeVqbewCc8NY9lCkqgwSywO8chlQH1+JVfwzfmlOpCeeddL ir8WDMIFe6sx2wEA55JyybCPBhEpqg/vfyoiWOWv7MhagbOKbO8lPdDqTDWvJscIAu6T g85dXRDbtNY6hSb/sZbRSHwGldG8kMBGLoi9Lcxh9F9wHALlSTO1M6IEA7bhddGDltAY uaPJXmxeBr/+rY0peyXTPwikF6BcvdKBZy1ivGuvz7hXUurZcqE3n6U9eAeqRYOQ8HXj ahsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=Eqv/19N5yEMgS5A7uMKIDvv+xbcnmfhfYxaJZgO8F20=; b=hs1us2/b6uCtimwWOtYP1BeBVIN5FZql2jQvFdl99BQfcaqjAxaa869e0McqSXVRny gXvd1gZCnLJI2mRoXSNeltI8nYO723KR2HXCQ4rAcDGCQccFLv21onn4/7xNjRWGksK7 ohOAK0h+4FLx13o/Z1bFmyIJKENdVadgN2cQMLl9hoPDngBNqQGSObLjlRAkigJChB3u 5K0xaHkH8ZYf2JUjwjH/MkfGfozwHns36sPZwZvRETphPbfMh1XS6hhujIFcz96Td6/c 9lmr2xmX91uVGrtKD1TqIgefL6q8JmdJVZDVhOqCRb+0Jwjs0q3CnlhqENMHAJOxQWbR /Ddg== X-Gm-Message-State: ACgBeo1ThAJmbUxZLyEe1bQueaSuXXTnGQpuOj4+fw5bd+LQzP6XDOiE VUHW/lk15/1zziYHWoQE13L1IBsKNeG6LshlTEf1jg== X-Google-Smtp-Source: AA6agR74JWGl5DtIW8j+H1KQUaVqCL/3GicPtrTzXAVqrBl/z2Ksrr0mXRq26zG4EyxF4PdTnY+kAzRg6WDkfsMNnW4= X-Received: by 2002:a17:907:2e0b:b0:730:8aee:d674 with SMTP id ig11-20020a1709072e0b00b007308aeed674mr11635721ejc.104.1661127880648; Sun, 21 Aug 2022 17:24:40 -0700 (PDT) MIME-Version: 1.0 References: <20220822001737.4120417-1-shakeelb@google.com> <20220822001737.4120417-3-shakeelb@google.com> In-Reply-To: <20220822001737.4120417-3-shakeelb@google.com> From: Soheil Hassas Yeganeh Date: Sun, 21 Aug 2022 20:24:04 -0400 Message-ID: Subject: Re: [PATCH 2/3] mm: page_counter: rearrange struct page_counter fields To: Shakeel Butt Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Eric Dumazet , Feng Tang , Oliver Sang , Andrew Morton , lkp@lists.01.org, cgroups@vger.kernel.org, linux-mm , netdev , linux-kernel Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661127882; a=rsa-sha256; cv=none; b=zmbo48uXC4XiQ/UF8Y+hKVVQOY4e9HN7iPk0vhgETw61jVcQwaA2yHozmp+6dnJPmCsTVA HrWrJZeV0LBSbH5XDBYcLR81/PpYvG33yP4uxhTgXe4ET4/kAlOfyUlMtw561Xdgl2fn2P V/mdQZxiRVrbm+ah96K3PTw3KBXzR4o= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UicQpWpE; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of soheil@google.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=soheil@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661127882; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Eqv/19N5yEMgS5A7uMKIDvv+xbcnmfhfYxaJZgO8F20=; b=LAPKiu8OcJ37j2pcwdXH+VbLhEMs0ybXvpowWaI4J8xaAGx9HrW+JhTF67bH8/ewBYHAfv jX/KJsqr7hUwHogTQW1YOz/goWEcvX4TyMj78nirnkKhs6Y+EFzxXXPH5SMbQo20qZcZ7/ 41EhXi3Rubjcha6Kc4GGlhNlBZqXpa8= Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UicQpWpE; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of soheil@google.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=soheil@google.com X-Rspam-User: X-Stat-Signature: sgxwomg3ucgudwyhaziza11g7hfpzy3t X-Rspamd-Queue-Id: 23C58A00AF X-Rspamd-Server: rspam06 X-HE-Tag: 1661127882-219861 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 Sun, Aug 21, 2022 at 8:18 PM Shakeel Butt wrote: > > With memcg v2 enabled, memcg->memory.usage is a very hot member for > the workloads doing memcg charging on multiple CPUs concurrently. > Particularly the network intensive workloads. In addition, there is a > false cache sharing between memory.usage and memory.high on the charge > path. This patch moves the usage into a separate cacheline and move all > the read most fields into separate cacheline. > > To evaluate the impact of this optimization, on a 72 CPUs machine, we > ran the following workload in a three level of cgroup hierarchy with top > level having min and low setup appropriately. More specifically > memory.min equal to size of netperf binary and memory.low double of > that. > > $ netserver -6 > # 36 instances of netperf with following params > $ netperf -6 -H ::1 -l 60 -t TCP_SENDFILE -- -m 10K > > Results (average throughput of netperf): > Without (6.0-rc1) 10482.7 Mbps > With patch 12413.7 Mbps (18.4% improvement) > > With the patch, the throughput improved by 18.4%. Shakeel, for my understanding: is this on top of the gains from the previous patch? > One side-effect of this patch is the increase in the size of struct > mem_cgroup. However for the performance improvement, this additional > size is worth it. In addition there are opportunities to reduce the size > of struct mem_cgroup like deprecation of kmem and tcpmem page counters > and better packing. > > Signed-off-by: Shakeel Butt > Reported-by: kernel test robot > --- > include/linux/page_counter.h | 34 +++++++++++++++++++++++----------- > 1 file changed, 23 insertions(+), 11 deletions(-) > > diff --git a/include/linux/page_counter.h b/include/linux/page_counter.h > index 679591301994..8ce99bde645f 100644 > --- a/include/linux/page_counter.h > +++ b/include/linux/page_counter.h > @@ -3,15 +3,27 @@ > #define _LINUX_PAGE_COUNTER_H > > #include > +#include > #include > #include > > +#if defined(CONFIG_SMP) > +struct pc_padding { > + char x[0]; > +} ____cacheline_internodealigned_in_smp; > +#define PC_PADDING(name) struct pc_padding name > +#else > +#define PC_PADDING(name) > +#endif > + > struct page_counter { > + /* > + * Make sure 'usage' does not share cacheline with any other field. The > + * memcg->memory.usage is a hot member of struct mem_cgroup. > + */ > + PC_PADDING(_pad1_); > atomic_long_t usage; > - unsigned long min; > - unsigned long low; > - unsigned long high; > - unsigned long max; > + PC_PADDING(_pad2_); > > /* effective memory.min and memory.min usage tracking */ > unsigned long emin; > @@ -23,16 +35,16 @@ struct page_counter { > atomic_long_t low_usage; > atomic_long_t children_low_usage; > > - /* 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. > - */ > + /* Keep all the read most fields in a separete cacheline. */ > + PC_PADDING(_pad3_); > + > + unsigned long min; > + unsigned long low; > + unsigned long high; > + unsigned long max; > struct page_counter *parent; > }; > > -- > 2.37.1.595.g718a3a8f04-goog >