Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp1316785iof; Tue, 7 Jun 2022 03:12:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyiiMxlH2mdXb6iXhCvooK+sKd12wokQWXCUm5y7+i7MbTFJweRCyyPLuYc+nfEgqYB7yI X-Received: by 2002:a17:907:d8d:b0:711:d82f:5d33 with SMTP id go13-20020a1709070d8d00b00711d82f5d33mr6646874ejc.595.1654596770326; Tue, 07 Jun 2022 03:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654596770; cv=none; d=google.com; s=arc-20160816; b=L1RqURqDATYJ1+X5zhAOyRjYUnuVVN9xTI4z+Z509KnXiN4GlmtCpSiO+bOQr6gqFv 7BeqoXzO21h56fXdOIfEJNJiHhaKo0xymDPP8TNXjQg5bLrDXZmZCweBAs6RzGwll4O8 Z0xBGJaTA18UJREWYtZiqsJlBXbwgoE5bAyCDnGRsvyjzJix9PZz1LtI46VTiexkIwLm YCI5uE4/j05FLQ75b0zMxZN7BwCR3LyLMMpJq4g8QgjWlkr9MQfBs6rCL8aZx9o/BO3E C+EF0eDBetyV8y8CQlcfn/N1ta//7I1gzx6yTt/tX7UFydt8nibR4HtUG6XIHxwYJrb+ 5gmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9yJbx0i06GNbf8v7gInYN9hw57l8mmMKWeeJflk0qEI=; b=aONcv0NWzPLScDm2uEHfKQr3rlimd0Xtx+LL4/BzttO6s5wiZffy/yBkvqk/C/tKWR 9FuUm47ZvSHhz8fSUYHN1nMkEut198EBNjdqkPuChNP5OBU3boOK4JfoUIRynv8nBsZe bZV+gFrWdrrARX+3egpUlflmFG+Z1mALm2lZrGsXoyXpI4mTEzmYcOtKIrJCKrhacpw/ xQ/FMF6Jv8ADMI2LZIw85zRlgmKksVSoBWZR4OjoJa8aT6qgO6rsmgFUrdhoA8ZhvQdo mSt/BnS85W5u8LZh1VP1+NZsEZfIUExs694IdlWQjWaji5W86+Ydm+WFnx4gWlHqgQ99 FzwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OfvEIo74; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y22-20020a056402359600b0042e00815a31si13189911edc.86.2022.06.07.03.12.21; Tue, 07 Jun 2022 03:12:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OfvEIo74; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232574AbiFFTls (ORCPT + 99 others); Mon, 6 Jun 2022 15:41:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232573AbiFFTlp (ORCPT ); Mon, 6 Jun 2022 15:41:45 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CF49ED3D6 for ; Mon, 6 Jun 2022 12:41:44 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id m26so9758452wrb.4 for ; Mon, 06 Jun 2022 12:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=9yJbx0i06GNbf8v7gInYN9hw57l8mmMKWeeJflk0qEI=; b=OfvEIo74VLd9T5IwhXy5EMZxZvHlk4ZiGd7W3x3BSiifBAa2m3eM7+P6GPdioIC0Qn iz6ZKfl/E1j1awO/0mJ51oC6k4LOuwaAlWqWPzNM+SuMDSeeyGIIGwgQU9iaetClFXA4 2F0EHH1Wesx4Auk9Qp16xrq/u4OxkVDuXgbmHdGQWwflbQeqFjx95Mk6emG7pXdBU41G 3NOtqqJsLeFht46E4vKE8nMQCMQrk5T7oswlFJLm+zjSAp54SqwK64fs7Gs6gUDSoijw GLxqGoBFMP7+UTCl1x9R8zJq26z9FFrFzDIAHxntIj10oKxJPrtwb2l3/EvgoowqzGl6 /YEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=9yJbx0i06GNbf8v7gInYN9hw57l8mmMKWeeJflk0qEI=; b=TsSO/Pu+reeK/3pAH6xgmcTU6ry/6L2/VlbJUETWlhWUfo6NVzCOJj1Y4Tws9sGomT R/HkeBNzAb0/h/mFTqTgm5ZUuMTMWzs5sOv0u9gzqbX9UO/tJB3lrMYrzr4qeQ1irHQR +0Xag+Ukcxlii+bdLZRtHHVkbqq1fDOYbPXjiCBKT36pTdbPqtBRk0uYxm6OIaP3X9/c +g+VCmD6+GcfvR5+7Aj8gxrvOYToGeTQ75Scax2GwyGHXuEVbri3ddsnLp1DZl+Bn5ma LskOqPmPpJIGTZQXW7ucFx+fDbi1lQXSXPlvCM9tHOk76U8MfICg43ZJsRpeSmD1X2j+ Et3g== X-Gm-Message-State: AOAM530V09WVMgWptEpNDGnqr5nhSJPIDWFGVJNTter6fbohqk65o8sd JR3RfBFvna9b3Pdw44rG+CuHfBnuHXAnBaLjpFO4lw== X-Received: by 2002:adf:fb05:0:b0:20a:e113:8f3f with SMTP id c5-20020adffb05000000b0020ae1138f3fmr23580389wrr.534.1654544502734; Mon, 06 Jun 2022 12:41:42 -0700 (PDT) MIME-Version: 1.0 References: <20220520012133.1217211-1-yosryahmed@google.com> <20220520012133.1217211-6-yosryahmed@google.com> <20220603162339.GA25043@blackbody.suse.cz> <20220606123222.GA4377@blackbody.suse.cz> In-Reply-To: <20220606123222.GA4377@blackbody.suse.cz> From: Yosry Ahmed Date: Mon, 6 Jun 2022 12:41:06 -0700 Message-ID: Subject: Re: [PATCH bpf-next v1 5/5] bpf: add a selftest for cgroup hierarchical stats collection To: =?UTF-8?Q?Michal_Koutn=C3=BD?= Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Hao Luo , Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan , Roman Gushchin , Michal Hocko , Stanislav Fomichev , David Rientjes , Greg Thelen , Shakeel Butt , Linux Kernel Mailing List , Networking , bpf , Cgroups Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 6, 2022 at 5:32 AM Michal Koutn=C3=BD wrote: > > On Fri, Jun 03, 2022 at 12:52:27PM -0700, Yosry Ahmed wrote: > > Good catch. I get confused between cgrp->subsys and > > task->cgroups->subsys sometimes because of different fallback > > behavior. IIUC cgrp->subsys should have NULL if the memory controller > > is not enabled (no nearest ancestor fallback), and hence I can use > > memory_subsys_enabled() that I defined just above task_memcg() to test > > for this (I have no idea why I am not already using it here). Is my > > understanding correct? > > You're correct, css_set (task->cgroups) has a css (memcg) always defined > (be it root only (or even a css from v1 hierarchy but that should not > relevant here)). A particular cgroup can have the css set to NULL. > > When I think about your stats collecting example now, task_memcg() looks > more suitable to achieve proper hierarchical counting in the end (IOW > you'd lose info from tasks who don't reside in memcg-enabled leaf). I guess it depends on how userspace reasons about this, and whether or not you want to collect stats from leaves that don't reside in a memcg-enabled leaf. I will go through all the memcg-enabled checks and make sure they make sense and are consistent, maybe add some comments to make the userspace policy here clear. > > (It's just that task_memcg won't return NULL. Unless the kernel is > compiled without memcg support completely, which makes me think how do > the config-dependent values propagate to BPF programs?) I don't know if there is a standard way to handle this, but I think you should know the configs of your kernel when you are loading a bpf program? In this particular case, if CONFIG_CGROUPS=3D0 then the bpf programs will not even load due to lack of hook points or kfuncs won't exist. If the CONFIG_CGROUPS=3D1 but CONFIG_MEMCG=3D0 I think everything will work normally except that task_memcg() will always return NULL so no stats will be collected, which makes sense. There will be some overhead to running bpf programs that will always do nothing, but I would argue that it's the userspace's fault here for loading bpf programs on a non-compatible kernel. > > Thanks, > Michal