Conversation
struct rb_node in the kernel has this pointless alignment attribute: __attribute__((aligned(sizeof(long)))).

It always makes me laugh because it was added in 2006 (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e977145aeaad23d443686f2a2d5b32800d1607c5) for an obscure architecture that the kernel dropped support for in 2018 (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c690eddc2f3b44b24520f4a77cc3a4c9bde7d571).
2
1
3

Vlastimil Babka πŸ‡¨πŸ‡ΏπŸ‡ͺπŸ‡ΊπŸ‡ΊπŸ‡¦

@osandov hm afaik m68k has only 2 byte alignment, and for address space pointers from struct page we use 2 lowest bits for flags? But whether it means we need to do this with rb_node... dunno.

1
0
0
@vbabka wow, I didn't know that about m68k. From what I can tell, the rb_node is aligned so that they can tag the parent pointer with the node color, which is just one bit. If that's true, then additional alignment shouldn't be necessary even on m68k, but who knows what else might be relying on the explicit alignment.
1
0
2

@osandov @vbabka We're trying to fix the alignment of int on m68k. See https://wiki.debian.org/M68k/Alignment (I don't think we have a good page for this in Gentoo yet).

The gist is that it's just.. not worth it, especially when it's "keep the platform alive at all" or "die 'pure'".

We've had a bunch of extended discussions on MLs and it turns out m68k wasn't even always 2-byte aligned anyway everywhere!

0
0
0

@ljs @thesamesam @osandov @vbabka Or use a self-documenting macro, something like this?

__tagged_pointer(nr_bits) \
__attribute__((aligned(((1 << nr_bits) + 7) / 8)))

https://godbolt.org/z/8fn3fMv5z

1
0
0

@vegard @ljs @thesamesam @osandov @vbabka if the pointer to a struct needs N low bits zero, the struct itself must be aligned to 1<<N byte boundary, so just

__attribute__((aligned(1<<nr_bits)))

1
0
0

@amonakov @ljs @thesamesam @osandov @vbabka Oh yeah, I think you're right. It's too early in the morning for this kind of stuff apparently...

0
0
0