- tmpfs: do not create dirent/node pools per-mount, there is no need to.

- tmpfs_mount: fix a leak of mount structures in error path.
This commit is contained in:
rmind 2011-05-19 03:21:23 +00:00
parent 4c16c0afd2
commit 7d4d81a323
3 changed files with 37 additions and 50 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs.h,v 1.39 2011/01/13 13:35:11 pooka Exp $ */
/* $NetBSD: tmpfs.h,v 1.40 2011/05/19 03:21:23 rmind Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@ -298,11 +298,6 @@ struct tmpfs_mount {
/* Node list. */
kmutex_t tm_lock;
struct tmpfs_node_list tm_nodes;
char tm_dwchan[32];
struct pool tm_dirent_pool;
char tm_nwchan[32];
struct pool tm_node_pool;
};
/* --------------------------------------------------------------------- */

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_mem.c,v 1.2 2010/06/28 19:32:43 rmind Exp $ */
/* $NetBSD: tmpfs_mem.c,v 1.3 2011/05/19 03:21:23 rmind Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_mem.c,v 1.2 2010/06/28 19:32:43 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_mem.c,v 1.3 2011/05/19 03:21:23 rmind Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -42,18 +42,13 @@ __KERNEL_RCSID(0, "$NetBSD: tmpfs_mem.c,v 1.2 2010/06/28 19:32:43 rmind Exp $");
#include <fs/tmpfs/tmpfs.h>
extern struct pool tmpfs_dirent_pool;
extern struct pool tmpfs_node_pool;
void
tmpfs_mntmem_init(struct tmpfs_mount *mp, uint64_t memlimit)
{
sprintf(mp->tm_dwchan, "tmpfs_dirent_%p", mp);
pool_init(&mp->tm_dirent_pool, sizeof(struct tmpfs_dirent), 0, 0, 0,
mp->tm_dwchan, &pool_allocator_nointr, IPL_NONE);
sprintf(mp->tm_nwchan, "tmpfs_node_%p", mp);
pool_init(&mp->tm_node_pool, sizeof(struct tmpfs_node), 0, 0, 0,
mp->tm_dwchan, &pool_allocator_nointr, IPL_NONE);
mutex_init(&mp->tm_acc_lock, MUTEX_DEFAULT, IPL_NONE);
mp->tm_mem_limit = memlimit;
mp->tm_bytes_used = 0;
@ -65,8 +60,6 @@ tmpfs_mntmem_destroy(struct tmpfs_mount *mp)
KASSERT(mp->tm_bytes_used == 0);
mutex_destroy(&mp->tm_acc_lock);
pool_destroy(&mp->tm_dirent_pool);
pool_destroy(&mp->tm_node_pool);
}
/*
@ -153,7 +146,7 @@ tmpfs_dirent_get(struct tmpfs_mount *mp)
if (!tmpfs_mem_incr(mp, sizeof(struct tmpfs_dirent))) {
return NULL;
}
return pool_get(&mp->tm_dirent_pool, PR_WAITOK);
return pool_get(&tmpfs_dirent_pool, PR_WAITOK);
}
void
@ -161,7 +154,7 @@ tmpfs_dirent_put(struct tmpfs_mount *mp, struct tmpfs_dirent *de)
{
tmpfs_mem_decr(mp, sizeof(struct tmpfs_dirent));
pool_put(&mp->tm_dirent_pool, de);
pool_put(&tmpfs_dirent_pool, de);
}
struct tmpfs_node *
@ -171,7 +164,7 @@ tmpfs_node_get(struct tmpfs_mount *mp)
if (!tmpfs_mem_incr(mp, sizeof(struct tmpfs_node))) {
return NULL;
}
return pool_get(&mp->tm_node_pool, PR_WAITOK);
return pool_get(&tmpfs_node_pool, PR_WAITOK);
}
void
@ -179,7 +172,7 @@ tmpfs_node_put(struct tmpfs_mount *mp, struct tmpfs_node *tn)
{
tmpfs_mem_decr(mp, sizeof(struct tmpfs_node));
pool_put(&mp->tm_node_pool, tn);
pool_put(&tmpfs_node_pool, tn);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_vfsops.c,v 1.47 2011/04/02 14:24:53 hannken Exp $ */
/* $NetBSD: tmpfs_vfsops.c,v 1.48 2011/05/19 03:21:23 rmind Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.47 2011/04/02 14:24:53 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.48 2011/05/19 03:21:23 rmind Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -60,7 +60,8 @@ __KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.47 2011/04/02 14:24:53 hannken Ex
MODULE(MODULE_CLASS_VFS, tmpfs, NULL);
/* --------------------------------------------------------------------- */
struct pool tmpfs_dirent_pool;
struct pool tmpfs_node_pool;
static int tmpfs_mount(struct mount *, const char *, void *, size_t *);
static int tmpfs_start(struct mount *, int);
@ -76,7 +77,23 @@ static void tmpfs_done(void);
static int tmpfs_snapshot(struct mount *, struct vnode *,
struct timespec *);
/* --------------------------------------------------------------------- */
static void
tmpfs_init(void)
{
pool_init(&tmpfs_dirent_pool, sizeof(struct tmpfs_dirent), 0, 0, 0,
"tmpfs_dirent", &pool_allocator_nointr, IPL_NONE);
pool_init(&tmpfs_node_pool, sizeof(struct tmpfs_node), 0, 0, 0,
"tmpfs_node", &pool_allocator_nointr, IPL_NONE);
}
static void
tmpfs_done(void)
{
pool_destroy(&tmpfs_dirent_pool);
pool_destroy(&tmpfs_node_pool);
}
static int
tmpfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
@ -169,8 +186,12 @@ tmpfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
mp->mnt_iflag |= IMNT_MPSAFE;
vfs_getnewfsid(mp);
return set_statvfs_info(path, UIO_USERSPACE, "tmpfs", UIO_SYSSPACE,
error = set_statvfs_info(path, UIO_USERSPACE, "tmpfs", UIO_SYSSPACE,
mp->mnt_op->vfs_name, mp, curlwp);
if (error) {
(void)tmpfs_unmount(mp, MNT_FORCE);
}
return error;
}
/* --------------------------------------------------------------------- */
@ -182,16 +203,12 @@ tmpfs_start(struct mount *mp, int flags)
return 0;
}
/* --------------------------------------------------------------------- */
/* ARGSUSED2 */
static int
tmpfs_unmount(struct mount *mp, int mntflags)
{
int error;
int flags = 0;
struct tmpfs_mount *tmp;
struct tmpfs_node *node;
int error, flags = 0;
/* Handle forced unmounts. */
if (mntflags & MNT_FORCE)
@ -360,24 +377,6 @@ tmpfs_sync(struct mount *mp, int waitfor,
return 0;
}
/* --------------------------------------------------------------------- */
static void
tmpfs_init(void)
{
}
/* --------------------------------------------------------------------- */
static void
tmpfs_done(void)
{
}
/* --------------------------------------------------------------------- */
static int
tmpfs_snapshot(struct mount *mp, struct vnode *vp,
struct timespec *ctime)