All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: Stephen Brennan <stephen@brennan.io>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Yonghong Song <yhs@fb.com>, Shung-Hsi Yu <shung-hsi.yu@suse.com>,
	bpf <bpf@vger.kernel.org>, Omar Sandoval <osandov@osandov.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Stephen Brennan <stephen.s.brennan@oracle.com>
Subject: Re: Question: missing vmlinux BTF variable declarations
Date: Mon, 9 May 2022 17:10:00 -0700	[thread overview]
Message-ID: <CAEf4BzZmJKqXaJMBxhKqFNXzjO=eN5gk2xQVnmQVdK2xd3HQ=g@mail.gmail.com> (raw)
In-Reply-To: <alpine.LRH.2.23.451.2205032254390.10133@MyRouter>

On Tue, May 3, 2022 at 3:32 PM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> On Tue, 3 May 2022, Stephen Brennan wrote:
>
> > >> Ideally we structure BTFs as a multi level tree.  Where BTF with
> > >> global vars and other non essential BTF info can be added to vmlinux
> > >> BTF at run-time. BTF of kernel mods can add on top and mods can have
> > >> split BTF too.
> >
> > I see what you mean. It does sound a bit frustrating to have an
> > additional BTF module to augment every external module, which would be
> > the third level of that tree.
> >
> > We'll need to allocate more module structs and pages within the kernel
> > for that data, I wonder whether it would be cheaper for the
> > "non-essential" module BTF to just reside in the same BTF section of
> > that module.
> >
> > I suppose I can run my modified pahole on some sample modules and see
> > the BTF size difference, rather than just speculating, I'll do that in a
> > follow-up here.
> >
> > > Yeah, reuses existing mechanizm, doesn't increase the kernel BTF
> > > footprint by default, allows for debuggers, profilers, tracers, etc to
> > > ask for extra info in the form of just loading btf_global_variables.ko.
> >
> > I agree, this is a quite elegant solution. Though it'll require a fair
> > bit of work to achieve, I do think it's important to keep the footprint
> > down. One thing I'd like to see in this world is a way to instruct the
> > kernel that "I always want the non-essential BTF loaded", maybe via
> > cmdline or sysctl. This way, the module loader would know to search for
> > "$MODNAME-btf" for each module which doesn't end with "-btf".
> >
>
> Hmm, could we just have a tristate CONFIG_DEBUG_INFO_BTF_EXTRA?
> If set to y, the extra vars are builtin to vmlinux BTF and
> modules, and if set to m, they reside in /sys/kernel/btf/vmlinux-btf-extra
> courtesy of the vmlinux-btf-extra.ko module (or whatever naming
> scheme makes sense). Looks like pahole already has an option to
> store encoded BTF elsewhere:
>
> --btf_encode_detached=FILENAME
>
> ...so maybe all we need is something like --btf_gen_var_only for
> the case where we build the btf-extra module
>
> pahole -J --btf_base vmlinux  --btf_gen_var_only
> --btf_encode_detached=vmlinux_btf_extra
>
> ?
>

So BTF dedup would take care of keeping only extra DATASEC in such
module while reusing all the types from vmlinux BTF, as long as the
module itself has all the vmlinux BTF types plus those variables. It's
just a question of having ability to enable/disable global variables
generation. Which honestly is not a bad idea in general to have
overall more or less granular control over which subsets of BTF pahole
should emit.

> That's still only 2-way split BTF (base vmlinux BTF
> plus vmlinux variables); we'd only need the
> three-way split for the case where modules use the
> -extra approach too, and I'd wonder about the viability
> of having an -extra BTF module for each module, especially
> if space-saving is the goal.
>

Yeah, it feels like having that for modules is taking this to another
level of complexity, while adding this for vmlinux only seems pretty
doable with minimal changes (we don't need any extra BTF functionality
as we will just leave current start-based topology with vmlinux BTF in
the center; it's only Kbuild/Makefile modifications). I also wonder if
it will allow saving much for modules, they are probably not having
that many global variables anyways and it's acceptable to have them in
module's BTF. We can also separately control VMLINUX_BTF_EXTRAS as
y/n/m and MODULE_BTF_EXTRAS as y/n (that is, none or built into the
module itself), for starters at least.

> Alan

      reply	other threads:[~2022-05-10  0:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-09 23:20 Question: missing vmlinux BTF variable declarations Stephen Brennan
2022-03-14  7:09 ` Shung-Hsi Yu
2022-03-15  5:53   ` Yonghong Song
2022-03-15 16:37     ` Stephen Brennan
2022-03-15 17:58       ` Arnaldo Carvalho de Melo
2022-03-16 16:06         ` Stephen Brennan
2022-03-25 17:07           ` Andrii Nakryiko
2022-04-27 18:24             ` Stephen Brennan
2022-04-29 17:10               ` Alexei Starovoitov
2022-05-03 14:39                 ` Arnaldo Carvalho de Melo
2022-05-03 17:29                   ` Stephen Brennan
2022-05-03 22:31                     ` Alan Maguire
2022-05-10  0:10                       ` Andrii Nakryiko [this message]

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='CAEf4BzZmJKqXaJMBxhKqFNXzjO=eN5gk2xQVnmQVdK2xd3HQ=g@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=alan.maguire@oracle.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=osandov@osandov.com \
    --cc=shung-hsi.yu@suse.com \
    --cc=stephen.s.brennan@oracle.com \
    --cc=stephen@brennan.io \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.