It instructs the compiler to place the struct at address multiple of MAX. In your case, it's multiple of 1024 * 64. I don't know why do you need that, it's even more than just a widely used page size, which is often only 4096.
This seems to over-align for me. Not sure what's your need.
As far as I can tell, there are several reasons to use this attribute:
1) You need aligned move for vector operations, like (x86-64 specific):
- {v,}movdqa w.r.t. xmm register (need 16-byte aligned).
- vmovdqa w.r.t. ymm register (need 32-byte aligned).
- vmovdqa64 w.r.t. zmm register (need 64-byte aligned).
[ There are more, but at least these cover the generic case. ]
If the source or destination memory address is not multiple of the specified above, your program will get #GP exception, so for userspace will just be segmentation fault.
2) You need to create your own allocator and for some reason you need to guarantee that the user gets the minimum alignment for the specific case. Like implementing malloc(). For example:
https://lore.kernel.org/io-uring/20211011064927.444704-1-ammar.faizi@students.amikom.ac.id/T/
3) You want to align your struct to avoid false sharing in SMP system (performance wise). In the Linux kernel, we have a macro that yields something like that, like ____cacheline_aligned and ____cacheline_aligned_in_smp.
Link: https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/include/linux/cache.h#L40-L50
4) Add yourself... there are a lot of reasons...
Thank you very much that was very informative.
数学の恋人
Anton
Puspam
\Device\NUL
Khaerul
Dmitriy
SLC
Pavel
Egro
Captain
Dima
Ahmed
Eyvaz