From patchwork Thu Aug 25 00:05:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 12954103 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 567ADC3F6B0 for ; Thu, 25 Aug 2022 00:05:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E671F940009; Wed, 24 Aug 2022 20:05:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEDF86B0075; Wed, 24 Aug 2022 20:05:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C684F940009; Wed, 24 Aug 2022 20:05:35 -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 B5C5D6B0074 for ; Wed, 24 Aug 2022 20:05:35 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8808F120219 for ; Thu, 25 Aug 2022 00:05:35 +0000 (UTC) X-FDA: 79836171030.04.6C2BAD6 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf10.hostedemail.com (Postfix) with ESMTP id F1DE8C0038 for ; Thu, 25 Aug 2022 00:05:34 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id a21-20020a62bd15000000b005360da6b25aso6821043pff.23 for ; Wed, 24 Aug 2022 17:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc; bh=PYwH6PVPNEHbvaxrK4rS2xJuwZB9u4thO5MZW7XvPbI=; b=P+EUKtE6ricb8wdTGimfBl8wJsULmlf1U1ls8bGlVkUaNforVbvQ3tC93r2Tpdhx/X hu4ZaMawAO1E12zWi9v+4nP6DUb1SVdPpLc3AZ/xudS37LWaRSiaGz4e0Ka35xNar8nS etTkXsMGtCUsHLIDJkq4yN6bXebVUWkeBXO36LV/lhjXudjbUt/w2JGO2qgaytESq7HV 6902pIR1fNvHv7YRbB2LtQuxsm8du6S+P2rMcQlo6xTb/H6Yi7+CtEya63vTqQFwHjtL G+IvhJMvzorYcD57EwbY2fI611avPsNj/SezAfStYMECqaRueXSKqxPmfC43aGfBG3ct BUhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc; bh=PYwH6PVPNEHbvaxrK4rS2xJuwZB9u4thO5MZW7XvPbI=; b=tHz3mtFwHv6wf9lcOFqIwqfwVOZGSY15AjD2tzuEEmEdup9udVIBt+OPsaDPIcQ71+ rtyC9V2H/pxOUaOogfm3Lj17a/MDlz7xORbtdVl5BnGPUXoC5j7c66c4hxYcSfKxsSMx UM7WG6LVjdDGdNcn+1e5LnTRhIn6RiIX5oCek7/B/Ytdv/4kYHcy/0M6IuFd4iZK+XHw tmmx16NsXea/HEER1Nj7JtKYx+LdN2rr642jeCAJMdvI1ze6T/MTMI03Z6aqdukr2hke BFkXXMeQC2p81qx9+GT6vVYMUvySbGjGMUSnJVwMPrA6sEROrZJUaok6isP9ef9Fa7W0 GcrQ== X-Gm-Message-State: ACgBeo0uAXGEqxevm6LgqKk7MWjCIEXAPQNKJySaOy7tFhb0/Jc8Qor6 uigXNslBGR53d2NI0xmZ6Z57SDrkuThtTQ== X-Google-Smtp-Source: AA6agR7GEZzDTz56S0z9ZFwwo3+8A2cJS+hBXK4FDB5SFen3ixUf21xrVf8m+nkxp75ju1W8OqgypD5lC+ctAw== X-Received: from shakeelb.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:262e]) (user=shakeelb job=sendgmr) by 2002:a17:90b:a14:b0:1fa:bc6e:e5e8 with SMTP id gg20-20020a17090b0a1400b001fabc6ee5e8mr118633pjb.1.1661385933916; Wed, 24 Aug 2022 17:05:33 -0700 (PDT) Date: Thu, 25 Aug 2022 00:05:05 +0000 In-Reply-To: <20220825000506.239406-1-shakeelb@google.com> Message-Id: <20220825000506.239406-3-shakeelb@google.com> Mime-Version: 1.0 References: <20220825000506.239406-1-shakeelb@google.com> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH v2 2/3] mm: page_counter: rearrange struct page_counter fields From: Shakeel Butt To: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song Cc: " =?utf-8?q?Michal_Koutn=C3=BD?= " , Eric Dumazet , Soheil Hassas Yeganeh , Feng Tang , Oliver Sang , Andrew Morton , lkp@lists.01.org, cgroups@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Shakeel Butt ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661385935; a=rsa-sha256; cv=none; b=D8rL+RsRONbDPEeHjAZqReauvbPmaD4w5p+p0Cd+UcBUBe6SKCVmbss9FKdaFB1ve+9mqK xTREEKLknnIaG1iQU0vrMWERDSP8DcQdNsKmGsC/RG/WLX5RATtZUpdX92z5SND18sHDFb 8W7rLjdCC4z5Ej8LZpNN9r77NLi91bg= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=P+EUKtE6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3zbwGYwgKCIAwleoiipfksskpi.gsqpmry1-qqozego.svk@flex--shakeelb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3zbwGYwgKCIAwleoiipfksskpi.gsqpmry1-qqozego.svk@flex--shakeelb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661385935; 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=PYwH6PVPNEHbvaxrK4rS2xJuwZB9u4thO5MZW7XvPbI=; b=NcREBk6vU8QkJCGSMnqzeZs0SBPJdhHrkTptWnM3yKYSCy1qfnw9TWo4xbMV428q/Qwc3L yt59GXnWfJ1sECVWKMWAGV/xQbcsp3OtZfhlSgiOPAaFFU2T6qOki1Cf7+ejm07HBvG3oZ pWnvVSmj+pHpZltL9zckUPaJkztx5jw= Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=P+EUKtE6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3zbwGYwgKCIAwleoiipfksskpi.gsqpmry1-qqozego.svk@flex--shakeelb.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3zbwGYwgKCIAwleoiipfksskpi.gsqpmry1-qqozego.svk@flex--shakeelb.bounces.google.com X-Rspamd-Queue-Id: F1DE8C0038 X-Rspamd-Server: rspam02 X-Stat-Signature: iaoxrh8x3u9xtw45wcy3s4yppug38mgq X-Rspam-User: X-HE-Tag: 1661385934-160524 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: 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. $ 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%. One side-effect of this patch is the increase in the size of struct mem_cgroup. For example with this patch on 64 bit build, the size of struct mem_cgroup increased from 4032 bytes to 4416 bytes. 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 Reviewed-by: Feng Tang Acked-by: Soheil Hassas Yeganeh Acked-by: Roman Gushchin Acked-by: Michal Hocko --- Changes since v1: - Updated the commit message - Make struct page_counter cache align. include/linux/page_counter.h | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/include/linux/page_counter.h b/include/linux/page_counter.h index 679591301994..78a1c934e416 100644 --- a/include/linux/page_counter.h +++ b/include/linux/page_counter.h @@ -3,15 +3,26 @@ #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. + */ atomic_long_t usage; - unsigned long min; - unsigned long low; - unsigned long high; - unsigned long max; + PC_PADDING(_pad1_); /* effective memory.min and memory.min usage tracking */ unsigned long emin; @@ -23,18 +34,18 @@ 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(_pad2_); + + unsigned long min; + unsigned long low; + unsigned long high; + unsigned long max; struct page_counter *parent; -}; +} ____cacheline_internodealigned_in_smp; #if BITS_PER_LONG == 32 #define PAGE_COUNTER_MAX LONG_MAX