> Add your stats hooks to do_mmap or mmap_region() ???<br><br>mmap is one time call to initialize virtual address space of current process with corresponding region on file's disk image. Once this setting is done, this the actual calls to read data from file is accomplish through memory area's (vma) page fault handlers which in turn call readpage address space operation of an inode:<br>
<br>inode->i_mapping->a_ops->readpage(file, page).<br><br>so, suitable position is to add hooks on readpage a_op. And of-course for doing that, you may have to capture various path thorugh which inode can come in memory, e.g. lookup and create directory inode operation (for regular files). For your worst nightmare, NFS implements its readdir with an additional feature with v3 protocol called READDIR PLUS, which not only gives you name of children of a directory, but also initializes their inodes in memory, so you may have to hook readdir as well and trap aops of all regular file child after nfs_readdir is finished.<br>
<br>As far as offset and length of I/O are concerned, page->index gives you its index in the page cache which in turn is equivalent to file offset (page->index << PAGE_SHIFT). readpage is invoked to bring in complete page in memory. It may so happen that page is a partial page (e.g. last page of file), in that case your I/O lenght will be inode->i_size & ~PAGE_MASK, otherwise it can be PAGE_SIZE. don't worry about file wholes, that is taken care by filesystem's original readpage method.<br>
<br>Having said above, it will still be better if you can state what you want to achieve in little layman language.<br><br>Rajat<br><br>On Fri, Jan 7, 2011 at 5:39 AM, Manish Katiyar <span dir="ltr"><<a href="mailto:mkatiyar@gmail.com">mkatiyar@gmail.com</a>></span> wrote:<br>
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">On Thu, Jan 6, 2011 at 3:49 PM, Sebastian Pipping <<a href="mailto:sebastian@pipping.org">sebastian@pipping.org</a>> wrote:<br>
> On 01/06/11 07:53, Rajat Sharma wrote:<br>
>> Hi Sebastian,<br>
>><br>
>> you guess for ELF header seems to be valid to me. When executables or<br>
>> binaries are loaded memory, it is done through mmap call to the file,<br>
>> and to understand what file is and what binary handler in kernel can<br>
>> handle its section, kernel needs to know its header first, which is<br>
>> within the first page of the header with fixed location for a magic<br>
>> number (identifier for binary handler e.g. ELF handler which further<br>
>> loads its other sections by reading section table). Note that there<br>
>> are multiple binary format handles within the kernel e.g. ELF, A.OUT<br>
>> which are tried sequentially to identify the file format.<br>
>><br>
>> From the file system perspective, mmap does not use vfs_read or<br>
>> vfs_write calls at all, thats why you don't see them. It directly<br>
>> works on address space operations of an inode (file) to populate data<br>
>> in page-cache. For a mmapped region, if you don't see a page in<br>
>> memory, kenel page faults and tries to read-in the page using readpage<br>
>> method of address_space_operations. Similarly when you modify a page,<br>
>> writepage method is called, but since executables are accessed<br>
>> read-only, you won't see writepage method getting called either.<br>
>><br>
>> Hope this makes it clearer.<br>
><br>
> Excellent, thank you! I find calls to readpages on file<br>
> /lib/<a href="http://libc-2.11.2.so" target="_blank">libc-2.11.2.so</a> now. That may be the missing reads.<br>
><br>
> Any ideas how get offset and length (like with vfs_read) for a certain<br>
> page passed to readpage(file, page) ?<br>
<br>
</div></div>Add your stats hooks to do_mmap or mmap_region() ???<br>
<font color="#888888"><br>
--<br>
Thanks -<br>
Manish<br>
==================================<br>
[$\*.^ -- I miss being one of them<br>
==================================<br>
</font></blockquote></div><br>