Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1355354pxj; Wed, 19 May 2021 04:18:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ0UHTqH7nI9XvIilGpCNGNFiOPV7a/qglwKwSyBosmIxZQCtkBZlpooTAesQOtU3z/gnQ X-Received: by 2002:a05:6638:13c4:: with SMTP id i4mr5031911jaj.37.1621423127223; Wed, 19 May 2021 04:18:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621423127; cv=none; d=google.com; s=arc-20160816; b=uJpNNaSRmHBL2OseeXYyDwmZc0xuRFFpuz/rO3V+fugPVCjXG1e7LUnpjKhQxa6cU+ +bw0MpHCBeSm3DrMMPuNEnog4O9S9/LmK2w6eI50tJsiK9GBSlIBVeQ/qygcoIU72ye8 icRHmHmN05b35ia92u9v4iDAWax7Cx5ymIbeJBAgJMGubdvfPTS9v/aPn0IyaFqj+KvX lsU8hh71uAOw0Yvyh4MR3lqot4xiVqccadccry4iQ4mlUchTh8FuHKyUxxNhevn/a0lU 6KkheX5eBuKJGt5Sz6TRMnYZ0Bcl/xHeCDQu34zqN8toGxTtBPFs2UeCgPJX1i5gmQgE zshA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=sZm5cS0Op3FLJ1htgR1p5EodcjeArnY0szqtWe/bTlE=; b=ZOidarADfJSdeOwQcEEq6gBhzOmcACRg9bWHld2ID1lDTJRTtz4spTk4IP+//HGypd FYrqAF7wMBmwNe2WDnuSxFgNRwkrAqWlXdoruRwsc+beKF+cWsT+57dgZnaDi/VoyaWR skzSD6BDnMplxzzS8pueP6stKWj8rNjT6RdV/l1i3CYRLy7C105XGHX/TJMybOwFCWl/ vnSZbr2zgwRQxshPAYMyxL5BqepWFau72c+Z16Kb9DJ7WjLIjhMRr8JaltyS93DeSxwC Zdx598OrEuklLgnrn1oo/c2IyoUxd+dqMigWfRn+W+YEkzfhOd79tNN8aT6Uh79FWwoz ynpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tEsQCNpK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j188si28042723jac.58.2021.05.19.04.18.34; Wed, 19 May 2021 04:18:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tEsQCNpK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244479AbhERCGd (ORCPT + 99 others); Mon, 17 May 2021 22:06:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236022AbhERCGc (ORCPT ); Mon, 17 May 2021 22:06:32 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 090D7C061756 for ; Mon, 17 May 2021 19:05:14 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id d14so3235011ybe.3 for ; Mon, 17 May 2021 19:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sZm5cS0Op3FLJ1htgR1p5EodcjeArnY0szqtWe/bTlE=; b=tEsQCNpKqbPJ1GszI9UYQvdpTWUwJRo9+c8TdRSFGjJe3xvNWN3/+5mYVQeYZeGTUl E9LPTljYrGwLHHt61jU+BYYBIWqzvc4vK4WS6xT/3zBzRobwN1Zn3TMxyS8KFshdbLQ6 nEIwYDMLI4Bwn/FySzkjuwj5E0TLAZ8bwpacmcIAXzs5fsz9JFvr2EPbFPAGN0TZGA81 qs1lBPSuRUW3CCNJiykAbRDYU/rI12igKQ+VTvSpwNjcu5irlWe7VuhtqRsKRUiUKCFC wLFWgq1rFqojnSW7oSNlv8nZFr+OtGgsJhZB58KTWLUoxlWABUCQy1yDWE/cZYFdp7Q7 thZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sZm5cS0Op3FLJ1htgR1p5EodcjeArnY0szqtWe/bTlE=; b=tn+PKOBd2SfOUoFelpOyrCxv5MXb1bVb4aoZZUvnaR04RlVq8A7HFnQngWD7zmVjAV FrKs29PSPxRm9kSclm6ffbN/8SQhuP0570J9XK+ELpZp49HOc53O97WcfcECgqw+HuMZ BOJ8ER994wK1vqoutbjw/Hbn778EcwuyLyMnHS7QkecVyyIZDA4X9WNDqU650ML3rQWP Z1Xt/s5h27SPjJD/Ms3rBKbDN/moQeMTVEO8Fs2ejlznTGQe0gbEIkiClWhEoVHsm9QZ aPi/CU5AD3p1yYvxTOHEoEdeqR0UijNgV2tdpSY2O7P3vPHiI95fj01sDtaO3n1BlTdj YO+w== X-Gm-Message-State: AOAM533/5DyEH/uv84Ebo0QlOZDqTarjtZ43KmddGgB5W7HrFJWUxxPi 3jyqFJOI4EHVqf/TEBHQGXXJziP2TZbymWalqAuNXg== X-Received: by 2002:a5b:7c5:: with SMTP id t5mr4033359ybq.190.1621303513064; Mon, 17 May 2021 19:05:13 -0700 (PDT) MIME-Version: 1.0 References: <20210513175349.959661-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 17 May 2021 19:05:02 -0700 Message-ID: Subject: Re: [PATCH 1/1] cgroup: make per-cgroup pressure stall tracking configurable To: Johannes Weiner Cc: Peter Zijlstra , Tejun Heo , lizefan.x@bytedance.com, Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Benjamin Segall , mgorman@suse.de, Minchan Kim , Jonathan Corbet , bristot@redhat.com, "Paul E . McKenney" , rdunlap@infradead.org, Andrew Morton , Thomas Gleixner , macro@orcam.me.uk, Viresh Kumar , mike.kravetz@oracle.com, linux-doc@vger.kernel.org, LKML , cgroups mailinglist , kernel-team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 17, 2021 at 1:02 PM Suren Baghdasaryan wrote: > > On Mon, May 17, 2021 at 11:31 AM Johannes Weiner wrote: > > > > On Sun, May 16, 2021 at 12:52:32PM -0700, Suren Baghdasaryan wrote: > > > After reworking the code to add a static key I had to expand the > > > #ifdef CONFIG_CGROUPS section, so I think a code refactoring below > > > would make sense. It localizes config-specific code and it has the > > > same exact code for CONFIG_CGROUPS=n and for > > > cgroup_psi_enabled()==false. WDYT?: > > > > > > --- a/kernel/sched/psi.c > > > +++ b/kernel/sched/psi.c > > > @@ -181,6 +181,7 @@ struct psi_group psi_system = { > > > }; > > > > > > static void psi_avgs_work(struct work_struct *work); > > > +static void cgroup_iterator_init(void); > > > > > > static void group_init(struct psi_group *group) > > > { > > > @@ -211,6 +212,8 @@ void __init psi_init(void) > > > return; > > > } > > > > > > + cgroup_iterator_init(); > > > + > > > psi_period = jiffies_to_nsecs(PSI_FREQ); > > > group_init(&psi_system); > > > } > > > @@ -742,11 +745,31 @@ static void psi_group_change(struct psi_group > > > *group, int cpu, > > > schedule_delayed_work(&group->avgs_work, PSI_FREQ); > > > } > > > > > > -static struct psi_group *iterate_groups(struct task_struct *task, void **iter) > > > +static inline struct psi_group *sys_group_iterator(struct task_struct *task, > > > + void **iter) > > > { > > > + *iter = &psi_system; > > > + return &psi_system; > > > +} > > > + > > > #ifdef CONFIG_CGROUPS > > > + > > > +DEFINE_STATIC_KEY_FALSE(psi_cgroups_disabled); > > > + > > > +static void cgroup_iterator_init(void) > > > +{ > > > + if (!cgroup_psi_enabled()) > > > + static_branch_enable(&psi_cgroups_disabled); > > > +} > > > + > > > +static struct psi_group *iterate_groups(struct task_struct *task, void **iter) > > > +{ > > > struct cgroup *cgroup = NULL; > > > > > > + /* Skip to psi_system if per-cgroup accounting is disabled */ > > > + if (static_branch_unlikely(&psi_cgroups_disabled)) > > > + return *iter ? NULL : sys_group_iterator(task, iter); > > > + > > > if (!*iter) > > > cgroup = task->cgroups->dfl_cgrp; > > > > That looks over-engineered. You have to check iter whether cgroups are > > enabled or not. Pulling the jump label check up doesn't save anything, > > but it ends up duplicating code. > > > > What you had in the beginning was better, it just had the system label > > in an unexpected place where it would check iter twice in a row. > > > > The (*iter == &psi_system) check inside the cgroups branch has the > > same purpose as the (*iter) check in the else branch. We could > > consolidate that by pulling it up front. > > > > If we wrap the entire cgroup iteration block into the static branch, > > IMO it becomes a bit clearer as well. > > > > How about this? > > > > static struct psi_group *iterate_groups(struct task_struct *task, void **iter) > > { > > if (*iter == &psi_system) > > return NULL; > > > > #ifdef CONFIG_CGROUPS > > if (!static_branch_likely(&psi_cgroups_disabled)) { > > struct cgroup *cgroup = NULL; > > > > if (!*iter) > > cgroup = task->cgroups->dfl_cgrp; > > else > > cgroup = cgroup_parent(*iter); > > > > if (cgroup && cgroup_parent(cgroup)) { > > *iter = cgroup; > > return cgroup_psi(cgroup); > > } > > } > > #endif > > > > *iter = &psi_system; > > return &psi_system; > > } > > This looks great to me. Will use it in the next version. Thanks! V2 is posted at https://lore.kernel.org/patchwork/patch/1430980