lkml.org 
[lkml]   [2014]   [Sep]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 5/5] rhashtable: Per bucket locks & expansion/shrinking in work queue
From
Date
On Mon, 2014-09-15 at 14:18 +0200, Thomas Graf wrote:

> +static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl)
> +{
> + unsigned int i, size;
> +#if defined(CONFIG_PROVE_LOCKING)
> + unsigned int nr_pcpus = 2;
> +#else
> + unsigned int nr_pcpus = num_possible_cpus();
> +#endif
> +
> + nr_pcpus = min_t(unsigned int, nr_pcpus, 32UL);
> + size = nr_pcpus * ht->p.locks_mul;
> +

You need to roundup to next power of two.

> + if (sizeof(spinlock_t) != 0) {
> +#ifdef CONFIG_NUMA
> + if (size * sizeof(spinlock_t) > PAGE_SIZE)
> + tbl->locks = vmalloc(size * sizeof(spinlock_t));
> + else
> +#endif
> + tbl->locks = kmalloc_array(size, sizeof(spinlock_t),
> + GFP_KERNEL);
> + if (!tbl->locks)
> + return -ENOMEM;
> + for (i = 0; i < size; i++)
> + spin_lock_init(&tbl->locks[i]);
> + }
> + tbl->locks_mask = size - 1;
> +
> + return 0;
> +}




\
 
 \ /
  Last update: 2014-09-15 18:01    [W:0.950 / U:0.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site