Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/tmpfs - tmpfs: do not create dirent/node pools per-mo...



details:   https://anonhg.NetBSD.org/src/rev/467fba78dcd2
branches:  trunk
changeset: 765092:467fba78dcd2
user:      rmind <rmind%NetBSD.org@localhost>
date:      Thu May 19 03:21:23 2011 +0000

description:
- 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.

diffstat:

 sys/fs/tmpfs/tmpfs.h        |   7 +----
 sys/fs/tmpfs/tmpfs_mem.c    |  25 +++++++-------------
 sys/fs/tmpfs/tmpfs_vfsops.c |  55 ++++++++++++++++++++++----------------------
 3 files changed, 37 insertions(+), 50 deletions(-)

diffs (216 lines):

diff -r 3a4d0962a6c2 -r 467fba78dcd2 sys/fs/tmpfs/tmpfs.h
--- a/sys/fs/tmpfs/tmpfs.h      Thu May 19 03:18:01 2011 +0000
+++ b/sys/fs/tmpfs/tmpfs.h      Thu May 19 03:21:23 2011 +0000
@@ -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 @@
        /* 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;
 };
 
 /* --------------------------------------------------------------------- */
diff -r 3a4d0962a6c2 -r 467fba78dcd2 sys/fs/tmpfs/tmpfs_mem.c
--- a/sys/fs/tmpfs/tmpfs_mem.c  Thu May 19 03:18:01 2011 +0000
+++ b/sys/fs/tmpfs/tmpfs_mem.c  Thu May 19 03:21:23 2011 +0000
@@ -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 @@
 
 #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 @@
 
        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 @@
        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_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 @@
        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_mem_decr(mp, sizeof(struct tmpfs_node));
-       pool_put(&mp->tm_node_pool, tn);
+       pool_put(&tmpfs_node_pool, tn);
 }
 
 /*
diff -r 3a4d0962a6c2 -r 467fba78dcd2 sys/fs/tmpfs/tmpfs_vfsops.c
--- a/sys/fs/tmpfs/tmpfs_vfsops.c       Thu May 19 03:18:01 2011 +0000
+++ b/sys/fs/tmpfs/tmpfs_vfsops.c       Thu May 19 03:21:23 2011 +0000
@@ -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 @@
 
 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 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 @@
        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 @@
        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 @@
        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)



Home | Main Index | Thread Index | Old Index