kmem_cache_* creates contiguous memory?

2019-06-14 08:13发布

Am I right assuming that a memory slab created and allocated with kmem_cache_create and kmem_cache_alloc is contiguous?

2条回答
贪生不怕死
2楼-- · 2019-06-14 08:23
  • A kmem_cache consists of 1 or more slabs.
  • A slab consists of 1 or more contiguous pages.

So when you call kmem_cache_alloc, it returns you a piece of memory in a slab which consists of 1 or more contiguous pages.

But if you call kmem_cache_alloc twice, the 2 pieces of memory you get may not contiguous.

And kmem_cache_create only creates and initializes the data structure for a kmem_cache and do not allocate the memories.

查看更多
时光不老,我们不散
3楼-- · 2019-06-14 08:28

AFAIK, kmalloc() and kmem_cache_*() APIs are returning contiguous memory - which is handled by slab allocator....

vmalloc() can be used to ask big chunk of memory and it will return "virtually contiguous" memory (means contiguous virtual address region).

查看更多
登录 后发表回答