What I understand from the discussion is that, since OS X has fully coherent VM and buffer cache,memory (iovec) passed to the
file system would get allocated from the page cache managed by VM rather than from separate memory pool (buffer cache).
Thus, mmap() and read()/ write() will both pass through UBC and the changes made by mmap by an application and an immediate
call to read(), will give updated version which is still in the cache. (Note: I am just talking about single threaded application.)
| -------------------| |--------------------|
| mmap | | read()/write() |
|--------------------| |--------------------|
| |
| |
|------------> |-------------| <-------- |
| UBC |
|-------------|
If that is the case, I fail to understand why is smbfs explicitly flushing the pages that were changed by mmap.
smbfs_read()
{
.................
/*
* Here we push any mmap-dirtied pages.
* The vnode lock is help, so we shouldn;t need to lock down
* all pages across the whole vop.
*/
error = smb_flushrange(vp, uio);
.................
.................
ubc_create_upl( ......);
.................
/* Do wire transaction */
smb_doread( ..........);
.................
/* dump the pages */
upc_upl_abort (..........);
}
Also, if the uio buffer (iovec) if it was allocated from the page cache, the what is the purpose of ubc_create_upl ? and after reading the contents why does it just dumps the pages ? (so that it does not cache the contents that could potentially become stale ?)
/Shail
On Sat, Jul 12, 2008 at 11:48 AM, Michael Smith <
email@hidden> wrote:
On Jul 11, 2008, at 3:56 PM, shailesh jain wrote:
1) If the user mmap's a file and makes some changes to it and then calls
read() system call (without msync'ing), is it the responsibility of a filesystem
to flush the changes that could have been made by mmap system call before
actually reading the file ?
No. The Darwin VM and buffer cache are fully coherent. The read(2) call may race with another thread that is currently updating the mapped region, however.
2) Also, while referring to source for smbfs, I came across a comment that said " we shall maintain synchronization between mmap and read/write by using UPL". Isn't just flushing mmaped pages enough ?
It's not clear what you mean by "flushing mmaped pages".
The smbfs code uses the UPL as its co-ordination with the VM; by passing file I/O through the buffer writes update the VM.
= Mike