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 5621BC2BD09 for ; Tue, 9 Jul 2024 23:17:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F2116B0083; Tue, 9 Jul 2024 19:17:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A1EB6B0088; Tue, 9 Jul 2024 19:17:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 769456B0089; Tue, 9 Jul 2024 19:17:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 570956B0083 for ; Tue, 9 Jul 2024 19:17:50 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D72031606B9 for ; Tue, 9 Jul 2024 23:17:49 +0000 (UTC) X-FDA: 82321778658.24.99AB355 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) by imf23.hostedemail.com (Postfix) with ESMTP id 6D00514000D for ; Tue, 9 Jul 2024 23:17:47 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ChKpY3vx; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720567036; 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=RK9Y5z4esCl/0wptVyHMDsH+At4AHH/Nt2PZDk2eccU=; b=RvCHNGASbL9lfZYNwaYkuIgXfr4mkhCrU1iN2XOF5p2RBzUJZef1HU3plB0XI7IU/XiqLW SYX1mwiolXMQ2Q/gWcv9t/mdmxsjE8nduafJfk47+89f1Kf+wCgQhIrdEDPKBeLltipWac HHFgg70eVvXfpLzrnW3znW5xgdBS79s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720567036; a=rsa-sha256; cv=none; b=IA2mOtfdqR7914NjTzJjx8guJhAp5iks/VUCmddt7qDZ+c5t74H7AaYnq6T/CBbF5rSWGr CcivFAEHoqU3OOOIAg7szHdaTrDXDx0W5SXjJoZ87P6qglssdj8WhNzR1/fc/YsZnzgImo rVhBMUXZxlShr6YbyDLwlKLtZ1+xhtM= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ChKpY3vx; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Envelope-To: hawk@kernel.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1720567065; h=from:from:reply-to:subject:subject: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=RK9Y5z4esCl/0wptVyHMDsH+At4AHH/Nt2PZDk2eccU=; b=ChKpY3vxx6hvZJVlnM5gYc5SXa7vsvbzJ9mPy/9wkA9eqerHdTd3W8vlsRFsZOgLyN+B37 ZbM5USYjUy55AzSJECEvXkyXSPb2f3+mJCD+k2s6HXGVVoB9b2wTXDZUFN9UpihF6L3mU2 P2JCIKziJIoO6+AUSBmK6j93sC/2Wdo= X-Envelope-To: tj@kernel.org X-Envelope-To: cgroups@vger.kernel.org X-Envelope-To: yosryahmed@google.com X-Envelope-To: hannes@cmpxchg.org X-Envelope-To: lizefan.x@bytedance.com X-Envelope-To: longman@redhat.com X-Envelope-To: kernel-team@cloudflare.com X-Envelope-To: linux-mm@kvack.org X-Envelope-To: linux-kernel@vger.kernel.org Date: Tue, 9 Jul 2024 16:17:31 -0700 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Jesper Dangaard Brouer Cc: tj@kernel.org, cgroups@vger.kernel.org, yosryahmed@google.com, hannes@cmpxchg.org, lizefan.x@bytedance.com, longman@redhat.com, kernel-team@cloudflare.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH V6] cgroup/rstat: Avoid thundering herd problem by kswapd across NUMA nodes Message-ID: <3oyf3p3xyhxxugucwsuhtuais6547rvzob5fkz3yc7jgocow2n@odqb6l2oweto> References: <172052399087.2357901.4955042377343593447.stgit@firesoul> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <172052399087.2357901.4955042377343593447.stgit@firesoul> X-Migadu-Flow: FLOW_OUT X-Stat-Signature: uxf8ofhibwxcue34f487qt35ocy6yaq8 X-Rspamd-Queue-Id: 6D00514000D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1720567067-756313 X-HE-Meta: U2FsdGVkX1/qpeFqjZ7kkZnYLGTx0tA7R1htR+kX7h0aJn8CaaSUYpvgDoMmTeF/aozIBVENQMoleTg1jLkbp36d80YcNHNVwmeIhZpJvndBkZkuGlX/DS0XK5ylMWwv2oxMDC+OuCVdxTzjY0TRnBWR8EhuYtCjttLqjFBPbBplZd+nFERD89E8yrRMnGwdfxuPW26KV6YMoLCTp94YU2a3NYjjx80o6A8TrVgeX8WxlpLhTETEXWiL4zMvigwLxBzUIEOw1i4sHLP/Ll2AdRzx5lyiRPn4jYA13lbbKBtxKLc23tW+DUv6Gctl1L/OfmVQlX6wkxxPFn4YQXMjvxH91QavbqCi2OhMjdasxFlq5avEH+xhhitdnjR2pjCb4FC3qRcuKJZukUcL5ceLNCdllWQFDQTS7mijX3DMfAijZ6nn1JjpGjWqfxU5eYl6CuEsU5IN5YixFuAwRvzSOyqiOp7XZ6HJzm8BKCd6/ikwjNZhZJOUiy8EbOcvr35GZ3uOTg5usahhvS+18c+Y2UmfY6dbQHaNdAGEW97iDIR0EE3F40HeRZaXfhBurXi0oG/V/P3uEW31jy0Ozp2U4wA5o8PaqDIXjFt4+37ajP8+Z/SRVBiU7Z6g1z7zJVpD0TxWVLkjaZ/I0M1rN/fQ7we+IcsKN9HYxtNsVzgQvFKwtVd01kxcJDppJ5SJCL9wfzHTGA9FIJkCCjvJ/0rIrccavb7TJjj+Eu4e9xn8n+oicrYl5R2Kxw442EWVEfsw9Cxhdib5qHmslhFVkOa8bC6+fx7FEZA2kl2GCoHR78DxkbY8+jwV9uXk2v9v1GZCFOZzFDFaqfTLD6gFrLq/7ZkoSBhYqk2CgTY3F8XMcvVRCkJaR5OqmW+/HLwATJaiomHqa2Fjqz0sbzW04P0Z85bK1c7oVhgGH8ioglHDywA9tk+GHWxceXfnQ7DjSHYtpcGS4IRipiHLnuUA14P PD6CoKHm ZlqJA0SZpuNROcSrGg8/f+/JtyORM3xovPzNzyR6ZbtGRs1XoYPJD3MlaE/Te1004KCZn4u/9HLHSV1EIxM/tcNCCPhONFMcjfVJwZijCvFeQ42i+2w0UJNFEq+s1QsqDfOengodXgmeBc0mdzZOPjd7lUx01XpGQ/ajSTmkGsVpDmG4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jul 09, 2024 at 01:20:48PM GMT, Jesper Dangaard Brouer wrote: > Avoid lock contention on the global cgroup rstat lock caused by kswapd > starting on all NUMA nodes simultaneously. At Cloudflare, we observed > massive issues due to kswapd and the specific mem_cgroup_flush_stats() > call inlined in shrink_node, which takes the rstat lock. > > On our 12 NUMA node machines, each with a kswapd kthread per NUMA node, > we noted severe lock contention on the rstat lock. This contention > causes 12 CPUs to waste cycles spinning every time kswapd runs. > Fleet-wide stats (/proc/N/schedstat) for kthreads revealed that we are > burning an average of 20,000 CPU cores fleet-wide on kswapd, primarily > due to spinning on the rstat lock. > > Help reviewers follow code: __alloc_pages_slowpath calls wake_all_kswapds > causing all kswapdN threads to wake up simultaneously. The kswapd thread > invokes shrink_node (via balance_pgdat) triggering the cgroup rstat flush > operation as part of its work. This results in kernel self-induced rstat > lock contention by waking up all kswapd threads simultaneously. Leveraging > this detail: balance_pgdat() have NULL value in target_mem_cgroup, this > cause mem_cgroup_flush_stats() to do flush with root_mem_cgroup. > > To avoid this kind of thundering herd problem, kernel previously had a > "stats_flush_ongoing" concept, but this was removed as part of commit > 7d7ef0a4686a ("mm: memcg: restore subtree stats flushing"). This patch > reintroduce and generalized the concept to apply to all users of cgroup > rstat, not just memcg. > > If there is an ongoing rstat flush, and current cgroup is a descendant, > then it is unnecessary to do the flush. For callers to still see updated > stats, wait for ongoing flusher to complete before returning, but add > timeout as stats are already inaccurate given updaters keeps running. > > Fixes: 7d7ef0a4686a ("mm: memcg: restore subtree stats flushing"). > Signed-off-by: Jesper Dangaard Brouer > --- > V5: https://lore.kernel.org/all/171956951930.1897969.8709279863947931285.stgit@firesoul/ Does this version fixes the contention you are observing in production for v5?