Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp633233imn; Thu, 28 Jul 2022 11:03:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4x0KcN6Mj2yu1sT4jxujIzTKqfHhajcOF+KG4fupsspOBdLgSAuKBebUGtcQdHBMN9+4p X-Received: by 2002:a05:6402:3807:b0:435:20fb:318d with SMTP id es7-20020a056402380700b0043520fb318dmr141698edb.272.1659031395235; Thu, 28 Jul 2022 11:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659031395; cv=none; d=google.com; s=arc-20160816; b=OYQrSfWIA/Xphn06j9Ft36dwTX3ZKkU1jdx9xsQykvxQQx7MgZ6L6ljAe672ynpR8t xLk6RBmB2nv9O7Et8fKAkfKmJqxrzFYlLGJtByQcfr8ClxKGVTkpEUtU5XfYPY0EMBox quNR9LMPFFR6CDC+x1cz31N65yP012mj2LnFGZ3u0ujRT/k/eqo1xPrAdLaOX9TBajcI 51dHFyoT3aN0M5FzfNQ08PkBNH/Rs60r1nAbTfC6/oX95ae5hKuGeS5VDgXKPCgAir3k dnUe2Mjh74131jkOH/RkIn+SjmUvz9Rq5epI3HSkK5MuVrgXRsgrOP9gOnRzTFqxueG9 jQmQ== 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=id4JWD15x2b6Sb0RDjkodbSRKI5pJBPMhp/NyAFO6Wg=; b=Y3V6aDOvQyHCYEhK+UzEYyQvAHClbOey1xv5rvk1/7dCGV8am5f7/S4s5HJOgCGXtP L/FBI3BwZ3DfT43e33+VwtApeq6b6h+0+9Kcch0V1crs97uoLnJPeFP9F8yfwytZ8KSZ OSVZfFCzqW+8TidwTTc+yDrCGqhMzWe319mRNI5ZxpBZ6Zy2NiLkVBT0pTGmBWAeCe4V jAs+hxIsjCPkBCCGLejUO9sq6aLJSz6Zgm1EQHYhoLdnfjJIBAKQw3O9gTtkigv6x/3u T9JBm94wBB2WXIQ/lLnPK0IS/DFlJ1niBGWmen0udv2adZuGIWpho6FzSSRn5j538V+l UNtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZIv6KqB5; 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 t12-20020a1709060c4c00b00726f9797afbsi989737ejf.569.2022.07.28.11.02.48; Thu, 28 Jul 2022 11:03:15 -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=ZIv6KqB5; 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 S232654AbiG1R0s (ORCPT + 99 others); Thu, 28 Jul 2022 13:26:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232503AbiG1R0q (ORCPT ); Thu, 28 Jul 2022 13:26:46 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF79CBF44 for ; Thu, 28 Jul 2022 10:26:44 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id w29so1597115qtv.9 for ; Thu, 28 Jul 2022 10:26: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; bh=id4JWD15x2b6Sb0RDjkodbSRKI5pJBPMhp/NyAFO6Wg=; b=ZIv6KqB5YatdsGxiUke6mhx2cB60Jg0nC16W2vfPQN0fh/N7+rSg2esvcPFp3oQ0Qo VHjyWTcrZS4B2xIeRUQg3Gp6mFclRSXQTuXEq4EBLT9560pu4oKuV2IcCmrPaN3K57YD fqkWbB62X3m1yLgVGqW29+TyZDcTl05KFRbvNOhw5qm4araf+Og1cnkexpRLSmrnqH+e 8dEi+uSiErW4xqdWg5wBrqWGS+eC2RKjvCWmK/k9Lgkgpintww82349+3yFfSGnbrQL3 TI8oLqq57xt37hUMYpK9bVuJrreQjyuyOPW6IV+epVfGVfQiPKHIQpUL5j+bEfgLBWYK qA4A== 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; bh=id4JWD15x2b6Sb0RDjkodbSRKI5pJBPMhp/NyAFO6Wg=; b=m/vSLPNuUGEaAglFtFhXlsk4VnJLJWfg2olMzVxg+FVDozcxuXd4O0L1yKctfo97Jz OA3MkIZG6toFDCxg+QXfYn6zNUmO5LN2CHKnKeHTppLygjERwEe6SZB4JrcuZK8jExqG CGySsKlhnROBY/VaI4Zg6LeKOnnSEh4ow/AnRtvo/WotEV+C76i30iyMW/tpwmGIxwCS oMt6LYxDwlYcfb0JnCYEUhTrNBbJSY67PLeqdHTJ/YY/bYfY/ioCratyWqPApyI2Mnw1 Yj/OcCXOP9RO+EjoUKyqrIBCRsorNgpnLTQqFlqKzwEh48uG0dZotuLOTvKwFLzdF56W l+7w== X-Gm-Message-State: AJIora96p69qDAr7zbUJ/hqQe5bSljK2ZQ7XofIYEHn/EoLkOagLwmQo czUfp33f14+bwGDDDfkFGkj8UTOjj7t9edQ04KURlg== X-Received: by 2002:a05:622a:54a:b0:31f:3822:7009 with SMTP id m10-20020a05622a054a00b0031f38227009mr7489qtx.478.1659029203831; Thu, 28 Jul 2022 10:26:43 -0700 (PDT) MIME-Version: 1.0 References: <20220722174829.3422466-1-yosryahmed@google.com> <20220722174829.3422466-5-yosryahmed@google.com> <639f575e-bc8c-46b9-b21b-bd9fbba835c1@fb.com> In-Reply-To: <639f575e-bc8c-46b9-b21b-bd9fbba835c1@fb.com> From: Hao Luo Date: Thu, 28 Jul 2022 10:26:32 -0700 Message-ID: Subject: Re: [PATCH bpf-next v5 4/8] bpf: Introduce cgroup iter To: Yonghong Song Cc: Kumar Kartikeya Dwivedi , Yosry Ahmed , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Tejun Heo , Zefan Li , Johannes Weiner , Shuah Khan , Michal Hocko , KP Singh , Benjamin Tissoires , John Fastabend , =?UTF-8?Q?Michal_Koutn=C3=BD?= , Roman Gushchin , David Rientjes , Stanislav Fomichev , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, cgroups@vger.kernel.org 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, 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 Wed, Jul 27, 2022 at 11:56 PM Yonghong Song wrote: > > > > On 7/22/22 1:33 PM, Hao Luo wrote: > > On Fri, Jul 22, 2022 at 11:36 AM Kumar Kartikeya Dwivedi > > wrote: > >> > >> On Fri, 22 Jul 2022 at 19:52, Yosry Ahmed wrote: <...> > >>> + > >>> +static int __cgroup_iter_seq_show(struct seq_file *seq, > >>> + struct cgroup_subsys_state *css, int in_stop); > >>> + > >>> +static void cgroup_iter_seq_stop(struct seq_file *seq, void *v) > >>> +{ > >>> + /* pass NULL to the prog for post-processing */ > >>> + if (!v) > >>> + __cgroup_iter_seq_show(seq, NULL, true); > >>> + mutex_unlock(&cgroup_mutex); > >> > >> I'm just curious, but would it be a good optimization (maybe in a > >> follow up) to move this mutex_unlock before the check on v? That > >> allows you to store/buffer some info you want to print as a compressed > >> struct in a map, then write the full text to the seq_file outside the > >> cgroup_mutex lock in the post-processing invocation. > >> > >> It probably also allows you to walk the whole hierarchy, if one > >> doesn't want to run into seq_file buffer limit (or it can decide what > >> to print within the limit in the post processing invocation), or it > >> can use some out of band way (ringbuf, hashmap, etc.) to send the data > >> to userspace. But all of this can happen without holding cgroup_mutex > >> lock. > > > > Thanks Kumar. > > > > It sounds like an idea, but the key thing is not about moving > > cgroup_mutex unlock before the check IMHO. The user can achieve > > compression using the current infra. Compression could actually be > > done in the bpf program. user can define and output binary content and > > implement a userspace library to parse/decompress when reading out the > > data. > > Right mutex_unlock() can be moved to the beginning of the > function since the cgroup is not used in > __cgroup_iter_seq_show(seq, NULL, true) Ok. Will do.