From patchwork Tue Dec 24 01:13:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JP Kobryn X-Patchwork-Id: 13919568 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 2DE44E7718E for ; Tue, 24 Dec 2024 01:14:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CB806B0082; Mon, 23 Dec 2024 20:14:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7552C6B0083; Mon, 23 Dec 2024 20:14:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CEC16B0085; Mon, 23 Dec 2024 20:14:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3CD406B0082 for ; Mon, 23 Dec 2024 20:14:18 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AC69C1A1AED for ; Tue, 24 Dec 2024 01:14:17 +0000 (UTC) X-FDA: 82928080620.24.AAE5D16 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf12.hostedemail.com (Postfix) with ESMTP id F147E4000B for ; Tue, 24 Dec 2024 01:13:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aKI9BeuJ; spf=pass (imf12.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.214.178 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=1735002811; 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=zYtPz7aK9YIb0L/ZbBa0RixlCtZNyuJIN6JSdj1lrsk=; b=F3CXk+Oy+bFi0u1NA0uaZtPQJGyOal7Nchzfuy/EG3W6WXnKVQuVopu36aMGHGQ3gd0Mgs PeQbvqJQipIBEM8HSEcdDyLY8BxrrjZbZ1glRdPvzUDm7DlbTkjRlPUHgXDm/awMZjuIq1 k28KrP/WyE85dD5wNi6mYpQV6bEqB5Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735002811; a=rsa-sha256; cv=none; b=nDYR9dvAjaA4bqLIRFwo2VrQ7eN5Xihz1SI2Yht/KABhi5iOtHu2T9eF4H4N/HERoyI6JN Gk3bnF+1t+jowPa83eV+A7v1MAZJa03Z+QVEnORp+c7xauxK4ydc5H5fTA95Uv0TIBU65h ZuAQq6rSxFl4Is6Yr/4/OFOw4kh4PR4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aKI9BeuJ; spf=pass (imf12.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21654fdd5daso44787095ad.1 for ; Mon, 23 Dec 2024 17:14:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735002855; x=1735607655; 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=zYtPz7aK9YIb0L/ZbBa0RixlCtZNyuJIN6JSdj1lrsk=; b=aKI9BeuJ4iambQmfTJceuTqn2rgyF5kK6adQzgk2dLwj7264PyqkoIqwHAdScKoGZv yZSxEIGPN0zyIg5w1ql4BESMbw9ccpwUwFJdLXiJt00v8JgHvARxYKTMxqjNyk3EIFTb YVh4fbcXu47JqPe5NluwzzNahmM0a6LkG0mzsR75K3R3X9iKIFxz+MADWCfRr0QazrxW rbcOJL2AnQyNDJErPtvlhmyRnqWDG5JVJaT3waXWKEGivetcoSTzguv1NPPeZhK7itlN apBTLpH2vgRfKBHsojZHPdyEJJzwPa3l0r1hp61lda7zHF84kEoVdMNe4+x3g7urtr+s BtXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735002855; x=1735607655; 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=zYtPz7aK9YIb0L/ZbBa0RixlCtZNyuJIN6JSdj1lrsk=; b=uR5wlkhAtTUWOpai7kV8ju3yHhVr3+zI8qryRj8MbrVU7mpxqz/+LvfALN/pnV3qHv +c2S9JBENHsaOWg5W/JzWFabVFDdQgGdgSXiTmQ5YcbQyYTXEfGb4qlMeNuo3p5TKS4q 8AtQYN03bPZHEb59c/b6DfeUEiaW7LiONqtJ62J+d3Jhxrc7MaAV1HSCFOigEKMoeoQa EO+7/e3nBchAzn3bhgZmSHa3mbVbmtb4NiddIlWloQkttGZ5cw0QMk5juaZf5pjyRYAb ho3XQ7dEikj2KfIWLHbG1PMaxqaHZ9mmilQHOrHBb4BOR+hP7oC41eMgxOCFNCdnBkUd kg5Q== X-Gm-Message-State: AOJu0YyA5T5zZiYXVl09tqd4Bda3IWxijB3UghPsYEfYjC1TMZrazm6s wgOXdDD3sQLopD2wI3RCUAHUll4DUcgy0xWz9R4k2NLxG9wT2WGz X-Gm-Gg: ASbGnct30oRoF1IBIP6c6Kdp5PR870NWU3Voa3OloukIAFrrUx9clhj9/DPcBHUADmx 4kYnnqa5+BMMGVd7KJvtns7+CImlmlTbcYZsvGEvk8qqheX8mdMJ4+Fr7j2hysVorN6/fYahU8x 3nVu3qqadvCSxV3TIYgo2ehV7Qta9zqDWeHkZuWpq4Tf9lRLFkczBm77ddrxi9jihvw/NV0PUM+ NBzaeFh0YpjF0Wctsw8kXlpj2Rkp6XEsiFAuOsMHM5Nou520GCSbNO0Gp/jIaMLb4gSr8JhNTZj OQMVOPwEiAg7AzHeuQ== X-Google-Smtp-Source: AGHT+IHxt/8FXT3EeHlti8KBRnrfHz4fCj1K+PzJkO4GExu/s7GdqY6WQo4vKMy3RCnOcrAt/99eqA== X-Received: by 2002:a17:902:e5c7:b0:216:393b:23e0 with SMTP id d9443c01a7336-219e6f2e9d4mr214204245ad.36.1735002854611; Mon, 23 Dec 2024 17:14:14 -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-219dc970c84sm79541255ad.58.2024.12.23.17.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Dec 2024 17:14:14 -0800 (PST) From: JP Kobryn To: shakeel.butt@linux.dev, hannes@cmpxchg.org, yosryahmed@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, cgroups@vger.kernel.org Subject: [PATCH 1/9 RFC] change cgroup to css in rstat updated and flush api Date: Mon, 23 Dec 2024 17:13:54 -0800 Message-ID: <20241224011402.134009-2-inwardvessel@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241224011402.134009-1-inwardvessel@gmail.com> References: <20241224011402.134009-1-inwardvessel@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F147E4000B X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 7i5s673tt4apwzx31z15sniwczmyny3x X-HE-Tag: 1735002838-225754 X-HE-Meta: U2FsdGVkX1+bqq+RI8qRmfRn0idwmf90iEXYm7FC0lvodxFmIageDbGpWjqa34iozlGQEtC2zC7kA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/KN0wW46LqzCg0vaDNjZhuOHb8amYBYVVeipQ+p/zj4eWFPHuVWJ/2JGp+W9kH9CKsBzQC16kYMzz//pmcCdry9CLHsL9WFz9lLy1pSIJAZOUOb9fYJxEZTUEtx0rINeKVHuUNAzsx0ZqnbQDDImG0f2pQYhavkKR+VeM5IewriLpdBiDqcGqUvNko8mRCexOVuQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000153, 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 API calls to accept a cgroup_subsys_state instead of a cgroup. Signed-off-by: JP Kobryn --- block/blk-cgroup.c | 4 ++-- include/linux/cgroup.h | 8 ++++---- kernel/cgroup/cgroup.c | 4 ++-- kernel/cgroup/rstat.c | 28 +++++++++++++++++++--------- mm/memcontrol.c | 4 ++-- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index 45a395862fbc..98e586ae21ec 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1200,7 +1200,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(&blkcg->css); rcu_read_lock(); hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) { @@ -2183,7 +2183,7 @@ void blk_cgroup_bio_start(struct bio *bio) } u64_stats_update_end_irqrestore(&bis->sync, flags); - cgroup_rstat_updated(blkcg->css.cgroup, cpu); + cgroup_rstat_updated(&blkcg->css, cpu); put_cpu(); } diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index f8ef47f8a634..eec970622419 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -687,10 +687,10 @@ static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) /* * cgroup scalable recursive statistics. */ -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(struct cgroup *cgrp); +void cgroup_rstat_updated(struct cgroup_subsys_state *css, int cpu); +void cgroup_rstat_flush(struct cgroup_subsys_state *css); +void cgroup_rstat_flush_hold(struct cgroup_subsys_state *css); +void cgroup_rstat_flush_release(struct cgroup_subsys_state *css); /* * Basic resource stats. diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 43c949824814..fdddd5ec5f3c 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5465,7 +5465,7 @@ static void css_release_work_fn(struct work_struct *work) /* css release path */ if (!list_empty(&css->rstat_css_node)) { - cgroup_rstat_flush(cgrp); + cgroup_rstat_flush(css); list_del_rcu(&css->rstat_css_node); } @@ -5493,7 +5493,7 @@ static void css_release_work_fn(struct work_struct *work) /* cgroup release path */ TRACE_CGROUP_PATH(release, cgrp); - cgroup_rstat_flush(cgrp); + cgroup_rstat_flush(css); spin_lock_irq(&css_set_lock); for (tcgrp = cgroup_parent(cgrp); tcgrp; diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 5877974ece92..1ed0f3aab0d9 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -82,8 +82,9 @@ void _cgroup_rstat_cpu_unlock(raw_spinlock_t *cpu_lock, int cpu, * rstat_cpu->updated_children list. See the comment on top of * cgroup_rstat_cpu definition for details. */ -__bpf_kfunc void cgroup_rstat_updated(struct cgroup *cgrp, int cpu) +__bpf_kfunc void cgroup_rstat_updated(struct cgroup_subsys_state *css, int cpu) { + struct cgroup *cgrp = css->cgroup; raw_spinlock_t *cpu_lock = per_cpu_ptr(&cgroup_rstat_cpu_lock, cpu); unsigned long flags; @@ -346,8 +347,10 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp) * * This function may block. */ -__bpf_kfunc void cgroup_rstat_flush(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); @@ -364,9 +367,11 @@ __bpf_kfunc void cgroup_rstat_flush(struct cgroup *cgrp) * * This function may block. */ -void cgroup_rstat_flush_hold(struct cgroup *cgrp) +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); @@ -376,9 +381,11 @@ void cgroup_rstat_flush_hold(struct cgroup *cgrp) * cgroup_rstat_flush_release - release cgroup_rstat_flush_hold() * @cgrp: cgroup used by tracepoint */ -void cgroup_rstat_flush_release(struct cgroup *cgrp) +void cgroup_rstat_flush_release(struct cgroup_subsys_state *css) __releases(&cgroup_rstat_lock) { + struct cgroup *cgrp = css->cgroup; + __cgroup_rstat_unlock(cgrp, -1); } @@ -408,7 +415,7 @@ void cgroup_rstat_exit(struct cgroup *cgrp) { int cpu; - cgroup_rstat_flush(cgrp); + cgroup_rstat_flush(&cgrp->self); /* sanity check */ for_each_possible_cpu(cpu) { @@ -512,8 +519,10 @@ static void cgroup_base_stat_cputime_account_end(struct cgroup *cgrp, struct cgroup_rstat_cpu *rstatc, unsigned long flags) { + struct cgroup_subsys_state *css = &cgrp->self; + u64_stats_update_end_irqrestore(&rstatc->bsync, flags); - cgroup_rstat_updated(cgrp, smp_processor_id()); + cgroup_rstat_updated(css, smp_processor_id()); put_cpu_ptr(rstatc); } @@ -612,16 +621,17 @@ static void cgroup_force_idle_show(struct seq_file *seq, struct cgroup_base_stat void cgroup_base_stat_cputime_show(struct seq_file *seq) { - struct cgroup *cgrp = seq_css(seq)->cgroup; + struct cgroup_subsys_state *css = seq_css(seq); + struct cgroup *cgrp = css->cgroup; u64 usage, utime, stime, ntime; if (cgroup_parent(cgrp)) { - cgroup_rstat_flush_hold(cgrp); + cgroup_rstat_flush_hold(css); usage = cgrp->bstat.cputime.sum_exec_runtime; cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime, &utime, &stime); ntime = cgrp->bstat.ntime; - cgroup_rstat_flush_release(cgrp); + cgroup_rstat_flush_release(css); } else { /* cgrp->bstat of root is not actually used, reuse it */ root_cgroup_cputime(&cgrp->bstat); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7b3503d12aaf..97552476b844 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -579,7 +579,7 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val) if (!val) return; - cgroup_rstat_updated(memcg->css.cgroup, cpu); + cgroup_rstat_updated(&memcg->css, cpu); statc = this_cpu_ptr(memcg->vmstats_percpu); for (; statc; statc = statc->parent) { stats_updates = READ_ONCE(statc->stats_updates) + abs(val); @@ -611,7 +611,7 @@ static void __mem_cgroup_flush_stats(struct mem_cgroup *memcg, bool force) if (mem_cgroup_is_root(memcg)) WRITE_ONCE(flush_last_time, jiffies_64); - cgroup_rstat_flush(memcg->css.cgroup); + cgroup_rstat_flush(&memcg->css); } /*