Subject: Re: *Very* strange interaction of /bin/cp and NFS reads
To: None <mike.long@analog.com>
From: John Dyson <dyson@freefall.freebsd.org>
List: netbsd-help
Date: 09/25/1995 12:22:28
> From: Mike Long 
> 
> >From: John Dyson <dyson@freefall.freebsd.org>
> >Date: Thu, 21 Sep 1995 16:56:18 -0700 (PDT)
> 
> >If your analysis of the problem is correct (and I have no reason to
> >suspect that you are wrong), it would probably be wise to "fix" cp
> >to do read/writes.  That is the way the FreeBSD did it before the
> >merged VM/Buffer cache code was done.  It looks like cp might be depending
> >on semantics that just don't exist in NetBSD currently.
> 
> I looked at the sources for -current's cp over the weekend, and found
> out that this had already been done.  Mea culpa.
> 
I make mistakes like that all of the time... :-).
>
> >Note that if you mmap to read when you don't have a merged cache, it can
> >double the amount of memory that the buffering takes for a given file
> >(up until the system starts paging.)  (You have a copy of the file in
> >the VM cache AND in the buffer cache.)
> 
> The VM copy exists only until cp terminates; then those pages should
> be reclaimed with the rest of the process' pages.  Right?
> 
(This is from what I remember of the original VM system)

Pages are faulted in by the VM system reqesting I/O from the block I/O
subsystem.  A copy operation is done to more the data from the buffer cache to
the VM object.  At this point there are two copies of the data in memory.
When the objects reference count drops to zero, it is placed on the
cache queue and it's pages are deactivated.  In order for the pages
to be made available for other processes, the pageout daemon needs to
wake up and dispose of the pages appropriately.  This could include
writing them out if they are dirty, but in the case of an input they
are protected off (removed from any processes page tables) and freed.
Until those pages are freed they take up memory along with the buffer
cache space used in reading the data.  (Of course the buffer cache space
can be independently re-used by the vfs_bio code also.)

(On FreeBSD - current)

Pages are faulted in by the VM system requesting I/O using the VOP_GETPAGES
filesystem entry point.  The data is read directly into the VM object.
When the objects reference count drops to zero, it is placed on the
cache queue, but its pages are not deactivated.  Pages on FreeBSD are managed
by a statistics gathering mechanism.  Note that if a filesystem
does not have a VOP_GETPAGES entry point, a default one is supplied that 
works with traditional filesystems.


John
dyson@freebsd.org