internel implemention of file operation
Rajat Sharma
fs.rajat at gmail.com
Fri Jan 11 02:09:26 EST 2013
Default read/write inerfaces are better suited for sequential read/write
within your program. Although you can seek to any location within the file,
you still have overhead to issue system calls to get data. However mmap
allows you to map a section of file into program address space. Now if your
access patter is rather random, modifying few bytes here and there, but at
random offset. You just get continous memory array, which is much easier
than issuing read and write at different file offsets.
A most common and mandatory use case of mmap is in mapping executable
binary program image, and libraries into process address spaces. Access
pattern for a program is not sequential, you can have multiple jump (if,
else, for loop), so it is better suited with mmap. It is read only and
private memory mapping, Any modifications you do will create a COW page
which if private to your process, so that is another advantage of mmap
which is completely transparent to user mode. If your filesystem does not
support, this basic mmap mode, you can not execute a binary file stored in
this filesystem, unless you copy it to some other filesystem which does.
Apart from this, read more about mmap from UTLK book.
-Rajat
On Fri, Jan 11, 2013 at 2:44 AM, horseriver <horserivers at gmail.com> wrote:
> hi:
>
> these two wayes of operating one file :
>
> 1.use open/write interface call .
>
> 2.mmap this file into memory , then access this memory area and do r/w .
>
> what is the essential difference between this teo wayes?
>
> thanks!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130111/5e5810b2/attachment.html
More information about the Kernelnewbies
mailing list