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 <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
This commit is contained in:
Andrew Deason 2022-10-25 14:06:32 -05:00
parent 2c208c2662
commit 68be40e469
4 changed files with 51 additions and 5 deletions

View File

@ -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_ */

View File

@ -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);
}

View File

@ -62,7 +62,6 @@
#include <vm/vm_pager.h>
#include <vm/vnode_pager.h>
#include <sys/vmmeter.h>
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);

View File

@ -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)