Thread (17 messages) 17 messages, 4 authors, 2020-01-21

Re: [PATCH net-next v4 05/10] pie: rearrange structure members and their initializations

From: Toke Høiland-Jørgensen <hidden>
Date: 2020-01-21 16:03:00

Gautam Ramakrishnan [off-list ref] writes:
On Tue, Jan 21, 2020 at 8:05 PM David Miller [off-list ref] wrote:
quoted
From: gautamramk@gmail.com
Date: Tue, 21 Jan 2020 19:42:44 +0530
quoted
From: "Mohit P. Tahiliani" <redacted>

Rearrange the members of the structures such that they appear in
order of their types. Also, change the order of their
initializations to match the order in which they appear in the
structures. This improves the code's readability and consistency.

Signed-off-by: Mohit P. Tahiliani <redacted>
Signed-off-by: Leslie Monis <redacted>
Signed-off-by: Gautam Ramakrishnan <redacted>
What matters for structure member ordering is dense packing and
grouping commonly-used-together elements for performance.
We shall reorder the variables as per their appearance in the
structure and re-submit. Could you elaborate a bit on dense packing?
The compiler will align struct member offsets according to their size,
adding padding as necessary to achieve this.
So this struct:

struct s1 {
       u32 mem32_1;
       u64 mem64_1;
       u32 mem32_2;
       u64 mem64_2;
};

will have 4 bytes of padding after both mem32_1 and mem32_2, whereas
this struct:

struct s2 {
       u64 mem64_1;
       u32 mem32_1;
       u32 mem32_2;
       u64 mem64_2;
};

won't. So sizeof(struct s1) == 32, and sizeof(struct s2) == 24, and we
say that s2 is densely packed, whereas s1 has holes in it.

The pahole tool is useful to see the layout of compiled structures
(pahole -C). It will also point out any holes.

-Toke
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help