diff options
author | csjp <csjp@FreeBSD.org> | 2006-03-20 00:13:47 +0000 |
---|---|---|
committer | csjp <csjp@FreeBSD.org> | 2006-03-20 00:13:47 +0000 |
commit | 7448676f59fe1294f9b5ec654564614a5c1edbe1 (patch) | |
tree | 877b09126e8496290f551828dbc6587427b278db | |
parent | 9d0a01c72c9e90544ae40c954d2d9e7529e09043 (diff) | |
download | FreeBSD-src-7448676f59fe1294f9b5ec654564614a5c1edbe1.zip FreeBSD-src-7448676f59fe1294f9b5ec654564614a5c1edbe1.tar.gz |
Restore fd optimization with a few minor tweaks, to quote tegge:
"fdinit() fails to initialize newfdp->fd_fd.fd_lastfile to -1. This breaks
fdcopy() which will incorrectly set newfdp->fd_freefile to 1 if no files are
open and the last file descriptor marked as unused for fdp was 0. This later
causes descriptor 0 to be unavailable in newfdp when the optimization is
enabled.
When the last file descriptor previously marked as used is nonzero and marked
as unused, fdunused() incorrectly sets fdp->fd_lastfile to fd - 1 due to
fd_last_used() returning (size - 1). This hides the problem that breaks the
optimization."
This allows us to keep the optimization, while un-breaking it.
This is a RELENG_6 candidate.
PR: kern/87208
MFC after: 1 week
Submitted by: tegge
-rw-r--r-- | sys/kern/kern_descrip.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 56ab05a..8482307 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -193,7 +193,7 @@ fd_last_used(struct filedesc *fdp, int low, int size) for (minoff = NDSLOT(low); off >= minoff; --off) if (map[off] != 0) return (off * NDENTRIES + flsl(map[off]) - 1); - return (size - 1); + return (low - 1); } static int @@ -1257,6 +1257,9 @@ fdalloc(struct thread *td, int minfd, int *result) FILEDESC_LOCK_ASSERT(fdp, MA_OWNED); + if (fdp->fd_freefile > minfd) + minfd = fdp->fd_freefile; + PROC_LOCK(p); maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc); PROC_UNLOCK(p); @@ -1286,7 +1289,6 @@ fdalloc(struct thread *td, int minfd, int *result) ("free descriptor isn't")); fdp->fd_ofileflags[fd] = 0; /* XXX needed? */ fdused(fdp, fd); - fdp->fd_freefile = fd_first_free(fdp, fd, fdp->fd_nfiles); *result = fd; return (0); } @@ -1420,6 +1422,7 @@ fdinit(struct filedesc *fdp) newfdp->fd_fd.fd_ofileflags = newfdp->fd_dfileflags; newfdp->fd_fd.fd_nfiles = NDFILE; newfdp->fd_fd.fd_map = newfdp->fd_dmap; + newfdp->fd_fd.fd_lastfile = -1; return (&newfdp->fd_fd); } |