All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dm-block-manager: use spinlocks that don't disable interrupts
@ 2011-09-12 11:24 Mikulas Patocka
  2011-09-12 13:52 ` Joe Thornber
  2011-09-12 13:57 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Mikulas Patocka @ 2011-09-12 11:24 UTC (permalink / raw)
  To: Edward Thornber; +Cc: dm-devel

dm-block-manager: use spinlocks that don't disable interrupts

This will never be called in an interrupt context, so we don't have to use
spinlocks that disable interrupts.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/md/persistent-data/dm-block-manager.c |   35 ++++++++++----------------
 1 file changed, 14 insertions(+), 21 deletions(-)

Index: linux-3.1-rc3-fast/drivers/md/persistent-data/dm-block-manager.c
===================================================================
--- linux-3.1-rc3-fast.orig/drivers/md/persistent-data/dm-block-manager.c	2011-09-12 13:17:44.000000000 +0200
+++ linux-3.1-rc3-fast/drivers/md/persistent-data/dm-block-manager.c	2011-09-12 13:20:01.000000000 +0200
@@ -200,19 +200,18 @@ static int bl_down_read(struct block_loc
 {
 	int r;
 	struct waiter w;
-	unsigned long flags;
 
-	spin_lock_irqsave(&lock->lock, flags);
+	spin_lock(&lock->lock);
 	r = __check_holder(lock);
 	if (r) {
-		spin_unlock_irqrestore(&lock->lock, flags);
+		spin_unlock(&lock->lock);
 		return r;
 	}
 
 	if (__available_for_read(lock)) {
 		lock->count++;
 		__add_holder(lock, current);
-		spin_unlock_irqrestore(&lock->lock, flags);
+		spin_unlock(&lock->lock);
 		return 0;
 	}
 
@@ -221,7 +220,7 @@ static int bl_down_read(struct block_loc
 	w.task = current;
 	w.wants_write = 0;
 	list_add_tail(&w.list, &lock->waiters);
-	spin_unlock_irqrestore(&lock->lock, flags);
+	spin_unlock(&lock->lock);
 
 	__wait(&w);
 	put_task_struct(current);
@@ -231,9 +230,8 @@ static int bl_down_read(struct block_loc
 static int bl_down_read_nonblock(struct block_lock *lock)
 {
 	int r;
-	unsigned long flags;
 
-	spin_lock_irqsave(&lock->lock, flags);
+	spin_lock(&lock->lock);
 	r = __check_holder(lock);
 	if (r)
 		goto out;
@@ -246,40 +244,37 @@ static int bl_down_read_nonblock(struct 
 		r = -EWOULDBLOCK;
 
 out:
-	spin_unlock_irqrestore(&lock->lock, flags);
+	spin_unlock(&lock->lock);
 	return r;
 }
 
 static void bl_up_read(struct block_lock *lock)
 {
-	unsigned long flags;
-
-	spin_lock_irqsave(&lock->lock, flags);
+	spin_lock(&lock->lock);
 	BUG_ON(lock->count <= 0);
 	__del_holder(lock, current);
 	--lock->count;
 	if (!list_empty(&lock->waiters))
 		__wake_many(lock);
-	spin_unlock_irqrestore(&lock->lock, flags);
+	spin_unlock(&lock->lock);
 }
 
 static int bl_down_write(struct block_lock *lock)
 {
 	int r;
 	struct waiter w;
-	unsigned long flags;
 
-	spin_lock_irqsave(&lock->lock, flags);
+	spin_lock(&lock->lock);
 	r = __check_holder(lock);
 	if (r) {
-		spin_unlock_irqrestore(&lock->lock, flags);
+		spin_unlock(&lock->lock);
 		return r;
 	}
 
 	if (lock->count == 0 && list_empty(&lock->waiters)) {
 		lock->count = -1;
 		__add_holder(lock, current);
-		spin_unlock_irqrestore(&lock->lock, flags);
+		spin_unlock(&lock->lock);
 		return 0;
 	}
 
@@ -289,7 +284,7 @@ static int bl_down_write(struct block_lo
 
 	/* writers given priority, we know there's only one mutator in the system, so ignoring the ordering reversal */
 	list_add(&w.list, &lock->waiters);
-	spin_unlock_irqrestore(&lock->lock, flags);
+	spin_unlock(&lock->lock);
 
 	__wait(&w);
 	put_task_struct(current);
@@ -299,14 +294,12 @@ static int bl_down_write(struct block_lo
 
 static void bl_up_write(struct block_lock *lock)
 {
-	unsigned long flags;
-
-	spin_lock_irqsave(&lock->lock, flags);
+	spin_lock(&lock->lock);
 	__del_holder(lock, current);
 	lock->count = 0;
 	if (!list_empty(&lock->waiters))
 		__wake_many(lock);
-	spin_unlock_irqrestore(&lock->lock, flags);
+	spin_unlock(&lock->lock);
 }
 
 static void report_recursive_bug(dm_block_t b, int r)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] dm-block-manager: use spinlocks that don't disable interrupts
  2011-09-12 11:24 [PATCH] dm-block-manager: use spinlocks that don't disable interrupts Mikulas Patocka
@ 2011-09-12 13:52 ` Joe Thornber
  2011-09-12 13:57 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Joe Thornber @ 2011-09-12 13:52 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: dm-devel

