[RFC] Alignment- / padding-requirements

Swen Schillig swen at vnet.ibm.com
Mon Mar 5 08:42:15 UTC 2018

For the last few days I've been looking at 
the memory handing within CTDB and I stumbled over code snippets like

        size = (length+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);

I might be wrong, but what is done here is padding and not alignment
and I might be wrong again, but padding memory to a multiple of the
wanted alignment does not guarantee the alignment.
So, I'm a bit puzzled what is really wanted here.

>From the comments around the define 

/* we must align packets to ensure ctdb works on all architectures (eg.
sparc) */

.. I take it that really alignment is required to make sure 64bit
access is 
guaranteed on architectures which need it (here SPARC !?)

But the structure(s) which are wanted to be aligned 
        struct ctdb_req_call_old
        struct ctdb_req_header 
do not contain any 64bit values.

So here comes my question, do we really need to do those ugly padding
tricks and
as a second question, if we really do need/want 64bit alignment why not
do it like

struct abc {
} __attribute__((aligned (8)));

I know this is gcc style but isn't this standard nowadays ?

Thanks for your support in advance !

Cheers Swen

More information about the samba-technical mailing list