Re: doubt regarding mmap/mmap2 system call and implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Himanshu,

mmap/mmap2 always create a vm_area_struct which is inserted into the process's userspace region. Given that this is the case, how is mmap/mmap2 more efficient than the read/write system call? Shouldn't it be less efficient, because each access to mmapped region might be access this vm_area_struct mapping?

The vm_area struct wouldn't have to be accessed unless access to the mapped region results in a page fault.
 

I have another doubt as well : if mmap/mmap2 are more efficient than a write call, then why don't all drivers just implement a mmap file operation. Why do they implement a write file-operation which is supposedly less efficient. I have found only a few drivers implementing the mmap file operation. Is there any reason for this? 

Also, i found that LDD3 book also gives a very "secondary" treatment to this topic. Shouldn't mmap be used more extensively in device driver development? Is there any reason for this?

Ooh, if you meant kernel space device drivers, you can't use mmap in kernel space for kernel memory. task_struct->mm is NULL for kernel threads.
 
I _think_ mmap is fast and read/write is slow because read/write system calls involve copying stuff from userspace space into page cache, while with mmap, there is only once copy of the data at any give point of time. Also read/write checks whether the address passed to the kernel is valid  and updates atime/mtime of the inode etc..

I wish we could use mmap in kernel space but I think its hard to implement this, all kernel memory is directly and permanently mapped and not swappable. You can vmalloc in kernel but you cannot mmap..

Thanks,
-Joel


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux