ring_buffer: pahole struct ring_buffer
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 9 Feb 2009 19:04:06 +0000 (17:04 -0200)
committerIngo Molnar <mingo@elte.hu>
Wed, 11 Feb 2009 12:21:40 +0000 (13:21 +0100)
While fixing some bugs in pahole (built-in.o files were not being
processed due to relocation problems) I found out about these packable
structures:

$ pahole --packable kernel/trace/ring_buffer.o  | grep ring
ring_buffer 72 64 8
ring_buffer_per_cpu 112 104 8

If we take a look at the current layout of struct ring_buffer we can see
that we have two 4 bytes holes.

$ pahole -C ring_buffer kernel/trace/ring_buffer.o
struct ring_buffer {
unsigned int               pages;           /*     0     4 */
unsigned int               flags;           /*     4     4 */
int                        cpus;            /*     8     4 */

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

cpumask_var_t              cpumask;         /*    16     8 */
atomic_t                   record_disabled; /*    24     4 */

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

struct mutex               mutex;           /*    32    32 */
/* --- cacheline 1 boundary (64 bytes) --- */
struct ring_buffer_per_cpu * * buffers;     /*    64     8 */

/* size: 72, cachelines: 2, members: 7 */
/* sum members: 64, holes: 2, sum holes: 8 */
/* last cacheline: 8 bytes */
};

So, if I ask pahole to reorganize it:

$ pahole -C ring_buffer --reorganize kernel/trace/ring_buffer.o

struct ring_buffer {
unsigned int               pages;           /*     0     4 */
unsigned int               flags;           /*     4     4 */
int                        cpus;            /*     8     4 */
atomic_t                   record_disabled; /*    12     4 */
cpumask_var_t              cpumask;         /*    16     8 */
struct mutex               mutex;           /*    24    32 */
struct ring_buffer_per_cpu * * buffers;     /*    56     8 */
/* --- cacheline 1 boundary (64 bytes) --- */

/* size: 64, cachelines: 1, members: 7 */
};   /* saved 8 bytes and 1 cacheline! */

We get it using just one 64 bytes cacheline.

To see what it did:

$ pahole -C ring_buffer --reorganize --show_reorg_steps \
kernel/trace/ring_buffer.o | grep \/
/* Moving 'record_disabled' from after 'cpumask' to after 'cpus' */

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
kernel/trace/ring_buffer.c

index 53ba3a6d16d026ff122b86c735781dd5c3ce23a4..27ef3bf13ed2192253c3a3b046c05bfc6909379f 100644 (file)
@@ -273,8 +273,8 @@ struct ring_buffer {
        unsigned                        pages;
        unsigned                        flags;
        int                             cpus;
-       cpumask_var_t                   cpumask;
        atomic_t                        record_disabled;
+       cpumask_var_t                   cpumask;
 
        struct mutex                    mutex;