简体   繁体   English

使用mmap写入文件

[英]Write file using mmap

I am creating a file with open using O_CREAT and then using ftruncate I set the size of the file. 我正在使用O_CREAT打开创建文件,然后使用ftruncate设置文件的大小。 Now I mmap the file with MAP_SHARED and start writing the file. 现在,我使用MAP_SHARED映射文件,然后开始写入文件。 I wanted to understand how is the file written back to disk. 我想了解如何将文件写回到磁盘。

Very specifically my question is: Is this going to be zero copy, that is the page in buffer cache will be mapped directly in the process address space, in which case the page daemon will flush the page back to disk when it is scheduled. 特别是我的问题是:这将是零副本,即缓冲区高速缓存中的页面将直接映射到进程地址空间中吗,在这种情况下,页面守护程序将在计划页面时将页面刷新回磁盘。 If not then there will be a page in the page cache and another page in the buffer cache. 如果没有,那么页面缓存中将有一个页面,而缓冲区缓存中将有另一个页面。 If this is the scenario at what granularity will the data be copied from the page in page cache to page in buffer cache? 如果是这种情况,那么将数据从页面缓存中的页面复制到缓冲区缓存中的页面的粒度是多少?

If there is some more insight you wish to give, it will be more than welcome :-) 如果您想提供更多的见解,将不胜感激:-)

Since Linux has a unified buffer cache, yes this is zero copy. 由于Linux具有统一的缓冲区高速缓存,是的,这是零副本。 Most modern OSes have a unified buffer cache now. 现在,大多数现代操作系统都具有统一的缓冲区缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM