git: cd37afd8b6dd - main - vm_object: Make is_object_active() global

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Mon, 20 Dec 2021 00:15:19 UTC
The branch main has been updated by rmacklem:

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

commit cd37afd8b6ddc38fe2441e37a8bf5f8cdce50bc6
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2021-12-20 00:11:44 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2021-12-20 00:11:44 +0000

    vm_object: Make is_object_active() global
    
    Commit 867c27c23a5c modified the NFS client so that
    it does IO_APPEND writes directly to the NFS server,
    bypassing the buffer cache.  However, this could result
    in stale data in client pages when the file is mmap(2)'d.
    As such, the NFS client needs to call is_object_active()
    to check if the file is mmap(2)'d.
    
    This patch renames is_object_active() to vm_object_is_active(),
    moves it to sys/vm/vm_object.c and makes it global, so that
    the NFS client can call it in a future commit.
    
    Reviewed by:    kib
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D33520
---
 sys/vm/vm_meter.c  | 19 ++-----------------
 sys/vm/vm_object.c | 15 +++++++++++++++
 sys/vm/vm_object.h |  1 +
 3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/sys/vm/vm_meter.c b/sys/vm/vm_meter.c
index f9e2b0c66cc8..f6ce0cfe39e3 100644
--- a/sys/vm/vm_meter.c
+++ b/sys/vm/vm_meter.c
@@ -142,21 +142,6 @@ SYSCTL_PROC(_vm, VM_LOADAVG, loadavg, CTLTYPE_STRUCT | CTLFLAG_RD |
     CTLFLAG_MPSAFE, NULL, 0, sysctl_vm_loadavg, "S,loadavg",
     "Machine loadaverage history");
 
-/*
- * This function aims to determine if the object is mapped,
- * specifically, if it is referenced by a vm_map_entry.  Because
- * objects occasionally acquire transient references that do not
- * represent a mapping, the method used here is inexact.  However, it
- * has very low overhead and is good enough for the advisory
- * vm.vmtotal sysctl.
- */
-static bool
-is_object_active(vm_object_t obj)
-{
-
-	return (obj->ref_count > obj->shadow_count);
-}
-
 #if defined(COMPAT_FREEBSD11)
 struct vmtotal11 {
 	int16_t	t_rq;
@@ -268,7 +253,7 @@ vmtotal(SYSCTL_HANDLER_ARGS)
 		}
 		total.t_vm += object->size;
 		total.t_rm += object->resident_page_count;
-		if (is_object_active(object)) {
+		if (vm_object_is_active(object)) {
 			total.t_avm += object->size;
 			total.t_arm += object->resident_page_count;
 		}
@@ -276,7 +261,7 @@ vmtotal(SYSCTL_HANDLER_ARGS)
 			/* shared object */
 			total.t_vmshr += object->size;
 			total.t_rmshr += object->resident_page_count;
-			if (is_object_active(object)) {
+			if (vm_object_is_active(object)) {
 				total.t_avmshr += object->size;
 				total.t_armshr += object->resident_page_count;
 			}
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index c465a2cf76dd..9bcf810df744 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -2498,6 +2498,21 @@ vm_object_busy_wait(vm_object_t obj, const char *wmesg)
 	(void)blockcount_sleep(&obj->busy, NULL, wmesg, PVM);
 }
 
+/*
+ * This function aims to determine if the object is mapped,
+ * specifically, if it is referenced by a vm_map_entry.  Because
+ * objects occasionally acquire transient references that do not
+ * represent a mapping, the method used here is inexact.  However, it
+ * has very low overhead and is good enough for the advisory
+ * vm.vmtotal sysctl.
+ */
+bool
+vm_object_is_active(vm_object_t obj)
+{
+
+	return (obj->ref_count > obj->shadow_count);
+}
+
 static int
 vm_object_list_handler(struct sysctl_req *req, bool swap_only)
 {
diff --git a/sys/vm/vm_object.h b/sys/vm/vm_object.h
index 3b280228de13..ef8245c266d5 100644
--- a/sys/vm/vm_object.h
+++ b/sys/vm/vm_object.h
@@ -391,6 +391,7 @@ boolean_t vm_object_sync(vm_object_t, vm_ooffset_t, vm_size_t, boolean_t,
 void vm_object_unwire(vm_object_t object, vm_ooffset_t offset,
     vm_size_t length, uint8_t queue);
 struct vnode *vm_object_vnode(vm_object_t object);
+bool vm_object_is_active(vm_object_t obj);
 #endif				/* _KERNEL */
 
 #endif				/* _VM_OBJECT_ */