silly write caching in nfs3

Bruce Evans brde at optusnet.com.au
Sat Feb 27 06:27:09 UTC 2016


On Fri, 26 Feb 2016, Rick Macklem wrote:

> Bruce Evans wrote:
>> nfs3 is slower than in old versions of FreeBSD.  I debugged one of the
>> reasons today.
>...
>> nfs_open() does the discarding for different reasons in the NMODIFIED
>> and !NMODIFIED cases.  In the NMODIFED case, it discard unconditionally.
>> This case can be avoided by fsync() before close or setting the sysctl
>> to commit in close.  iozone does he fsync().  This helps in oldnfs but
>> not in newfs.  With it, iozone on newfs now behaves like it did on oldnfs
>> 10-20 years ago.  Something (perhaps just the timestamp bugs discussed
>> later) "fixed" the discarding on oldnfs 5-10 years ago.
>...
>> The other reason for discarding is because the timestamps changed -- you
>> just wrote them, so the timestamps should have changed.  Different bugs
>> in comparing the timestamps gave different misbehaviours.
>>
> You could easily test to see if second-resolution timestamps make a
> difference by redefining the NFS_TIMESPEC_COMPARE() macro
> { in sys/fs/nfsclient/nfsnode.h } so that it only compares the
> tv_sec field and not the tv_nsec field.
> --> Then the client would only think the mtime has changed when tv_sec
>    changes.

My server has vfs.timestamp_precision for other reasons, so I get this
automatically.  So the fixes to use NFS_TIMESTAMP_COMPARE() don't actually
work.  This together with enabling write commit gives a useful
optimization for compiling (it reduces the build time for a FreeBSD-4
kernel from 4.5 seconds to 4.4 seconds.  Very useful for compiling
hundreds of these :-).  Write commit clears NMODIFIED and the buggy
timestamp compare then avoids most cache invalidations.

BTW, I don't kike the NFS_TIMESTAMP_COMPARE() macro.  FreeBSD has a better
standard macro timespeccmp().  The names of these macros have different bugs,
but timespeccmp() is easier to use since it is shorter and you can see the
comparison operator in it and it is not limited to comparing for inequality.
NFS_TIMESTAMP_COMPARE() looks like it compares for equality, but actually
compares for inequality.

Bruce


More information about the freebsd-fs mailing list