git: 0f613ab85e5a - main - tmpfs: add a knob to enable pgcache read for mount

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 09 Aug 2023 04:03:12 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=0f613ab85e5a5274704d179f39fb15163d46e7c4

commit 0f613ab85e5a5274704d179f39fb15163d46e7c4
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-08-06 01:35:36 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-08-09 03:54:15 +0000

    tmpfs: add a knob to enable pgcache read for mount
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D41334
---
 sys/fs/tmpfs/tmpfs.h        | 3 +++
 sys/fs/tmpfs/tmpfs_subr.c   | 3 ++-
 sys/fs/tmpfs/tmpfs_vfsops.c | 4 +++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/sys/fs/tmpfs/tmpfs.h b/sys/fs/tmpfs/tmpfs.h
index 126b99acba6b..7e24fd5e1924 100644
--- a/sys/fs/tmpfs/tmpfs.h
+++ b/sys/fs/tmpfs/tmpfs.h
@@ -428,6 +428,9 @@ struct tmpfs_mount {
 	bool			tm_nonc;
 	/* Do not update mtime on writes through mmaped areas. */
 	bool			tm_nomtime;
+
+	/* Read from page cache directly. */
+	bool			tm_pgread;
 };
 #define	TMPFS_LOCK(tm) mtx_lock(&(tm)->tm_allnode_lock)
 #define	TMPFS_UNLOCK(tm) mtx_unlock(&(tm)->tm_allnode_lock)
diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c
index 28834a96ee9a..69a9936ebcde 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -1061,7 +1061,8 @@ loop:
 		VI_LOCK(vp);
 		KASSERT(vp->v_object == NULL, ("Not NULL v_object in tmpfs"));
 		vp->v_object = object;
-		vn_irflag_set_locked(vp, VIRF_PGREAD | VIRF_TEXT_REF);
+		vn_irflag_set_locked(vp, (tm->tm_pgread ? VIRF_PGREAD : 0) |
+		    VIRF_TEXT_REF);
 		VI_UNLOCK(vp);
 		VM_OBJECT_WUNLOCK(object);
 		break;
diff --git a/sys/fs/tmpfs/tmpfs_vfsops.c b/sys/fs/tmpfs/tmpfs_vfsops.c
index 7a88e7deba9d..b04b3c084b3b 100644
--- a/sys/fs/tmpfs/tmpfs_vfsops.c
+++ b/sys/fs/tmpfs/tmpfs_vfsops.c
@@ -329,7 +329,7 @@ tmpfs_mount(struct mount *mp)
 	struct tmpfs_mount *tmp;
 	struct tmpfs_node *root;
 	int error;
-	bool nomtime, nonc;
+	bool nomtime, nonc, pgread;
 	/* Size counters. */
 	u_quad_t pages;
 	off_t nodes_max, size_max, maxfilesize, ea_max_size;
@@ -412,6 +412,7 @@ tmpfs_mount(struct mount *mp)
 		ea_max_size = 0;
 	nonc = vfs_getopt(mp->mnt_optnew, "nonc", NULL, NULL) == 0;
 	nomtime = vfs_getopt(mp->mnt_optnew, "nomtime", NULL, NULL) == 0;
+	pgread = vfs_getopt(mp->mnt_optnew, "pgread", NULL, NULL) == 0;
 
 	/* Do not allow mounts if we do not have enough memory to preserve
 	 * the minimum reserved pages. */
@@ -462,6 +463,7 @@ tmpfs_mount(struct mount *mp)
 	tmp->tm_ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
 	tmp->tm_nonc = nonc;
 	tmp->tm_nomtime = nomtime;
+	tmp->tm_pgread = pgread;
 
 	/* Allocate the root node. */
 	error = tmpfs_alloc_node(mp, tmp, VDIR, root_uid, root_gid,