Re: [PATCH] task_struct: Only use anon struct under randstruct plugin
From: Linus Torvalds
Date: Tue Mar 27 2018 - 20:22:41 EST
On Tue, Mar 27, 2018 at 1:03 PM, Andrew Morton
<akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> Why? What caused this padding? It happens in all configs?
I assume what happens is that the anonymous struct ends up containing
fields that are cacheline-aligned, and then the whole anonymous struct
is cacheline-aligned.
Which is all kinds of stupid, since the anonymous struct itself does
not exist outside of the outer struct. So it would be entirely
sufficient to just make the outer struct cacheline aligned (like it
used to be), but not align the inner anonymous one - just the fields
in it.
But there may be "reasons" why the inner anonymous one needs to be
aligned. Maybe it's some standards requirement, or maybe it's just an
internal gcc implementation detail.
Regardless, it's a bit sad. It also means that when randomization is
on, that unnecessary padding will be there.
I wonder if there is some acceptable trick to avoid it. Maybe the
anonymous struct can be marked as not needing alignment, even if the
fields inside of it would still need to be aligned wrt the outer
struct.
>> Instead,
>> move the anonymous struct to being only used when struct layout
>> randomization is enabled.
>
> So the mysterious 40 byte bloat is still present in this case?
Almost certainly. And the struct randomization will possibly add much
*more* padding elsewhere, since at least some of our structures are
laid out to try to avoid padding, and then the randomization might be
breaking that.
Linus