← Back to team overview

maria-developers team mailing list archive

Re: bzr commit into MariaDB 5.1, with Maria 1.5:maria branch (knielsen:2702)

 

Michael Widenius <monty@xxxxxxxxxxxx> writes:

> knielsen> +/*
> knielsen> +  We initialise the hashes for deadlock detection lazily.
> knielsen> +  This greatly helps with performance when lots of mutexes are initiased but
> knielsen> +  only a few of them are actually used (eg. XtraDB).
> knielsen> +*/
> knielsen> +static int safe_mutex_lazy_init_deadlock_detection(safe_mutex_t *mp)
> knielsen> +{
> knielsen> +  if (!my_multi_malloc(MY_FAE | MY_WME,
> knielsen> +                       &mp->locked_mutex, sizeof(*mp->locked_mutex),
> knielsen> +                       &mp->used_mutex, sizeof(*mp->used_mutex), NullS))
> knielsen> +  {
>
> Add:
>    /* Disable deadlock handling for this mutex */
>    mp->flags|= MYF_NO_DEADLOCK_DETECTION;

Ok, done.

(It is not strictly necessary, as the caller checks the return value. The
difference is if in case of out-of-memory, the malloc() will be re-tried on
next access or not. It very likely doesn't matter one way or the other).

> knielsen> @@ -167,35 +196,8 @@ int safe_mutex_init(safe_mutex_t *mp,
> knielsen>    mp->line= line;
> knielsen>    /* Skip the very common '&' prefix from the autogenerated name */
> knielsen>    mp->name= name[0] == '&' ? name + 1 : name;
> knielsen> +  /* Deadlock detection is initialised only lazily, on first use. */
>  
> knielsen> -  if (safe_mutex_deadlock_detector && !( my_flags & MYF_NO_DEADLOCK_DETECTION))
> knielsen> -  {
> knielsen> -    if (!my_multi_malloc(MY_FAE | MY_WME,
> knielsen> -                         &mp->locked_mutex, sizeof(*mp->locked_mutex),
> knielsen> -                         &mp->used_mutex, sizeof(*mp->used_mutex), NullS))
> knielsen> -    {
> knielsen> -      /* Disable deadlock handling for this mutex */
> knielsen> -      my_flags|= MYF_NO_DEADLOCK_DETECTION;
> knielsen> -    }
> knielsen> -    else
> knielsen> -    {
> knielsen> -      pthread_mutex_lock(&THR_LOCK_mutex);
> knielsen> -      mp->id= ++safe_mutex_id;
> knielsen> -      pthread_mutex_unlock(&THR_LOCK_mutex);
> knielsen> -      hash_init(mp->locked_mutex, &my_charset_bin,
> knielsen> -                1000,
> knielsen> -                offsetof(safe_mutex_deadlock_t, id),
> knielsen> -                sizeof(mp->id),
> knielsen> -                0, 0, HASH_UNIQUE);
> knielsen> -      hash_init(mp->used_mutex, &my_charset_bin,
> knielsen> -                1000,
> knielsen> -                offsetof(safe_mutex_t, id),
> knielsen> -                sizeof(mp->id),
> knielsen> -                0, 0, HASH_UNIQUE);
> knielsen> -    }
> knielsen> -  }
> knielsen> -  else
> knielsen> -    my_flags|= MYF_NO_DEADLOCK_DETECTION;
>
> You accidently removed checking of 'safe_mutex_deadlock_detector here.

Oops :-(

Fixed, thanks for catching this!

 - Kristian.



References