From patchwork Mon Aug 22 00:17:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 12950092 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 37DBCC00140 for ; Mon, 22 Aug 2022 00:18:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5D498E0001; Sun, 21 Aug 2022 20:18:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0DC76B0074; Sun, 21 Aug 2022 20:18:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FC408E0001; Sun, 21 Aug 2022 20:18:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7EECF6B0073 for ; Sun, 21 Aug 2022 20:18:02 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 521EC80129 for ; Mon, 22 Aug 2022 00:18:02 +0000 (UTC) X-FDA: 79825316004.18.6154438 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf09.hostedemail.com (Postfix) with ESMTP id 1A4891400A8 for ; Mon, 22 Aug 2022 00:18:01 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id j11-20020a170902da8b00b0016f17813479so6260345plx.5 for ; Sun, 21 Aug 2022 17:18:01 -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=V/ZZIFSPKFcCAZIO5J88CNRgR4nImf4CDqSEwHgZtc8=; b=VRt8PiD5az0Dl+WRznAYAHoEFU2MambiOUqw9hJIF1ucU60TS0sVFR1bUuaJD8nPng xGG21VhjqfptsMV9A8m6NtDIcNUxnu3moTzE7NDuS0132TTFDbZUQdoq7PUgYhDiEc88 VWXGevOtBTC071FhOwLWbdC2RbpbtXjJBP30qVmnMrkSyaRORF9MkIgIOE44YT8fPxhx MXMroQq5cbkgX/PlRdMgvF1WbQYDo+Czb0BC6hLgVyoEUZLM+nIZRg1Iz+BkUSiS19+u NDrsfq1Tm8UcqdVd/B6tTxgxOaUMNvPwSrhSYvXv0b64wiY5pKs+NN5viMa0qiHMezJn gzSQ== 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=V/ZZIFSPKFcCAZIO5J88CNRgR4nImf4CDqSEwHgZtc8=; b=Y57x/WJ7AewxchKwWcDIVRu6lhOmeLonz8PKLiYueqeM5ooQfkZ2gAx895gDPNuGzu nxwSnnl87Z3dD7lU/KMTJeLKSzhFejCdRTHi9wXWeYBt3NtgCEnwnyD4M66ld9CYVagR X08MNRvpOqovbpDnu4ixQXcRLjbOM1lawKMGHHeXRaIaWId/WlADstJ9cxLK20nw+cya rmETEESG879LemQzt3a0xJHEYgtxiwNUvkp2CPvR8Yn8L2PzD0yV10iRXfdhH6CWUFOk WT7uttuebNjZbQPxapHtNBgrh2BQ7NW6ed7iuwxRamGJQJs9XVI3/+z2LU5cTrtEEW3N 2Ezg== X-Gm-Message-State: ACgBeo1PaHcblLRnG4jez6XXZjU4hmo0nTG6I3gN6+dpjVifAOgQca/F gtMNym/71FnexR2tBv6ezsUhYNkwTG7G4Q== X-Google-Smtp-Source: AA6agR4ZgdLQRLm8RNOfyL+FjO9Haoqcxi6ZB51K8Zqax6/eLDbW7KkNV8E35m3mv6YMj7ylkoz8NrwpsF9kng== X-Received: from shakeelb.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:28b]) (user=shakeelb job=sendgmr) by 2002:a17:902:da8e:b0:172:9f0b:3778 with SMTP id j14-20020a170902da8e00b001729f0b3778mr17761139plx.166.1661127480895; Sun, 21 Aug 2022 17:18:00 -0700 (PDT) Date: Mon, 22 Aug 2022 00:17:36 +0000 In-Reply-To: <20220822001737.4120417-1-shakeelb@google.com> Message-Id: <20220822001737.4120417-3-shakeelb@google.com> Mime-Version: 1.0 References: <20220822001737.4120417-1-shakeelb@google.com> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog Subject: [PATCH 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=1661127482; a=rsa-sha256; cv=none; b=gAFGkwlbN/nHuZIB/Z/ty7odfoSiKZ17iHl0yp1IJ02jolnsxgCXL+CngOEPnwj+DIB2bM LV112K87oeCMkd4FUPSUBWvFMiwJ7d3Szyznaq5/vdjgZd8+eLYpL8CrboXHSfzSphFgbW tVFaBdKRrEMYpY8dHO0HNTRrZH2318k= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VRt8PiD5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3OMsCYwgKCPcrgZjddkafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--shakeelb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3OMsCYwgKCPcrgZjddkafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--shakeelb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661127482; 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=V/ZZIFSPKFcCAZIO5J88CNRgR4nImf4CDqSEwHgZtc8=; b=7MzVkFBa4/wxCzYV3GqAiAeTrPSEhTpapmB3ixNB8B+8CYUIn0bsHRjHRw3hbntPiWU5ZT tpTGoDRn8iCqAmwjmIf3QkjIz8bmYw+6spaHHqh4HEW4K7qnQTH4b0twec0857bdLNw4EO JLJcs8rgcFrrtyZfybCSWi6Hxr17gCk= X-Rspamd-Queue-Id: 1A4891400A8 X-Stat-Signature: gpxjw6po1ge6t6tgksexnkf6k43u6d5s Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VRt8PiD5; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 3OMsCYwgKCPcrgZjddkafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--shakeelb.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3OMsCYwgKCPcrgZjddkafnnfkd.bnlkhmtw-lljuZbj.nqf@flex--shakeelb.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1661127481-452831 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 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%. 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 Reviewed-by: Feng Tang Acked-by: Roman Gushchin --- 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; };