Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3930132ioo; Mon, 30 May 2022 13:13:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRiA1kQ8+y4UnE2miOg71nE9McNfHZWEHA/17dwrx65pnC2Uo9rW0z8pv4Lj4q+FNWzpag X-Received: by 2002:a05:6402:3593:b0:42b:550e:ddb with SMTP id y19-20020a056402359300b0042b550e0ddbmr46816961edc.403.1653941630808; Mon, 30 May 2022 13:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653941630; cv=none; d=google.com; s=arc-20160816; b=AR9s+2sg3FVak6nc/PYoxgu/iDkvxFYBGIpP2l7zKhXCmNGRDol3hZKzLj6bue5VI9 CYbWwCsfsX7OE6XU0bRcTM9fmTjvY1TibQj2HTzOkmPYvymmkMpx3tbvNd/KpaF87nEn aKrOTyTmKLyQC85LTQsFEOn8Y9QLWZKxY7UBy/EQrpcxLaqOkR4s7guYpLhIA3y0lDG/ I3ZJd3MvwG8TPbnMAJfzoDWmsG6zn98XXUHhuj81i9Gr/OELpayHFykLnYNfPGL605/l /AP9BhiduS566C+vBcmf1lEDGKOmWun5kpCEN8k2Jaw5C1saYHyt4K9rErTNmQGZhiaT IGaQ== 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=JNP+R0ohcLUjNtDJRZoqQVoepX4pDHJ5Tzsqw/Ip/us=; b=OckzVFagrGapxbbBP3kJjc40GHTIw82HO3X5reBRHDRavB+t4KenzmAq3PcYa0A+B5 68JSn7Sh+OSwRatJBJblyu2elASFwEpdtWugScS3OGpwB5fzDJq1onBXBMHT+4CGH4I5 21J5kqqPak6SbcN6yrQhpJ4iNhel6LhRTuh0oPaP0ETxcyNnkN2irilBdZq21nEJPc7o PRZjmsCs3Q/JKiXL70qo2g9HXwRlHYyMiiIksqlsxLwGtf8a1sURuAoTLTWJLVezRAlZ lnyeKXwoVdfZ897/Ypiz47G6iAaaVBS9UZGYokuK0j4meoc5ct/BtK7bfmWRBR0ca+Ox GOiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=1zsRDNM7; 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 v8-20020aa7d648000000b004285db05e3csi12575592edr.87.2022.05.30.13.13.21; Mon, 30 May 2022 13:13: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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=1zsRDNM7; 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 S234701AbiE3JNz (ORCPT + 99 others); Mon, 30 May 2022 05:13:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234599AbiE3JNy (ORCPT ); Mon, 30 May 2022 05:13:54 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FFE25D19D for ; Mon, 30 May 2022 02:13:53 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id l20-20020a17090a409400b001dd2a9d555bso10197450pjg.0 for ; Mon, 30 May 2022 02:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JNP+R0ohcLUjNtDJRZoqQVoepX4pDHJ5Tzsqw/Ip/us=; b=1zsRDNM7+bOnSAXrGT8GTnB+LPiaiWeULGvPDxnh8ygbaIBhoXtWi5qIMtlR+0jVC3 mCvGt4XP1HvP05Ke+93gP1wyUTIWPC8TqTkPUCoiPi8wDLv8QUjVuAY9G0wfAwfbjglm NoKvGVb3RhJ+KbFn1b/3H6xRut1xSH5jjCVxn04Hu4IuhaomW+hHiu/5rI8BZ8F3q5pX eBlK0Kq1pBmWUk7cwGnPfxh4Z4PAB1MyZytQjrashWTXpKvEnWe8/jjjhSVvNtkcdGZ2 VnvSXj+wY3xyfzW3dI1WBCB648rq6dK65QaH+KQdProsmF9O+QYp5Geg7zOqauaANpg9 6iUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=JNP+R0ohcLUjNtDJRZoqQVoepX4pDHJ5Tzsqw/Ip/us=; b=6TVCUgMNSIbBxoZNRoTPM81nrYp0OBdTVNtrWabFg5ZOK7pmWh/pgu4kIpvuznn6cS jEnsUHWqIYTMcLJVIzqEYUTIbcwOMfXfA+vu74bL4MaGHYvkjeEu3XkV+dibaZVKc5gx 6XZA0TcOPAqyjwEJcmL3NPAjU5khMKijSuxENnZGmB241jl6m/Jh6dZfoBXwih507vwA 0KYT41cm6H5In8Y1pkdIOvoWznGMx4nvteXmSWYMZ49yTUzbqF7U+3ivf4rgwTcSBvn3 +g5tZOS1irwa27IlS/p5SAzQC5vjgnyj16Jr9wx3wxbnCAhS2Tc90GFvT3qqqGcY2Uus a4rA== X-Gm-Message-State: AOAM533lB97ZQgStdC9wwqJZHOBnl61d2JZebamkmzozmIAG54vMmmxH Lgb4lVo2kKS2GgxAtz9xqAGuUQ== X-Received: by 2002:a17:903:22cc:b0:162:4d8b:e2eb with SMTP id y12-20020a17090322cc00b001624d8be2ebmr29890361plg.22.1653902032530; Mon, 30 May 2022 02:13:52 -0700 (PDT) Received: from C02F52LSML85.bytedance.net ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id p2-20020a170902ebc200b0015e8d4eb20dsm8640644plg.87.2022.05.30.02.13.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 May 2022 02:13:52 -0700 (PDT) From: Feng zhou To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com, songmuchun@bytedance.com, wangdongdong.6@bytedance.com, cong.wang@bytedance.com, zhouchengming@bytedance.com, zhoufeng.zf@bytedance.com Subject: [PATCH v3 0/2] Optimize performance of update hash-map when free is zero Date: Mon, 30 May 2022 17:13:38 +0800 Message-Id: <20220530091340.53443-1-zhoufeng.zf@bytedance.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) 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, T_SCC_BODY_TEXT_LINE 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 From: Feng Zhou We encountered bad case on big system with 96 CPUs that alloc_htab_elem() would last for 1ms. The reason is that after the prealloc hashtab has no free elems, when trying to update, it will still grab spin_locks of all cpus. If there are multiple update users, the competition is very serious. 0001: Add is_empty to check whether the free list is empty or not before taking the lock. 0002: Add benchmark to reproduce this worst case. Changelog: v2->v3: Addressed comments from Alexei Starovoitov, Andrii Nakryiko. - Adjust the way the benchmark is tested. - Adjust the code format. some details in here: https://lore.kernel.org/all/20220524075306.32306-1-zhoufeng.zf@bytedance.com/T/ v1->v2: Addressed comments from Alexei Starovoitov. - add a benchmark to reproduce the issue. - Adjust the code format that avoid adding indent. some details in here: https://lore.kernel.org/all/877ac441-045b-1844-6938-fcaee5eee7f2@bytedance.com/T/ Feng Zhou (2): bpf: avoid grabbing spin_locks of all cpus when no free elems selftest/bpf/benchs: Add bpf_map benchmark kernel/bpf/percpu_freelist.c | 28 +++++- kernel/bpf/percpu_freelist.h | 1 + tools/testing/selftests/bpf/Makefile | 4 +- tools/testing/selftests/bpf/bench.c | 2 + .../benchs/bench_bpf_hashmap_full_update.c | 96 +++++++++++++++++++ .../run_bench_bpf_hashmap_full_update.sh | 11 +++ .../bpf/progs/bpf_hashmap_full_update_bench.c | 40 ++++++++ 7 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 tools/testing/selftests/bpf/benchs/bench_bpf_hashmap_full_update.c create mode 100755 tools/testing/selftests/bpf/benchs/run_bench_bpf_hashmap_full_update.sh create mode 100644 tools/testing/selftests/bpf/progs/bpf_hashmap_full_update_bench.c -- 2.20.1