BPF Archive on lore.kernel.org
 help / color / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: "Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Andrii Nakryiko" <andrii.nakryiko@gmail.com>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"Andrii Nakryiko" <andriin@fb.com>,
	"Quentin Monnet" <quentin.monnet@netronome.com>
Subject: [RFC] btf: Some structs are doubled because of struct ring_buffer
Date: Fri, 13 Dec 2019 16:35:53 +0100
Message-ID: <20191213153553.GE20583@krava> (raw)

hi,
the current BTF vmlinux file have some of the structs doubled:

  $ bpftool btf dump file /sys/kernel/btf/vmlinux | grep task_struct
  [150] STRUCT 'task_struct' size=11008 vlen=205
  [12262] STRUCT 'task_struct' size=11008 vlen=205

  $ bpftool btf dump file /sys/kernel/btf/vmlinux | grep "STRUCT 'perf_event'"
  [1666] STRUCT 'perf_event' size=1160 vlen=70
  [12301] STRUCT 'perf_event' size=1160 vlen=70

The reason seems to be that we have two distinct 'struct ring_buffer'
objects used in kernel: one in perf subsystem and one in kernel trace
subsystem.

When we compile kernel/trace/ring_buffer.c we have 'struct task_struct',
which references 'struct ring_buffer', which is at that compile time
defined in kernel/trace/ring_buffer.c.

While when we compile kernel/events/core.c we have 'struct task_struct',
which references ring buffer, which is at that compile time defined
in kernel/events/internal.h.

So we end up with 2 different 'struct task_struct' objects, and few
other objects which are on the way to the 'struct ring_buffer' field,
like:

	[1666] STRUCT 'perf_event' size=1160 vlen=70
		...
		'rb' type_id=2289 bits_offset=5632
		...

		[2289] PTR '(anon)' type_id=10872

			-> trace ring buffer

			[10872] STRUCT 'ring_buffer' size=184 vlen=12
				'flags' type_id=10 bits_offset=0
				'cpus' type_id=22 bits_offset=32
				'record_disabled' type_id=81 bits_offset=64
				...

	[12301] STRUCT 'perf_event' size=1160 vlen=70
		...
		'rb' type_id=13148 bits_offset=5632
		...

		[13148] PTR '(anon)' type_id=13147

			-> perf ring buffer

			[13147] STRUCT 'ring_buffer' size=240 vlen=33
				'refcount' type_id=795 bits_offset=0
				'callback_head' type_id=90 bits_offset=64
				'nr_pages' type_id=22 bits_offset=192
				'overwrite' type_id=22 bits_offset=224
				'paused' type_id=22 bits_offset=256
				...

I don't think dedup algorithm can handle this and I'm not sure if there's
some way in pahole to detect/prevent this.

I only found that if I rename the ring_buffer objects to have distinct
names, it will help:

  $ bpftool btf dump file /sys/kernel/btf/vmlinux | grep task_struct
  [150] STRUCT 'task_struct' size=11008 vlen=205

  $ bpftool btf dump file /sys/kernel/btf/vmlinux | grep "STRUCT 'perf_event'"
  [1665] STRUCT 'perf_event' size=1160 vlen=70

also the BTF data get smaller ;-) before:

  $ ll /sys/kernel/btf/vmlinux
  -r--r--r--. 1 root root 2067432 Dec 13 22:56 /sys/kernel/btf/vmlinux

after:
  $ ll /sys/kernel/btf/vmlinux
  -r--r--r--. 1 root root 1984345 Dec 13 23:02 /sys/kernel/btf/vmlinux


Peter, Steven,
if above is correct and there's no other better solution, would it be possible
to straighten up the namespace and user some distinct names for perf and ftrace
ring buffers?

thoughts?
jirka


             reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13 15:35 Jiri Olsa [this message]
2019-12-13 16:25 ` Steven Rostedt
2019-12-13 16:51   ` Alexei Starovoitov
2019-12-13 17:11     ` Steven Rostedt
2019-12-13 17:30       ` Alexei Starovoitov
2019-12-13 18:28         ` Jiri Olsa
2019-12-13 18:02       ` Peter Zijlstra
2019-12-13 18:29         ` Steven Rostedt
2019-12-13 18:36           ` Jiri Olsa
2019-12-13 18:43             ` Steven Rostedt
2019-12-13 18:46           ` Peter Zijlstra
2019-12-13 19:03             ` Steven Rostedt
2019-12-13 19:05               ` Steven Rostedt
2019-12-14 11:35                 ` Jiri Olsa
2019-12-18 16:14                   ` Jiri Olsa
2019-12-18 16:22                     ` Steven Rostedt

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=20191213153553.GE20583@krava \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andriin@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=quentin.monnet@netronome.com \
    --cc=rostedt@goodmis.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

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git