Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp280647pxk; Wed, 2 Sep 2020 22:30:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy/wvNhcn0VCgiEnZY0Xf32Skv+3C3GOxba5SBCUXkXZa19TftgU1AjzjIa794V+aS0WFE X-Received: by 2002:aa7:cad3:: with SMTP id l19mr1269026edt.352.1599111006755; Wed, 02 Sep 2020 22:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599111006; cv=none; d=google.com; s=arc-20160816; b=ZKy0wDpKyu+WUI6sUSm8tuvDqQd6XwgY3QbK3cJ6YBZ2kdOnqFcS7e0H0RID7VZoWw xQt5WTKov91usx17Qpv8FMsFIDfqMcPTYMJ55PdryN1rExO+oMjar6+KnOd/tu/bShI2 MvnkHJtiWih3TdT5j4XgvPLCI3RVj24Jh39GTHjfKM3RZ/sAkLHe+gNYHENlvnwZRIyi j4Q3CQ/bHcmq4RhpsGUN9+PFmKTkwZUaqXs17+zAhPFeocElZdedFyZSfSVlccCrIzaH ObxcDMbA0lJCKmOZrRVYaW3quEDEiV7YrsJLtp7olnoZ7UKOyj3xaBKHq3elfuF/FQmg Dyyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=aqSzJ+G6e3sItDAMEGO8323I5vOUOvMlVHBhDl0yekQ=; b=vRgB+BbYnSln2PZAsFNOmyIfRLTm5crqPqdve3ZkpzjqbuBgckgyaJTgF/nlWKVX/R RACvgL1kBqLJ8dh7AiOE/dgZERAnlFQegKZOlGeEcFIaBkrvNtGRH43l1E93WXogP/Vc SKlkJ96B0OCn3yVVH1rRuQ/iKcFdi4b94Dt1FMOHxaGDPVTV0DID9pfixTC7CobMk8Ls 7ouUCSVF/Yv8TOfwOzTiujqoyIDAzsNqxqyjKISnKV2A0GbluPBeXSjh1XlSqxz/UyDT g6pW/5rsGiyVBHYdgE/L1sO07XoCBNvydfRSasXfmpToiEpkv2jl7lIWns5Er6EppTel jlJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Uk2NZA9Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si1184253ejd.405.2020.09.02.22.29.43; Wed, 02 Sep 2020 22:30:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Uk2NZA9Y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726320AbgICF3J (ORCPT + 99 others); Thu, 3 Sep 2020 01:29:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725919AbgICF3H (ORCPT ); Thu, 3 Sep 2020 01:29:07 -0400 Received: from mail-yb1-xb43.google.com (mail-yb1-xb43.google.com [IPv6:2607:f8b0:4864:20::b43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55433C061244; Wed, 2 Sep 2020 22:29:07 -0700 (PDT) Received: by mail-yb1-xb43.google.com with SMTP id s92so1333342ybi.2; Wed, 02 Sep 2020 22:29:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aqSzJ+G6e3sItDAMEGO8323I5vOUOvMlVHBhDl0yekQ=; b=Uk2NZA9Y6bbWDzHmEYkTzTD/xekG9voY1J+n9mxwJ4+ALoTFqBDICwWpq6/R+8d+vI yKCWrlEc+RcRxR3jzOIM+5iVImoeONAuAtwQ886mTRXRSKLTxi72QVmk+Z2XiPbs5h1h VXZv6V43lZAjfsmo6SLg07Ny7wUmdid/vL6t1QPmvUUb+WxS6lAYMrBZ13TanFWpqCvb 5xJzdmSdqh4ImXo7ktkMBsD0h+baSJC807sNKiYPjnq0MpaEO61VfpQf63jxb5Ay2D8e D16buykU7kxpt9LOprHiTIn4btydJJnTm+gVRCjI9YGkhQHG2r5PzJD3oDZAa3earEbs V4gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aqSzJ+G6e3sItDAMEGO8323I5vOUOvMlVHBhDl0yekQ=; b=Dh7lL/axoK5opqXooztNcw6KbnAQavckdRF3StNaMHzrV7qgGliFvE/N/Kz0LjbkCK gKDHVWsR+Ri5UuOIFvlREzxT2LaKdPn13efzoVAFuws/Y4yk4c81ndrllhaWqn+5BUcu 3JSgmLDdqN+9bA6/qlV+uSo8QrixFqbVdPfX/w4Hg9d7BTi5WPL4CTM6PH3Z/9Ee62QP lSVHWuw7YegQtjfEOCgiZSrte6Y8r9UHQPgS/GoZPxDbhsKktVYlyUBBjD8cTIMndWrI jzBOzPX1iwj6VazuMJ4cG8gQPJORPFb/go50c39rFJ9N90So2AbpDxOtq9AE8fvwIY/k 4dFg== X-Gm-Message-State: AOAM530R0u3kvkeHoRbk6uCFNAhbuPCkPl5q14YO3Ntl4f+2H9XcWwod lZIJRBcT1q6hZW5UJ91XEP5lQidHEEQ1f9NX0Uw= X-Received: by 2002:a25:824a:: with SMTP id d10mr442313ybn.260.1599110946446; Wed, 02 Sep 2020 22:29:06 -0700 (PDT) MIME-Version: 1.0 References: <20200831224933.2129891-1-brho@google.com> In-Reply-To: <20200831224933.2129891-1-brho@google.com> From: Andrii Nakryiko Date: Wed, 2 Sep 2020 22:28:55 -0700 Message-ID: Subject: Re: [RFC PATCH] libbpf: Support setting map max_entries at runtime To: Barret Rhoden Cc: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Networking , bpf , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 31, 2020 at 4:03 PM Barret Rhoden wrote: > > The max_entries for a BPF map may depend on runtime parameters. > Currently, we need to know the maximum value at BPF compile time. For > instance, if you want an array map with NR_CPUS entries, you would hard > code your architecture's largest value for CONFIG_NR_CPUS. This wastes > memory at runtime. > > For the NR_CPU case, one could use a PERCPU map type, but those maps are > limited in functionality. For instance, BPF programs can only access > their own PERCPU part of the map, and the maps are not mmappable. > > This commit allows the use of sentinel values in BPF map definitions, > which libbpf patches at runtime. > > For starters, we support NUM_POSSIBLE_CPUS: e.g. > > struct { > __uint(type, BPF_MAP_TYPE_ARRAY); > __uint(max_entries, NUM_POSSIBLE_CPUS); > __type(key, u32); > __type(value, struct cpu_data); > } cpu_blobs SEC(".maps"); > > This can be extended to other runtime dependent values, such as the > maximum number of threads (/proc/sys/kernel/threads-max). > > Signed-off-by: Barret Rhoden > --- libbpf provides bpf_map__set_max_entries() API exactly for such use cases, please use that. > tools/lib/bpf/bpf_helpers.h | 4 ++++ > tools/lib/bpf/libbpf.c | 40 ++++++++++++++++++++++++++++++------- > tools/lib/bpf/libbpf.h | 4 ++++ > 3 files changed, 41 insertions(+), 7 deletions(-) > [...]