How does memory mapping a file have significant performance increases over the standard I/O system calls?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Operating System Concepts says




Consider a sequential read of a file on disk using the standard
system calls open(), read(), and write()
. Each file access requires
a system call and disk access
.



Alternatively, we can use the virtual memory techniques discussed so
far to treat file I/O as routine memory accesses. This approach, known
as
memory mapping a file, allows a part of the virtual address space to be logically associated with the file. As we shall see, this can
lead to significant performance increases. Memory mapping a file is
accomplished by mapping a disk block to a page (or pages) in memory.
Initial access to the file proceeds through ordinary demand paging,
resulting in a page fault. However, a page-sized portion of the file is
read from the file system into a physical page (some systems may opt to
read in more than a page-sized chunk of memory at a time). Subsequent
reads and writes to the file are handled as routine memory accesses.
Manipulating files through memory rather than incurring the overhead of
using the read() and write() system calls simplifies and speeds up file
access and usage.




If I am correct, memory mapping file works as following. It takes a system call to create a memory mapping.
Then when it accesses the mapped memory, page faults happen. Page faults also have overhead.



How does memory mapping a file have significant performance increases over the standard I/O system calls?



Thanks.









share

























    up vote
    0
    down vote

    favorite












    Operating System Concepts says




    Consider a sequential read of a file on disk using the standard
    system calls open(), read(), and write()
    . Each file access requires
    a system call and disk access
    .



    Alternatively, we can use the virtual memory techniques discussed so
    far to treat file I/O as routine memory accesses. This approach, known
    as
    memory mapping a file, allows a part of the virtual address space to be logically associated with the file. As we shall see, this can
    lead to significant performance increases. Memory mapping a file is
    accomplished by mapping a disk block to a page (or pages) in memory.
    Initial access to the file proceeds through ordinary demand paging,
    resulting in a page fault. However, a page-sized portion of the file is
    read from the file system into a physical page (some systems may opt to
    read in more than a page-sized chunk of memory at a time). Subsequent
    reads and writes to the file are handled as routine memory accesses.
    Manipulating files through memory rather than incurring the overhead of
    using the read() and write() system calls simplifies and speeds up file
    access and usage.




    If I am correct, memory mapping file works as following. It takes a system call to create a memory mapping.
    Then when it accesses the mapped memory, page faults happen. Page faults also have overhead.



    How does memory mapping a file have significant performance increases over the standard I/O system calls?



    Thanks.









    share























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Operating System Concepts says




      Consider a sequential read of a file on disk using the standard
      system calls open(), read(), and write()
      . Each file access requires
      a system call and disk access
      .



      Alternatively, we can use the virtual memory techniques discussed so
      far to treat file I/O as routine memory accesses. This approach, known
      as
      memory mapping a file, allows a part of the virtual address space to be logically associated with the file. As we shall see, this can
      lead to significant performance increases. Memory mapping a file is
      accomplished by mapping a disk block to a page (or pages) in memory.
      Initial access to the file proceeds through ordinary demand paging,
      resulting in a page fault. However, a page-sized portion of the file is
      read from the file system into a physical page (some systems may opt to
      read in more than a page-sized chunk of memory at a time). Subsequent
      reads and writes to the file are handled as routine memory accesses.
      Manipulating files through memory rather than incurring the overhead of
      using the read() and write() system calls simplifies and speeds up file
      access and usage.




      If I am correct, memory mapping file works as following. It takes a system call to create a memory mapping.
      Then when it accesses the mapped memory, page faults happen. Page faults also have overhead.



      How does memory mapping a file have significant performance increases over the standard I/O system calls?



      Thanks.









      share













      Operating System Concepts says




      Consider a sequential read of a file on disk using the standard
      system calls open(), read(), and write()
      . Each file access requires
      a system call and disk access
      .



      Alternatively, we can use the virtual memory techniques discussed so
      far to treat file I/O as routine memory accesses. This approach, known
      as
      memory mapping a file, allows a part of the virtual address space to be logically associated with the file. As we shall see, this can
      lead to significant performance increases. Memory mapping a file is
      accomplished by mapping a disk block to a page (or pages) in memory.
      Initial access to the file proceeds through ordinary demand paging,
      resulting in a page fault. However, a page-sized portion of the file is
      read from the file system into a physical page (some systems may opt to
      read in more than a page-sized chunk of memory at a time). Subsequent
      reads and writes to the file are handled as routine memory accesses.
      Manipulating files through memory rather than incurring the overhead of
      using the read() and write() system calls simplifies and speeds up file
      access and usage.




      If I am correct, memory mapping file works as following. It takes a system call to create a memory mapping.
      Then when it accesses the mapped memory, page faults happen. Page faults also have overhead.



      How does memory mapping a file have significant performance increases over the standard I/O system calls?



      Thanks.







      linux io virtual-memory





      share












      share










      share



      share










      asked 9 mins ago









      Tim

      23.9k67232418




      23.9k67232418

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474926%2fhow-does-memory-mapping-a-file-have-significant-performance-increases-over-the-s%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474926%2fhow-does-memory-mapping-a-file-have-significant-performance-increases-over-the-s%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay