Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev Use IO_DIRECT for file I/O to reduce buffer cache co...



details:   https://anonhg.NetBSD.org/src/rev/0bcae539b036
branches:  trunk
changeset: 836277:0bcae539b036
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Oct 07 12:00:07 2018 +0000

description:
Use IO_DIRECT for file I/O to reduce buffer cache contention.

Restore old behaviour to flush pages only when usage exceeds 1MB.

No longer use PGO_SYNCIO, regular writes to the device do not require
the data to reach stable storage, the DIOCCACHESYNC ioctl is used
for that.

diffstat:

 sys/dev/vnd.c |  21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diffs (52 lines):

diff -r 0d54a7adac96 -r 0bcae539b036 sys/dev/vnd.c
--- a/sys/dev/vnd.c     Sun Oct 07 11:54:14 2018 +0000
+++ b/sys/dev/vnd.c     Sun Oct 07 12:00:07 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vnd.c,v 1.268 2018/10/07 11:54:14 mlelstv Exp $        */
+/*     $NetBSD: vnd.c,v 1.269 2018/10/07 12:00:07 mlelstv Exp $        */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.268 2018/10/07 11:54:14 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.269 2018/10/07 12:00:07 mlelstv Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vnd.h"
@@ -159,6 +159,7 @@
     (MAKEDISKDEV(major((dev)), vndunit((dev)), RAW_PART))
 
 #define        VND_MAXPENDING(vnd)     ((vnd)->sc_maxactive * 4)
+#define        VND_MAXPAGES(vnd)       (1024 * 1024 / PAGE_SIZE)
 
 
 static void    vndclear(struct vnd_softc *, int);
@@ -810,12 +811,22 @@
        bp->b_error =
            vn_rdwr(doread ? UIO_READ : UIO_WRITE,
            vp, bp->b_data, len, offset, UIO_SYSSPACE,
-           IO_ADV_ENCODE(POSIX_FADV_NOREUSE), vnd->sc_cred, &resid, NULL);
+           IO_ADV_ENCODE(POSIX_FADV_NOREUSE) | IO_DIRECT,
+               vnd->sc_cred, &resid, NULL);
        bp->b_resid = resid;
 
+       /*
+        * Avoid caching too many pages, the vnd user
+        * is usually a filesystem and caches itself.
+        * We need some amount of caching to not hinder
+        * read-ahead and write-behind operations.
+        */
        mutex_enter(vp->v_interlock);
-       (void) VOP_PUTPAGES(vp, 0, 0,
-           PGO_ALLPAGES | PGO_CLEANIT | PGO_FREE | PGO_SYNCIO);
+       if (vp->v_uobj.uo_npages > VND_MAXPAGES(vnd))
+               (void) VOP_PUTPAGES(vp, 0, 0,
+                   PGO_ALLPAGES | PGO_CLEANIT | PGO_FREE);
+       else
+               mutex_exit(vp->v_interlock);
 
        fstrans_done(vp->v_mount);
 



Home | Main Index | Thread Index | Old Index