lkml.org 
[lkml]   [2023]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v4 02/24] powerpc/pseries: Fix alignment of PLPKS structures and buffers
Date
Andrew Donnellan <ajd@linux.ibm.com> writes:
> On Thu, 2023-01-26 at 17:31 +0000, David Laight wrote:
>> Changing the size to kzalloc() doesn't help.
>> The alignment depends on the allocator and is only required to have
>> a relatively small alignment (ARCH_MINALIGN?) regardless of the size.
>>
>> IIRC one of the allocators adds a small header to every item.
>> It won't return 16 byte aligned items at all.
>
> I'm relying on the behaviour described in Documentation/core-
> api/memory-allocation.rst:
>
> The address of a chunk allocated with kmalloc is aligned to at
> least ARCH_KMALLOC_MINALIGN bytes. For sizes which are a power of
> two, the alignment is also guaranteed to be at least the respective
> size.
>
> Is this wrong?

I believe it's correct.

For SLAB and SLUB it boils down to:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/slab_common.c?commit=830b3c68c1fb1e9176028d02ef86f3cf76aa2476#n640

That's where the kmalloc slabs are created (see create_kmalloc_cache())
just below.

If you create your own slab (with kmem_cache_create()) then the
alignment is up to you, so that's why there's no power-of-2 logic in
calculate_alignment().

And SLOB (which we don't use) does something similar:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/slob.c?commit=830b3c68c1fb1e9176028d02ef86f3cf76aa2476#n493

cheers

\
 
 \ /
  Last update: 2023-03-26 23:58    [W:0.114 / U:0.196 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site