Kmalloc Alignment

谁说胖子不能爱 提交于 2019-12-11 07:28:11

问题


Lets say I allocate with kmalloc an array of uint64_t (and lets assume the size of the array is 32kB). I have the following questions :

1) Is the array guaranteed to be page aligned ? 2) Is the array guaranteed to be cache / block aligned ? 3) Is there no guarantee at all ?

When I allocate the array , and i use virt_to_phys to get the physical address of the array i am gettign physical addresses like 00000040142d5c00 and virtual addresses like fffffe07df400000

Is there any chance that i will end up with alignment smaller than uint64_t , lets say 4 byte alignment or not ?

Thank you in advance


回答1:


The alignment defined by preprocessor constant ARCH_KMALLOC_MINALIGN,

it was calculeted like this:

#if defined(ARCH_DMA_MINALIGN) && ARCH_DMA_MINALIGN > 8
#define ARCH_KMALLOC_MINALIGN ARCH_DMA_MINALIGN
#define KMALLOC_MIN_SIZE ARCH_DMA_MINALIGN
#define KMALLOC_SHIFT_LOW ilog2(ARCH_DMA_MINALIGN)
#else
#define ARCH_KMALLOC_MINALIGN __alignof__(unsigned long long)
#endif

So in theory __alignof__(unsigned long long) may return some smaller then 8 on some exotic case, but in practice __alignof__(unsigned long long) >= 8, and so ARCH_KMALLOC_MINALIGN would be >= 8.



来源:https://stackoverflow.com/questions/44255742/kmalloc-alignment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!