fs/buffer: Make BH_Uptodate_Lock bit_spin_lock a regular spinlock_t

Bit spinlocks are problematic if PREEMPT_RT is enabled, because they
disable preemption, which is undesired for latency reasons and breaks when
regular spinlocks are taken within the bit_spinlock locked region because
regular spinlocks are converted to 'sleeping spinlocks' on RT.

PREEMPT_RT replaced the bit spinlocks with regular spinlocks to avoid this
problem. The replacement was done conditionaly at compile time, but
Christoph requested to do an unconditional conversion.

Jan suggested to move the spinlock into a existing padding hole which
avoids a size increase of struct buffer_head on production kernels.

As a benefit the lock gains lockdep coverage.

[ bigeasy: Remove the wrapper and use always spinlock_t and move it into
           the padding hole ]

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@infradead.org>
Link: https://lkml.kernel.org/r/20191118132824.rclhrbujqh4b4g4d@linutronix.de
This commit is contained in:
Thomas Gleixner 2019-11-18 14:28:24 +01:00
parent fc32150e6f
commit f1e67e355c
4 changed files with 16 additions and 26 deletions

View File

@ -274,8 +274,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
* decide that the page is now completely done. * decide that the page is now completely done.
*/ */
first = page_buffers(page); first = page_buffers(page);
local_irq_save(flags); spin_lock_irqsave(&first->b_uptodate_lock, flags);
bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
clear_buffer_async_read(bh); clear_buffer_async_read(bh);
unlock_buffer(bh); unlock_buffer(bh);
tmp = bh; tmp = bh;
@ -288,8 +287,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
} }
tmp = tmp->b_this_page; tmp = tmp->b_this_page;
} while (tmp != bh); } while (tmp != bh);
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state); spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
local_irq_restore(flags);
/* /*
* If none of the buffers had errors and they are all * If none of the buffers had errors and they are all
@ -301,8 +299,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
return; return;
still_busy: still_busy:
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state); spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
local_irq_restore(flags);
return; return;
} }
@ -371,8 +368,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate)
} }
first = page_buffers(page); first = page_buffers(page);
local_irq_save(flags); spin_lock_irqsave(&first->b_uptodate_lock, flags);
bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
clear_buffer_async_write(bh); clear_buffer_async_write(bh);
unlock_buffer(bh); unlock_buffer(bh);
@ -384,14 +380,12 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate)
} }
tmp = tmp->b_this_page; tmp = tmp->b_this_page;
} }
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state); spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
local_irq_restore(flags);
end_page_writeback(page); end_page_writeback(page);
return; return;
still_busy: still_busy:
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state); spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
local_irq_restore(flags);
return; return;
} }
EXPORT_SYMBOL(end_buffer_async_write); EXPORT_SYMBOL(end_buffer_async_write);
@ -3385,6 +3379,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags); struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
if (ret) { if (ret) {
INIT_LIST_HEAD(&ret->b_assoc_buffers); INIT_LIST_HEAD(&ret->b_assoc_buffers);
spin_lock_init(&ret->b_uptodate_lock);
preempt_disable(); preempt_disable();
__this_cpu_inc(bh_accounting.nr); __this_cpu_inc(bh_accounting.nr);
recalc_bh_state(); recalc_bh_state();

View File

@ -125,11 +125,10 @@ static void ext4_finish_bio(struct bio *bio)
} }
bh = head = page_buffers(page); bh = head = page_buffers(page);
/* /*
* We check all buffers in the page under BH_Uptodate_Lock * We check all buffers in the page under b_uptodate_lock
* to avoid races with other end io clearing async_write flags * to avoid races with other end io clearing async_write flags
*/ */
local_irq_save(flags); spin_lock_irqsave(&head->b_uptodate_lock, flags);
bit_spin_lock(BH_Uptodate_Lock, &head->b_state);
do { do {
if (bh_offset(bh) < bio_start || if (bh_offset(bh) < bio_start ||
bh_offset(bh) + bh->b_size > bio_end) { bh_offset(bh) + bh->b_size > bio_end) {
@ -141,8 +140,7 @@ static void ext4_finish_bio(struct bio *bio)
if (bio->bi_status) if (bio->bi_status)
buffer_io_error(bh); buffer_io_error(bh);
} while ((bh = bh->b_this_page) != head); } while ((bh = bh->b_this_page) != head);
bit_spin_unlock(BH_Uptodate_Lock, &head->b_state); spin_unlock_irqrestore(&head->b_uptodate_lock, flags);
local_irq_restore(flags);
if (!under_io) { if (!under_io) {
fscrypt_free_bounce_page(bounce_page); fscrypt_free_bounce_page(bounce_page);
end_page_writeback(page); end_page_writeback(page);

View File

@ -92,8 +92,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
"0x%llx.", (unsigned long long)bh->b_blocknr); "0x%llx.", (unsigned long long)bh->b_blocknr);
} }
first = page_buffers(page); first = page_buffers(page);
local_irq_save(flags); spin_lock_irqsave(&first->b_uptodate_lock, flags);
bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
clear_buffer_async_read(bh); clear_buffer_async_read(bh);
unlock_buffer(bh); unlock_buffer(bh);
tmp = bh; tmp = bh;
@ -108,8 +107,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
} }
tmp = tmp->b_this_page; tmp = tmp->b_this_page;
} while (tmp != bh); } while (tmp != bh);
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state); spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
local_irq_restore(flags);
/* /*
* If none of the buffers had errors then we can set the page uptodate, * If none of the buffers had errors then we can set the page uptodate,
* but we first have to perform the post read mst fixups, if the * but we first have to perform the post read mst fixups, if the
@ -142,8 +140,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
unlock_page(page); unlock_page(page);
return; return;
still_busy: still_busy:
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state); spin_unlock_irqrestore(&first->b_uptodate_lock, flags);
local_irq_restore(flags);
return; return;
} }

View File

@ -22,9 +22,6 @@ enum bh_state_bits {
BH_Dirty, /* Is dirty */ BH_Dirty, /* Is dirty */
BH_Lock, /* Is locked */ BH_Lock, /* Is locked */
BH_Req, /* Has been submitted for I/O */ BH_Req, /* Has been submitted for I/O */
BH_Uptodate_Lock,/* Used by the first bh in a page, to serialise
* IO completion of other buffers in the page
*/
BH_Mapped, /* Has a disk mapping */ BH_Mapped, /* Has a disk mapping */
BH_New, /* Disk mapping was newly created by get_block */ BH_New, /* Disk mapping was newly created by get_block */
@ -76,6 +73,9 @@ struct buffer_head {
struct address_space *b_assoc_map; /* mapping this buffer is struct address_space *b_assoc_map; /* mapping this buffer is
associated with */ associated with */
atomic_t b_count; /* users using this buffer_head */ atomic_t b_count; /* users using this buffer_head */
spinlock_t b_uptodate_lock; /* Used by the first bh in a page, to
* serialise IO completion of other
* buffers in the page */
}; };
/* /*