Kmalloc对齐 [英] Kmalloc Alignment
问题描述
让我们说我用kmalloc分配了一个uint64_t数组(并假设该数组的大小为32kB).我有以下问题:
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)数组是否保证是页面对齐的? 2)数组是否保证是缓存/块对齐的? 3)根本没有保证吗?
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 ?
当我分配数组时,我使用virt_to_phys来获取数组的物理地址,我是像00000040142d5c00这样的gettign物理地址和像是fffffe07df400000这样的虚拟地址
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
我是否有可能以小于uint64_t的对齐方式结束对齐,是否可以说4字节对齐?
Is there any chance that i will end up with alignment smaller than uint64_t , lets say 4 byte alignment or not ?
提前谢谢
推荐答案
预处理器常量ARCH_KMALLOC_MINALIGN
,
它是这样计算的:
#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
因此从理论上讲__alignof__(unsigned long long)
可能会返回小于8的值
在一些异国情调的情况下,
但实际上__alignof__(unsigned long long)
> = 8,因此ARCH_KMALLOC_MINALIGN将是> = 8.
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.
这篇关于Kmalloc对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!