From patchwork Fri Jan 3 01:50:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JP Kobryn X-Patchwork-Id: 13925084 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 2CB6CE77188 for ; Fri, 3 Jan 2025 01:50:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C7FC6B0083; Thu, 2 Jan 2025 20:50:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 751FB6B0085; Thu, 2 Jan 2025 20:50:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57C046B0088; Thu, 2 Jan 2025 20:50:37 -0500 (EST) 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 3C9686B0083 for ; Thu, 2 Jan 2025 20:50:37 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E22FF80239 for ; Fri, 3 Jan 2025 01:50:36 +0000 (UTC) X-FDA: 82964459676.30.1C720CE Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf15.hostedemail.com (Postfix) with ESMTP id 2806CA0006 for ; Fri, 3 Jan 2025 01:49:00 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="bx0n/+pF"; spf=pass (imf15.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735869001; 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:in-reply-to:references:references:dkim-signature; bh=HgCq5Td2Z/AmRDTJOLyjzlVyZ7Vs1foFuhquS5rZUBM=; b=nypksiZ5PEez1MIi/MilTqfVDTHFsUkZDjJhzW9Tk0kAk0eJo57Axqx1ddceG/Qi/h9bsP 3WxYaVujI6383YMYxIp+K/6xPYIgPJD4t7Ovx9uFSbSOAnPPV+TnbxuTIwJBS2btJRDlKX ++Z1eBI05OLaRgEERmQObDXr2fCFECc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735869001; a=rsa-sha256; cv=none; b=GT7B2gg3eL9L1gDjgk60vHhuaPKUudk8qY5eC5XpFfOYD5BSDIkCPPunvzHtKqpaBEHh4p YCB73W0Gl249Ax9a7kFld0zyoSBeRP62CZZaHB2XYubE1rygCiAwtayWsHhxhXdevr9u5h mFw1v681Z1RQxLEj+Z/n9SWJw975MnA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="bx0n/+pF"; spf=pass (imf15.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2ef72924e53so16575637a91.3 for ; Thu, 02 Jan 2025 17:50:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735869033; x=1736473833; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HgCq5Td2Z/AmRDTJOLyjzlVyZ7Vs1foFuhquS5rZUBM=; b=bx0n/+pF+i2b56Jb7ewUl/ytetXqY3ByDHh/6H9rjW5EhSglQ3VYAIpzHuZnBS3awA Ua+aWCoX6GmBRgRzJ0gXt1IKWrFhjcQI+gCZu9BMDitABEkbxtkYYtg0a37kir5ivMyg sb5esOd9+q3xo1NFeMHW325BcdQbfw4zLpJ0n8+oTbfNs2J61KvmjbeuVMCNCSmHIcW/ 6DZNkUAMJdKgkx0X9e0R32shkYchBX4WbtY728zoBCCX1FTIMzqysjnj6xEOVpvzPBy7 L/3VU6H9WBHmrPR8sNpwziIfU0lq4aLjwa/M5UgZfx5pVDJJvca+TGskEsnzEBbaVK3c DpVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735869033; x=1736473833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HgCq5Td2Z/AmRDTJOLyjzlVyZ7Vs1foFuhquS5rZUBM=; b=Yhht4h/rbIecX2+RwFiFQC6HeebwIPY0DUyISCxuZf4qV9wXYXtoMkijpjAy0LZx3t 8lQNEZiHJeReDKspF9/w6AjEE2rPL+bF46i4MX0OPihvNuECLpP1Bf4TmzDMlUyZmgWg hSVd/0CDOPha6ph+oieAaQvDfvOskcXZJI7sHko5lYxHveAydFW70+8rfTcWaFn7+Qky Gc8vEzWEd5gqqMzaCaYWLxd4iTfqpQ74QzQOOm/2ddjg1CiigoQVbjCMBZAH2NPQ/duJ pJVxJ22QC5gnT147JZBWjauHkY8XNIu/iLVE6PEJmwmIA+HB3K03YOLFnWrph0/iH28g lG0w== X-Gm-Message-State: AOJu0Yz2OJ5a9R0vjZ1hRh2AW3OjaTPv5Wp5vT5scQYNu7vUGUqc303N v0ja7ym0TPiLXK2uaPM7xtH8hhxRsom7yEko/G5VxLHVmXe/aXaq X-Gm-Gg: ASbGnctc3GwZlnkDK1hdUyUIoYoXXr+rhYbvYgazosNwNqnTc1Bw28Z5CD69OX0AjUg FUkVbILhfYQxlwtiWSO16/EEnp18Hywm9p+BD1BF5PkmFxQyMhKSQ5s2kMR2JDsto4kozFtnx7Z 6GAyDIwUencedVILspMAS5xnGFs6qpy8ELWH/RFBusdPA5BpKUECre5RlXJzqI6g1LN7ZnybxXd G3GfJ8Lmzq0ZgXZqmyDdq8AgclFzzDDsQ/g67wVLZWtAismCgUBHMduJz4aE6fADX6Nm5fjmQx2 KiKYFFV0udWBcwBmVA== X-Google-Smtp-Source: AGHT+IGkWtACbpMmHueLMAjxpHU9KrMkr+iF3LJPrQIgx8bENjfG+waIs+Dzt0sDPxQQ6X70fr4+hw== X-Received: by 2002:a17:90a:e18f:b0:2ee:c291:765a with SMTP id 98e67ed59e1d1-2f452debd4fmr80002639a91.8.1735869033613; Thu, 02 Jan 2025 17:50:33 -0800 (PST) Received: from saturn.. (c-67-188-127-15.hsd1.ca.comcast.net. [67.188.127.15]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca04ce7sm228851505ad.283.2025.01.02.17.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 17:50:33 -0800 (PST) From: JP Kobryn To: shakeel.butt@linux.dev, tj@kernel.org, mhocko@kernel.org, hannes@cmpxchg.org, yosryahmed@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, cgroups@vger.kernel.org Subject: [RFC PATCH 2/9 v2] cgroup: change cgroup to css in rstat internal flush and lock funcs Date: Thu, 2 Jan 2025 17:50:13 -0800 Message-ID: <20250103015020.78547-3-inwardvessel@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250103015020.78547-1-inwardvessel@gmail.com> References: <20250103015020.78547-1-inwardvessel@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2806CA0006 X-Stat-Signature: ai1r8kc6cgnindzid3o7mnn7yk6rixxn X-Rspam-User: X-HE-Tag: 1735868940-760580 X-HE-Meta: U2FsdGVkX18sHeuRS5QshZx/I3VyWsQL/IUMCq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ADQos58GBeuPnmaoaUPB+u8/z4arGXlf+VTFX7TwKP8vk3s4KnJwu1eURv1unvY21rAIwSNzE8pleWKN1rVOtbGwOr4l0mMh3S4JK9k9zhLPoe4Hd0r0h3rN3t+j9XZWPEFELiSwpDtkomDb5kp4vvLEBe2nrIFLzH38e1gsxMGDPx7F8Gow86CrsAIL+Vywv8a3Tb0WbopUsCUIkwb1Ie5rW9nfvccP/yX/hw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.014009, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Change internal rstat functions to accept a cgroup_subsys_state instead of a cgroup. Signed-off-by: JP Kobryn --- kernel/cgroup/rstat.c | 45 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 1ed0f3aab0d9..1b7ef8690a09 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -201,8 +201,10 @@ static struct cgroup *cgroup_rstat_push_children(struct cgroup *head, * within the children list and terminated by the parent cgroup. An exception * here is the cgroup root whose updated_next can be self terminated. */ -static struct cgroup *cgroup_rstat_updated_list(struct cgroup *root, int cpu) +static struct cgroup *cgroup_rstat_updated_list(struct cgroup_subsys_state *root_css, + int cpu) { + struct cgroup *root = root_css->cgroup; raw_spinlock_t *cpu_lock = per_cpu_ptr(&cgroup_rstat_cpu_lock, cpu); struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(root, cpu); struct cgroup *head = NULL, *parent, *child; @@ -280,9 +282,11 @@ __bpf_hook_end(); * 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) +static inline void __cgroup_rstat_lock(struct cgroup_subsys_state *css, + int cpu_in_loop) __acquires(&cgroup_rstat_lock) { + struct cgroup *cgrp = css->cgroup; bool contended; contended = !spin_trylock_irq(&cgroup_rstat_lock); @@ -293,15 +297,18 @@ static inline void __cgroup_rstat_lock(struct cgroup *cgrp, int cpu_in_loop) trace_cgroup_rstat_locked(cgrp, cpu_in_loop, contended); } -static inline void __cgroup_rstat_unlock(struct cgroup *cgrp, int cpu_in_loop) +static inline void __cgroup_rstat_unlock(struct cgroup_subsys_state *css, + int cpu_in_loop) __releases(&cgroup_rstat_lock) { + struct cgroup *cgrp = css->cgroup; + 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) +static void cgroup_rstat_flush_locked(struct cgroup_subsys_state *css) __releases(&cgroup_rstat_lock) __acquires(&cgroup_rstat_lock) { int cpu; @@ -309,27 +316,27 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp) lockdep_assert_held(&cgroup_rstat_lock); for_each_possible_cpu(cpu) { - struct cgroup *pos = cgroup_rstat_updated_list(cgrp, cpu); + struct cgroup *pos = cgroup_rstat_updated_list(css, cpu); for (; pos; pos = pos->rstat_flush_next) { - struct cgroup_subsys_state *css; + struct cgroup_subsys_state *css_iter; cgroup_base_stat_flush(pos, cpu); bpf_rstat_flush(pos, cgroup_parent(pos), cpu); rcu_read_lock(); - list_for_each_entry_rcu(css, &pos->rstat_css_list, + list_for_each_entry_rcu(css_iter, &pos->rstat_css_list, rstat_css_node) - css->ss->css_rstat_flush(css, cpu); + css_iter->ss->css_rstat_flush(css_iter, cpu); rcu_read_unlock(); } /* play nice and yield if necessary */ if (need_resched() || spin_needbreak(&cgroup_rstat_lock)) { - __cgroup_rstat_unlock(cgrp, cpu); + __cgroup_rstat_unlock(css, cpu); if (!cond_resched()) cpu_relax(); - __cgroup_rstat_lock(cgrp, cpu); + __cgroup_rstat_lock(css, cpu); } } } @@ -349,13 +356,11 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp) */ __bpf_kfunc void cgroup_rstat_flush(struct cgroup_subsys_state *css) { - struct cgroup *cgrp = css->cgroup; - might_sleep(); - __cgroup_rstat_lock(cgrp, -1); - cgroup_rstat_flush_locked(cgrp); - __cgroup_rstat_unlock(cgrp, -1); + __cgroup_rstat_lock(css, -1); + cgroup_rstat_flush_locked(css); + __cgroup_rstat_unlock(css, -1); } /** @@ -370,11 +375,9 @@ __bpf_kfunc void cgroup_rstat_flush(struct cgroup_subsys_state *css) void cgroup_rstat_flush_hold(struct cgroup_subsys_state *css) __acquires(&cgroup_rstat_lock) { - struct cgroup *cgrp = css->cgroup; - might_sleep(); - __cgroup_rstat_lock(cgrp, -1); - cgroup_rstat_flush_locked(cgrp); + __cgroup_rstat_lock(css, -1); + cgroup_rstat_flush_locked(css); } /** @@ -384,9 +387,7 @@ void cgroup_rstat_flush_hold(struct cgroup_subsys_state *css) void cgroup_rstat_flush_release(struct cgroup_subsys_state *css) __releases(&cgroup_rstat_lock) { - struct cgroup *cgrp = css->cgroup; - - __cgroup_rstat_unlock(cgrp, -1); + __cgroup_rstat_unlock(css, -1); } int cgroup_rstat_init(struct cgroup *cgrp)