Bug #38265 thread local variables in innodb do not scale on SMP
Submitted: 21 Jul 2008 16:43 Modified: 17 Jan 2014 9:48
Reporter: Mark Callaghan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S4 (Feature request)
Version:5.0.62 OS:Any
Assigned to: Heikki Tuuri CPU Architecture:Any
Tags: innodb, local, thread

[21 Jul 2008 16:43] Mark Callaghan
Description:
The thread local support in InnoDB doesn't scale on SMP. There is one mutex that  must be locked to access thread local storage. Percona added a patch (micro slow or IO accounting) that uses this more frequently than the current code in InnoDB.

ulint
thr_local_get_slot_no(
/*==================*/
                                /* out: slot number */
        os_thread_id_t  id)     /* in: thread id of the thread */
{
        ulint           slot_no;
        thr_local_t*    local;

        mutex_enter(&thr_local_mutex);

        local = thr_local_get(id);

        slot_no = local->slot_no;

        mutex_exit(&thr_local_mutex);

        return(slot_no);
}

How to repeat:
Read the code in innobase/thr/thr0loc.c

Suggested fix:
Use pthread_setspecific
[22 Jul 2008 18:25] MySQL Verification Team
Thank you for the bug report.
[24 Oct 2008 13:23] Heikki Tuuri
InnoDB's own 'thread local storage' is inefficient and only to be used if no top performance is needed.

We could use MySQL's thread local storage machinery to implement fast thread local variables.

Marking this as a feature request as this would involve some new code.
[17 Jan 2014 9:48] Marko Mäkelä
I fixed this in MySQL 5.5.12:
Bug#59392 Remove thr0loc.c and ibuf_inside()