From: Matthew Dillon Date: Thu, 1 Jun 2006 06:10:58 +0000 (+0000) Subject: Use the MP friendly objcache instead of zalloc to allocate temporary X-Git-Tag: v2.0.1~4853 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/70aac194af9ca1c170324e666bf9b6864680c04c Use the MP friendly objcache instead of zalloc to allocate temporary MAXPATHLEN space. --- diff --git a/sys/kern/kern_objcache.c b/sys/kern/kern_objcache.c index 2c8a164c55..874fa960de 100644 --- a/sys/kern/kern_objcache.c +++ b/sys/kern/kern_objcache.c @@ -29,7 +29,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_objcache.c,v 1.6 2006/04/14 02:58:49 dillon Exp $ + * $DragonFly: src/sys/kern/kern_objcache.c,v 1.7 2006/06/01 06:10:50 dillon Exp $ */ #include @@ -153,7 +153,7 @@ mag_alloc(int capacity) * Create an object cache. */ struct objcache * -objcache_create(char *name, int cluster_limit, int mag_capacity, +objcache_create(const char *name, int cluster_limit, int mag_capacity, objcache_ctor_fn *ctor, objcache_dtor_fn *dtor, void *private, objcache_alloc_fn *alloc, objcache_free_fn *free, void *allocator_args) @@ -211,6 +211,22 @@ objcache_create(char *name, int cluster_limit, int mag_capacity, return (oc); } +struct objcache * +objcache_create_simple(malloc_type_t mtype, size_t objsize) +{ + struct objcache_malloc_args *margs; + struct objcache *oc; + + margs = malloc(sizeof(*margs), M_OBJCACHE, M_WAITOK|M_ZERO); + margs->objsize = objsize; + margs->mtype = mtype; + oc = objcache_create(mtype->ks_shortdesc, 0, 0, + null_ctor, null_dtor, NULL, + objcache_malloc_alloc, objcache_malloc_free, + margs); + return (oc); +} + #define MAGAZINE_EMPTY(mag) (mag->rounds == 0) #define MAGAZINE_NOTEMPTY(mag) (mag->rounds != 0) #define MAGAZINE_FULL(mag) (mag->rounds == mag->capacity) @@ -523,6 +539,12 @@ null_dtor(void *obj, void *private) /* do nothing */ } +boolean_t +null_ctor(void *obj, void *private, int ocflags) +{ + return TRUE; +} + /* * De-construct and de-allocate objects in a magazine. * Returns the number of objects freed. diff --git a/sys/kern/vfs_init.c b/sys/kern/vfs_init.c index 9b6c2aa62c..1d5f301dd1 100644 --- a/sys/kern/vfs_init.c +++ b/sys/kern/vfs_init.c @@ -70,7 +70,7 @@ * * @(#)vfs_init.c 8.3 (Berkeley) 1/4/94 * $FreeBSD: src/sys/kern/vfs_init.c,v 1.59 2002/04/30 18:44:32 dillon Exp $ - * $DragonFly: src/sys/kern/vfs_init.c,v 1.11 2006/03/24 18:35:33 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_init.c,v 1.12 2006/06/01 06:10:50 dillon Exp $ */ /* * Manage vnode VOP operations vectors @@ -82,14 +82,15 @@ #include #include #include -#include +#include static MALLOC_DEFINE(M_VNODEOP, "vnodeops", "vnode operations vectors"); +static MALLOC_DEFINE(M_NAMEI, "nameibufs", "namei path buffers"); /* * Zone for namei */ -struct vm_zone *namei_zone; +struct objcache *namei_oc; /* * vfs_init() will set maxvfsconf @@ -275,7 +276,7 @@ static void vfsinit(void *dummy) { TAILQ_INIT(&vnodeopv_list); - namei_zone = zinit("NAMEI", MAXPATHLEN, 0, 0, 2); + namei_oc = objcache_create_simple(M_NAMEI, MAXPATHLEN); /* * Initialize the vnode table diff --git a/sys/kern/vfs_nlookup.c b/sys/kern/vfs_nlookup.c index 6a90ae39de..f51f8d8dee 100644 --- a/sys/kern/vfs_nlookup.c +++ b/sys/kern/vfs_nlookup.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/vfs_nlookup.c,v 1.16 2006/05/17 18:30:20 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_nlookup.c,v 1.17 2006/06/01 06:10:50 dillon Exp $ */ /* * nlookup() is the 'new' namei interface. Rather then return directory and @@ -64,7 +64,7 @@ #include #include #include -#include +#include #ifdef KTRACE #include @@ -93,7 +93,7 @@ nlookup_init(struct nlookupdata *nd, * note: the pathlen set by copy*str() includes the terminating \0. */ bzero(nd, sizeof(struct nlookupdata)); - nd->nl_path = zalloc(namei_zone); + nd->nl_path = objcache_get(namei_oc, M_WAITOK); nd->nl_flags |= NLC_HASBUF; if (seg == UIO_SYSSPACE) error = copystr(path, nd->nl_path, MAXPATHLEN, &pathlen); @@ -145,7 +145,7 @@ nlookup_init_raw(struct nlookupdata *nd, td = curthread; bzero(nd, sizeof(struct nlookupdata)); - nd->nl_path = zalloc(namei_zone); + nd->nl_path = objcache_get(namei_oc, M_WAITOK); nd->nl_flags |= NLC_HASBUF; if (seg == UIO_SYSSPACE) error = copystr(path, nd->nl_path, MAXPATHLEN, &pathlen); @@ -215,7 +215,7 @@ nlookup_done(struct nlookupdata *nd) nd->nl_jailncp = NULL; } if ((nd->nl_flags & NLC_HASBUF) && nd->nl_path) { - zfree(namei_zone, nd->nl_path); + objcache_put(namei_oc, nd->nl_path); nd->nl_path = NULL; } if (nd->nl_cred) { @@ -482,12 +482,12 @@ nlookup(struct nlookupdata *nd) len = strlen(ptr); if (nlc.nlc_namelen == 0 || nlc.nlc_namelen + len >= MAXPATHLEN) { error = nlc.nlc_namelen ? ENAMETOOLONG : ENOENT; - zfree(namei_zone, nlc.nlc_nameptr); + objcache_put(namei_oc, nlc.nlc_nameptr); break; } bcopy(ptr, nlc.nlc_nameptr + nlc.nlc_namelen, len + 1); if (nd->nl_flags & NLC_HASBUF) - zfree(namei_zone, nd->nl_path); + objcache_put(namei_oc, nd->nl_path); nd->nl_path = nlc.nlc_nameptr; nd->nl_flags |= NLC_HASBUF; ptr = nd->nl_path; @@ -634,7 +634,7 @@ nlookup_mp(struct mount *mp, struct namecache **ncpp) /* * Read the contents of a symlink, allocate a path buffer out of the - * namei_zone and initialize the supplied nlcomponent with the result. + * namei_oc and initialize the supplied nlcomponent with the result. * * If an error occurs no buffer will be allocated or returned in the nlc. */ @@ -655,7 +655,7 @@ nreadsymlink(struct nlookupdata *nd, struct namecache *ncp, return(ENOENT); if ((error = cache_vget(ncp, nd->nl_cred, LK_SHARED, &vp)) != 0) return(error); - cp = zalloc(namei_zone); + cp = objcache_get(namei_oc, M_WAITOK); aiov.iov_base = cp; aiov.iov_len = MAXPATHLEN; auio.uio_iov = &aiov; @@ -682,7 +682,7 @@ nreadsymlink(struct nlookupdata *nd, struct namecache *ncp, vput(vp); return(0); fail: - zfree(namei_zone, cp); + objcache_put(namei_oc, cp); vput(vp); return(error); } diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 85aefc65b1..3e2468932e 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -37,7 +37,7 @@ * * @(#)vfs_syscalls.c 8.13 (Berkeley) 4/15/94 * $FreeBSD: src/sys/kern/vfs_syscalls.c,v 1.151.2.18 2003/04/04 20:35:58 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_syscalls.c,v 1.94 2006/05/25 07:36:34 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_syscalls.c,v 1.95 2006/06/01 06:10:50 dillon Exp $ */ #include @@ -64,13 +64,13 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include @@ -775,7 +775,7 @@ mountctl(struct mountctl_args *uap) /* * Allocate the necessary buffers and copyin data */ - path = zalloc(namei_zone); + path = objcache_get(namei_oc, M_WAITOK); error = copyinstr(uap->path, path, MAXPATHLEN, NULL); if (error) goto done; @@ -808,7 +808,7 @@ mountctl(struct mountctl_args *uap) error = copyout(buf, uap->buf, uap->sysmsg_result); done: if (path) - zfree(namei_zone, path); + objcache_put(namei_oc, path); if (ctl) free(ctl, M_TEMP); if (buf) @@ -1767,7 +1767,7 @@ symlink(struct symlink_args *uap) int error; int mode; - path = zalloc(namei_zone); + path = objcache_get(namei_oc, M_WAITOK); error = copyinstr(uap->path, path, MAXPATHLEN, NULL); if (error == 0) { error = nlookup_init(&nd, uap->link, UIO_USERSPACE, 0); @@ -1777,7 +1777,7 @@ symlink(struct symlink_args *uap) } nlookup_done(&nd); } - zfree(namei_zone, path); + objcache_put(namei_oc, path); return (error); } diff --git a/sys/netgraph/netgraph/ng_base.c b/sys/netgraph/netgraph/ng_base.c index ece5eb2893..f0db326b13 100644 --- a/sys/netgraph/netgraph/ng_base.c +++ b/sys/netgraph/netgraph/ng_base.c @@ -38,7 +38,7 @@ * Archie Cobbs * * $FreeBSD: src/sys/netgraph/ng_base.c,v 1.11.2.17 2002/07/02 23:44:02 archie Exp $ - * $DragonFly: src/sys/netgraph/netgraph/ng_base.c,v 1.19 2006/05/20 06:32:39 dillon Exp $ + * $DragonFly: src/sys/netgraph/netgraph/ng_base.c,v 1.20 2006/06/01 06:10:54 dillon Exp $ * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $ */ @@ -312,10 +312,10 @@ linker_api_available(void) if (curproc == NULL) return 0; /* - * nlookup_init() relies on namei_zone to be initialized, + * nlookup_init() relies on namei_oc to be initialized, * but it's not when the netgraph module is loaded during boot. */ - if (namei_zone == NULL) + if (namei_oc == NULL) return 0; return 1; } diff --git a/sys/sys/objcache.h b/sys/sys/objcache.h index 153554cf28..abe4eaf135 100644 --- a/sys/sys/objcache.h +++ b/sys/sys/objcache.h @@ -29,7 +29,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/objcache.h,v 1.5 2006/05/21 03:43:47 dillon Exp $ + * $DragonFly: src/sys/sys/objcache.h,v 1.6 2006/06/01 06:10:52 dillon Exp $ */ #ifndef _OBJCACHE_H_ @@ -51,6 +51,7 @@ typedef void (objcache_dtor_fn)(void *obj, void *private); #ifdef _KERNEL extern objcache_dtor_fn null_dtor; +extern objcache_ctor_fn null_ctor; #endif /* @@ -64,11 +65,13 @@ typedef void (objcache_free_fn)(void *obj, void *allocator_args); struct objcache; struct objcache - *objcache_create(char *name, int cluster_limit, int mag_capacity, + *objcache_create(const char *name, int cluster_limit, int mag_capacity, objcache_ctor_fn *ctor, objcache_dtor_fn *dtor, void *private, objcache_alloc_fn *alloc, objcache_free_fn *free, void *allocator_args); +struct objcache + *objcache_create_simple(malloc_type_t mtype, size_t objsize); void *objcache_get(struct objcache *oc, int ocflags); void objcache_put(struct objcache *oc, void *obj); void objcache_dtor(struct objcache *oc, void *obj); diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 90e89b29ba..6d88d554a8 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -32,7 +32,7 @@ * * @(#)vnode.h 8.7 (Berkeley) 2/4/94 * $FreeBSD: src/sys/sys/vnode.h,v 1.111.2.19 2002/12/29 18:19:53 dillon Exp $ - * $DragonFly: src/sys/sys/vnode.h,v 1.57 2006/05/27 01:57:42 dillon Exp $ + * $DragonFly: src/sys/sys/vnode.h,v 1.58 2006/06/01 06:10:52 dillon Exp $ */ #ifndef _SYS_VNODE_H_ @@ -366,6 +366,8 @@ extern int vttoif_tab[]; /* * Global vnode data. */ +struct objcache; + extern struct vnode *rootvnode; /* root (i.e. "/") vnode */ extern struct namecache *rootncp; /* root (i.e. "/") namecache */ extern int desiredvnodes; /* number of vnodes desired */ @@ -373,7 +375,7 @@ extern time_t syncdelay; /* max time to delay syncing data */ extern time_t filedelay; /* time to delay syncing files */ extern time_t dirdelay; /* time to delay syncing directories */ extern time_t metadelay; /* time to delay syncing metadata */ -extern struct vm_zone *namei_zone; +extern struct objcache *namei_oc; extern int prtactive; /* nonzero to call vprint() */ extern struct vattr va_null; /* predefined null vattr structure */ extern int vfs_ioopt; diff --git a/sys/vfs/isofs/cd9660/cd9660_vnops.c b/sys/vfs/isofs/cd9660/cd9660_vnops.c index 883fe69d2c..dc723d8d8a 100644 --- a/sys/vfs/isofs/cd9660/cd9660_vnops.c +++ b/sys/vfs/isofs/cd9660/cd9660_vnops.c @@ -37,7 +37,7 @@ * * @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95 * $FreeBSD: src/sys/isofs/cd9660/cd9660_vnops.c,v 1.62 1999/12/15 23:01:51 eivind Exp $ - * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vnops.c,v 1.26 2006/05/26 16:56:21 dillon Exp $ + * $DragonFly: src/sys/vfs/isofs/cd9660/cd9660_vnops.c,v 1.27 2006/06/01 06:10:56 dillon Exp $ */ #include @@ -55,9 +55,9 @@ #include #include #include +#include #include -#include #include #include "iso.h" @@ -706,14 +706,14 @@ cd9660_readlink(struct vop_readlink_args *ap) if (uio->uio_segflg == UIO_SYSSPACE) symname = uio->uio_iov->iov_base; else - symname = zalloc(namei_zone); + symname = objcache_get(namei_oc, M_WAITOK); /* * Ok, we just gathering a symbolic name in SL record. */ if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) { if (uio->uio_segflg != UIO_SYSSPACE) - zfree(namei_zone, symname); + objcache_put(namei_oc, symname); brelse(bp); return (EINVAL); } @@ -727,7 +727,7 @@ cd9660_readlink(struct vop_readlink_args *ap) */ if (uio->uio_segflg != UIO_SYSSPACE) { error = uiomove(symname, symlen, uio); - zfree(namei_zone, symname); + objcache_put(namei_oc, symname); return (error); } uio->uio_resid -= symlen; diff --git a/sys/vfs/nfs/nfs_subs.c b/sys/vfs/nfs/nfs_subs.c index 2a6d74054f..3cf56095aa 100644 --- a/sys/vfs/nfs/nfs_subs.c +++ b/sys/vfs/nfs/nfs_subs.c @@ -35,7 +35,7 @@ * * @(#)nfs_subs.c 8.8 (Berkeley) 5/22/95 * $FreeBSD: /repoman/r/ncvs/src/sys/nfsclient/nfs_subs.c,v 1.128 2004/04/14 23:23:55 peadar Exp $ - * $DragonFly: src/sys/vfs/nfs/nfs_subs.c,v 1.38 2006/05/05 21:15:10 dillon Exp $ + * $DragonFly: src/sys/vfs/nfs/nfs_subs.c,v 1.39 2006/06/01 06:10:57 dillon Exp $ */ /* @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -1455,7 +1456,7 @@ nfs_namei(struct nlookupdata *nd, struct ucred *cred, int nameiop, struct vnode *dp; int error, rdonly; - namebuf = zalloc(namei_zone); + namebuf = objcache_get(namei_oc, M_WAITOK); flags = 0; *dirpp = NULL; @@ -1520,7 +1521,7 @@ nfs_namei(struct nlookupdata *nd, struct ucred *cred, int nameiop, * Oh joy. For WebNFS, handle those pesky '%' escapes, * and the 'native path' indicator. */ - cp = zalloc(namei_zone); + cp = objcache_get(namei_oc, M_WAITOK); fromcp = namebuf; tocp = cp; if ((unsigned char)*fromcp >= WEBNFS_SPECCHAR_START) { @@ -1538,7 +1539,7 @@ nfs_namei(struct nlookupdata *nd, struct ucred *cred, int nameiop, */ default: error = EIO; - zfree(namei_zone, cp); + objcache_put(namei_oc, cp); goto out; } } @@ -1554,14 +1555,14 @@ nfs_namei(struct nlookupdata *nd, struct ucred *cred, int nameiop, continue; } else { error = ENOENT; - zfree(namei_zone, cp); + objcache_put(namei_oc, cp); goto out; } } else *tocp++ = *fromcp++; } *tocp = '\0'; - zfree(namei_zone, namebuf); + objcache_put(namei_oc, namebuf); namebuf = cp; } @@ -1633,7 +1634,7 @@ nfs_namei(struct nlookupdata *nd, struct ucred *cred, int nameiop, * Finish up. */ out: - zfree(namei_zone, namebuf); + objcache_put(namei_oc, namebuf); return (error); } diff --git a/sys/vfs/union/union_subr.c b/sys/vfs/union/union_subr.c index 09afdf67e9..77f41a9633 100644 --- a/sys/vfs/union/union_subr.c +++ b/sys/vfs/union/union_subr.c @@ -36,7 +36,7 @@ * * @(#)union_subr.c 8.20 (Berkeley) 5/20/95 * $FreeBSD: src/sys/miscfs/union/union_subr.c,v 1.43.2.2 2001/12/25 01:44:45 dillon Exp $ - * $DragonFly: src/sys/vfs/union/union_subr.c,v 1.24 2006/05/06 02:43:15 dillon Exp $ + * $DragonFly: src/sys/vfs/union/union_subr.c,v 1.25 2006/06/01 06:10:58 dillon Exp $ */ #include @@ -808,7 +808,7 @@ union_relookup(struct union_mount *um, struct vnode *dvp, struct vnode **vpp, * Conclusion: Horrible. */ cn->cn_namelen = pathlen; - cn->cn_nameptr = zalloc(namei_zone); + cn->cn_nameptr = objcache_get(namei_oc, M_WAITOK); bcopy(path, cn->cn_nameptr, cn->cn_namelen); cn->cn_nameptr[cn->cn_namelen] = '\0'; @@ -831,11 +831,11 @@ union_relookup(struct union_mount *um, struct vnode *dvp, struct vnode **vpp, */ if ((error = relookup(dvp, vpp, cn)) != 0) { - zfree(namei_zone, cn->cn_nameptr); + objcache_put(namei_oc, cn->cn_nameptr); vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY); return(error); } - zfree(namei_zone, cn->cn_nameptr); + objcache_put(namei_oc, cn->cn_nameptr); /* * If no error occurs, dvp will be returned locked with the reference @@ -980,7 +980,7 @@ union_vn_create(struct vnode **vpp, struct union_node *un, struct thread *td) * copied in the first place). */ cn.cn_namelen = strlen(un->un_path); - cn.cn_nameptr = zalloc(namei_zone); + cn.cn_nameptr = objcache_get(namei_oc, M_WAITOK); bcopy(un->un_path, cn.cn_nameptr, cn.cn_namelen+1); cn.cn_nameiop = NAMEI_CREATE; cn.cn_flags = CNP_LOCKPARENT; @@ -995,7 +995,7 @@ union_vn_create(struct vnode **vpp, struct union_node *un, struct thread *td) */ vref(un->un_dirvp); error = relookup(un->un_dirvp, &vp, &cn); - zfree(namei_zone, cn.cn_nameptr); + objcache_put(namei_oc, cn.cn_nameptr); if (error) return (error);