Loaded from: http://www.cnblogs.com/xuqiang/archive/2010/03/29/1953689.html
The "ing" concept is often mentioned in the above explanation. What is ing?
A linear zone can be associated with a file on the disk or a part of a file, this means that the kernel converts the access of a byte in the access page of the linear area to access the corresponding page in the file. This technology is called "memory ing ".
Use strace hello to get:
...
Open ("/usr/lib/locale/en_AU.UTF-8/lc_time", o_rdonly) =-1 enoent (no such file or directory)
Open ("/usr/lib/locale/en_au.utf8/lc_time", o_rdonly) = 3
Fstat64 (3, {st_mode = s_ifreg | 0644, st_size = 2454,...}) = 0
Mmap2 (null, 2454, prot_read, map_private, 3, 0) = 0xb80bf000
... When the hello program is loaded, Linux kernel uses MMAP to map files. Before explaining the principles of file ing, Let's first look at the data structure required for the ing: The following picture is taken from a deep understanding of Linux memory management, see http://blog.chinaunix.net/u3/99507/showart_2121121.html
The Linux kernel is easily confused by the structure of struct address_space. Does it represent an address space? Actually it is not. It is used to manage the page (struct inode) mapped to the memory (struct page). Correspondingly, address_space_operations is used to operate the page mapped to the memory, for example, write the changes in the memory back to the file, read the data from the file to the page buffer, and so on.
That is to say, the address_space structure corresponds to the file: after a specific file is opened, the kernel will create a struct inode structure for it in the memory, where the I _mapping domain points to an address_space structure. In this way, a file corresponds to an address_space structure, and an address_space and an offset can determine a page in a page cache or swap cache. Therefore, to address a specific data, it is easy to locate the corresponding page based on the given file and data offset in the file.
Task_struct ---> vm_area_struct ---> file ---> address_space ---> pages (the Memory Page actually pointed to by this file) when a process needs to create a memory ing, the system calls MMAP, the MMAP system call returns the linear unit at the first unit position. The main operation of the MMAP function is to initialize the vm_file field of the task_struct structure of the process, specifically: Call the file structure of the file to initialize the vm_file field and call the generic_file_mmap function. The generic_file_mmap function executes the following steps: Use the generic_file_vm_ops table address to initialize the vm_ops field of the vm_area_struct structure. In fact, in this table, except the nopage and populate methods, all other methods are empty. The nopage method is implemented by the filemap_nopage function, and populate is implemented by filemap_populate. In fact, the real "ing" work has been completed. At this time, the hello file is not actually loaded into the memory. when trying to access a page that is not in the memory, the page is interrupted, then, call the nopage method in the vm_ops field to read the actual file to the memory. To sum up the above process, I roughly divided the "ing" into two terminologies, first, it only marks a "corresponding" file on the disk (in this scenario, it is a hello executable program) on a virtual memory address of the process ), then the kernel starts to execute other things. When this process tries to start addressing the marked page, a page exception is generated, and then the actual memory (RAM) allocation is triggered, load the ing file to the memory. Note that to determine whether a page box belongs to a process, you need to check whether the corresponding page table is set. In the preceding page missing processing, call the do_no_page function in the vm_ops-> nopage () function. In the do_no_page function, set the page table items. Because csdn does not support Image Upload, full version: http://cid-f41b44b9285d0b86.spaces.live.com/blog/cns! F41b44b9285d0b86! 307. Entry