Re: [PATCH 2/2] locking/rwsem: Use a return variable in rwsem_spin_on_owner()

From: Ingo Molnar
Date: Fri Apr 10 2015 - 05:04:52 EST



* Jason Low <jason.low2@xxxxxx> wrote:

> +static inline bool owner_running(struct rw_semaphore *sem, struct task_struct *owner)
> +{
> + bool ret;
> +
> +#ifdef CONFIG_DEBUG_PAGEALLOC
> + rcu_read_lock();
> +#endif
> + if (READ_ONCE(sem->owner) == owner) {
> + /*
> + * Ensure we emit the owner->on_cpu dereference
> + * after checking sem->owner still matches owner.
> + */
> + barrier();
> + ret = owner->on_cpu;
> + } else {
> + /* Owner changed. */
> + ret = false;
> + }
> +
> +#ifdef CONFIG_DEBUG_PAGEALLOC
> + rcu_read_unlock();
> +#endif
> + return ret;
> +}

So I really don't like this due to the assymetric RCU pattern. (Also,
the fact that we might read from already freed kernel memory here
needs big honking comments.)

But, I think we can do this differently, see the patch I just sent:

[PATCH] mutex: Speed up mutex_spin_on_owner() by not taking the RCU lock

that should I think work just as well, without having to introduce
owner_running() as the whole mutex_spin_on_owner() logic is kept
pretty simple.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/