On Mon, Sep 12, 2011 at 07:24:48AM -0400, Mikulas Patocka wrote:
> dm-block-manager: use spinlocks that don't disable interrupts
> 
> This will never be called in an interrupt context, so we don't have to use
> spinlocks that disable interrupts.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

yep

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] dm-block-manager: use spinlocks that don't disable interrupts
  2011-09-12 11:24 [PATCH] dm-block-manager: use spinlocks that don't disable interrupts Mikulas Patocka
  2011-09-12 13:52 ` Joe Thornber
@ 2011-09-12 13:57 ` Christoph Hellwig
  2011-09-12 14:11   ` Joe Thornber
  1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2011-09-12 13:57 UTC (permalink / raw)
  To: device-mapper development; +Cc: Edward Thornber

On Mon, Sep 12, 2011 at 07:24:48AM -0400, Mikulas Patocka wrote:
> dm-block-manager: use spinlocks that don't disable interrupts
> 
> This will never be called in an interrupt context, so we don't have to use
> spinlocks that disable interrupts.

The code looks like a re-implementation of rw_semaphores to me.

Is there any good reason to do this? (hint: normally there isn't :))

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] dm-block-manager: use spinlocks that don't disable interrupts
  2011-09-12 13:57 ` Christoph Hellwig
@ 2011-09-12 14:11   ` Joe Thornber
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Thornber @ 2011-09-12 14:11 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: device-mapper development

On Mon, Sep 12, 2011 at 09:57:42AM -0400, Christoph Hellwig wrote:
> On Mon, Sep 12, 2011 at 07:24:48AM -0400, Mikulas Patocka wrote:
> > dm-block-manager: use spinlocks that don't disable interrupts
> > 
> > This will never be called in an interrupt context, so we don't have to use
> > spinlocks that disable interrupts.
> 
> The code looks like a re-implementation of rw_semaphores to me.
> 
> Is there any good reason to do this? (hint: normally there isn't :))

Yes, largely it is.  The major difference is it errors on recursive
use (which can occur due to malicious metadata as well as programming
errors).  This is far better than deadlocking (which rwsemaphores to),
livelocking (which no-locking may do), or not noticing something's
wrong (which no-locking may do).

I can understand that people may well want to turn locking off to get
the better performance.  So there's a Kconfig option for this.

- Joe

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-12 14:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-12 11:24 [PATCH] dm-block-manager: use spinlocks that don't disable interrupts Mikulas Patocka
2011-09-12 13:52 ` Joe Thornber
2011-09-12 13:57 ` Christoph Hellwig
2011-09-12 14:11   ` Joe Thornber

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.