Thread (6 messages) flat view 6 messages, 4 authors, 2021-03-29

Re: [RFC PATCH] block: protect bi_status with spinlock

From: Bart Van Assche <bvanassche@acm.org>
Date: 2021-03-29 03:50:12

On 3/28/21 8:02 PM, Keith Busch wrote:
On Sun, Mar 28, 2021 at 10:23:37PM -0400, Yufen Yu wrote:
quoted
 static struct bio *__bio_chain_endio(struct bio *bio)
 {
 	struct bio *parent = bio->bi_private;
+	unsigned long flags;
 
+	spin_lock_irqsave(&parent->bi_lock, flags);
 	if (!parent->bi_status)
 		parent->bi_status = bio->bi_status;
+	spin_unlock_irqrestore(&parent->bi_lock, flags);

I don't see a spin_lock_init() on this new lock, though a spinlock seems
overkill here. If you need an atomic update, you could do:

	cmpxchg(&parent->bi_status, 0, bio->bi_status);
Hmm ... isn't cmpxchg() significantly slower than a spinlock?

Thanks,

Bart.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help