Re: weird bugs with mmap-ing via NFS

From: Mikhail Teterin <mi+mx_at_aldan.algebra.com>
Date: Tue, 21 Mar 2006 17:17:33 -0500
	[Moved from -current to -stable]

ืฆืิฯาฯห 21 ยลาลฺลฮุ 2006 16:23, Matthew Dillon ๗ษ ฮมะษำมฬษ:
> š š You might be doing just writes to the mmap()'d memory, but the system
> š š doesn't know that.

Actually, it does. The program tells it, that I don't care to read, what's 
currently there, by specifying the PROT_READ flag only.

> š š The moment you touch any mmap()'d page, reading or writing, the system
> š š has to fault it in, which means it has to read it and load valid data
> š š into the page.

Sounds like a missed optimization opportunity :-(

> :When I mount with large read and write sizes:
> :
> :šššššššmount_nfs -r 65536 -w 65536 -U -ointr pandora:/backup /backup
> :
> :it changes -- for the worse. Short time into it -- the file stops growing
> :according to the `ls -sl' run on the NFS server (pandora) at exactly 3200
> : FS blocks (the FS was created with `-b 65536 -f 8129').
> :
> :At the same time, according to `systat -if' on both client and server, the
> : š client continues to send (and the server continues to receive) about
> : 30Mb of some (?) data per second.

> š š It kinda sounds like the buffer cache is getting blown out, but not
> š š having seen the program I can't really analyze it.

See http://aldan.algebra.com/~mi/mzip.c

> š š It will always be more efficient to write to a file using write() then
> š š using mmap()

I understand, that write() is much better optimized at the moment, but the 
mmap interface carries some advantages, which may allow future OSes to 
optimize their ways. The application can hint at its planned usage of the 
data via madvise, for example.

Unfortunately, my problem, so far, is with it not writing _at all_...

> š š and it will always be far, far more efficient to write to an NFS file in
> š š nfs block-sized chunks rather then in smaller chunks 
> š š due to the way the buffer cache works.

Yes, this is an example of how a good implemented mmap can be better than 
write. Without explicit writes by the application and without doubling the 
memory requirements, the data can be written in the most optimal way.

Thanks for your help. Yours,

	-mi
Received on Tue Mar 21 2006 - 21:18:20 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:53 UTC