From this post I realized that:
the smallest allocation that kmalloc can handle is as big as 32 or 64 bytes
and
The actual memory you get back is dependent on the system's architecture
But also memory page size is mentioned there and on other sites. I can't figure out how the page size is related to smallest kmalloc() allocation? The page size is usually 4096 bytes, but the smallest allocation is 32 or 64 bytes (depending on arch).
So what is the relation between the smallest kmalloc() allocation and page size? And why is the smallest allocation is 32 or 64 bytes but not 16 (e.g.)?
None. They are unrelated.
As you can see from the source code:
None of the macros that end up defining
KMALLOC_MIN_SIZEfor different allocators depends on the page size, so there's no relation between page size andkmalloc()minimum allocation size.On some architectures though, the minimum size can be different if
kmalloc()memory is also used for direct memory access. That's why you see the various#ifndefabove. It's still not related to page size though.The value of
ARCH_DMA_MINALIGNis architecture-specific and is usually related to the processor L1 cache size, as you can see for example for ARM: