From owner-dev-commits-src-branches@freebsd.org Sat May 22 09:46:27 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DAAC66493B3; Sat, 22 May 2021 09:46:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FnJX35Dmyz3llX; Sat, 22 May 2021 09:46:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9287A2252F; Sat, 22 May 2021 09:46:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14M9kRJE012412; Sat, 22 May 2021 09:46:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14M9kRM4012411; Sat, 22 May 2021 09:46:27 GMT (envelope-from git) Date: Sat, 22 May 2021 09:46:27 GMT Message-Id: <202105220946.14M9kRM4012411@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 9a311cf995fe - stable/13 - Add pgo_getvp method MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9a311cf995febd628c8d18c9b91c0d80bf95267b Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 May 2021 09:46:28 -0000 The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9a311cf995febd628c8d18c9b91c0d80bf95267b commit 9a311cf995febd628c8d18c9b91c0d80bf95267b Author: Konstantin Belousov AuthorDate: 2021-05-01 01:04:04 +0000 Commit: Konstantin Belousov CommitDate: 2021-05-22 09:38:28 +0000 Add pgo_getvp method (cherry picked from commit 192112b74fed56ca652cf1d70c11ba7e17bc1ce2) --- sys/vm/swap_pager.c | 28 ++++++++++++++++++++++++++++ sys/vm/vm_map.c | 33 +-------------------------------- sys/vm/vm_pager.c | 11 +++++++++++ sys/vm/vm_pager.h | 20 ++++++++++++++++++++ sys/vm/vnode_pager.c | 8 ++++++++ 5 files changed, 68 insertions(+), 32 deletions(-) diff --git a/sys/vm/swap_pager.c b/sys/vm/swap_pager.c index 7cfce53aba79..91383244a0f9 100644 --- a/sys/vm/swap_pager.c +++ b/sys/vm/swap_pager.c @@ -435,6 +435,8 @@ static void swap_pager_release_writecount(vm_object_t object, vm_offset_t start, vm_offset_t end); static void swap_pager_set_writeable_dirty(vm_object_t object); static bool swap_pager_mightbedirty(vm_object_t object); +static void swap_pager_getvp(vm_object_t object, struct vnode **vpp, + bool *vp_heldp); struct pagerops swappagerops = { .pgo_init = swap_pager_init, /* early system initialization of pager */ @@ -449,6 +451,7 @@ struct pagerops swappagerops = { .pgo_release_writecount = swap_pager_release_writecount, .pgo_set_writeable_dirty = swap_pager_set_writeable_dirty, .pgo_mightbedirty = swap_pager_mightbedirty, + .pgo_getvp = swap_pager_getvp, }; /* @@ -3146,3 +3149,28 @@ swap_pager_mightbedirty(vm_object_t object) return (vm_object_mightbedirty_(object)); return (false); } + +static void +swap_pager_getvp(vm_object_t object, struct vnode **vpp, bool *vp_heldp) +{ + struct vnode *vp; + + KASSERT((object->flags & OBJ_TMPFS_NODE) != 0, + ("swap_pager_getvp: swap and !TMPFS obj %p", object)); + + /* + * Tmpfs VREG node, which was reclaimed, has + * OBJ_TMPFS_NODE flag set, but not OBJ_TMPFS. In + * this case there is no v_writecount to adjust. + */ + VM_OBJECT_RLOCK(object); + if ((object->flags & OBJ_TMPFS) != 0) { + vp = object->un_pager.swp.swp_tmpfs; + if (vp != NULL) { + vhold(vp); + *vpp = vp; + *vp_heldp = true; + } + } + VM_OBJECT_RUNLOCK(object); +} diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index f17342b2a545..60c88a7b71bf 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -561,38 +561,7 @@ vm_map_entry_set_vnode_text(vm_map_entry_t entry, bool add) * referenced by the entry we are processing, so it cannot go * away. */ - vp = NULL; - vp_held = false; - if (object->type == OBJT_DEAD) { - /* - * For OBJT_DEAD objects, v_writecount was handled in - * vnode_pager_dealloc(). - */ - } else if (object->type == OBJT_VNODE) { - vp = object->handle; - } else if (object->type == OBJT_SWAP) { - KASSERT((object->flags & OBJ_TMPFS_NODE) != 0, - ("vm_map_entry_set_vnode_text: swap and !TMPFS " - "entry %p, object %p, add %d", entry, object, add)); - /* - * Tmpfs VREG node, which was reclaimed, has - * OBJ_TMPFS_NODE flag set, but not OBJ_TMPFS. In - * this case there is no v_writecount to adjust. - */ - VM_OBJECT_RLOCK(object); - if ((object->flags & OBJ_TMPFS) != 0) { - vp = object->un_pager.swp.swp_tmpfs; - if (vp != NULL) { - vhold(vp); - vp_held = true; - } - } - VM_OBJECT_RUNLOCK(object); - } else { - KASSERT(0, - ("vm_map_entry_set_vnode_text: wrong object type, " - "entry %p, object %p, add %d", entry, object, add)); - } + vm_pager_getvp(object, &vp, &vp_held); if (vp != NULL) { if (add) { VOP_SET_TEXT_CHECKED(vp); diff --git a/sys/vm/vm_pager.c b/sys/vm/vm_pager.c index b113ce569e14..587407a06291 100644 --- a/sys/vm/vm_pager.c +++ b/sys/vm/vm_pager.c @@ -100,6 +100,7 @@ static vm_object_t dead_pager_alloc(void *, vm_ooffset_t, vm_prot_t, static void dead_pager_putpages(vm_object_t, vm_page_t *, int, int, int *); static boolean_t dead_pager_haspage(vm_object_t, vm_pindex_t, int *, int *); static void dead_pager_dealloc(vm_object_t); +static void dead_pager_getvp(vm_object_t, struct vnode **, bool *); static int dead_pager_getpages(vm_object_t obj, vm_page_t *ma, int count, int *rbehind, @@ -144,12 +145,22 @@ dead_pager_dealloc(vm_object_t object) } +static void +dead_pager_getvp(vm_object_t object, struct vnode **vpp, bool *vp_heldp) +{ + /* + * For OBJT_DEAD objects, v_writecount was handled in + * vnode_pager_dealloc(). + */ +} + static struct pagerops deadpagerops = { .pgo_alloc = dead_pager_alloc, .pgo_dealloc = dead_pager_dealloc, .pgo_getpages = dead_pager_getpages, .pgo_putpages = dead_pager_putpages, .pgo_haspage = dead_pager_haspage, + .pgo_getvp = dead_pager_getvp, }; struct pagerops *pagertab[] = { diff --git a/sys/vm/vm_pager.h b/sys/vm/vm_pager.h index 014a67c2e055..cb2a896c8749 100644 --- a/sys/vm/vm_pager.h +++ b/sys/vm/vm_pager.h @@ -47,6 +47,7 @@ #include TAILQ_HEAD(pagerlst, vm_object); +struct vnode; typedef void pgo_init_t(void); typedef vm_object_t pgo_alloc_t(void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t, @@ -64,6 +65,8 @@ typedef void pgo_pageunswapped_t(vm_page_t); typedef void pgo_writecount_t(vm_object_t, vm_offset_t, vm_offset_t); typedef void pgo_set_writeable_dirty_t(vm_object_t); typedef bool pgo_mightbedirty_t(vm_object_t); +typedef void pgo_getvp_t(vm_object_t object, struct vnode **vpp, + bool *vp_heldp); struct pagerops { pgo_init_t *pgo_init; /* Initialize pager. */ @@ -79,6 +82,7 @@ struct pagerops { pgo_writecount_t *pgo_release_writecount; pgo_set_writeable_dirty_t *pgo_set_writeable_dirty; pgo_mightbedirty_t *pgo_mightbedirty; + pgo_getvp_t *pgo_getvp; }; extern struct pagerops defaultpagerops; @@ -216,6 +220,22 @@ vm_pager_release_writecount(vm_object_t object, vm_offset_t start, method(object, start, end); } +static __inline void +vm_pager_getvp(vm_object_t object, struct vnode **vpp, bool *vp_heldp) +{ + pgo_getvp_t *method; + + *vpp = NULL; + *vp_heldp = false; + method = pagertab[object->type]->pgo_getvp; + if (method != NULL) { + method(object, vpp, vp_heldp); + } else { + KASSERT(0, + ("vm_pager_getvp: wrong object type obj %p", object)); + } +} + struct cdev_pager_ops { int (*cdev_pg_fault)(vm_object_t vm_obj, vm_ooffset_t offset, int prot, vm_page_t *mres); diff --git a/sys/vm/vnode_pager.c b/sys/vm/vnode_pager.c index 5e89d91548fd..eeced1b981d1 100644 --- a/sys/vm/vnode_pager.c +++ b/sys/vm/vnode_pager.c @@ -105,6 +105,7 @@ static void vnode_pager_update_writecount(vm_object_t, vm_offset_t, vm_offset_t); static void vnode_pager_release_writecount(vm_object_t, vm_offset_t, vm_offset_t); +static void vnode_pager_getvp(vm_object_t, struct vnode **, bool *); struct pagerops vnodepagerops = { .pgo_alloc = vnode_pager_alloc, @@ -117,6 +118,7 @@ struct pagerops vnodepagerops = { .pgo_release_writecount = vnode_pager_release_writecount, .pgo_set_writeable_dirty = vm_object_set_writeable_dirty_, .pgo_mightbedirty = vm_object_mightbedirty_, + .pgo_getvp = vnode_pager_getvp, }; static struct domainset *vnode_domainset = NULL; @@ -1604,3 +1606,9 @@ vnode_pager_release_writecount(vm_object_t object, vm_offset_t start, if (mp != NULL) vn_finished_write(mp); } + +static void +vnode_pager_getvp(vm_object_t object, struct vnode **vpp, bool *vp_heldp) +{ + *vpp = object->handle; +}