FILEDESC_LOCK() implementation

From: Kris Kennaway <kris_at_obsecurity.org>
Date: Mon, 12 Jun 2006 01:41:15 -0400
I fixed mutex profiling to a) not be as wrong and b) not suck so very
much, and here is a revised profiling trace from mysql supersmack on a
12 cpu E4500, sorted by ratio of cnt_lock/count; filedesc lock
contention (via FILEDESC_[UN]LOCK()) is the major mutex contention
problem.

     0          0      55381      0        672       3195   .057 kern/kern_sig.c:998 (process lock)
     0          0      31451      0       3657       2446   .077 kern/subr_sleepqueue.c:374 (process lock)
     0          0      31706      0       3570       2623   .082 kern/kern_sx.c:245 (lockbuilder mtxpool)
     0          0     458877      0      83592      48024   .104 kern/kern_descrip.c:1988 (filedesc structure)
     0          0      45069      0       5342       6085   .135 kern/kern_umtx.c:195 (umtxq_lock)
     0          0     458877      0      22609      72747   .158 kern/kern_descrip.c:1967 (filedesc structure)
     0          0      40046      0       6845       6925   .172 kern/uipc_usrreq.c:621 (unp_global_mtx)
     0          0      31706      0       3159       6075   .191 kern/kern_sx.c:157 (lockbuilder mtxpool)
     0          0      66539      0      22823      12844   .193 kern/kern_descrip.c:420 (filedesc structure)
     0          0      66569      0       5352      20913   .314 kern/kern_descrip.c:368 (filedesc structure)
     0          0     110665      0      38632      76441   .690 kern/kern_synch.c:222 (filedesc structure)
#

kern/kern_descrip.c:1967,1988 are _fget()
kern/kern_descrip.c:368,420 is kern_fcntl()
kern/kern_synch.c:222 is msleep() (called in a loop from FILEDESC_LOCK)

I wonder if something better can be done with the funky home-grown
locking in FILEDESC_LOCK() (see <sys/filedesc.h>) to make it more
light-weight?

/* Lock a file descriptor table. */
#define FILEDESC_LOCK(fd)                                                               \
        do {                                                                            \
                mtx_lock(&(fd)->fd_mtx);                                                \
                (fd)->fd_wanted++;                                                      \
                while ((fd)->fd_locked)                                                 \
                        msleep(&(fd)->fd_locked, &(fd)->fd_mtx, PLOCK, "fdesc", 0);     \
                (fd)->fd_locked = 2;                                                    \
                (fd)->fd_wanted--;                                                      \
                mtx_unlock(&(fd)->fd_mtx);                                              \
        } while (0)

Kris


Received on Mon Jun 12 2006 - 03:41:16 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:57 UTC