Is the virtual memory contiguous after "mmap" call

Hi Folks,

I’m using “mmap()” with MAP_PHYS|MAP_ANON to alloc a physical contiguous memory, the return value is the corresponding virtual address. Is this virtual address also contiguous?

Another question is, can I use “mmap()” to implement “kmalloc()” in linux? Is there any better way to do it?

Thanks!
Yicheng

Yes, the virtual address is contiguous.

As for replacing kmalloc(), note that mmap() allocates at a 4k granularity, plus it doesn’t implement a cache of memory, so it if you are doing frequent kmalloc/kfree operations you may find it suffers from a performance issue.

so what’s the best way to do “kmalloc()” on QNX?

It depends on what you want to do with that memory. If you need it contiguous mmap is the only way, if you don’t care about contiguous and don’t need to share it with another process then malloc is fine.