summaryrefslogtreecommitdiff
path: root/sys/miscfs
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2009-05-24 21:41:25 +0000
committerad <ad@NetBSD.org>2009-05-24 21:41:25 +0000
commitd991fcb3b6084e8abc162cd006cfe3ad32a3bbf3 (patch)
treea72683aa4722bcaccc1875447f3f65e8cd5a472c /sys/miscfs
parent13573078f8c68c3135a250c496868137890c2edd (diff)
More changes to improve kern_descrip.c.
- Avoid atomics in more places. - Remove the per-descriptor mutex, and just use filedesc_t::fd_lock. It was only being used to synchronize close, and in any case we needed to take fd_lock to free the descriptor slot. - Optimize certain paths for the <NDFDFILE case. - Sprinkle more comments and assertions. - Cache more stuff in filedesc_t. - Fix numerous minor bugs spotted along the way. - Restructure how the open files array is maintained, for clarity and so that we can eliminate the membar_consumer() call in fd_getfile(). This is mostly syntactic sugar; the main functional change is that fd_nfiles now lives alongside the open file array. Some measurements with libmicro: - simple file syscalls are like close() are between 1 to 10% faster. - some nice improvements, e.g. poll(1000) which is ~50% faster.
Diffstat (limited to 'sys/miscfs')
-rw-r--r--sys/miscfs/fdesc/fdesc_vfsops.c22
-rw-r--r--sys/miscfs/fdesc/fdesc_vnops.c41
-rw-r--r--sys/miscfs/portal/portal_vnops.c6
-rw-r--r--sys/miscfs/procfs/procfs_vnops.c6
4 files changed, 34 insertions, 41 deletions
diff --git a/sys/miscfs/fdesc/fdesc_vfsops.c b/sys/miscfs/fdesc/fdesc_vfsops.c
index 754ddfa67aa..35d9d9be0bb 100644
--- a/sys/miscfs/fdesc/fdesc_vfsops.c
+++ b/sys/miscfs/fdesc/fdesc_vfsops.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fdesc_vfsops.c,v 1.79 2009/03/14 15:36:22 dsl Exp $ */
+/* $NetBSD: fdesc_vfsops.c,v 1.80 2009/05/24 21:41:26 ad Exp $ */
/*
* Copyright (c) 1992, 1993, 1995
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.79 2009/03/14 15:36:22 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.80 2009/05/24 21:41:26 ad Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -164,13 +164,13 @@ fdesc_root(struct mount *mp, struct vnode **vpp)
int
fdesc_statvfs(struct mount *mp, struct statvfs *sbp)
{
- struct lwp *l = curlwp;
- struct filedesc *fdp;
- struct proc *p;
+ lwp_t *l = curlwp;
+ proc_t *p;
int lim;
int i;
int last;
int freefd;
+ fdtab_t *dt;
/*
* Compute number of free file descriptors.
@@ -179,20 +179,20 @@ fdesc_statvfs(struct mount *mp, struct statvfs *sbp)
* of open files... ]
*/
p = l->l_proc;
+ dt = l->l_fd->fd_dt;
lim = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
- fdp = p->p_fd;
- last = min(fdp->fd_nfiles, lim);
+ last = min(dt->dt_nfiles, lim);
freefd = 0;
- for (i = fdp->fd_freefile; i < last; i++)
- if (fdp->fd_ofiles[i] == NULL)
+ for (i = l->l_fd->fd_freefile; i < last; i++)
+ if (dt->dt_ff[i]->ff_file == NULL)
freefd++;
/*
* Adjust for the fact that the fdesc array may not
* have been fully allocated yet.
*/
- if (fdp->fd_nfiles < lim)
- freefd += (lim - fdp->fd_nfiles);
+ if (dt->dt_nfiles < lim)
+ freefd += (lim - dt->dt_nfiles);
sbp->f_bsize = DEV_BSIZE;
sbp->f_frsize = DEV_BSIZE;
diff --git a/sys/miscfs/fdesc/fdesc_vnops.c b/sys/miscfs/fdesc/fdesc_vnops.c
index 3f154237743..c753374beed 100644
--- a/sys/miscfs/fdesc/fdesc_vnops.c
+++ b/sys/miscfs/fdesc/fdesc_vnops.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fdesc_vnops.c,v 1.106 2009/03/15 17:22:37 cegger Exp $ */
+/* $NetBSD: fdesc_vnops.c,v 1.107 2009/05/24 21:41:26 ad Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.106 2009/03/15 17:22:37 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.107 2009/05/24 21:41:26 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -276,12 +276,13 @@ fdesc_lookup(void *v)
struct lwp *l = curlwp;
const char *pname = cnp->cn_nameptr;
struct proc *p = l->l_proc;
- filedesc_t *fdp = p->p_fd;
- int numfiles = fdp->fd_nfiles;
unsigned fd = 0;
int error;
struct vnode *fvp;
const char *ln;
+ fdtab_t *dt;
+
+ dt = curlwp->l_fd->fd_dt;
if (cnp->cn_namelen == 1 && *pname == '.') {
*vpp = dvp;
@@ -370,7 +371,7 @@ fdesc_lookup(void *v)
fd = 0;
while (*pname >= '0' && *pname <= '9') {
fd = 10 * fd + *pname++ - '0';
- if (fd >= numfiles)
+ if (fd >= dt->dt_nfiles)
break;
}
@@ -379,14 +380,11 @@ fdesc_lookup(void *v)
goto bad;
}
- mutex_enter(&fdp->fd_lock);
- if (fd >= numfiles ||fdp->fd_ofiles[fd] == NULL ||
- fdp->fd_ofiles[fd]->ff_file == NULL) {
- mutex_exit(&fdp->fd_lock);
+ if (fd >= dt->dt_nfiles || dt->dt_ff[fd] == NULL ||
+ dt->dt_ff[fd]->ff_file == NULL) {
error = EBADF;
goto bad;
}
- mutex_exit(&fdp->fd_lock);
error = fdesc_allocvp(Fdesc, FD_DESC+fd, dvp->v_mount, &fvp);
if (error)
@@ -650,12 +648,12 @@ fdesc_readdir(void *v)
} */ *ap = v;
struct uio *uio = ap->a_uio;
struct dirent d;
- filedesc_t *fdp;
off_t i;
int j;
int error;
off_t *cookies = NULL;
int ncookies;
+ fdtab_t *dt;
switch (VTOFDESC(ap->a_vp)->fd_type) {
case Fctty:
@@ -668,7 +666,7 @@ fdesc_readdir(void *v)
break;
}
- fdp = curproc->p_fd;
+ dt = curlwp->l_fd->fd_dt;
if (uio->uio_resid < UIO_MX)
return EINVAL;
@@ -709,14 +707,11 @@ fdesc_readdir(void *v)
case FD_STDIN:
case FD_STDOUT:
case FD_STDERR:
- if (fdp == NULL)
- continue;
if ((ft->ft_fileno - FD_STDIN) >=
- fdp->fd_nfiles)
+ dt->dt_nfiles)
continue;
- membar_consumer();
- if (fdp->fd_ofiles[ft->ft_fileno - FD_STDIN]
- == NULL || fdp->fd_ofiles[ft->ft_fileno -
+ if (dt->dt_ff[ft->ft_fileno - FD_STDIN]
+ == NULL || dt->dt_ff[ft->ft_fileno -
FD_STDIN]->ff_file == NULL)
continue;
break;
@@ -733,16 +728,15 @@ fdesc_readdir(void *v)
*cookies++ = i + 1;
}
} else {
- int nfdp = fdp ? fdp->fd_nfiles : 0;
membar_consumer();
if (ap->a_ncookies) {
- ncookies = min(ncookies, nfdp + 2);
+ ncookies = min(ncookies, dt->dt_nfiles + 2);
cookies = malloc(ncookies * sizeof(off_t),
M_TEMP, M_WAITOK);
*ap->a_cookies = cookies;
*ap->a_ncookies = ncookies;
}
- for (; i - 2 < nfdp && uio->uio_resid >= UIO_MX; i++) {
+ for (; i - 2 < dt->dt_nfiles && uio->uio_resid >= UIO_MX; i++) {
switch (i) {
case 0:
case 1:
@@ -754,10 +748,9 @@ fdesc_readdir(void *v)
break;
default:
- KASSERT(fdp != NULL);
j = (int)i - 2;
- if (fdp == NULL || fdp->fd_ofiles[j] == NULL ||
- fdp->fd_ofiles[j]->ff_file == NULL)
+ if (dt->dt_ff[j] == NULL ||
+ dt->dt_ff[j]->ff_file == NULL)
continue;
d.d_fileno = j + FD_STDIN;
d.d_namlen = sprintf(d.d_name, "%d", j);
diff --git a/sys/miscfs/portal/portal_vnops.c b/sys/miscfs/portal/portal_vnops.c
index e66e0a9b41c..1416a1a1c9c 100644
--- a/sys/miscfs/portal/portal_vnops.c
+++ b/sys/miscfs/portal/portal_vnops.c
@@ -1,4 +1,4 @@
-/* $NetBSD: portal_vnops.c,v 1.82 2009/03/14 15:36:23 dsl Exp $ */
+/* $NetBSD: portal_vnops.c,v 1.83 2009/05/24 21:41:26 ad Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: portal_vnops.c,v 1.82 2009/03/14 15:36:23 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: portal_vnops.c,v 1.83 2009/05/24 21:41:26 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -483,7 +483,7 @@ portal_open(void *v)
* Check that the mode the file is being opened for is a subset
* of the mode of the existing descriptor.
*/
- fp = l->l_proc->p_fd->fd_ofiles[fd]->ff_file;
+ fp = l->l_fd->fd_dt->dt_ff[fd]->ff_file;
if (((ap->a_mode & (FREAD|FWRITE)) | fp->f_flag) != fp->f_flag) {
portal_closefd(l, fd); /* XXXNJWLWP */
error = EACCES;
diff --git a/sys/miscfs/procfs/procfs_vnops.c b/sys/miscfs/procfs/procfs_vnops.c
index ae3f1c6f935..a534c3dfc25 100644
--- a/sys/miscfs/procfs/procfs_vnops.c
+++ b/sys/miscfs/procfs/procfs_vnops.c
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs_vnops.c,v 1.173 2008/12/17 20:51:36 cegger Exp $ */
+/* $NetBSD: procfs_vnops.c,v 1.174 2009/05/24 21:41:26 ad Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -105,7 +105,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.173 2008/12/17 20:51:36 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.174 2009/05/24 21:41:26 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1338,7 +1338,7 @@ procfs_readdir(void *v)
return ESRCH;
}
- nfd = p->p_fd->fd_nfiles;
+ nfd = p->p_fd->fd_dt->dt_nfiles;
lim = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfiles);
if (i >= lim) {