Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3717774rwe; Mon, 29 Aug 2022 18:45:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR7u7LV7SVX2kp3Eir+MlMW7cIKGqXl5n8Bm0Bz+lybiCugsXwI/TW2RccP555rdnZ1X+2W+ X-Received: by 2002:a17:907:2e19:b0:730:acf0:4921 with SMTP id ig25-20020a1709072e1900b00730acf04921mr14583291ejc.416.1661823917508; Mon, 29 Aug 2022 18:45:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661823917; cv=none; d=google.com; s=arc-20160816; b=dqjg06XZCAjPyczC+5eOMgtG+WcOUGeeTXHG4Jn7NBHe2Wh4b60KEKV9gKoWf+sVEn bWEOJePhUhax5PLCTGqQpMCkbsMGNo4DKe5vaAs274h0nZmrvm2Ucm5WqNk/L7s6zW/f v0bfW5ulHCcsWynN+hCoLXSQmn+u+T9WOqrUy71oeR3OVIX3CDDBy0U6q9fJpKO8coxF ahxZivtl6OFR7KgAHLcV/Nu2KOi4qWfT7owGPOsfsRDoR6b9N11xX4NCtnj3gKmHHUOR M8pRuQO9lQsJ7k8Gz+h/HWKmetSQY2OK3ZdOTH4Z3ul+bI6xc6idYZdPmE7XftihBQLP 94Gw== 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=iXY5dhqtt+GaEA9JOFgzSPC/9abv6ejSAU61pIxPRME=; b=B5eRPxSEpj7FPPbZL9Taz10zP83/dYtYXQK7twIrmXBM08FsoPz5V/YqsE9Tfk0tTT 3aCAl0moC9N0GQ/77B7K6wwpX8anTI5wMAu4X9v3ditWqAxvwdvJ+0n+V1XUuoRwh6wY Xt2Pgpc5GOLnqz0CYuT2pSRcMJBWfMCUo7b4ytqr7nl7KSZIXG/u6reRBf1ZvyCB+JtE cZqV1T4E44T8b2iua0lfl4bdiGTIWagCa06F/6dQAP2NDN67idPx29pKLWZNGKvf549S AvkzAc+nY8vfNrOUcnkwqapTNGbtuEi4Jlcf5rcEoThtkoM/Bio7VneX5cw6OoXJ36nS Hu8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=e+J0vrzS; 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 bk8-20020a170906b0c800b007317ad1f9a4si7428578ejb.310.2022.08.29.18.44.48; Mon, 29 Aug 2022 18:45:17 -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=e+J0vrzS; 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 S229776AbiH3BHW (ORCPT + 99 others); Mon, 29 Aug 2022 21:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbiH3BHU (ORCPT ); Mon, 29 Aug 2022 21:07:20 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21BDE8B99C for ; Mon, 29 Aug 2022 18:07:19 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id c7so5520520wrp.11 for ; Mon, 29 Aug 2022 18:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=iXY5dhqtt+GaEA9JOFgzSPC/9abv6ejSAU61pIxPRME=; b=e+J0vrzSvlrS/JYfTy6KJKqq2wPKrVIbDyyvdMcZDx0cukujnLwwEuE09UVpZsTIAc WgDUJPFSixngaWvcffnSoqXD2kXhZ6g1QKgSsvvesr0pzFw1cnb1vO6ewlKuiWL5IWWT xa+Ek3JQXteMT6if21DTss98t5liylC04Sr3rVBI7xhoJqFZhyGKVEniLSaEG++HeNeE A/oowX+5ooZ9nTIfQmd2mcUQbCHmgzB2+8Y/mkvnM4OiwagA2z1KOpzhzgr70vdzduR/ ENcCGtEIZ9zLCRgt5FewxbL7D6k+3BHDU9xzYWh/j9ZYGidwofBMXTt0fFkLfaPCHN2C PXXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=iXY5dhqtt+GaEA9JOFgzSPC/9abv6ejSAU61pIxPRME=; b=cbwStnODpnWK5E8ovffazKtIaUR/THSPN+i+O2cUD95B63PFbtlPYTTVp4pZB84L+H KM+nMIRcvUW5FPS0dTutTa/7JSzebTh4a0QIhKD7b2s82gNX4IIqddMiQg2SSr7TJZbc XLBVJTooJVUnbFxFwG5UMDsRrlH2SqBy+KYpT5sRJyS1WytnErVr7TxlyV4KN8fuO1dT GHNQS0shBY+IuPhn8u9bDOER8KcHWLBTANJgCzgnKXP1wgLwgNS2JdUT6ANkRQuU6Ycp NBcz0lFaVglc18+i/3hzP2vZqqme/R62oll58wfvb1KYyIKTDcY/cn+chHVOwn6r5Dlb mg4w== X-Gm-Message-State: ACgBeo0PrJ1df/OLkeLhQ/HTHoq5iBuMOLoi76UyZOLHMCbPpp4lR0xI fD/wlX1qGTrTGPIGna15RY4oVxFB+EESQGH/GYCxlA== X-Received: by 2002:a5d:5a82:0:b0:224:f744:1799 with SMTP id bp2-20020a5d5a82000000b00224f7441799mr7421991wrb.582.1661821637538; Mon, 29 Aug 2022 18:07:17 -0700 (PDT) MIME-Version: 1.0 References: <20220826230639.1249436-1-yosryahmed@google.com> In-Reply-To: From: Yosry Ahmed Date: Mon, 29 Aug 2022 18:06:41 -0700 Message-ID: Subject: Re: [PATCH] selftests/bpf: simplify cgroup_hierarchical_stats selftest To: Hao Luo Cc: Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Mykola Lysenko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Jiri Olsa , bpf , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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=unavailable 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, Aug 29, 2022 at 3:15 PM Yosry Ahmed wrote: > > Hi Hao, > > Thanks for taking a look! > > On Mon, Aug 29, 2022 at 1:08 PM Hao Luo wrote: > > > > On Fri, Aug 26, 2022 at 4:06 PM Yosry Ahmed wrote: > > > > > > The cgroup_hierarchical_stats selftest is complicated. It has to be, > > > because it tests an entire workflow of recording, aggregating, and > > > dumping cgroup stats. However, some of the complexity is unnecessary. > > > The test now enables the memory controller in a cgroup hierarchy, invokes > > > reclaim, measure reclaim time, THEN uses that reclaim time to test the > > > stats collection and aggregation. We don't need to use such a > > > complicated stat, as the context in which the stat is collected is > > > orthogonal. > > > > > > Simplify the test by using a simple stat instead of reclaim time, the > > > total number of times a process has ever entered a cgroup. This makes > > > the test simpler and removes the dependency on the memory controller and > > > the memory reclaim interface. > > > > > > Signed-off-by: Yosry Ahmed > > > --- > > > > Yosry, please tag the patch with the repo it should be applied on: > > bpf-next or bpf. > > > > Will do for v2. > > > > > > > When the test failed on Alexei's setup because the memory controller was > > > not enabled I realized this is an unnecessary dependency for the test, > > > which inspired this patch :) I am not sure if this prompt a Fixes tag as > > > the test wasn't broken. > > > > > > --- > > > .../prog_tests/cgroup_hierarchical_stats.c | 157 ++++++--------- > > > .../bpf/progs/cgroup_hierarchical_stats.c | 181 ++++++------------ > > > 2 files changed, 118 insertions(+), 220 deletions(-) > > > > > [...] > > > diff --git a/tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c b/tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c > > > index 8ab4253a1592..c74362854948 100644 > > > --- a/tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c > > > +++ b/tools/testing/selftests/bpf/progs/cgroup_hierarchical_stats.c > > > @@ -1,7 +1,5 @@ > > > // SPDX-License-Identifier: GPL-2.0-only > > > /* > > > - * Functions to manage eBPF programs attached to cgroup subsystems > > > - * > > > > Please also add comments here explaining what the programs in this file do. > > > > Will do. > > > > * Copyright 2022 Google LLC. > > > */ > > [...] > > > > > > -SEC("tp_btf/mm_vmscan_memcg_reclaim_begin") > > > -int BPF_PROG(vmscan_start, int order, gfp_t gfp_flags) > > > +SEC("fentry/cgroup_attach_task") > > > > Can we select an attachpoint that is more stable? It seems > > 'cgroup_attach_task' is an internal helper function in cgroup, and its > > signature can change. I'd prefer using those commonly used tracepoints > > and EXPORT'ed functions. IMHO their interfaces are more stable. > > > > Will try to find a more stable attach point. Thanks! Hey Hao, I couldn't find any suitable stable attach points under kernel/cgroup. Most tracepoints are created using TRACE_CGROUP_PATH which only invokes the tracepoint if the trace event is enabled, which I assume is not something we can rely on. Otherwise, there is only trace_cgroup_setup_root() and trace_cgroup_destroy_root() which are irrelevant here. A lot of EXPORT'ed functions are not called in the kernel, or cannot be invoked from userspace (the test) in a straightforward way. Even if they did, future changes to such code paths can also change in the future, so I don't think there is really a way to guarantee that future changes don't break the test. Let me know what you think. > > > > +int BPF_PROG(counter, struct cgroup *dst_cgrp, struct task_struct *leader, > > > + bool threadgroup) > > > { > > > - struct task_struct *task = bpf_get_current_task_btf(); > > > - __u64 *start_time_ptr; > > > - > > > - start_time_ptr = bpf_task_storage_get(&vmscan_start_time, task, 0, > > > - BPF_LOCAL_STORAGE_GET_F_CREATE); > > > - if (start_time_ptr) > > > - *start_time_ptr = bpf_ktime_get_ns(); > > > - return 0; > > > -} > > [...] > > > } > > > -- > > > 2.37.2.672.g94769d06f0-goog > > >