0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-27 03:10:03 +00:00

lib: Unify alignment of allocators

Different internal allocators (memory blocks, linpools, and slabs) used
different way to compute alignment. Unify it to use alignment based on
standard max_align_t type.

On x86_64, this does not change alignment of memory blocks and linpools
(both old and new is 16), but it increases alignment of slabs from 8 to
16.

Minor changes by commiter.
This commit is contained in:
Ondrej Zajicek 2025-01-09 16:44:51 +01:00 committed by Maria Matejka
parent 85aa283071
commit abecb5bb40
4 changed files with 6 additions and 14 deletions

View File

@ -10,17 +10,16 @@
#define _BIRD_BIRDLIB_H_
#include "lib/alloca.h"
#include <stddef.h>
#include <stdarg.h>
#include <stdalign.h>
/* Ugly structure offset handling macros */
struct align_probe { char x; long int y; };
#define OFFSETOF(s, i) ((size_t) &((s *)0)->i)
#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
#define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1))
#define CPU_STRUCT_ALIGN (sizeof(struct align_probe))
#define CPU_STRUCT_ALIGN (alignof(max_align_t))
/* Utility macros */

View File

@ -27,7 +27,7 @@
struct lp_chunk {
struct lp_chunk *next;
uintptr_t data_align[0];
max_align_t data_align[0];
byte data[0];
};

View File

@ -316,7 +316,7 @@ resource_init(void)
struct mblock {
resource r;
unsigned size;
uintptr_t data_align[0];
max_align_t data_align[0];
byte data[0];
};

View File

@ -68,7 +68,7 @@ static struct resclass sl_class = {
struct sl_obj {
node n;
uintptr_t data_align[0];
max_align_t data_align[0];
byte data[0];
};
@ -168,11 +168,6 @@ struct sl_head {
u32 used_bits[0];
};
struct sl_alignment { /* Magic structure for testing of alignment */
byte data;
int x[0];
};
#define TLIST_PREFIX sl_head
#define TLIST_TYPE struct sl_head
#define TLIST_ITEM n
@ -219,9 +214,7 @@ slab *
sl_new(pool *p, uint size)
{
slab *s = ralloc(p, &sl_class);
uint align = sizeof(struct sl_alignment);
if (align < sizeof(void *))
align = sizeof(void *);
uint align = CPU_STRUCT_ALIGN;
s->data_size = size;
size = (size + align - 1) / align * align;
s->obj_size = size;