From 68be40e469759776d68568f489897c9c846b19dc Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Tue, 25 Oct 2022 14:06:32 -0500 Subject: [PATCH] FBSD: Use UMA allocations instead of getpbuf() FreeBSD commit 756a5412798b7de1709bb1de2db5ba2a5908cba3 (Allocate pager bufs from UMA instead of 80-ish mutex protected linked list.) removed getpbuf() and related functions; callers are supposed to use UMA allocator functions instead. Use a private zone allocated by pbuf_zsecond_create() like other filesystems do, and make our callers go through new abstractions afs_getpbuf() and afs_relpbuf() to use the right functions. Change-Id: I303e9f848485481adb94ef5c7db5885f22288003 Reviewed-on: https://gerrit.openafs.org/15165 Tested-by: BuildBot Reviewed-by: Michael Meffie Reviewed-by: Andrew Deason --- src/afs/FBSD/osi_machdep.h | 6 ++++++ src/afs/FBSD/osi_vfsops.c | 13 +++++++++++++ src/afs/FBSD/osi_vnodeops.c | 32 +++++++++++++++++++++++++++----- src/config/param.generic_fbsd.h | 5 +++++ 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/afs/FBSD/osi_machdep.h b/src/afs/FBSD/osi_machdep.h index f82ab0c3d8..6efd5b1142 100644 --- a/src/afs/FBSD/osi_machdep.h +++ b/src/afs/FBSD/osi_machdep.h @@ -143,4 +143,10 @@ osi_GetTime(osi_timeval32_t *atv) atv->tv_usec = now.tv_usec; } +#ifdef FBSD_UMA_GETPBUF +extern uma_zone_t afs_pbuf_zone; +#else +extern int afs_pbuf_freecnt; +#endif + #endif /* _OSI_MACHDEP_H_ */ diff --git a/src/afs/FBSD/osi_vfsops.c b/src/afs/FBSD/osi_vfsops.c index 4fde03760f..3b789ae02d 100644 --- a/src/afs/FBSD/osi_vfsops.c +++ b/src/afs/FBSD/osi_vfsops.c @@ -15,7 +15,12 @@ struct vcache *afs_globalVp = NULL; struct mount *afs_globalVFS = NULL; + +#ifdef FBSD_UMA_GETPBUF +uma_zone_t afs_pbuf_zone; +#else int afs_pbuf_freecnt = -1; +#endif extern int Afs_xsetgroups(); @@ -52,7 +57,11 @@ afs_init(struct vfsconf *vfc) return code; } osi_Init(); +#ifdef FBSD_UMA_GETPBUF + afs_pbuf_zone = pbuf_zsecond_create("afspbuf", nswbuf / 2); +#else afs_pbuf_freecnt = nswbuf / 2 + 1; +#endif return 0; } @@ -62,6 +71,10 @@ afs_uninit(struct vfsconf *vfc) if (afs_globalVFS) return EBUSY; +#ifdef FBSD_UMA_GETPBUF + uma_zdestroy(afs_pbuf_zone); +#endif + return syscall_helper_unregister(afs_syscalls); } diff --git a/src/afs/FBSD/osi_vnodeops.c b/src/afs/FBSD/osi_vnodeops.c index bcc6f973cd..7b20693231 100644 --- a/src/afs/FBSD/osi_vnodeops.c +++ b/src/afs/FBSD/osi_vnodeops.c @@ -62,7 +62,6 @@ #include #include #include -extern int afs_pbuf_freecnt; #define GETNAME() \ struct componentname *cnp = ap->a_cnp; \ @@ -104,6 +103,29 @@ static __inline void ma_vm_page_unlock(vm_page_t m) { vm_page_unlock(m); }; # define AFS_VM_CNT_INC(var) PCPU_INC(cnt.var) #endif +static __inline struct buf * +afs_getpbuf(void) +{ +#ifdef FBSD_UMA_GETPBUF + return uma_zalloc(afs_pbuf_zone, M_WAITOK); +#else + return getpbuf(&afs_pbuf_freecnt); +#endif +} + +static __inline void +afs_relpbuf(struct buf **a_bp) +{ + if (*a_bp == NULL) + return; +#ifdef FBSD_UMA_GETPBUF + uma_zfree(afs_pbuf_zone, *a_bp); +#else + relpbuf(*a_bp, &afs_pbuf_freecnt); +#endif + *a_bp = NULL; +} + /* * Mosty copied from sys/ufs/ufs/ufs_vnops.c:ufs_pathconf(). * We should know the correct answers to these questions with @@ -546,7 +568,7 @@ afs_vop_getpages(struct vop_getpages_args *ap) ma_vm_page_unlock_queues(); AFS_VM_OBJECT_WUNLOCK(object); } - bp = getpbuf(&afs_pbuf_freecnt); + bp = afs_getpbuf(); kva = (vm_offset_t) bp->b_data; pmap_qenter(kva, pages, npages); @@ -574,7 +596,7 @@ afs_vop_getpages(struct vop_getpages_args *ap) AFS_GUNLOCK(); pmap_qremove(kva, npages); - relpbuf(bp, &afs_pbuf_freecnt); + afs_relpbuf(&bp); if (code && (uio.uio_resid == count)) { #ifndef FBSD_VOP_GETPAGES_BUSIED @@ -730,7 +752,7 @@ afs_vop_putpages(struct vop_putpages_args *ap) npages = btoc(ap->a_count); for (i = 0; i < npages; i++) ap->a_rtvals[i] = VM_PAGER_AGAIN; - bp = getpbuf(&afs_pbuf_freecnt); + bp = afs_getpbuf(); kva = (vm_offset_t) bp->b_data; pmap_qenter(kva, ap->a_m, npages); @@ -772,7 +794,7 @@ afs_vop_putpages(struct vop_putpages_args *ap) AFS_GUNLOCK(); pmap_qremove(kva, npages); - relpbuf(bp, &afs_pbuf_freecnt); + afs_relpbuf(&bp); if (!code) { AFS_VM_OBJECT_WLOCK(vp->v_object); diff --git a/src/config/param.generic_fbsd.h b/src/config/param.generic_fbsd.h index 3ce2e1ba94..7d119e5ed1 100644 --- a/src/config/param.generic_fbsd.h +++ b/src/config/param.generic_fbsd.h @@ -128,6 +128,11 @@ enum vcexcl { NONEXCL, EXCL }; # define AFS_FBSD_NET_FOREACH TAILQ_FOREACH #endif +/* r343030 removed getpbuf() et al, use UMA alloc instead */ +#if __FreeBSD_version >= 1300008 +# define FBSD_UMA_GETPBUF +#endif + /* r355537 removed VI_DOOMED, use VN_IS_DOOMED instead */ #if __FreeBSD_version >= 1300064 # define AFS_IS_DOOMED(vp) VN_IS_DOOMED(vp)