kvm のソースを読んでたら kvm_kvzalloc() なる関数が出てきた
/* * Avoid using vmalloc for a small buffer. * Should not be used when the size is statically known. */ void *kvm_kvzalloc(unsigned long size) { if (size > PAGE_SIZE) return vzalloc(size); else return kzalloc(size, GFP_KERNEL); }
割り当てたいサイズによって vzalloc() と kzalloc() を使い分ける。 kzalloc() は下記のような感じ
/** * kzalloc - allocate memory. The memory is set to zero. * @size: how many bytes of memory are required. * @flags: the type of memory to allocate (see kmalloc). */ static inline void *kzalloc(size_t size, gfp_t flags) { return kmalloc(size, flags | __GFP_ZERO);
__GFP_ZERO を指定すると 割り当てた領域は 0
で初期化済みで返してくれる。
#define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) /* Return zeroed page on success */
疑問
ここんところの実装がどうなってるかを追ってみた
といっても memset() しているだけだった。ちょっと面白みがないので下記のような検証を加えた
続きを読む