Why is mmap faster than Read/write?

Source: Internet
Author: User

Blog Park can not be reproduced, directly see the original

Http://www.cnblogs.com/huxiao-tee/p/4660352.html?utm_source=tuicool&utm_medium=referral

Summary:

The kernel also manages the data in the page cache before it can actually read and write user data to disk or to a storage device. These page's existence effectively manages the user data and reads and writes the efficiency. User data is not directly from the application layer, read or write disk and storage media, but is divided into a layer of application, each level will have a different function corresponding. At the end of the interaction, the operation of the disk is triggered at the most appropriate time. Write to disk and storage media via IO drive. The main emphasis here is on page cache management. The management of the page should be designed to cache, which is managed in page units. Before the IO operation, it is temporarily stored in the system space and is not written directly to the disk or storage media.

Mmap in the system call:

When a process is created or switched, the system information belonging to the current process is loaded. These system information contains the running space of the current process. When the user program calls Mmap. The function finds the appropriate VMA in the space of the current process to describe the area that it is going to map. The function of this area is to map the contents of the specific file that the file descriptor points to in the Mmap function.

The principle is: the execution of Mmap, only in the kernel to establish the file and virtual memory space corresponding relationship. When users access these virtual memory spaces, there are table entries in the page table that do not have these spaces. When the user program attempts to access these mapped spaces, a fault is generated. The kernel captures these exceptions and gradually loads the files into them. The so-called onboarding process, the specific operation is read and write in the management Pagecache. The VMA structure has a very set of file operations. The VMA operation set has its own collection of operations about the page cache. Thus, although there are two different system calls, the path triggered by the operation and the call is different. But finally, the management of page cache was implemented. Implements the operation of the file contents.

Why is mmap faster than Read/write?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.