In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
MMAP document accelerated reading and writing tips are what, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
In addition to read and write, the process can also use mmap for file mapping when reading and writing data, as shown in the following figure:
As you can see, after the disk file is loaded into memory, you need to perform another copy operation.
If you use mmap, the disk file is loaded directly into user space, that is, the dark yellow part of the image above, and the process can manipulate the file directly through the pointer.
It looks like mmap is missing a copy, which is theoretically faster than read. However, calling mmap does not actually load files into memory, so a large number of interrupts are triggered during reading and writing (especially large files), resulting in slow performance, even using madvise call acceleration parameters. Here is a small way to read the first byte on each page of the file:
In the above code, we use two 8m files with exactly the same data to see what happens after preloading and not preloading:
You can see that preloading calls are significantly faster than not executing them. Is it effective to use madvise acceleration? Take a look:
There is no effect, but the speed of preloading calls is significantly faster than that of none. There is a slight deviation in the time for the program to read the file twice because of the electrical characteristics of cpu and memory itself.
Robustness
When using mmap for shared mapping, multiple processes can manipulate the same file. A typical scenario is to use vim to edit the file, and then use cat to view the file, as shown below:
At this point, there will be a competitive scenario. Processes 1 and 2 can only see their own private virtual addresses, respectively. You need to implement the locking mechanism by the caller. For more information, please see the copy-on-write mechanism.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.