本文将浅谈ioremapvmallockmapmmap的区别。

首先,mmap是在用户态中使用的函数,而ioremapvmallockmap是在内核态中使用的函数。

1. mmap

Normally user space processes can’t access device memory directly for security purpose. So, user space processes use the mmap system call to ask kernel to map the device into virtual address space of the calling process. After the mapping the user space process can write directly into the device memory via the returned address.
The mmap system call is declared as follows:
mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset);

Where as, the mmap field in the driver’s file operation structure is declared as:
int (*mmap) (struct file *filp, struct vm_area_struct *vma);

2. ioremap

ioremap is used to map cpu physical memory address into virtual address space of the kernel.

Detail

3. vmalloc

1
2
3
4
5
6
7
8
9
10
/**
* vmalloc - allocate virtually contiguous memory
* @size: allocation size
*
* Allocate enough pages to cover @size from the page level
* allocator and map them into contiguous kernel virtual space.
*
* Return: pointer to the allocated memory or %NULL on error
*/
void *vmalloc(unsigned long size)

vmalloc and ioremap build new page tables; vmalloc allocates RAM memory, while ioremap doesn’t allocates RAM memory.

4. kmap

To map a given page structure into the kernel’s address space, use this function, declared
void *kmap(struct page *page).


参考资料:

  1. How are mmap, ioremap and kmap different
  2. ldd3