fprintf: Show statistics about holes due to forced alignments

$ pahole -C task_struct | tail

	/* --- cacheline 104 boundary (6656 bytes) --- */
	struct thread_struct       thread __attribute__((__aligned__(64)); /*  6656  4352 */

	/* size: 11008, cachelines: 172, members: 207 */
	/* sum members: 10902, holes: 16, sum holes: 98 */
	/* sum bitfield members: 10 bits, bit holes: 2, sum bit holes: 54 bits */
	/* paddings: 3, sum paddings: 14 */
	/* forced alignments: 6, forced holes: 1, sum forced holes: 40 */
  };
  $ pahole -C inet_timewait_death_row
  struct inet_timewait_death_row {
	atomic_t                   tw_count;             /*     0     4 */

	/* XXX 60 bytes hole, try to pack */

	/* --- cacheline 1 boundary (64 bytes) --- */
	struct inet_hashinfo *     hashinfo __attribute__((__aligned__(64)); /*    64     8 */
	int                        sysctl_max_tw_buckets; /*    72     4 */

	/* size: 128, cachelines: 2, members: 3 */
	/* sum members: 16, holes: 1, sum holes: 60 */
	/* padding: 52 */
	/* forced alignments: 1, forced holes: 1, sum forced holes: 60 */
  };
  $

Cc: Alexei Starovoitov <ast@fb.com>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Wielaard <mark@klomp.org>
Cc: Yonghong Song <yhs@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2019-04-03 13:33:37 -03:00
parent ec772f21f6
commit b95961db69
1 changed files with 19 additions and 4 deletions

View File

@ -1231,7 +1231,8 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu,
size_t last_size = 0, size;
uint8_t newline = 0;
uint16_t nr_paddings = 0;
uint16_t nr_forced_alignments = 0;
uint16_t nr_forced_alignments = 0, nr_forced_alignment_holes = 0;
uint32_t sum_forced_alignment_holes = 0;
uint32_t sum_bytes = 0, sum_bits = 0;
uint32_t sum_holes = 0;
uint32_t sum_paddings = 0;
@ -1342,8 +1343,15 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu,
}
pos = tag__class_member(tag_pos);
if (!cconf.suppress_aligned_attribute && pos->alignment != 0)
if (!cconf.suppress_aligned_attribute && pos->alignment != 0) {
uint32_t forced_alignment_hole = last ? last->hole : class->pre_hole;
if (forced_alignment_hole != 0) {
++nr_forced_alignment_holes;
sum_forced_alignment_holes += forced_alignment_hole;
}
++nr_forced_alignments;
}
/*
* These paranoid checks doesn't make much sense on
* DW_TAG_inheritance, have to understand why virtual public
@ -1554,10 +1562,17 @@ static size_t __class__fprintf(struct class *class, const struct cu *cu,
printed += fprintf(fp, "%.*s/* bit_padding: %u bits */\n",
cconf.indent, tabs,
class->bit_padding);
if (!cconf.suppress_aligned_attribute && nr_forced_alignments != 0)
printed += fprintf(fp, "%.*s/* forced alignments: %u */\n",
if (!cconf.suppress_aligned_attribute && nr_forced_alignments != 0) {
printed += fprintf(fp, "%.*s/* forced alignments: %u",
cconf.indent, tabs,
nr_forced_alignments);
if (nr_forced_alignment_holes != 0) {
printed += fprintf(fp, ", forced holes: %u, sum forced holes: %u",
nr_forced_alignment_holes,
sum_forced_alignment_holes);
}
printed += fprintf(fp, " */\n");
}
cacheline = (cconf.base_offset + type->size) % cacheline_size;
if (cacheline != 0)
printed += fprintf(fp, "%.*s/* last cacheline: %u bytes */\n",