mem_slab: enforce minimum alignment on statically allocated slabs
There is no point allowing smaller alignments. And on 64-bit systems the minimum becomes 8 rather than 4, so let's adjust things automatically. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
bc30f4f019
commit
46cd5a0330
1 changed files with 5 additions and 4 deletions
|
@ -3912,11 +3912,11 @@ struct k_mem_slab {
|
||||||
* @req K-MSLAB-001
|
* @req K-MSLAB-001
|
||||||
*/
|
*/
|
||||||
#define K_MEM_SLAB_DEFINE(name, slab_block_size, slab_num_blocks, slab_align) \
|
#define K_MEM_SLAB_DEFINE(name, slab_block_size, slab_num_blocks, slab_align) \
|
||||||
char __noinit __aligned(slab_align) \
|
char __noinit __aligned(WB_UP(slab_align)) \
|
||||||
_k_mem_slab_buf_##name[(slab_num_blocks) * (slab_block_size)]; \
|
_k_mem_slab_buf_##name[(slab_num_blocks) * WB_UP(slab_block_size)]; \
|
||||||
Z_STRUCT_SECTION_ITERABLE(k_mem_slab, name) = \
|
Z_STRUCT_SECTION_ITERABLE(k_mem_slab, name) = \
|
||||||
_K_MEM_SLAB_INITIALIZER(name, _k_mem_slab_buf_##name, \
|
_K_MEM_SLAB_INITIALIZER(name, _k_mem_slab_buf_##name, \
|
||||||
slab_block_size, slab_num_blocks)
|
WB_UP(slab_block_size), slab_num_blocks)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize a memory slab.
|
* @brief Initialize a memory slab.
|
||||||
|
@ -3925,7 +3925,8 @@ struct k_mem_slab {
|
||||||
*
|
*
|
||||||
* The memory slab's buffer contains @a slab_num_blocks memory blocks
|
* The memory slab's buffer contains @a slab_num_blocks memory blocks
|
||||||
* that are @a slab_block_size bytes long. The buffer must be aligned to an
|
* that are @a slab_block_size bytes long. The buffer must be aligned to an
|
||||||
* N-byte boundary, where N is a power of 2 larger than 2 (i.e. 4, 8, 16, ...).
|
* N-byte boundary matching a word boundary, where N is a power of 2
|
||||||
|
* (i.e. 4 on 32-bit systems, 8, 16, ...).
|
||||||
* To ensure that each memory block is similarly aligned to this boundary,
|
* To ensure that each memory block is similarly aligned to this boundary,
|
||||||
* @a slab_block_size must also be a multiple of N.
|
* @a slab_block_size must also be a multiple of N.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue