Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp1839899rwl; Fri, 4 Nov 2022 20:51:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ExhVqXAh49lZtem8aX1wkcCpIvFDz4OBJJ2rRBjhFeYszzLT5coZeIuuHoNlUHofJ7Zut X-Received: by 2002:a17:907:1dd7:b0:7ae:41e1:cdfb with SMTP id og23-20020a1709071dd700b007ae41e1cdfbmr3364345ejc.58.1667620295890; Fri, 04 Nov 2022 20:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667620295; cv=none; d=google.com; s=arc-20160816; b=paDQ3722b7a6kcSPBjYmvWb9U0FgjbG1I+uaiY5LzZrEMwJPkgjVFV8TIRDr+rci64 RAUU9iE5kKR9ofhkipWreLSH65lu35yxmbnqPlkfkyK2p8oXgkFRxb/42rDzzT6HhUMT WRLw5h1mlRVEV1rrfePAfw7BT1mAyzeZmuO72Qs682ZzGr4XDHvUm5/VDJzmsuU59ZgM zH2cx9SCrE4d7WcLrCzN/0Uore/Lrr6W6DZxF/qlzgbgWaxOJf/lZUokEgXA73yYToEu avt2PQZiHheIsChR+BZaXRtZC04pEXGYBQkO0LSvULYk9xzIuGYHR3uBCbeprnYbjYV0 1xqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=eCxoN6ChgDmmemcuz37gCvFaemxJyQ9HSvlBAAP7JaU=; b=XoeR89TS4UBSRH9nFeXsd0WjADL0XXc3FYNYU2WYsW9a9uhuieg/jFcuQcqRm1C/Q2 HrCYszkeznhfIGuboA5VIU64nYd46GAUuaIg+MBVhYAmW7i5fAtNxW8tOzVPnea5nksq HTXlpmXXsn4ig5F1sDura8k1zwMuZsBtRQpGKaOPwhw7H7ftQCrRb0r1fKdadDVs4ko6 x4XPvA0o2VFDd12U/fW0izuaNes3eCENzoba97ajOP98SvQFt5tcIWiWw1HRJ2pUwOda 2daEwWf3e7ekJ2U+Q7LPCHd5S6cdVrlTw/RgBlnlvf/qBxtf3loB+tF4qAiK62/03VZK rCvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Knez7Hwb; 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 dd18-20020a1709069b9200b007adf558e182si1132012ejc.926.2022.11.04.20.51.13; Fri, 04 Nov 2022 20:51:35 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Knez7Hwb; 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 S229560AbiKECwg (ORCPT + 97 others); Fri, 4 Nov 2022 22:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiKECw2 (ORCPT ); Fri, 4 Nov 2022 22:52:28 -0400 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2895F3FB83 for ; Fri, 4 Nov 2022 19:52:27 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id mi9so4639331qvb.8 for ; Fri, 04 Nov 2022 19:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=eCxoN6ChgDmmemcuz37gCvFaemxJyQ9HSvlBAAP7JaU=; b=Knez7Hwb0qj9NP8+cMkRu09v3XcaTT/OuAB32+CgReZn9N6VuUDh5A7MQnYd0QYlyq sp4nR+UWrN9ZQ0UnOb3uUhABMcgDHku50dFtVXLS1fR4Jjb2FGobmqsSemV7tRIuPSuj LLgId/2ET+lNwnPjlilXkO7Mrv7qA5OTmHnKncWQVSFWga2m8tbk9TYvkTGIuSxV0Lcq zBxUO4Tt4d8Rszj/H5ZncVG3mq/tBwI3LAk6IpTvI65p6RqE0ZVYAkom/OJV7UKDqaW6 zYvWy+t8C4d7k5nyj6w59YMItGnaC44wAgREV+33Cr4oukyfobzKYvSlMx8CQJNGmrm3 IY9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eCxoN6ChgDmmemcuz37gCvFaemxJyQ9HSvlBAAP7JaU=; b=gkPlFsV+C86CE9ZtU+XG5/fCJgUkHB4pDmT0kyEYZMMaBNdK4qH7nnU7SaZzafeHYq TYhBfP5IOiA9l1+xqAsEBxaopbcKBuZo3+VnKS4XmP4kUajAxlcPcPjOSABpBojDhqiY YHy2I9xrAKRx3rhbA/E+SUf+WxkjizGzMSDW+iHjDHNS+RbvrmGrDqn3Md+g7IVKfQzP ckQBN04YgGIh4rmCcyKy22kK+Lm8Fh6hbS3PGei7pDlkvCnSa2RguM7EdcbtQvP3rZkL 6FqqREvaPpJi78mj2jMqYeEfJcpTxSouSAAwMdnAnrULLAgHYV2NbeMnTsk+8S7mnJyM MAug== X-Gm-Message-State: ACrzQf07G6VYIth6uL1Ga0FuT3xybjNSf17D5oPd0GTGtNJ9IA47w3sR lMVNqF/D8Ze1kE2l7FxMle9L8w== X-Received: by 2002:a0c:e2d4:0:b0:4bb:5902:922c with SMTP id t20-20020a0ce2d4000000b004bb5902922cmr34764425qvl.57.1667616746264; Fri, 04 Nov 2022 19:52:26 -0700 (PDT) Received: from 192-168-53-12.byted.org ([130.44.212.119]) by smtp.gmail.com with ESMTPSA id ay14-20020a05620a178e00b006bb366779a4sm805905qkb.6.2022.11.04.19.52.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 19:52:25 -0700 (PDT) From: "Ho-Ren (Jack) Chuang" To: Alexei Starovoitov , 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 , Hao Xiang , Punit Agrawal , Yifei Ma , Xiaoning Ding , bpf@vger.kernel.org Cc: Ho-Ren Chuang , Ho-Ren Chuang , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH bpf-next v1 0/4] Add BPF htab map's used size for monitoring Date: Sat, 5 Nov 2022 02:51:42 +0000 Message-Id: <20221105025146.238209-1-horenchuang@bytedance.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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/ This patch series adds a new field "used_entries" to struct bpf_map_info and keeps tracking the "count" field in bpf_htab in both the preallocated and non-preallocated cases. bpftool is modified to report the newly added "used_entries" field in struct bpf_map_info and to mark pre-allocated htab maps with "*". These make it easier to view the current memory situation of a hashmap. We have added a new interface function map_get_used_elem in bpf_map_ops to provide an abstraction layer so that other map type implementations can support the "used_entries" attribute in a future change. A concurrency testing for pre-allocated and dynamically allocated htab maps is introduced to test the correctness and performance of htab map's used size. Existing unit tests are integrated to test the correctness of htab map's used size. Thank you, Ho-Ren (Jack) Chuang (4): bpf: Support reporting BPF htab map's used size for monitoring bpftool: Add tools support to show BPF htab map's used size samples/bpf: Add concurrency testing for BPF htab map's used size selftests/bpf: Add unit tests for BPF htab map's used size include/linux/bpf.h | 1 + include/uapi/linux/bpf.h | 1 + kernel/bpf/hashtab.c | 19 +++ kernel/bpf/syscall.c | 2 + samples/bpf/Makefile | 4 + samples/bpf/test_map_used_kern.c | 65 ++++++++ samples/bpf/test_map_used_user.c | 204 ++++++++++++++++++++++++ tools/bpf/bpftool/map.c | 9 +- tools/include/uapi/linux/bpf.h | 1 + tools/testing/selftests/bpf/test_maps.c | 74 ++++++++- 10 files changed, 377 insertions(+), 3 deletions(-) create mode 100644 samples/bpf/test_map_used_kern.c create mode 100644 samples/bpf/test_map_used_user.c -- Ho-Ren (Jack) Chuang