How copy_to_user and MMAP work

Source: Internet
Author: User

Copy_to_user needs to check the validity of the pointer during each copy, that is, the pointer to the address of the user space is indeed the address of the process itself, instead of pointing to the location that does not belong to it, in addition, data is copied once each time, and memory is frequently accessed. Because the virtual address is continuous, the physical address may not necessarily be consecutive, resulting in frequent cache failures of the CPU, thus reducing the speed.
MMAP only creates a page table for the process when it is used for the first time, that is, maps a physical address to a virtual address, in the future, the legality of its address will not be checked (the legality is determined by the CPU page protection exception). In addition, the MMAP address can be directly operated in the kernel without frequent copying, that is to say, you can directly operate on the address using a pointer in the kernel, instead of opening a buffer in the kernel, and then copy the data in the buffer, MMAP maps a consecutive physical address to a virtual address. Of course, you can also map consecutive physical addresses in each segment to a continuous virtual address, in any case, the physical address is continuous in each segment, so that the CPU cache will not become invalid frequently, thus greatly saving time.

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.