From patchwork Fri Jan 3 01:50:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: JP Kobryn X-Patchwork-Id: 13925083 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 D5276E77197 for ; Fri, 3 Jan 2025 01:50:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1B7F6B0082; Thu, 2 Jan 2025 20:50:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ECBA76B0083; Thu, 2 Jan 2025 20:50:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF5876B0085; Thu, 2 Jan 2025 20:50:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B479A6B0082 for ; Thu, 2 Jan 2025 20:50:35 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 565A6AEB6D for ; Fri, 3 Jan 2025 01:50:35 +0000 (UTC) X-FDA: 82964457660.20.08D9DAA Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf30.hostedemail.com (Postfix) with ESMTP id 8FA6B80009 for ; Fri, 3 Jan 2025 01:48:55 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FxjhjS5O; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1735868985; a=rsa-sha256; cv=none; b=x1fXdRMj9bZZ/2lCQ+Dp/eTJ6wXMzsI99c9VoTOrcRK9bf/BdA6Rftkzj387/uurtW0I/w FwvxSf6GpFaKkxBhehZ7DE5BmUTpvPj+21VepdG+3CvjyATs8je/btF5Aa36Yxi7KLHB1D MNOQzh74iq9iq27lHM5GknaPfUTEL/M= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FxjhjS5O; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of inwardvessel@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=inwardvessel@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1735868985; 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=04f8f3o/yaDsG08ligEdR1CTtfIwVHAWlueUkfYDoXo=; b=b8Sy+sdqsmtLi4nhtJnXIt47sTxoxgEXKJ45qXvmxRNE+9KSVVam5jPsXv/Ux1zabQL4Ml oYfOfJklZu6g7pVUi1bc++V3mZh2NqvQrmH6gqycYn1JbNNRqh9eijk36EiaJOK6pIZSQC Ca8/gYa18vT+/lCy1jFpfR+bu3rQj/M= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2165cb60719so165630055ad.0 for ; Thu, 02 Jan 2025 17:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735869032; x=1736473832; 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=04f8f3o/yaDsG08ligEdR1CTtfIwVHAWlueUkfYDoXo=; b=FxjhjS5ONE97NMTJgwFIuIMYES5CpHrp4hqpfIRNjPi2sCAPZWEL8oGRsLVeYY9C/+ nia23ONyNzyCpIpU+RXGjGST3+jsO7K0h4bLC8nLuPGXn1rzInzb0TMXhDdJlDjI9y1w ZfqglP98XVe+2hZmUVcQXKTbWjTNQkkR6gaQD7awPPmkmbnOyAp2xxB/8+6dKhTu/chf uGXNJkqdr/YN72mM2g/OwCPVDEOOLt4a3JQdp+TIPuYOO/152sCiJIf48cPVwNxR0P3N G7h8splDNsOEVca8sPtV90caRBiXDwgg36qyC452guPsFUT3L8saRaZvnkcazWR0Ziv8 usGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735869032; x=1736473832; 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=04f8f3o/yaDsG08ligEdR1CTtfIwVHAWlueUkfYDoXo=; b=v4V9PwkPI0LhGDY/rUUbTyp3HtCFpTULaqbNPcpbxmlatu88/vpgsL4bOvv6HO2uSF 7rlotFG4qyg27OkcFAuyQP036jVuU/SG31qebXepkch8NpmWQc9JFMBtIrALW/pvTuSV DwT+yMnPdKKike6qm9+9rZ/hf4qutOmb5ckFgsp0mpSycpzncBRiwM7oxDMLFrqFk2lP GOH9/XvNh2Cnxl5Q/WnQzVmvFOMbmbpCR4/kiG2TgYK1/dq6MZHut7KpiWEUThiNcL/o 0aIv68AM0G6xC9vK1E6aOMv/N+yfKCA2giFT+Gnxou8EIvrfw5sEilmmsoRUZK1bfm/j 0FAQ== X-Gm-Message-State: AOJu0YzgoHqu0+IjSE1S89xJlU9S2ItLBXbDKgKimpmRbS67r1cmpW+x Vjensmzdqp9xyXyyiphARVx8LKJSx8eyL9xUqpJpXFir9MahJb2Q X-Gm-Gg: ASbGncvUGSJgIjxcyJmEuRU4jZMfUUo08pY9pIMj12HqcfZ7QAX9iZFbIYBI9YkfQI7 BbvibPoWET31fHOVW7ThQGlZuj/y/zmJK6h1koqyvzt3yzIUb3otuBexGuVaSQo8aBygFGEll8B l5XsAIhtIBYElXI6qhFTJ4iqCPk4d9AQTQOvxmEtEL1MbwP4e0LSIQsnnf++fQA5bMxhhBK+dkH fu2VwEW/z6YtupgWuHEvMS7xnQavRJQXRCsAe7eQwpGbLPiFUaK581JcEtBLdO1vUn5gBS9cFHB rI+ufCN15CCwGE4zsg== X-Google-Smtp-Source: AGHT+IGDhdL6/CNaSo3pGtV64+fqNxC6hz2SLueRvx2WGBRXmMrSjYEpM/Emx32nG9JYyUBV8OcXLA== X-Received: by 2002:a17:903:234f:b0:216:4b6f:ddda with SMTP id d9443c01a7336-219e6f0e6c3mr678754295ad.35.1735869032286; Thu, 02 Jan 2025 17:50:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jan 2025 17:50:31 -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 1/9 v2] cgroup: change cgroup to css in rstat updated and flush api Date: Thu, 2 Jan 2025 17:50:12 -0800 Message-ID: <20250103015020.78547-2-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: rspam04 X-Rspamd-Queue-Id: 8FA6B80009 X-Stat-Signature: mhjw77nz7nj5j4thuqf8e1xx43pupjqp X-Rspam-User: X-HE-Tag: 1735868935-980412 X-HE-Meta: U2FsdGVkX18/2ud/62aIy37O1ciV4QqVIONc3xmgD4MT0D7Q4NN6AI9Yvc7FaNpbgIi+nj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l0f/Mxye7KF6M/UojShcRZcN4RXHcN+gzCCt6klaxoIX/Nhk1jNVpIXRu5rH0tLoXME/UKJP4wG7YPgOE+VVICxNriWHZUsTin0qQOUpT4LTdu+SR6v/tputi7m3jwSk5H8+zKkzUc6vZtIN27LzaygCWkkoF7yZzCL+Q+jLtFWUGj8febiIKz/jLBx8Zo+QK6Wayev0yCL2xzcQ== 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: Change rstat flush and updated 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); } /*