- Use fd_lastfile + 1 as the upper bound on nd. This is more correct than
using the size of the descriptor array. - A lock is not needed to fetch fd_lastfile. The results are stale the instant it is dropped. - Use a private mutex pool for select since the pool mutex is not used as a leaf. - Fetch the si_mtx pointer first before resorting to hashing to compute the mutex address. Reviewed by: McKusick Approved by: re (kib)
This commit is contained in:
parent
8edfe76ab5
commit
2141453eb4
@ -124,6 +124,7 @@ struct selfd {
|
||||
};
|
||||
|
||||
static uma_zone_t selfd_zone;
|
||||
static struct mtx_pool *mtxpool_select;
|
||||
|
||||
#ifndef _SYS_SYSPROTO_H_
|
||||
struct read_args {
|
||||
@ -794,11 +795,8 @@ kern_select(struct thread *td, int nd, fd_set *fd_in, fd_set *fd_ou,
|
||||
if (nd < 0)
|
||||
return (EINVAL);
|
||||
fdp = td->td_proc->p_fd;
|
||||
|
||||
FILEDESC_SLOCK(fdp);
|
||||
if (nd > td->td_proc->p_fd->fd_nfiles)
|
||||
nd = td->td_proc->p_fd->fd_nfiles; /* forgiving; slightly wrong */
|
||||
FILEDESC_SUNLOCK(fdp);
|
||||
if (nd > fdp->fd_lastfile + 1)
|
||||
nd = fdp->fd_lastfile + 1;
|
||||
|
||||
/*
|
||||
* Allocate just enough bits for the non-null fd_sets. Use the
|
||||
@ -1373,7 +1371,9 @@ selrecord(selector, sip)
|
||||
stp->st_free2 = NULL;
|
||||
else
|
||||
panic("selrecord: No free selfd on selq");
|
||||
mtxp = mtx_pool_find(mtxpool_sleep, sip);
|
||||
mtxp = sip->si_mtx;
|
||||
if (mtxp == NULL)
|
||||
mtxp = mtx_pool_find(mtxpool_select, sip);
|
||||
/*
|
||||
* Initialize the sfp and queue it in the thread.
|
||||
*/
|
||||
@ -1529,6 +1529,8 @@ SYSINIT(select, SI_SUB_SYSCALLS, SI_ORDER_ANY, selectinit, NULL);
|
||||
static void
|
||||
selectinit(void *dummy __unused)
|
||||
{
|
||||
|
||||
selfd_zone = uma_zcreate("selfd", sizeof(struct selfd), NULL, NULL,
|
||||
NULL, NULL, UMA_ALIGN_PTR, 0);
|
||||
mtxpool_select = mtx_pool_create("select mtxpool", 128, MTX_DEF);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user