svn commit: r281451 - head/sys/vm

Dimitry Andric dim at FreeBSD.org
Fri Apr 24 11:46:25 UTC 2015


On 24 Apr 2015, at 13:01, Chris Torek <torek at elf.torek.net> wrote:
> 
> The problem seems likely to be related to odd compiler handling of
> alignment.  Consider this code bit, which extracts the essentials:
> 
> 	struct x {
> 		int x;
> 	} __attribute__((__aligned__(32)));
> 
> 	struct s1 {
> 		int a;
> 		struct x b[1];
> 	};
> 
> 	struct s2 {
> 		int a;
> 		struct x b[];
> 	};
> 
> 	extern void test2(int);
> 	void test(void) {
> 	    test2(sizeof(struct s1));
> 	    test2(sizeof(struct s2));
> 	}
> 
> Compiled, here are the two sizeof values (this particular compiler
> output is from clang but gcc and clang both agree on sizeof here):
> 
> 	movl	$64, %edi
> 	callq	test2
> 	movl	$32, %edi
> 	popq	%rbp
> 	jmp	test2                   # TAILCALL
> 
> With the flexible array, (sizeof(struct uma_cache)) is going to be
> 32 bytes smaller than without it.
> 
> (I have not looked closely enough to determine what the size should be.)

I'm not sure I would consider this odd.  For purposes of sizeof(), the
flexible array member declaration can be thought of as:

		struct x b[0];

so while both struct s1 and s2 have members that must be aligned at 32
bytes, the former has one extra, while the latter doesn't.  Ergo, 2x32
bytes and 1x32 bytes.

-Dimitry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freebsd.org/pipermail/svn-src-head/attachments/20150424/e9cd3f2a/attachment.sig>


More information about the svn-src-head mailing list