mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-04 07:31:11 +00:00
Push acquisition of Giant from fdrop_closed() into fo_close() so that
individual file object implementations can optionally acquire Giant if they require it: - soo_close(): depends on debug.mpsafenet - pipe_close(): Giant not acquired - kqueue_close(): Giant required - vn_close(): Giant required - cryptof_close(): Giant required (conservative) Notes: Giant is still acquired in close() even when closing MPSAFE objects due to kqueue requiring Giant in the calling closef() code. Microbenchmarks indicate that this removal of Giant cuts 3%-3% off of pipe create/destroy pairs from user space with SMP compiled into the kernel. The cryptodev and opencrypto code appears MPSAFE, but I'm unable to test it extensively and so have left Giant over fo_close(). It can probably be removed given some testing and review.
This commit is contained in:
parent
df04411ac4
commit
1c1ce9253f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=132549
|
@ -2070,13 +2070,11 @@ fdrop_locked(fp, td)
|
|||
FILE_UNLOCK(fp);
|
||||
if (fp->f_count < 0)
|
||||
panic("fdrop: count < 0");
|
||||
mtx_lock(&Giant);
|
||||
if (fp->f_ops != &badfileops)
|
||||
error = fo_close(fp, td);
|
||||
else
|
||||
error = 0;
|
||||
ffree(fp);
|
||||
mtx_unlock(&Giant);
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
|
|
@ -906,7 +906,7 @@ kqueue_close(struct file *fp, struct thread *td)
|
|||
struct knote **knp, *kn, *kn0;
|
||||
int i;
|
||||
|
||||
GIANT_REQUIRED;
|
||||
mtx_lock(&Giant);
|
||||
|
||||
FILEDESC_LOCK(fdp);
|
||||
for (i = 0; i < fdp->fd_knlistsize; i++) {
|
||||
|
@ -957,6 +957,7 @@ kqueue_close(struct file *fp, struct thread *td)
|
|||
free(kq, M_KQUEUE);
|
||||
fp->f_data = NULL;
|
||||
|
||||
mtx_unlock(&Giant);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
@ -262,11 +262,13 @@ soo_close(fp, td)
|
|||
int error = 0;
|
||||
struct socket *so;
|
||||
|
||||
NET_LOCK_GIANT();
|
||||
so = fp->f_data;
|
||||
fp->f_ops = &badfileops;
|
||||
fp->f_data = NULL;
|
||||
|
||||
if (so)
|
||||
error = soclose(so);
|
||||
NET_UNLOCK_GIANT();
|
||||
return (error);
|
||||
}
|
||||
|
|
|
@ -915,11 +915,11 @@ vn_closefile(fp, td)
|
|||
{
|
||||
struct vnode *vp;
|
||||
struct flock lf;
|
||||
|
||||
GIANT_REQUIRED;
|
||||
int error;
|
||||
|
||||
vp = fp->f_vnode;
|
||||
|
||||
mtx_lock(&Giant);
|
||||
if (fp->f_type == DTYPE_VNODE && fp->f_flag & FHASLOCK) {
|
||||
lf.l_whence = SEEK_SET;
|
||||
lf.l_start = 0;
|
||||
|
@ -930,7 +930,9 @@ vn_closefile(fp, td)
|
|||
|
||||
fp->f_ops = &badfileops;
|
||||
|
||||
return (vn_close(vp, fp->f_flag, fp->f_cred, td));
|
||||
error = vn_close(vp, fp->f_flag, fp->f_cred, td);
|
||||
mtx_unlock(&Giant);
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -623,12 +623,19 @@ cryptof_close(struct file *fp, struct thread *td)
|
|||
struct fcrypt *fcr = fp->f_data;
|
||||
struct csession *cse;
|
||||
|
||||
/*
|
||||
* XXXRW: The cryptodev and called code all appears to be
|
||||
* MPSAFE, but I'm not set up to test it. Acquire Giant
|
||||
* for now.
|
||||
*/
|
||||
mtx_lock(&Giant);
|
||||
while ((cse = TAILQ_FIRST(&fcr->csessions))) {
|
||||
TAILQ_REMOVE(&fcr->csessions, cse, next);
|
||||
(void)csefree(cse);
|
||||
}
|
||||
FREE(fcr, M_XDATA);
|
||||
fp->f_data = NULL;
|
||||
mtx_unlock(&Giant);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue