Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2715415rwb; Mon, 7 Nov 2022 17:17:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf7/vPn6cQhqRLpoj4m/B2gCJO7k87Vg8ilY9IOGbiXYkm2Fovt4Q/5ePNXptq3YMRyyww/n X-Received: by 2002:a17:906:2284:b0:7ae:5aa5:518f with SMTP id p4-20020a170906228400b007ae5aa5518fmr12105312eja.760.1667870238622; Mon, 07 Nov 2022 17:17:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667870238; cv=none; d=google.com; s=arc-20160816; b=gaqdC9p2Er5bgzCziSqlfkgL898iMgdZkS6eI5naom8sNoAmEwXiZWXL9cfw5Rhh+h AxU7P+hNNq89lMJXHcnCga7qBBjCIGdAu7PvndW/EYbHMLSOF4EG7QBPOB+V3ZVGZmqa 0Y+BqYHBlyCuONnvxiLpc2VaLKpM1xdNLOMrdPjlrKDyU7Ai9NJNtDvtQzMY/m2iKcz0 V300BhQ6kbn8jiJY02LK4ucZ5LeiU5WM2iMoIokJImkjcV8d1sVzIb5h6KPSARTvY75J e/LImJHNJHsz+60WkoC4euEQgyzx1qikYFZ3wHo4Txl4eVKd9qGUMSZN2Sv5ovBEBmKk s9qQ== 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=NF/Xjl4bGX60sTFdSkyJB0iuEuG5H4mSvhGQEhyFFsE=; b=TpdCCIiuJkeAddldyo6GbyC2AguzDIxbINIRBdTIce3d/55yeb2GvBedpmDKJjuMVp pSvi8ZBTdJM00+G0uS91LY9EtqsXpAuQPGNcxLDg26HVGE6QF6/m2YCHKgG9KjTeTH4q d5jy7BvFWl8RuIja+hP6mku4K9OwJ5UxvW8oNeVB31VZ67qVhejIENPwfohkoZ+hOJV1 YzQPgBNbI8f+VL7WXzPeFjI07EqJF+6olyXF7owA05AqN9e2UP8JPhB1inKTTF5s5HLk LyqLcKFw9psRVRE918pP6Z3dJ0BSr6YuGMSUxlrm6CYzfb3RgtUTqoI3YJ/q5Y5+c7jl h/kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=optWeMbK; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt19-20020a1709072d9300b0078d450cbb02si12999372ejc.452.2022.11.07.17.16.56; Mon, 07 Nov 2022 17:17:18 -0800 (PST) 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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=optWeMbK; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232939AbiKHAaY (ORCPT + 92 others); Mon, 7 Nov 2022 19:30:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232913AbiKHAaV (ORCPT ); Mon, 7 Nov 2022 19:30:21 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F6831DDEA for ; Mon, 7 Nov 2022 16:30:19 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id e15so7910850qts.1 for ; Mon, 07 Nov 2022 16:30:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=NF/Xjl4bGX60sTFdSkyJB0iuEuG5H4mSvhGQEhyFFsE=; b=optWeMbKrLwYAP5/SViogLQxgNk3k+gmgqGwknY4DN9tkcLWh/wvnIQA+FvQ1HWubL ZUGbEfIdlQ6roFAuBmalgMPoCEwLMx34IM7LoPms25sDGh628s9gpq5i9RLxDfaixGTU HwZs2Y2ovr7Mf+NT6Zg9yF8PNLTUueIQPRqwEUgvtZBAJ8GSjpel3OIpP/3ZGSV4+dZJ STzKJL5Ltpd393Ba/7QUFPAHknZdU5y9VPwMUpD+4ho6bTlyRs0E7jhXJ8UIr4UWK/1o 4obrgLwAFMea8d1x0oAIP/x9Ht9EJN3vCkqLweHFlubiHgVaa0+b0O5cOd3vawaAJbGc wYfQ== 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:subject:date:message-id :reply-to; bh=NF/Xjl4bGX60sTFdSkyJB0iuEuG5H4mSvhGQEhyFFsE=; b=Dt08UrC4VnRrmO8YgwIHrrq3PSKtq0yfg0EjkXPiXoPQrNfRkTOP0HU32HpQI2k09Z 2wxBzUGY/Gb6aiJCcFV54HI2zqPiEsjsNaz/6+PC4WRG7/m/Fq5G/svUWmd3e8H5gge1 3wx+e6ZcmqfdE7FkEBPrJ+7CyuLbyfLN3/9GoyzPyRfPMX9BzmIzjSdg8lMgLhYe3QbP bHyJ91SJn+/4f4h0YABl1zZ/6P32t5u+NnCL7sLlUiOHy98PRoXHECkKQOpLVDh+8Pdu Z56p/sGu5ou9lEXMVNH6KIRkEuhiez2LdnSmk5KoipQ/zOMP4h2X0Wy7asb+jCiUNpRH VxeA== X-Gm-Message-State: ACrzQf1ZmlYpOaUMN/yUV7464HkweOOytoHEWWAzlW/7gnrccCTrMhY0 FbfEFrsN7wLL5i1DNANBjUE+iEQVnrX1iwOC3v0s3w== X-Received: by 2002:a05:622a:a05:b0:3a5:2c5f:9a66 with SMTP id bv5-20020a05622a0a0500b003a52c5f9a66mr32343641qtb.508.1667867418139; Mon, 07 Nov 2022 16:30:18 -0800 (PST) MIME-Version: 1.0 References: <20221105025146.238209-1-horenchuang@bytedance.com> In-Reply-To: From: "Hao Xiang ." Date: Mon, 7 Nov 2022 16:30:08 -0800 Message-ID: Subject: Re: [External] Re: [PATCH bpf-next v1 0/4] Add BPF htab map's used size for monitoring To: Alexei Starovoitov Cc: "Ho-Ren (Jack) Chuang" , Alexei Starovoitov , Hao Luo , Jiri Olsa , Jiri Olsa , Andrii Nakryiko , Daniel Borkmann , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Quentin Monnet , Mykola Lysenko , Shuah Khan , Nathan Chancellor , Nick Desaulniers , Tom Rix , Joanne Koong , Kui-Feng Lee , Lorenzo Bianconi , Maxim Mikityanskiy , Punit Agrawal , Yifei Ma , Xiaoning Ding , bpf , Ho-Ren Chuang , LKML , "open list:KERNEL SELFTEST FRAMEWORK" , clang-built-linux Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Hi Alexei, We understand the concern on added performance overhead. We had some discussion about this while working on the patch and decided to give it a try (my bad). Adding some more context. We are leveraging the BPF_OBJ_GET_INFO_BY_FD syscall to trace CPU usage per prog and memory usage per map. We would like to use this patch to add an interface for map types to return its internal "count". For instance, we are thinking of having the below map types to report the "count" and those won't add overhead to the hot path. 1. ringbuf to return its "count" by calculating the distance between producer_pos and consumer_pos 2. queue and stack to return its "count" from the head's position 3. dev map hash to returns its "count" from items There are other map types, similar to the hashtab pre-allocation case, will introduce overhead in the hot path in order to count the stats. I think we can find alternative solutions for those (eg, iterate the map and count, count only if bpf_stats_enabled switch is on, etc). There are cases where this can't be done at the application level because applications don't see the internal stats in order to do the right counting. We can remove the counting for the pre-allocated case in this patch. Please let us know what you think. Thanks, Hao On Sat, Nov 5, 2022 at 9:20 AM Alexei Starovoitov wrote: > > On Fri, Nov 4, 2022 at 7:52 PM Ho-Ren (Jack) Chuang > wrote: > > > > Hello everyone, > > > > We have prepared patches to address an issue from a previous discussion. > > The previous discussion email thread is here: https://lore.kernel.org/all/CAADnVQLBt0snxv4bKwg1WKQ9wDFbaDCtZ03v1-LjOTYtsKPckQ@mail.gmail.com/ > > Rephrasing what was said earlier. > We're not keeping the count of elements in a preallocated hash map > and we are not going to add one. > The bpf prog needs to do the accounting on its own if it needs > this kind of statistics. > Keeping the count for non-prealloc is already significant performance > overhead. We don't trade performance for stats.