ioremap vs vmalloc vs kmap vs mmap
本文将浅谈ioremap
、 vmalloc
、 kmap
和 mmap
的区别。
首先,mmap
是在用户态中使用的函数,而ioremap
、 vmalloc
和 kmap
是在内核态中使用的函数。
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.
3. vmalloc
1 | /** |
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, declaredvoid *kmap(struct page *page)
.
参考资料: