Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1026545pxj; Tue, 18 May 2021 20:00:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUfQ2VlE01cmCwYG4BaoFFbW5IvxrpYNq4dg6HVgKJg0inDdihhp310BzsSPsc/gX7ywbn X-Received: by 2002:a05:6402:518:: with SMTP id m24mr10908321edv.133.1621393245607; Tue, 18 May 2021 20:00:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621393245; cv=none; d=google.com; s=arc-20160816; b=v3C92PlsPTF+AgSFUB2Levp3XOjXCrnkNQwkjO7FOzsfZN8+SzWBJ73ABpDzEfUjJn 0/ZSD7mFeDOGJa9dXkkal/pcPJrMwKyrt8HsAsiSaTwcGHqJQX8Clkcj1TWDv4GX81br AHZYRU8yzxFrehn0sFAtUpgkALcD+mXDxB4Oo6geGeTBCovWHzosVaWM//4icNNm7QGy s+4V0rLAoKk48SPzH858mp8ikmVDhitPMCv18bdqUuy3ShrxxxCbOEdyC+AhiVaf0RTK T/YKv9/vlGLE90ImFtwNJhjMrslsXLW5xVisIuuurz3qh6GDo73u6dlwgQUIb5yZDqGE egIA== 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=WOt8pDHxf8UyV1g+frGSSeqaqXf66O0fXn4ZHmPI4BY=; b=fB5wg2LRouYxHLTVDu6LXzAEKVy63TYPpFWIDrdMZAAR3R7+Rk5yTo9sSKOyZVcX4P d/RcpswVBf20EI75ChwS+3qCOpLrY+EastVtdWlOnlIpjdCSF5WEwu9dqsSZKiClKT+H Yym5C8scxMveuQQDoQSDfF9v/6mi313GMqErHPPyJ9XrX7P/4x+/oXcRgwL58NySUBba sn7crN5839KTykZ8rYr4Dx8aL0wD8uIwZI6LuM6zJyGQ6Ub/KiT5SKrO6NyWK0k40Btd O+BdUpZXfHtF8mhoLoZfrNqUxnBIiwoike/fN3YanKSXTXf9dFJpU3o8Q12Edmlvfgl7 h+ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=IBDLeDDy; 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 qp24si2335820ejb.718.2021.05.18.20.00.22; Tue, 18 May 2021 20:00:45 -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=IBDLeDDy; 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 S237385AbhEQUEG (ORCPT + 99 others); Mon, 17 May 2021 16:04:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237381AbhEQUEF (ORCPT ); Mon, 17 May 2021 16:04:05 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5AD4C061756 for ; Mon, 17 May 2021 13:02:48 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id d14so2241527ybe.3 for ; Mon, 17 May 2021 13:02:48 -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=WOt8pDHxf8UyV1g+frGSSeqaqXf66O0fXn4ZHmPI4BY=; b=IBDLeDDyYTZmykeL/+LFDwgPTgobab9QhFzNZXP5nCatE9wX6vMPUuVFw47KyiCuJj s3tU2+Z6FlHGFt5jub3pypsxakKfEMMWX8JATwGw+A6DOZ7IcS97vNj0j58FP2I6dMra 9aucHTVz60UpOes9MJ1DrxSliX2MFb2qU8bNHwF+dmLlJbtrVzgsT+g1gqcM26hZKqiP LdOdJAhVBxMrYEXcMZv3cYMHzJm32/KS5+qeTwTRxUFE9jek/lSR+D1+lQbN5wleKBMO 1RICp7/Xo9U75cigVEV0k4hoFPPHitNmba1xyZzwzQ3Ij2DYpLc+nHIHgFjOFHf82Pwh um3w== 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=WOt8pDHxf8UyV1g+frGSSeqaqXf66O0fXn4ZHmPI4BY=; b=kpn/ArgWTW320SDFbbvab5zx6b4UaxE6yM04bvFCIJp8Rsdo54G+ozJInl+95m6zpo LCCADIPlVcsrshUmd5aWcLYEP8cqNaGxbNnqD0gGZonsFMxMza8V14n3I7gXl7h42k5R CLrEkq0hi/hd5OeSCYRXZCiQQIcxiQBtuFek2sHnb7ZRXun7LNAoHxkggmoeCcALkOAp WPw/6WlABjMECxMIwKBXJAho2hnoO2msH/VppWDf697m5sTSX2XFDZUdRU++a29P9agV jAg1xfo2TMlLRCEwgr6MlVpXdkPzBCu8ZA3cTfHKNy37NWHamy9UG2U5ocflZ9RPwQtN cS7w== X-Gm-Message-State: AOAM533/+XR2ls8GkgXGkYX70mK1N8GtmQgO4CVV237q9ud+2zvSmPY4 oWd70xog5PV+bedF66nogaQS0yqGQo5Vt9h/ltqA2w== X-Received: by 2002:a5b:7c5:: with SMTP id t5mr2189351ybq.190.1621281767582; Mon, 17 May 2021 13:02:47 -0700 (PDT) MIME-Version: 1.0 References: <20210513175349.959661-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Mon, 17 May 2021 13:02:36 -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 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!