From patchwork Tue Apr 16 17:51:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Dangaard Brouer X-Patchwork-Id: 13632261 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 4988DC4345F for ; Tue, 16 Apr 2024 17:51:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBDBB6B009B; Tue, 16 Apr 2024 13:51:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D6E5B6B009C; Tue, 16 Apr 2024 13:51:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C355D6B009D; Tue, 16 Apr 2024 13:51:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A53826B009B for ; Tue, 16 Apr 2024 13:51:35 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3D050A0FCF for ; Tue, 16 Apr 2024 17:51:35 +0000 (UTC) X-FDA: 82016137350.27.CEC4065 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf25.hostedemail.com (Postfix) with ESMTP id 7EDCFA000C for ; Tue, 16 Apr 2024 17:51:33 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dBq3Bzz0; spf=pass (imf25.hostedemail.com: domain of hawk@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=hawk@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713289893; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7FERMcdJ/nypr/NtJibSgI0Cn/LJnTGynFKq1MlnNQE=; b=qYfN330T+lrnm0v6oDbhpH/8BpNLbBxj2MdD9Tc3GNeJZqBsFzVybdi1/7Ns0OmQnw4tgB 2JUR9Q4sA867uWT9cI7ORT0AbXOdjX5n6wDqZ4EkRO4LDKQWZjd9xW3VKrq/hhphQzRWwC a09dK4J5MyQOsznZ67H9GTQ9H9qKVBY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713289893; a=rsa-sha256; cv=none; b=bmeHv8oGMWb0I+cKgdaXka+euzHKDypsuD6KzjyzjIU2STVDoZ7t1UWhl7vKNdt2GhCI2B trydI6P3GQRD2t07yFCjamOmMz7jwoUTYLLzGGGJ9D9EsID9xGl0AqXhFBV4pRpSvmsPyx DKMZxsDeePUM2PMEuBfk4HxT8+FQYjs= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dBq3Bzz0; spf=pass (imf25.hostedemail.com: domain of hawk@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=hawk@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 69C6061257; Tue, 16 Apr 2024 17:51:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D599C113CE; Tue, 16 Apr 2024 17:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713289892; bh=6AoQjMmtCpA92ORAYahs1Yjyu49n9JrorgvUAsN4z7A=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=dBq3Bzz0EYHz6B9QSkhEnwznlxP5JAAVUOO63eojPw9TTIgF3RqHAWDqPv1j32x3D xkmhmtazuEqtuuOT8YiBeCcHSwk6K+gA3L+Wi6kjmC3GH0i16vmnvB5Xt/xCHpwMmu z+MAOQsXce/0Af8YKLkJfedtDulk2hgU9LdLgXJr0xLiUIlHKUa9KM3i1HIPw64p1g 6Su3c4lVRrtAcw1srlnua2Y/o5gACkabKTgADjyYhaDuaavJ4iLOtWk257IydQkkjb DKymWfbCHI5jEW2guzlRNnok/PlUl+gV+QUhfqBCTIX47xul1EKw3nClMy4KFOd3vc 6im5vJq/eah5Q== Subject: [PATCH v1 1/3] cgroup/rstat: add cgroup_rstat_lock helpers and tracepoints From: Jesper Dangaard Brouer To: tj@kernel.org, hannes@cmpxchg.org, lizefan.x@bytedance.com, cgroups@vger.kernel.org, yosryahmed@google.com, longman@redhat.com Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, shakeel.butt@linux.dev, kernel-team@cloudflare.com, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Sebastian Andrzej Siewior , mhocko@kernel.org Date: Tue, 16 Apr 2024 19:51:26 +0200 Message-ID: <171328988660.3930751.17537768209042139758.stgit@firesoul> In-Reply-To: <171328983017.3930751.9484082608778623495.stgit@firesoul> References: <171328983017.3930751.9484082608778623495.stgit@firesoul> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7EDCFA000C X-Stat-Signature: j8f197ski9ooo9gii91e6efeinx1bc7r X-HE-Tag: 1713289893-891590 X-HE-Meta: U2FsdGVkX1/1TZXOludwzYEPzoEh7QRu+OW31RHtlP4xMQ21+tBdkIxplMoP4qZOxF6T08KnQbKT4S7w+f/HyTb/insGgafC/2PrMbLDHHz107RJeR2ULkeLPnCwzu+iH3sn0I5ZclaHG7hvtpb+bgotDfnWeiqDrUmuWIH4+5v7Ec5MMhlWw+/wwZ63EENuXl4L8poJY4jzcJm6C9oN8/HHl7iPOcZeusy5ySxBnM0ZH+gEJNnVfe1Ec4Ckkb1VpTw4BDR4UU7hyLqV/IpjNqVwDFCjUYQpeSX+23chXqBIO2KNAsBH0jjAcnqp5PmxqdkZzey3ZydL5EIur9taQf76vqAq8cDBSEBr66EpIHHox0FpU4vrxR7cZxETV/T/g/eCs4blqwzdMqPQ+szjFVYquH/lhoz6tbLsTFLLndzouh/s/v88b8+c7Nswltag73wpbP3NVCZ3Sz+u9UnUUqwlPOZHXs85V142KVHIqVkB0N0KDey8oohaVNpMbqYWAtwWvDwCanzm70EbAKxSmNa2RhjPkSCb/aMzjeKV5997o2mhpx8YnlFdlpA6MWpAjGSD1ACm0wZGmNYGhOgWUTzEa7QMxYPh/g0umzn59kg38gH8mYX29HAtDbKGyKNOLo/SMFyZ3agnA/iNr1VNAef6ry2CfqkKZqZwKlFPQO0oqwWccpaMPIjWo9TmiqDsCIeusQTLoH/iTdK9nQKdIjYn54EhPrdNyoZpJ9bq2P+0qFf0ZP+0d8vIER545mjimwbIiTcBPHBvWwcPKWqsTarg7ZMfAZaUnD40d6/+xMHBkZ313Im8mHIr67kI/VSLKdAH4G3YJor1ZRKRWr646TBl8ZaEtzPgNIeuETT6tilW9n0PnuEBw4PghwePYEddAPLKH2liSOmEiUnlSUJVgDiJEMKGyWtzHPFHb+6ghVlicwxS7jmCRvowicTE8KOt0Zm7Un4fj/5h3YQ3v2K gU5KQeoc 7C7LlkwiLPkBGuBtBCoPwkQ6ePIIZkDGFO5pg09egCXjmrvjZvSR3Y5G1wXneGjxNF3GcNavtR7zLtaQ7Ok4AqC/QFBIp9m7SkiVPYGZOfbUGi67npi1gtYhEXZpy2acDHPJ76erNo+VW5U6Pl3mpED+JW970RzsQl++4oumq5c8Hbkhz3rhLiHOPXod/HXOFEzbAE2l191ZaE7h11VA/yR7XNqKruWBePUNzxSQ1T03/YyLgrCA9+gXMiYU0DKA4sy/6zzXtykHtPsObrF3yJoOHg9M9YTTRv/ljAYwPBNyw0AI= 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: This commit enhances the ability to troubleshoot the global cgroup_rstat_lock by introducing wrapper helper functions for the lock along with associated tracepoints. Although global, the cgroup_rstat_lock helper APIs and tracepoints take arguments such as cgroup pointer and cpu_in_loop variable. This adjustment is made because flushing occurs per cgroup despite the lock being global. Hence, when troubleshooting, it's important to identify the relevant cgroup. The cpu_in_loop variable is necessary because the global lock may be released within the main flushing loop that traverses CPUs. In the tracepoints, the cpu_in_loop value is set to -1 when acquiring the main lock; otherwise, it denotes the CPU number processed last. The new feature in this patchset is detecting when lock is contended. The tracepoints are implemented with production in mind. For minimum overhead attach to cgroup:cgroup_rstat_lock_contended, which only gets activated when trylock detects lock is contended. A quick production check for issues could be done via this perf commands: perf record -g -e cgroup:cgroup_rstat_lock_contended Next natural question would be asking how long time do lock contenders wait for obtaining the lock. This can be answered by measuring the time between cgroup:cgroup_rstat_lock_contended and cgroup:cgroup_rstat_locked when args->contended is set. Like this bpftrace script: bpftrace -e ' tracepoint:cgroup:cgroup_rstat_lock_contended {@start[tid]=nsecs} tracepoint:cgroup:cgroup_rstat_locked { if (args->contended) { @wait_ns=hist(nsecs-@start[tid]); delete(@start[tid]);}} interval:s:1 {time("%H:%M:%S "); print(@wait_ns); }' Extending with time spend holding the lock will be more expensive as this also looks at all the non-contended cases. Like this bpftrace script: bpftrace -e ' tracepoint:cgroup:cgroup_rstat_lock_contended {@start[tid]=nsecs} tracepoint:cgroup:cgroup_rstat_locked { @locked[tid]=nsecs; if (args->contended) { @wait_ns=hist(nsecs-@start[tid]); delete(@start[tid]);}} tracepoint:cgroup:cgroup_rstat_unlock { @locked_ns=hist(nsecs-@locked[tid]); delete(@locked[tid]);} interval:s:1 {time("%H:%M:%S "); print(@wait_ns);print(@locked_ns); }' Signes-off-by: Jesper Dangaard Brouer --- include/linux/cgroup.h | 2 +- include/trace/events/cgroup.h | 48 +++++++++++++++++++++++++++++++++++++++++ kernel/cgroup/rstat.c | 47 +++++++++++++++++++++++++++++++++------- 3 files changed, 88 insertions(+), 9 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 34aaf0e87def..2150ca60394b 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -690,7 +690,7 @@ static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) void cgroup_rstat_updated(struct cgroup *cgrp, int cpu); void cgroup_rstat_flush(struct cgroup *cgrp); void cgroup_rstat_flush_hold(struct cgroup *cgrp); -void cgroup_rstat_flush_release(void); +void cgroup_rstat_flush_release(struct cgroup *cgrp); /* * Basic resource stats. diff --git a/include/trace/events/cgroup.h b/include/trace/events/cgroup.h index dd7d7c9efecd..13f375800135 100644 --- a/include/trace/events/cgroup.h +++ b/include/trace/events/cgroup.h @@ -204,6 +204,54 @@ DEFINE_EVENT(cgroup_event, cgroup_notify_frozen, TP_ARGS(cgrp, path, val) ); +DECLARE_EVENT_CLASS(cgroup_rstat, + + TP_PROTO(struct cgroup *cgrp, int cpu_in_loop, bool contended), + + TP_ARGS(cgrp, cpu_in_loop, contended), + + TP_STRUCT__entry( + __field( int, root ) + __field( int, level ) + __field( u64, id ) + __field( int, cpu_in_loop ) + __field( bool, contended ) + ), + + TP_fast_assign( + __entry->root = cgrp->root->hierarchy_id; + __entry->id = cgroup_id(cgrp); + __entry->level = cgrp->level; + __entry->cpu_in_loop = cpu_in_loop; + __entry->contended = contended; + ), + + TP_printk("root=%d id=%llu level=%d cpu_in_loop=%d lock contended:%d", + __entry->root, __entry->id, __entry->level, + __entry->cpu_in_loop, __entry->contended) +); + +DEFINE_EVENT(cgroup_rstat, cgroup_rstat_lock_contended, + + TP_PROTO(struct cgroup *cgrp, int cpu, bool contended), + + TP_ARGS(cgrp, cpu, contended) +); + +DEFINE_EVENT(cgroup_rstat, cgroup_rstat_locked, + + TP_PROTO(struct cgroup *cgrp, int cpu, bool contended), + + TP_ARGS(cgrp, cpu, contended) +); + +DEFINE_EVENT(cgroup_rstat, cgroup_rstat_unlock, + + TP_PROTO(struct cgroup *cgrp, int cpu, bool contended), + + TP_ARGS(cgrp, cpu, contended) +); + #endif /* _TRACE_CGROUP_H */ /* This part must be outside protection */ diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 07e2284bb499..ff68c904e647 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -7,6 +7,8 @@ #include #include +#include + static DEFINE_SPINLOCK(cgroup_rstat_lock); static DEFINE_PER_CPU(raw_spinlock_t, cgroup_rstat_cpu_lock); @@ -222,6 +224,35 @@ __weak noinline void bpf_rstat_flush(struct cgroup *cgrp, __bpf_hook_end(); +/* + * Helper functions for locking cgroup_rstat_lock. + * + * This makes it easier to diagnose locking issues and contention in + * production environments. The parameter @cpu_in_loop indicate lock + * was released and re-taken when collection data from the CPUs. The + * value -1 is used when obtaining the main lock else this is the CPU + * number processed last. + */ +static inline void __cgroup_rstat_lock(struct cgroup *cgrp, int cpu_in_loop) + __acquires(&cgroup_rstat_lock) +{ + bool contended; + + contended = !spin_trylock_irq(&cgroup_rstat_lock); + if (contended) { + trace_cgroup_rstat_lock_contended(cgrp, cpu_in_loop, contended); + spin_lock_irq(&cgroup_rstat_lock); + } + trace_cgroup_rstat_locked(cgrp, cpu_in_loop, contended); +} + +static inline void __cgroup_rstat_unlock(struct cgroup *cgrp, int cpu_in_loop) + __releases(&cgroup_rstat_lock) +{ + trace_cgroup_rstat_unlock(cgrp, cpu_in_loop, false); + spin_unlock_irq(&cgroup_rstat_lock); +} + /* see cgroup_rstat_flush() */ static void cgroup_rstat_flush_locked(struct cgroup *cgrp) __releases(&cgroup_rstat_lock) __acquires(&cgroup_rstat_lock) @@ -248,10 +279,10 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp) /* play nice and yield if necessary */ if (need_resched() || spin_needbreak(&cgroup_rstat_lock)) { - spin_unlock_irq(&cgroup_rstat_lock); + __cgroup_rstat_unlock(cgrp, cpu); if (!cond_resched()) cpu_relax(); - spin_lock_irq(&cgroup_rstat_lock); + __cgroup_rstat_lock(cgrp, cpu); } } } @@ -273,9 +304,9 @@ __bpf_kfunc void cgroup_rstat_flush(struct cgroup *cgrp) { might_sleep(); - spin_lock_irq(&cgroup_rstat_lock); + __cgroup_rstat_lock(cgrp, -1); cgroup_rstat_flush_locked(cgrp); - spin_unlock_irq(&cgroup_rstat_lock); + __cgroup_rstat_unlock(cgrp, -1); } /** @@ -291,17 +322,17 @@ void cgroup_rstat_flush_hold(struct cgroup *cgrp) __acquires(&cgroup_rstat_lock) { might_sleep(); - spin_lock_irq(&cgroup_rstat_lock); + __cgroup_rstat_lock(cgrp, -1); cgroup_rstat_flush_locked(cgrp); } /** * cgroup_rstat_flush_release - release cgroup_rstat_flush_hold() */ -void cgroup_rstat_flush_release(void) +void cgroup_rstat_flush_release(struct cgroup *cgrp) __releases(&cgroup_rstat_lock) { - spin_unlock_irq(&cgroup_rstat_lock); + __cgroup_rstat_unlock(cgrp, -1); } int cgroup_rstat_init(struct cgroup *cgrp) @@ -533,7 +564,7 @@ void cgroup_base_stat_cputime_show(struct seq_file *seq) #ifdef CONFIG_SCHED_CORE forceidle_time = cgrp->bstat.forceidle_sum; #endif - cgroup_rstat_flush_release(); + cgroup_rstat_flush_release(cgrp); } else { root_cgroup_cputime(&bstat); usage = bstat.cputime.sum_exec_runtime; From patchwork Tue Apr 16 17:51:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Dangaard Brouer X-Patchwork-Id: 13632262 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 C8CEAC4345F for ; Tue, 16 Apr 2024 17:51:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66B1D6B009E; Tue, 16 Apr 2024 13:51:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 61B456B009F; Tue, 16 Apr 2024 13:51:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50A816B00A0; Tue, 16 Apr 2024 13:51:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 31A016B009E for ; Tue, 16 Apr 2024 13:51:45 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BA9B41C0176 for ; Tue, 16 Apr 2024 17:51:44 +0000 (UTC) X-FDA: 82016137728.02.6BAD3A4 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf26.hostedemail.com (Postfix) with ESMTP id 9AE7C140013 for ; Tue, 16 Apr 2024 17:51:42 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="I/GAY3Fl"; spf=pass (imf26.hostedemail.com: domain of hawk@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=hawk@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713289903; a=rsa-sha256; cv=none; b=jwKi0poe+R4xxCEzFjqGTdDDbSV8817XqiGhdQQ4BreOK0qoisPDWMf1H97Sxtyv5D7hAa SFR3lpmWtUNaI0GkZdqkXbrX8b5ODbiHwmFybl8OMIaK2/f0yLaorLyGsQxU2QwIQbsFee m+pEEFsmWkBTvOf0I2sATsb3aBMZ52k= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="I/GAY3Fl"; spf=pass (imf26.hostedemail.com: domain of hawk@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=hawk@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713289903; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RtxP6lvJoWmnCdIurYnb/RminvL93fz0m6ijjOetiP4=; b=W6dXA8OTPOUUle+PQk77v0xpOk8BM/5lNMAALuabCZzFjc3friZzp7qEoKu6uV1HmY23Sa bIm8zXkqI3OASq9UtiTOJx9d7MljojJ+eNAzOTUcumdn77biMdtpgSBoZHZAZqkquwF+ob 2tChSB888yaqlE1Ec+BlNqei2qLDRDQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id BAC99CE068B; Tue, 16 Apr 2024 17:51:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AB99C2BD11; Tue, 16 Apr 2024 17:51:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713289898; bh=5yq8vAYf6xC8gXi+nuWR4s1aX8FwORkuEEx5b9YmRYs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=I/GAY3FlPH6B1QRPQ2dqGR9a/rlcVnfGdvRVTQLO45RzGqp+LU4MWf4UwES2dc8+a 0BKM1Hre4ug7oBUZv1rJzeMn16gFlal2lBFm4UKtNvuhqrygHncYibMZMgGCxfxXeI ymw2t80RgVLeCyqPphCGqemiZ6vti6QTZxAtrPY9iUorEpW90I2Ko8DQ7xkOq7uA+t f0RH0cGf0dGovxwsZX5/eNt3Mk9J46hRV5nKs1Yz+PrESejCcpZoER+HybDBcH588p FutiTe1lgqsteYKqc599Y8n2e/uPvzK1sA8VHal2CeKFIT5/QKqFRby+WL5Sn53u6q JDZTow0vfEVEA== Subject: [PATCH v1 2/3] cgroup/rstat: convert cgroup_rstat_lock back to mutex From: Jesper Dangaard Brouer To: tj@kernel.org, hannes@cmpxchg.org, lizefan.x@bytedance.com, cgroups@vger.kernel.org, yosryahmed@google.com, longman@redhat.com Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, shakeel.butt@linux.dev, kernel-team@cloudflare.com, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Sebastian Andrzej Siewior , mhocko@kernel.org Date: Tue, 16 Apr 2024 19:51:33 +0200 Message-ID: <171328989335.3930751.3091577850420501533.stgit@firesoul> In-Reply-To: <171328983017.3930751.9484082608778623495.stgit@firesoul> References: <171328983017.3930751.9484082608778623495.stgit@firesoul> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9AE7C140013 X-Stat-Signature: ibsz5arkgss68xds6f44dz4es1ugnyg6 X-Rspam-User: X-HE-Tag: 1713289902-661336 X-HE-Meta: U2FsdGVkX1/K5YQuuqIP8DANpZ77vqBd5NZyrJZww1i4Zgonj4+b7ZU1kE7PSULxprzsU36KF7NyK4zDj4uMtESDfPXsusS2QCPCoAWwxgozfdAAbF+TvZUMGT+O4nrqnZNGQgaVxjueO8lYPgGzekjcMrtMEWBrUSiulwCECd8HT+8uhxV6rKCqge15gyx3X+XJIHLyHzyjMHLjmHUuqz3BXV3vDhbMveq/rt9LlsBuv8wz0sbRSk4tU4lVcfk5NF0jTVCRvFXukEksYkbJnyh0q++SVmTCeVHuMK6RXHStaAsiCNaahlApkcPT9goKHPp0XdOzsUxK2JqCsYSNzbgoeeLA4RHpG9xdfYEUeRPgqsmJYXy2HxdwoWBkzVIXNby5io13MlpweUc9FXMRq1FLFXLOZhZQucQanm3YPiUQgNXWP37aRrHsnADsBTsBpSYHcMRsGkbFgLaaVz9s1u9mH5wddXglp8ubYMFnAVWmAIy0iR2p78eqD1byepx5OAdMMVWwvGh7TbFNfkggyJDgbIMO0GDQH0YiSXx2Vlrmm+GWpRjnoILSlsR+4ldqin+MFQMJ78vRnFfsO77u90HMiJ99bB2K5l83t4ZlMmySYqQTj1IDTRJywroQewyalqE6ZzFqx8BhK0Hc0qhaVcK9aSOXtOiivAmp/QFf8DSlbIe1oqn+xJjmr80VBzDcJtv4TBmrC2cA85vfa3N9RTcaZotYtAQ8vG6VD+yVOp9OChmiM/EOWtLUVOn5st61dIyx/dqekxkS6WwQRDX9OewBbKxIBYxkUiqB5iYo+TQYozoZ8udx7zJQHr7shR5/O5u47csv4Ud/DLveMG68pm302LbRGT/Gr7RZHNuwYUG1e/0FHGd4JMqknQleCoE2OSIDpoLqAz9H3zoqXC5vIcJ4rMb6q4+ikJFwAs8SuI6cR+87kkexYg== 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: Since kernel v4.18, cgroup_rstat_lock has been an IRQ-disabling spinlock, as introduced by commit 0fa294fb1985 ("cgroup: Replace cgroup_rstat_mutex with a spinlock"). Despite efforts in cgroup_rstat_flush_locked() to yield the lock when necessary during the collection of per-CPU stats, this approach has led to several scaling issues observed in production environments. Holding this IRQ lock has caused starvation of other critical kernel functions, such as softirq (e.g., timers and netstack). Although kernel v6.8 introduced optimizations in this area, we continue to observe instances where the spin_lock is held for 64-128 ms in production. This patch converts cgroup_rstat_lock back to being a mutex lock. This change is made possible thanks to the significant effort by Yosry Ahmed to eliminate all atomic context use-cases through multiple commits, ending in 0a2dc6ac3329 ("cgroup: removecgroup_rstat_flush_atomic()"), included in kernel v6.5. After this patch lock contention will be less obvious, as converting this to a mutex avoids multiple CPUs spinning while waiting for the lock, but it doesn't remove the lock contention. It is recommended to use the tracepoints to diagnose this. Signed-off-by: Jesper Dangaard Brouer --- kernel/cgroup/rstat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index ff68c904e647..a90d68a7c27f 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -9,7 +9,7 @@ #include -static DEFINE_SPINLOCK(cgroup_rstat_lock); +static DEFINE_MUTEX(cgroup_rstat_lock); static DEFINE_PER_CPU(raw_spinlock_t, cgroup_rstat_cpu_lock); static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu); @@ -238,10 +238,10 @@ static inline void __cgroup_rstat_lock(struct cgroup *cgrp, int cpu_in_loop) { bool contended; - contended = !spin_trylock_irq(&cgroup_rstat_lock); + contended = !mutex_trylock(&cgroup_rstat_lock); if (contended) { trace_cgroup_rstat_lock_contended(cgrp, cpu_in_loop, contended); - spin_lock_irq(&cgroup_rstat_lock); + mutex_lock(&cgroup_rstat_lock); } trace_cgroup_rstat_locked(cgrp, cpu_in_loop, contended); } @@ -250,7 +250,7 @@ static inline void __cgroup_rstat_unlock(struct cgroup *cgrp, int cpu_in_loop) __releases(&cgroup_rstat_lock) { trace_cgroup_rstat_unlock(cgrp, cpu_in_loop, false); - spin_unlock_irq(&cgroup_rstat_lock); + mutex_unlock(&cgroup_rstat_lock); } /* see cgroup_rstat_flush() */ @@ -278,7 +278,7 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp) } /* play nice and yield if necessary */ - if (need_resched() || spin_needbreak(&cgroup_rstat_lock)) { + if (need_resched()) { __cgroup_rstat_unlock(cgrp, cpu); if (!cond_resched()) cpu_relax(); From patchwork Tue Apr 16 17:51:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Dangaard Brouer X-Patchwork-Id: 13632263 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 5AE5CC4345F for ; Tue, 16 Apr 2024 17:51:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E82F56B0085; Tue, 16 Apr 2024 13:51:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E332E6B00A0; Tue, 16 Apr 2024 13:51:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD2AC6B00A1; Tue, 16 Apr 2024 13:51:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AD90C6B0085 for ; Tue, 16 Apr 2024 13:51:48 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6B520140C4C for ; Tue, 16 Apr 2024 17:51:48 +0000 (UTC) X-FDA: 82016137896.17.C53A06A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id BB795140003 for ; Tue, 16 Apr 2024 17:51:46 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rBTGA/j4"; spf=pass (imf26.hostedemail.com: domain of hawk@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=hawk@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713289906; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=30qwxIg3n7d0cGAI8RQitFODbGL0D34b+7PToxEV0lQ=; b=XuO+uIyRvgpwfQ+uZ//KVTIVgyv9V74+9zp0EslntWEOQ3Rduo5CaWlmbS0vIhqPdfVEyr qPJO4vF2tNTci4eVIMvkfZOubHZ9/DkibKLIrMeYnxWTG46vzrgpyON6hQWDeOF/LF7Rr5 Gnuinp2QpE1Juj8hVLPas9I1dFIqsrY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713289906; a=rsa-sha256; cv=none; b=ulGSq7/hi23LwTUFgqYhaEdmbc7+bgY68SeiNDXjpOxGhmBvro8y/QY4f//37EHhXsDihV XaKHH2v60XgKFpXHK/CetLNCdtuab0Z9+dX6FoS9kZ7/o3dChAT6MgCZueXFwMVeJMcAqL RR/12SHpB4rc6cATLEckUnftXtsnyaU= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="rBTGA/j4"; spf=pass (imf26.hostedemail.com: domain of hawk@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=hawk@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D055D61257; Tue, 16 Apr 2024 17:51:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0820FC2BD11; Tue, 16 Apr 2024 17:51:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713289905; bh=xykn9xlAKIRlCdpBDJjUFA6u/Fh4oeaFhP6Oe5BJZ9w=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=rBTGA/j4eYXaha1zep2XsWqQMo/7AuaFqKvR+9ztUt384qlMMGAN+2aCqPtF1UGaK U2ZPG0IxNZ5eBgCilfLyWL7Af8dqomP8JBPxoNHkHEQrQ9yumvgnBhvEkzyfFooiYh UfuchUwUlMiYHINfQ1r4Of3CW93zlTmy08apcPnyltNYZTekRluD60kr7Yi5rvjlco eKvF5OPmD8pQ46Zmo4DAUT/lv+uhsTwiXWRXDTCWzlfR2mmHCpoiw3Bnwu4NSLAo0f BbHg1J8OD7NoRHbsi3B6F+e5OyqeUQ1cNugA+Vu+KrvrJNxx1NXzHZ2s1+sDQcTf3h yFyl/RclpMJmg== Subject: [PATCH v1 3/3] cgroup/rstat: introduce ratelimited rstat flushing From: Jesper Dangaard Brouer To: tj@kernel.org, hannes@cmpxchg.org, lizefan.x@bytedance.com, cgroups@vger.kernel.org, yosryahmed@google.com, longman@redhat.com Cc: Jesper Dangaard Brouer , netdev@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, shakeel.butt@linux.dev, kernel-team@cloudflare.com, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Sebastian Andrzej Siewior , mhocko@kernel.org Date: Tue, 16 Apr 2024 19:51:40 +0200 Message-ID: <171328990014.3930751.10674097155895405137.stgit@firesoul> In-Reply-To: <171328983017.3930751.9484082608778623495.stgit@firesoul> References: <171328983017.3930751.9484082608778623495.stgit@firesoul> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Stat-Signature: 6gsdhwrwkimt7ka3xczngitsqqie7o8x X-Rspamd-Queue-Id: BB795140003 X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1713289906-510566 X-HE-Meta: U2FsdGVkX18Lmm1sUrTkV39LbyQREyLKTeOsu7DX/SPuP80N0neZrOW2Yd83gJNg55CH45tHw71M5xu35jw1KonN1jngof4iDJq4gxlg9fYrXhAwrzEHrUJm9ClNU/urdJbJi8dFQHqo+M6K9v7rx+Kehv+BNoHwH02gxEmFb5PYqMbKbNnk5BZql8fmbxQYZPy6SFTVx0G6WgXGKL++7lGndmAemS67Xxi4UiVMNO9yLfKmqQqqcHfLgXZu1YRD2IyjhDCAoXejIKx3Kvtqmvu+zjnnAbLo2kb60H3/o8tuSOixld8/+tmRcZ8Qhf6ao7OcxUQOL8sCDkleEnPFxIwNBY5lrEw8jP55XK40LsPDwCEx7KwyuPrnfejKPTSwqtSDniBYchPqV1ZyXbUN8bNhj0xQ6cIfekWD1dGxM6P0y+fS3ibTgTooCJIah/+UpG9rLy5fmeRVh70Iugejo4xIbwAxMWsEBnZ8oysDs3mpqQLf+tTAgN3KcFoEEgu4qgCwF66Ayo61HtmNGedPd8TDRr1COZFC1LxAGWNg14KhBd64ta1foM3s66bASC7L4LW/ItjHSkwS5z667hDSJmsEjwbBL7lGWvt+L1lH/h7OSRe1pMxMNDCKcxOmDIZlN92iPl/M2kKPS2HHbjB+k6Y3RkUpwNyHQ4KvmJdHUt3o9IP4FY733yDSwkxNq45PKrx20HWyMwrJ7SKDe5B1JlB4GY9VcWOXTC9CTkiw39GxOYjNZr5Z94sEZf9Q0/PvPa8wwq98FBTl0WQL2bMJziASLdmTDEqogjL5L5Uezaj803qrCZq4jMKOz6Hg3Pf3przjXnY66JuoKPApCG8Tgp5xqMWmHJ0YXkPKS5mTzt0OvzdDINtf1+SZn6Nt0L4cOCVsf1nQWYc6sJQCuvOq5O8hNEYGF5GCJhgi0IiCknlyfX0Quax1N9F6ptxlB3kXzZgj6zLpakb+HIsc0W4 vaZVIMeQ RNuZQ6zyDxHlaUi8gakUwYlzd0kPyPNzOdK1QG0Arfi/7xAqzkbmcfoX0UDNpGT/4mL6nzd+Pslnqusdj8rKwvP/nhzMcC0xQMwvWRQIjEeK4k5wBGUzB4YqvipRLB36JxDB7fQMltOw/CmCxzmIeHMotxyotAHFKtX+0a+JeZaXcbM208BuE5qdGJrwUGhiHka+eiA8CxSITAF0jClP+hG7TxKpD1st4xPYhqxFDBhAXQu8iNxjBj6dbXg== 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: This patch aims to reduce userspace-triggered pressure on the global cgroup_rstat_lock by introducing a mechanism to limit how often reading stat files causes cgroup rstat flushing. In the memory cgroup subsystem, memcg_vmstats_needs_flush() combined with mem_cgroup_flush_stats_ratelimited() already limits pressure on the global lock (cgroup_rstat_lock). As a result, reading memory-related stat files (such as memory.stat, memory.numa_stat, zswap.current) is already a less userspace-triggerable issue. However, other userspace users of cgroup_rstat_flush(), such as when reading io.stat (blk-cgroup.c) and cpu.stat, lack a similar system to limit pressure on the global lock. Furthermore, userspace can easily trigger this issue by reading those stat files. Typically, normal userspace stats tools (e.g., cadvisor, nomad, systemd) spawn threads that read io.stat, cpu.stat, and memory.stat (even from the same cgroup) without realizing that on the kernel side, they share the same global lock. This limitation also helps prevent malicious userspace applications from harming the kernel by reading these stat files in a tight loop. To address this, the patch introduces cgroup_rstat_flush_ratelimited(), similar to memcg's mem_cgroup_flush_stats_ratelimited(). Flushing occurs per cgroup (even though the lock remains global) a variable named rstat_flush_last_time is introduced to track when a given cgroup was last flushed. This variable, which contains the jiffies of the flush, shares properties and a cache line with rstat_flush_next and is updated simultaneously. For cpu.stat, we need to acquire the lock (via cgroup_rstat_flush_hold) because other data is read under the lock, but we skip the expensive flushing if it occurred recently. Regarding io.stat, there is an opportunity outside the lock to skip the flush, but inside the lock, we must recheck to handle races. Signed-off-by: Jesper Dangaard Brouer --- block/blk-cgroup.c | 2 + include/linux/cgroup-defs.h | 1 + include/linux/cgroup.h | 3 +- kernel/cgroup/rstat.c | 60 ++++++++++++++++++++++++++++++++++++++++++- mm/memcontrol.c | 1 + 5 files changed, 63 insertions(+), 4 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index bdbb557feb5a..4156fedbb910 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1162,7 +1162,7 @@ static int blkcg_print_stat(struct seq_file *sf, void *v) if (!seq_css(sf)->parent) blkcg_fill_root_iostats(); else - cgroup_rstat_flush(blkcg->css.cgroup); + cgroup_rstat_flush_ratelimited(blkcg->css.cgroup); rcu_read_lock(); hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) { diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index ea48c861cd36..366dc644e075 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -509,6 +509,7 @@ struct cgroup { * cgroup_rstat_flush_locked() and protected by cgroup_rstat_lock. */ struct cgroup *rstat_flush_next; + unsigned long rstat_flush_last_time; /* cgroup basic resource statistics */ struct cgroup_base_stat last_bstat; diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 2150ca60394b..8622b222453e 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -689,7 +689,8 @@ static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) */ void cgroup_rstat_updated(struct cgroup *cgrp, int cpu); void cgroup_rstat_flush(struct cgroup *cgrp); -void cgroup_rstat_flush_hold(struct cgroup *cgrp); +int cgroup_rstat_flush_hold(struct cgroup *cgrp); +int cgroup_rstat_flush_ratelimited(struct cgroup *cgrp); void cgroup_rstat_flush_release(struct cgroup *cgrp); /* diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index a90d68a7c27f..8c71af67b197 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -193,6 +193,7 @@ static struct cgroup *cgroup_rstat_updated_list(struct cgroup *root, int cpu) /* Push @root to the list first before pushing the children */ head = root; root->rstat_flush_next = NULL; + root->rstat_flush_last_time = jiffies; child = rstatc->updated_children; rstatc->updated_children = root; if (child != root) @@ -261,12 +262,15 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp) lockdep_assert_held(&cgroup_rstat_lock); + cgrp->rstat_flush_last_time = jiffies; + for_each_possible_cpu(cpu) { struct cgroup *pos = cgroup_rstat_updated_list(cgrp, cpu); for (; pos; pos = pos->rstat_flush_next) { struct cgroup_subsys_state *css; + pos->rstat_flush_last_time = jiffies; cgroup_base_stat_flush(pos, cpu); bpf_rstat_flush(pos, cgroup_parent(pos), cpu); @@ -309,6 +313,49 @@ __bpf_kfunc void cgroup_rstat_flush(struct cgroup *cgrp) __cgroup_rstat_unlock(cgrp, -1); } +#define FLUSH_TIME msecs_to_jiffies(50) + +/** + * cgroup_rstat_flush_ratelimited - limit pressure on global lock (cgroup_rstat_lock) + * @cgrp: target cgroup + * + * Trade accuracy for less pressure on global lock. Only use this when caller + * don't need 100% up-to-date stats. + * + * Userspace stats tools spawn threads reading io.stat, cpu.stat and memory.stat + * from same cgroup, but kernel side they share same global lock. This also + * limit malicious userspace from hurting kernel by reading these stat files in + * a tight loop. + * + * This function exit early if flush recently happened. + * + * Returns 1 if flush happened + */ +int cgroup_rstat_flush_ratelimited(struct cgroup *cgrp) +{ + int res = 0; + + might_sleep(); + + /* Outside lock: check if this flush and lock can be skipped */ + if (time_before(jiffies, + READ_ONCE(cgrp->rstat_flush_last_time) + FLUSH_TIME)) + return 0; + + __cgroup_rstat_lock(cgrp, -1); + + /* Recheck inside lock, do flush after enough time have passed */ + if (time_after(jiffies, + cgrp->rstat_flush_last_time + FLUSH_TIME)) { + cgroup_rstat_flush_locked(cgrp); + res = 1; + } + + __cgroup_rstat_unlock(cgrp, -1); + + return res; +} + /** * cgroup_rstat_flush_hold - flush stats in @cgrp's subtree and hold * @cgrp: target cgroup @@ -317,13 +364,22 @@ __bpf_kfunc void cgroup_rstat_flush(struct cgroup *cgrp) * paired with cgroup_rstat_flush_release(). * * This function may block. + * + * Returns 1 if flush happened */ -void cgroup_rstat_flush_hold(struct cgroup *cgrp) +int cgroup_rstat_flush_hold(struct cgroup *cgrp) __acquires(&cgroup_rstat_lock) { might_sleep(); __cgroup_rstat_lock(cgrp, -1); - cgroup_rstat_flush_locked(cgrp); + + /* Only do expensive flush after enough time have passed */ + if (time_after(jiffies, + cgrp->rstat_flush_last_time + FLUSH_TIME)) { + cgroup_rstat_flush_locked(cgrp); + return 1; + } + return 0; } /** diff --git a/mm/memcontrol.c b/mm/memcontrol.c index fabce2b50c69..771261612ec1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -742,6 +742,7 @@ static void do_flush_stats(struct mem_cgroup *memcg) if (mem_cgroup_is_root(memcg)) WRITE_ONCE(flush_last_time, jiffies_64); + /* memcg have own ratelimit layer */ cgroup_rstat_flush(memcg->css.cgroup); }