From patchwork Thu May 23 03:48:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13671248 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 0202BC25B75 for ; Thu, 23 May 2024 03:48:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 263896B0089; Wed, 22 May 2024 23:48:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 212436B008C; Wed, 22 May 2024 23:48:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DBDF6B0093; Wed, 22 May 2024 23:48:37 -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 E41726B0089 for ; Wed, 22 May 2024 23:48:36 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 33988801FA for ; Thu, 23 May 2024 03:48:36 +0000 (UTC) X-FDA: 82148278632.01.CC5B760 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by imf27.hostedemail.com (Postfix) with ESMTP id D4CBA4000F for ; Thu, 23 May 2024 03:48:33 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=r3eDKVBX; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716436114; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=9tRgZzPEJaTN9YuDC4V2f++GoQNnZ4Ze+CSXfRX166U=; b=4VwfhGlrdrtl0CeGL75Bl6ipv6QZyQ6YrCpGjOoXAOjjPcJV0hjxP7zadU4qdPPnIYGjt+ mCfz1HFkfOEiNy9nVREgRqtqg9Z83CoQVXFASwoffqj1bu74AxLryPTjkVvfStQB/RhJI3 fXcSnXW25zGk1SHKGkvWqjJ7djfC28A= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=r3eDKVBX; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf27.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.181 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716436114; a=rsa-sha256; cv=none; b=05zp1h3UhTrGXDh2vFZWY1HB+BNE2OrIdliK/+H1LW6ebOWmd+h69fDDs2RTMwLUfnN7D/ eyzXaDlfy23vbF1eDP+D1FcCLupqskhgVmeB2ir6Kv7R7Umh7sy+CXazRxYfnL5vEQcVPu PQ/lf0/XyGlwsG9Xmw304UYTk3LAaIU= X-Envelope-To: akpm@linux-foundation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1716436111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=9tRgZzPEJaTN9YuDC4V2f++GoQNnZ4Ze+CSXfRX166U=; b=r3eDKVBX9w7H4aGL4t4v+4/UcYTl0OATfN707odf84XUtGWG1uh8PBqJF7P2H2909mvwkw Br64rnLByw/jpLjSZQLdN13e5o72SgHQ1AbBVq/vSDFiAxvqe++U6fZmA0EaXoxnknehWE elzJcJ0GPfuQW1QcxY5WMTgVAM1qP2U= X-Envelope-To: hannes@cmpxchg.org X-Envelope-To: mhocko@kernel.org X-Envelope-To: roman.gushchin@linux.dev X-Envelope-To: muchun.song@linux.dev X-Envelope-To: yosryahmed@google.com X-Envelope-To: ying.huang@intel.com X-Envelope-To: feng.tang@intel.com X-Envelope-To: fengwei.yin@intel.com X-Envelope-To: oliver.sang@intel.com X-Envelope-To: kernel-team@meta.com X-Envelope-To: linux-mm@kvack.org X-Envelope-To: linux-kernel@vger.kernel.org X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Yosry Ahmed Cc: ying.huang@intel.com, feng.tang@intel.com, fengwei.yin@intel.com, oliver.sang@intel.com, kernel-team@meta.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] memcg: rearrage fields of mem_cgroup_per_node Date: Wed, 22 May 2024 20:48:24 -0700 Message-ID: <20240523034824.1255719-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: D4CBA4000F X-Stat-Signature: bwfycoq591wrdn1irqzmipd4d61bddb4 X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1716436113-267817 X-HE-Meta: U2FsdGVkX1/yOfBypNAHnwI8R5WPGuvGIzAAW1RMT9qkIWTR2IbrfyryKVug0Y+IXHf2Xn0JQHW5mHPYduA0LhsGaKqpK4+0jLTTSjIuuBZh33GlvbFjL+0RpuGerlXxRPhUDje9w3+NVMyK4IUCi4rTbeiEGCNbdXdmqk0TktS/C2Kgskzaio2aDP5IJyincDynTj92bDcQi2SSYbsrj7I7dmgZQ7qE/PA946IIck3MNOMQmSSR3x5BITe5QWqSHwF86ivENHrF4HIBqyI4j4abruPVLLZQtkTFwNiYyoCU7ZPr345NkpKOrPGAjSXagG4iiU6CkVdDUeX+PEq4WsKVekRUVNht2Uiegq7sWQNbf1M1a2sEDwbZHSrjvc2mI+jcnfEKwqzhF6QbKGu6wb4SlYqDdOH91vToZvT2SZ82oA5PrNNvz8vR6IU5ppSTYEViRA/C4V3cSl8uIFIXYIMf00bANl1NsoIvCzlMc/Zx5wp1l05h/Ykknu6q1Fnf24HxcnZD5fh2DgoTjGGJ1d6F9j4U5PehscYTJzUMLyzjnSJDCwSjO4m+cAowpqyfSu2+qTTrWFSRAnFb6HEmXuB3AMLbAlpmq66S/mLZE+J7igyAgZ7M9UoXJ75i51288Y1gsoUmR4k66QEtMcmH3EEPkIgW3a2EzPgLD7arEK/OS+ZZLFLsqhS4MnYjJhI/Ia7R0FmEZ2jbnlB6xo8WJGaGatQGxqCGmA+v9L4ns8ZIFK+/mYMe2CSkQ8R7NgQqqEhdSRThczB5jeibzE0Fct5Cm+GMeZWlBxV2xIkCln9YUTJdV3FGZOTTkMTI/fk5Bl7Aq5hbQr2MnzEXY0kVUXZeX60RvWuiMFpxoAV3Bk2o8//ayxA2HZAkG+szgB3YddoJIIbIzxgXC7vkT0tgWAmUDz4scN/sQgq+47jIsWC+QndYmAU7gI1oRDlr4WxhKhmRcZVt4hRhMHlol0P lU69ld33 awV0jEFh8MGmmIn2BsxmdZoexsEwplgJrgB+lPp9Ztg8UPEEyecO0U6f9eSIQFBZ9OAonjt20diJqBstdnFmJV4VcboYEkHx/z+xWGiRE3Tvkyf9iJ7kWhy5FJQFoZTm1D63vA5DtWJgtwVxo7SAquMyzOJTB4K4GV70uif8z4em0VNl2viMLKx8COco4Ei/PlM9fGLsNs9VB9WtCGC/zXUuPuQ== 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: List-Subscribe: List-Unsubscribe: Kernel test robot reported [1] performance regression for will-it-scale test suite's page_fault2 test case for the commit 70a64b7919cb ("memcg: dynamically allocate lruvec_stats"). After inspection it seems like the commit has unintentionally introduced false cache sharing. After the commit the fields of mem_cgroup_per_node which get read on the performance critical path share the cacheline with the fields which get updated often on LRU page allocations or deallocations. This has caused contention on that cacheline and the workloads which manipulates a lot of LRU pages are regressed as reported by the test report. The solution is to rearrange the fields of mem_cgroup_per_node such that the false sharing is eliminated. Let's move all the read only pointers at the start of the struct, followed by memcg-v1 only fields and at the end fields which get updated often. Experiment setup: Ran fallocate1, fallocate2, page_fault1, page_fault2 and page_fault3 from the will-it-scale test suite inside a three level memcg with /tmp mounted as tmpfs on two different machines, one a single numa node and the other one, two node machine. $ ./[testcase]_processes -t $NR_CPUS -s 50 Results for single node, 52 CPU machine: Testcase base with-patch fallocate1 1031081 1431291 (38.80 %) fallocate2 1029993 1421421 (38.00 %) page_fault1 2269440 3405788 (50.07 %) page_fault2 2375799 3572868 (50.30 %) page_fault3 28641143 28673950 ( 0.11 %) Results for dual node, 80 CPU machine: Testcase base with-patch fallocate1 2976288 3641185 (22.33 %) fallocate2 2979366 3638181 (22.11 %) page_fault1 6221790 7748245 (24.53 %) page_fault2 6482854 7847698 (21.05 %) page_fault3 28804324 28991870 ( 0.65 %) Fixes: 70a64b7919cb ("memcg: dynamically allocate lruvec_stats") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202405171353.b56b845-oliver.sang@intel.com Signed-off-by: Shakeel Butt Reviewed-by: Yosry Ahmed Reviewed-by: Roman Gushchin --- include/linux/memcontrol.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 030d34e9d117..16efd9737be9 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -96,23 +96,25 @@ struct mem_cgroup_reclaim_iter { * per-node information in memory controller. */ struct mem_cgroup_per_node { - struct lruvec lruvec; + /* Keep the read-only fields at the start */ + struct mem_cgroup *memcg; /* Back pointer, we cannot */ + /* use container_of */ struct lruvec_stats_percpu __percpu *lruvec_stats_percpu; struct lruvec_stats *lruvec_stats; - - unsigned long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS]; - - struct mem_cgroup_reclaim_iter iter; - struct shrinker_info __rcu *shrinker_info; + /* memcg-v1 only stuff in middle */ + struct rb_node tree_node; /* RB tree node */ unsigned long usage_in_excess;/* Set to the value by which */ /* the soft limit is exceeded*/ bool on_tree; - struct mem_cgroup *memcg; /* Back pointer, we cannot */ - /* use container_of */ + + /* Fields which get updated often at the end. */ + struct lruvec lruvec; + unsigned long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS]; + struct mem_cgroup_reclaim_iter iter; }; struct mem_cgroup_threshold {