bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	Jesper Dangaard Brouer <brouer@redhat.com>,
	David Miller <davem@davemloft.net>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 3/4] libbpf: Support configurable pinning of maps from BTF annotations
Date: Thu, 24 Oct 2019 20:19:56 -0700	[thread overview]
Message-ID: <CAEf4BzYeMBYDx6TXAqdkpWpW43yKWNbGaA+67LV1zPao-u779A@mail.gmail.com> (raw)
In-Reply-To: <157192270077.234778.5965993521171571751.stgit@toke.dk>

On Thu, Oct 24, 2019 at 6:11 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> From: Toke Høiland-Jørgensen <toke@redhat.com>
>
> This adds support to libbpf for setting map pinning information as part of
> the BTF map declaration. We introduce a version new
> bpf_object__map_pin_opts() function to pin maps based on this setting, as
> well as a getter and setter function for the pin information that callers
> can use after map load.
>
> The pinning type currently only supports a single PIN_BY_NAME mode, where
> each map will be pinned by its name in a path that can be overridden, but
> defaults to /sys/fs/bpf.
>
> The pinning options supports a 'pin_all' setting, which corresponds to the
> old bpf_object__map_pin() function with an explicit path. In addition, the
> function now defaults to just skipping over maps that are already
> pinned (since the previous commit started recording this in struct
> bpf_map). This behaviour can be turned off with the 'no_skip_pinned' option.
>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---

I think you are overcomplicating this... Here's how I think we can
satisfy both simplicity goals, as well as good usability:

1. add `const char *pin_root_path` to bpf_object_open_opts. This
pinning path override doesn't need to leave in some separate set of
options, it's BPF object's parameter, so let's put it into open
settings.

2. If BTF-defined map definition has pinning set to PIN_BY_NAME, that
means bpf_object__load should do auto-pinning. If not, no
auto-pinning, only if manually requested by explicit bpf_map__pin.
Further, if someone wants to auto-pin map to a custom location, do
bpf_map__set_pin_path() before bpf_object__load(), and load should
auto-pin it as well.

3. bpf_map__get_pinning/bpf_map__set_pinning are unnecessary, at least
for now. Let's not add unnecessary APIs.

4. pin_all/skip_pinned seems unnecessary. What scenarios are you
solving with them? Given #1 and #4, just drop
bpf_object__pin_maps_opts().

The way I see it, libbpf should behave sanely for declarative use
case, but allow custom tuning programmatically. If map is set to
PIN_BY_NAME in map definition - we derive pin_path (potentially taking
into account custom pin root path from open opts) and auto-pin on load
(unless application set pin_path manually). In a weird case, where map
is declaratively defined as auto-pinnable, but application for
whatever reason decides not to do it - it can unset pin_path with
bpf_map__set_pin_path(NULL).

Full control, but simple and intuitive default behavior? Does it make sense?


>  tools/lib/bpf/bpf_helpers.h |    6 ++
>  tools/lib/bpf/libbpf.c      |  134 ++++++++++++++++++++++++++++++++++---------
>  tools/lib/bpf/libbpf.h      |   26 ++++++++
>  tools/lib/bpf/libbpf.map    |    3 +
>  4 files changed, 142 insertions(+), 27 deletions(-)
>

  parent reply	other threads:[~2019-10-25  3:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24 13:11 [PATCH bpf-next v2 0/4] libbpf: Support automatic pinning of maps using 'pinning' BTF attribute Toke Høiland-Jørgensen
2019-10-24 13:11 ` [PATCH bpf-next v2 1/4] libbpf: Fix error handling in bpf_map__reuse_fd() Toke Høiland-Jørgensen
2019-10-25  2:46   ` Andrii Nakryiko
2019-10-24 13:11 ` [PATCH bpf-next v2 2/4] libbpf: Store map pin path and status in struct bpf_map Toke Høiland-Jørgensen
2019-10-25  3:00   ` Andrii Nakryiko
2019-10-24 13:11 ` [PATCH bpf-next v2 3/4] libbpf: Support configurable pinning of maps from BTF annotations Toke Høiland-Jørgensen
2019-10-24 13:25   ` Toke Høiland-Jørgensen
2019-10-25  3:19   ` Andrii Nakryiko [this message]
2019-10-25 12:32   ` Jesper Dangaard Brouer
2019-10-25 17:28     ` Andrii Nakryiko
2019-10-24 13:11 ` [PATCH bpf-next v2 4/4] libbpf: Add option to auto-pin maps when opening BPF object Toke Høiland-Jørgensen
2019-10-25  4:41   ` Andrii Nakryiko
2019-10-27 12:04     ` Toke Høiland-Jørgensen
2019-10-27 20:12       ` Andrii Nakryiko
2019-10-27 20:44         ` Toke Høiland-Jørgensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEf4BzYeMBYDx6TXAqdkpWpW43yKWNbGaA+67LV1zPao-u779A@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=kafai@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=toke@redhat.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).