Re: [PATCH v3 1/2] kernfs: use hashed mutex and spinlock in place of global ones.
From: Tejun Heo
Date: Thu Jan 13 2022 - 11:37:51 EST
Hello,
On Thu, Jan 13, 2022 at 09:42:58PM +1100, Imran Khan wrote:
> +#ifdef CONFIG_SMP
> +#define NR_KERNFS_LOCK_BITS (2 * (ilog2(NR_CPUS < 32 ? NR_CPUS : 32)))
How did the 32 limit come to be? It'd be nice to have a comment explaining
that this is something which affects scalability and brief rationale on the
current number.
> +static inline spinlock_t *open_node_lock_ptr(struct kernfs_node *kn)
> +{
> + int index = hash_ptr(kn, NR_KERNFS_LOCK_BITS);
> +
> + return &kernfs_global_locks.open_node_locks[index].lock;
> +}
> +
> +static inline struct mutex *open_file_mutex_ptr(struct kernfs_node *kn)
> +{
> + int index = hash_ptr(kn, NR_KERNFS_LOCK_BITS);
> +
> + return &kernfs_global_locks.open_file_mutex[index].lock;
> +}
I wonder whether it'd be useful to provide some helpers so that users don't
have to get the pointer for the lock and then lock it in separate steps.
Would it make sense to provide something which locks and returns the pointer
(or token)?
Thanks.
--
tejun