1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-15 10:17:20 +00:00

Reduce the overhead of semop() by using the kernel stack instead of

malloc'd memory to store the operations array if it is small enough
to fit.
This commit is contained in:
Tim J. Robbins 2003-12-19 13:07:17 +00:00
parent 22df7d650a
commit f5925b7436
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=123667

View File

@ -877,6 +877,8 @@ semop(td, uap)
struct thread *td;
struct semop_args *uap;
{
#define SMALL_SOPS 8
struct sembuf small_sops[SMALL_SOPS];
int semid = uap->semid;
size_t nsops = uap->nsops;
struct sembuf *sops;
@ -900,16 +902,20 @@ semop(td, uap)
return (EINVAL);
/* Allocate memory for sem_ops */
if (nsops > seminfo.semopm) {
if (nsops <= SMALL_SOPS)
sops = small_sops;
else if (nsops <= seminfo.semopm)
sops = malloc(nsops * sizeof(*sops), M_TEMP, M_WAITOK);
else {
DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm,
nsops));
return (E2BIG);
}
sops = malloc(nsops * sizeof(sops[0]), M_SEM, M_WAITOK);
if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) {
DPRINTF(("error = %d from copyin(%08x, %08x, %d)\n", error,
uap->sops, sops, nsops * sizeof(sops[0])));
free(sops, M_SEM);
if (sops != small_sops)
free(sops, M_SEM);
return (error);
}
@ -1137,7 +1143,8 @@ semop(td, uap)
td->td_retval[0] = 0;
done2:
mtx_unlock(sema_mtxp);
free(sops, M_SEM);
if (sops != small_sops)
free(sops, M_SEM);
return (error);
}