Messages in this thread | | | Subject | Re: [PATCH 5/5] rhashtable: Per bucket locks & expansion/shrinking in work queue | From | Eric Dumazet <> | Date | Mon, 15 Sep 2014 08:23:00 -0700 |
| |
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; > +}
| |