Re: [PATCH 2/2] rwsem: do optimistic spinning for writer lock acquisition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/24/2013 04:17 PM, Tim Chen wrote:
On Mon, 2013-06-24 at 14:49 -0400, Peter Hurley wrote:
On 06/24/2013 01:11 PM, Tim Chen wrote:
On Sun, 2013-06-23 at 13:03 -0700, Davidlohr Bueso wrote:
On Sat, 2013-06-22 at 03:57 -0400, Peter Hurley wrote:
On 06/21/2013 07:51 PM, Tim Chen wrote:

+static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem)
+{
+	int retval = true;
+
+	/* Spin only if active writer running */
+	if (!sem->owner)
+		return false;
+
+	rcu_read_lock();
+	if (sem->owner)
+		retval = sem->owner->on_cpu;
                            ^^^^^^^^^^^^^^^^^^

Why is this a safe dereference? Could not another cpu have just
dropped the sem (and thus set sem->owner to NULL and oops)?


The rcu read lock should protect against sem->owner being NULL.

It doesn't.

Here's the comment from mutex_spin_on_owner():

    /*
     * Look out! "owner" is an entirely speculative pointer
     * access and not reliable.
     */

On second thought, I agree with you.  I should change this to
something like

	int retval = true;
	task_struct *sem_owner;

	/* Spin only if active writer running */
	if (!sem->owner)
		return false;

	rcu_read_lock();
	sem_owner = sem->owner;
	if (sem_owner)
		retval = sem_owner->on_cpu;


Our emails passed each other.

Also, I haven't given a lot of thought to if preemption must be disabled
before calling rwsem_can_spin_on_owner(). If so, wouldn't you just drop
rwsem_can_spin_on_owner() (because the conditions tested in the loop are
equivalent)?

Regards,
Peter Hurley


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]