A solution for a Solaris kernel problem
Author: BadcoffeeEmail: blog.oliver@gmail.comBlog: http://blog.9cbs.net/yayong2004年 November
The question of others can prompt yourself to learn a lot.
Here is a record that I am answering the chinaunix netizen about Solaris kernel programming, absolutely worth collecting, maybe I will write some things according to this one day :)
Question: Under Solaris, the MAP file is a virtual memory address, and then the virtual memory address is written, the write operation has been written directly to the physical disk directly from the VNODE VOP_WRITE operation of the kernel. Excuse me: How do this IO address on disk? I have been painful for a few weeks, which master help! ! !
A: Do you use MMAP (2)? What is the specific parameters? If you use Map_Shared, and use prot_write, modify the memory file will definitely be modified together. The following excerpt from the man page:.. The MAP_SHARED and MAP_PRIVATE options describe the disposi- tion of write references to the underlying object If MAP_SHARED is specified, write references will change the memory object If MAP_PRIVATE is specified, the initial write reference will create a private Copy of the memory Object Page and redirect the mapping to the copy.
Asked: If the upstairs said, modifying the memory file will definitely be modified, but I want to know how the kernel is written to disk. The WRITE operation of the ordinary file, the kernel is written by vnode vop_write, while the MAP operation does not do so, but written to disk by other routes. What is the way, I studied the kernel of Solaris, using a lot of methods, still do not understand. Have you familiar with Solaris kernel code? I am not grateful.
Rethink again: MMAP is shadowed with a UFS system to memory is a VOP_map using vNode. After the MAP is successful, read and write is directly accessing memory. The first read will generate Page Fault, resulting in final call_getpage, ufs_getpage write The VOP_PUTPAGE, UFS_PUTPAGE, the final page is logged to Dirty, written back by FFLUSH, so use MMAP does not use Vop_Write Vop_write and Vop_read to call, ie, file IO