linux2021
align_up
的程式碼,並舉例說明其用法main
得到下列結果
align_up
的程式碼,說明其用法在 <include/linux/mm.h> 和 <include/linux/kernel.h> 有定義出
PAGE_ALIGN
及 ALIGN
#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
其中 PAGE_SIZE
在 <arch/x86/include/asm/page_types.h> 中定義
可以了解到 PAGE_SIZE 預設在 x86下為 4KB
#define ALIGN(x, a) __ALIGN_KERNEL((x), (a))
由此可知內部的實作為 __ALIGN_KERNEL
#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
typeof
為 gcc 的 extension 將會回傳對應的 x 的 type 。
由此可以知道 mask = (typeof(x))(a) - 1
也可以對應到題目的 mask = alignment - 1;
ALIGN
的部分videobuf2
__vb2_buf_mem_alloc
__vb2_buf_mem_alloc() - allocate video memory for the given buffer
PAGE_ALIGN
在於決定記憶體配置的大小 size