Disable timestamping on devfs read/write operations by default.

Currently we update timestamps unconditionally when doing read or
write operations.  This may slow things down on hardware where
reading timestamps is expensive (e.g. HPET, because of the default
vfs.timestamp_precision setting is nanosecond now) with limited
benefit.

A new sysctl variable, vfs.devfs.dotimes is added, which can be
set to non-zero value when the old behavior is desirable.

Differential Revision:	https://reviews.freebsd.org/D2104
Reported by:	Mike Tancsa <mike sentex net>
Reviewed by:	kib
Relnotes:	yes
Sponsored by:	iXsystems, Inc.
MFC after:	2 weeks
This commit is contained in:
delphij 2015-03-21 01:14:11 +00:00
parent f0d9946f04
commit 041657da93
2 changed files with 12 additions and 3 deletions

View File

@ -61,7 +61,7 @@ static MALLOC_DEFINE(M_DEVFS2, "DEVFS2", "DEVFS data 2");
static MALLOC_DEFINE(M_DEVFS3, "DEVFS3", "DEVFS data 3");
static MALLOC_DEFINE(M_CDEVP, "DEVFS1", "DEVFS cdev_priv storage");
static SYSCTL_NODE(_vfs, OID_AUTO, devfs, CTLFLAG_RW, 0, "DEVFS filesystem");
SYSCTL_NODE(_vfs, OID_AUTO, devfs, CTLFLAG_RW, 0, "DEVFS filesystem");
static unsigned devfs_generation;
SYSCTL_UINT(_vfs_devfs, OID_AUTO, generation, CTLFLAG_RD,

View File

@ -57,6 +57,7 @@
#include <sys/proc.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/ttycom.h>
#include <sys/unistd.h>
@ -79,6 +80,12 @@ SX_SYSINIT(clone_drain_lock, &clone_drain_lock, "clone events drain lock");
struct mtx cdevpriv_mtx;
MTX_SYSINIT(cdevpriv_mtx, &cdevpriv_mtx, "cdevpriv lock", MTX_DEF);
SYSCTL_DECL(_vfs_devfs);
static int devfs_dotimes;
SYSCTL_INT(_vfs_devfs, OID_AUTO, dotimes, CTLFLAG_RW,
&devfs_dotimes, 0, "Update timestamps on DEVFS");
static int
devfs_fp_check(struct file *fp, struct cdev **devp, struct cdevsw **dswp,
int *ref)
@ -1221,7 +1228,8 @@ devfs_read_f(struct file *fp, struct uio *uio, struct ucred *cred,
foffset_lock_uio(fp, uio, flags | FOF_NOLOCK);
error = dsw->d_read(dev, uio, ioflag);
if (uio->uio_resid != resid || (error == 0 && resid != 0))
if (devfs_dotimes &&
(uio->uio_resid != resid || (error == 0 && resid != 0)))
vfs_timestamp(&dev->si_atime);
td->td_fpop = fpop;
dev_relthread(dev, ref);
@ -1700,7 +1708,8 @@ devfs_write_f(struct file *fp, struct uio *uio, struct ucred *cred,
resid = uio->uio_resid;
error = dsw->d_write(dev, uio, ioflag);
if (uio->uio_resid != resid || (error == 0 && resid != 0)) {
if (devfs_dotimes &&
(uio->uio_resid != resid || (error == 0 && resid != 0))) {
vfs_timestamp(&dev->si_ctime);
dev->si_mtime = dev->si_ctime;
}