fs/buffer: Make BH_Uptodate_Lock bit_spin_lock a regular spinlock_t
Subsystems (3)
PATCH 1/1 fs/buffer: Make BH_Uptodate_Lock bit_spin_lock a regular spinlock_t
From: Thomas Gleixner <[email protected]>
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. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.
Substitute the BH_Uptodate_Lock bit spinlock with a regular spinlock.
--- fs/buffer.c | 19 +++++++------------ fs/ext4/page-io.c | 8 +++----- fs/ntfs/aops.c | 9 +++------ include/linux/buffer_head.h | 6 +++--- 4 files changed, 16 insertions(+), 26 deletions(-)
fs/buffer.c +7 -12
@@ -275,8 +275,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)* decide that the page is now completely done. */ first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (bh); tmp = bh;
@@ -289,8 +288,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);/* * If none of the buffers had errors and they are all
@@ -302,8 +300,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }
@@ -331,8 +328,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_write (bh);unlock_buffer (bh);
@@ -344,14 +340,12 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; } -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);end_page_writeback (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }EXPORT_SYMBOL (end_buffer_async_write);
@@ -3420,6 +3414,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)struct buffer_head *ret =kmem_cache_zalloc (bh_cachep, gfp_flags);if (ret) {INIT_LIST_HEAD (&ret->b_assoc_buffers); +spin_lock_init (&ret->uptodate_lock);preempt_disable ();__this_cpu_inc (bh_accounting.nr);recalc_bh_state ();
fs/ext4/page-io.c +3 -5
@@ -87,11 +87,10 @@ static void ext4_finish_bio(struct bio *bio) } bh = head =page_buffers (page);/* -* We check all buffers in the page under BH_Uptodate_Lock +* We check all buffers in the page under uptodate_lock * to avoid races with other end io clearing async_write flags */ -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &head->b_state); +spin_lock_irqsave (&head->uptodate_lock, flags); do { if (bh_offset(bh) < bio_start || bh_offset(bh) + bh->b_size > bio_end) {
@@ -103,8 +102,7 @@ static void ext4_finish_bio(struct bio *bio)if (bio->bi_status)buffer_io_error (bh); }while ((bh = bh->b_this_page) != head); -bit_spin_unlock (BH_Uptodate_Lock, &head->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&head->uptodate_lock, flags);if (!under_io) {fscrypt_free_bounce_page (bounce_page);end_page_writeback (page);
fs/ntfs/aops.c +3 -6
@@ -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); } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (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; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);/* * 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
@@ -142,8 +140,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)unlock_page (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }
include/linux/buffer_head.h +3 -3
@@ -22,9 +22,6 @@ enum bh_state_bits { BH_Dirty,/* Is dirty */ BH_Lock,/* Is locked */ 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_New, /* Disk mapping was newly created by get_block */
@@ -62,6 +59,9 @@ typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);*/ struct buffer_head {unsigned long b_state;/* buffer state bitmap (see above) */ +spinlock_t uptodate_lock;/* Used by the first bh in a page, to +* serialise IO completion of other +* buffers in the page */ struct buffer_head *b_this_page;/* circular list of page's buffers */ struct page *b_page;/* the page this bh is mapped to */
Signature · 1 line
2.23.0.rc1
Quoted 11 lines · Sebastian Siewior
Bit spinlocks are problematic if
PREEMPT_RTis enabled, because they disable preemption, which is undesired for latency reasons and breaks when regular spinlocks are taken within thebit_spinlocklocked region because regular spinlocks are converted to 'sleeping spinlocks' on RT. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.Substitute the
BH_Uptodate_Lockbit spinlock with a regular spinlock.Signed-off-by Thomas Gleixner <[email protected]>[bigeasy: remove the wrapper and use always spinlock_t]
Uhh ... always grow the buffer_head, even for non-PREEMPT_RT? Why?
Quoted 8 lines · Matthew Wilcox
Quoted 7 lines · Sebastian Siewior
Bit spinlocks are problematic if
PREEMPT_RTis enabled, because they disable preemption, which is undesired for latency reasons and breaks when regular spinlocks are taken within thebit_spinlocklocked region because regular spinlocks are converted to 'sleeping spinlocks' on RT. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.
Quoted 6 lines
Quoted 4 lines
Substitute the
BH_Uptodate_Lockbit spinlock with a regular spinlock.Signed-off-by Thomas Gleixner <[email protected]>[bigeasy: remove the wrapper and use always spinlock_t]Uhh ... always grow the
buffer_head, even for non-PREEMPT_RT? Why?
Christoph requested that:
https://lkml.kernel.org/r/[email protected]
Thanks,
tglx
Quoted 11 lines · Thomas Gleixner
Quoted 10 lines · Matthew Wilcox
Quoted 9 lines · Sebastian Siewior
Bit spinlocks are problematic if
PREEMPT_RTis enabled, because they disable preemption, which is undesired for latency reasons and breaks when regular spinlocks are taken within thebit_spinlocklocked region because regular spinlocks are converted to 'sleeping spinlocks' on RT. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.Substitute the
BH_Uptodate_Lockbit spinlock with a regular spinlock.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Thomas Gleixner <[email protected]>[bigeasy: remove the wrapper and use always spinlock_t]Uhh ... always grow the
buffer_head, even for non-PREEMPT_RT? Why?Christoph requested that:
What do we do about this one?
Quoted 3 lines
Thanks,
tglx
Sebastian
Jan Kara
reviewerQuoted 15 lines · Sebastian Siewior
Quoted 14 lines · Thomas Gleixner
Quoted 13 lines · Matthew Wilcox
Quoted 11 lines · Sebastian Siewior
Bit spinlocks are problematic if
PREEMPT_RTis enabled, because they disable preemption, which is undesired for latency reasons and breaks when regular spinlocks are taken within thebit_spinlocklocked region because regular spinlocks are converted to 'sleeping spinlocks' on RT. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.Substitute the
BH_Uptodate_Lockbit spinlock with a regular spinlock.Signed-off-by Thomas Gleixner <[email protected]>[bigeasy: remove the wrapper and use always spinlock_t]
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Uhh ... always grow the
buffer_head, even for non-PREEMPT_RT? Why?Christoph requested that:
What do we do about this one?
I was thinking about this for quite some time. In the end I think the patch is almost fine but I'd name the lock b_update_lock and put it just after b_size element in struct buffer_head to use the hole there. That way we don't grow struct buffer_head.
With some effort, we could even shrink struct buffer_head from 104 bytes (on x86_64) to 96 bytes but I don't think that effort is worth it (I'd find it better use of time to actually work on getting rid of buffer heads completely).
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Theodore Y. Ts'o
maintainerQuoted 4 lines · Jan Kara
With some effort, we could even shrink struct
buffer_headfrom 104 bytes (onx86_64) to 96 bytes but I don't think that effort is worth it (I'd find it better use of time to actually work on getting rid of buffer heads completely).
Is that really realistic? All aside from the very large number of file systems which use buffer_heads that would have to be reworked, the concept of buffer heads is pretty fundamental to how jbd2 is architected.
- Ted
Jan Kara
reviewerQuoted 10 lines · Theodore Y. Ts'o
Quoted 4 lines · Jan Kara
With some effort, we could even shrink struct
buffer_headfrom 104 bytes (onx86_64) to 96 bytes but I don't think that effort is worth it (I'd find it better use of time to actually work on getting rid of buffer heads completely).Is that really realistic? All aside from the very large number of file systems which use
buffer_headsthat would have to be reworked, the concept of buffer heads is pretty fundamental to how jbd2 is architected.
I think it is reasonably possible to remove buffer_heads from data path (including direct IO path) of all filesystems. That way memory consumption of buffer_heads becomes mostly irrelevant and we can have a look how much from the current bh framework still makes sense...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v2 1/1 fs/buffer: Make BH_Uptodate_Lock bit_spin_lock a regular spinlock_t
In reply to Jan KaraFrom: Thomas Gleixner <[email protected]>
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. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.
Substitute the BH_Uptodate_Lock bit spinlock with a regular spinlock.
[bigeasy: remove the wrapper and use always spinlock_t and move it into
the padding hole]
---
v1…v2: Move the spinlock_t to the padding hole as per Jan Kara. pahole says its total size remained unchanged, before
| atomic_t b_count; /* 96 4 */ | | /* size: 104, cachelines: 2, members: 12 */ | /* padding: 4 */ | /* last cacheline: 40 bytes */
after
| atomic_t b_count; /* 96 4 */ | spinlock_t uptodate_lock; /* 100 4 */ | | /* size: 104, cachelines: 2, members: 13 */ | /* last cacheline: 40 bytes */
fs/buffer.c | 19 +++++++------------ fs/ext4/page-io.c | 8 +++----- fs/ntfs/aops.c | 9 +++------ include/linux/buffer_head.h | 6 +++--- 4 files changed, 16 insertions(+), 26 deletions(-)
fs/buffer.c +7 -12
@@ -277,8 +277,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)* decide that the page is now completely done. */ first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (bh); tmp = bh;
@@ -291,8 +290,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);/* * If none of the buffers had errors and they are all
@@ -304,8 +302,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }
@@ -333,8 +330,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_write (bh);unlock_buffer (bh);
@@ -346,14 +342,12 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; } -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);end_page_writeback (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }EXPORT_SYMBOL (end_buffer_async_write);
@@ -3422,6 +3416,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)struct buffer_head *ret =kmem_cache_zalloc (bh_cachep, gfp_flags);if (ret) {INIT_LIST_HEAD (&ret->b_assoc_buffers); +spin_lock_init (&ret->uptodate_lock);preempt_disable ();__this_cpu_inc (bh_accounting.nr);recalc_bh_state ();
fs/ext4/page-io.c +3 -5
@@ -125,11 +125,10 @@ static void ext4_finish_bio(struct bio *bio) } bh = head =page_buffers (page);/* -* We check all buffers in the page under BH_Uptodate_Lock +* We check all buffers in the page under uptodate_lock * to avoid races with other end io clearing async_write flags */ -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &head->b_state); +spin_lock_irqsave (&head->uptodate_lock, flags); do { if (bh_offset(bh) < bio_start || bh_offset(bh) + bh->b_size > bio_end) {
@@ -141,8 +140,7 @@ static void ext4_finish_bio(struct bio *bio)if (bio->bi_status)buffer_io_error (bh); }while ((bh = bh->b_this_page) != head); -bit_spin_unlock (BH_Uptodate_Lock, &head->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&head->uptodate_lock, flags);if (!under_io) {fscrypt_free_bounce_page (bounce_page);end_page_writeback (page);
fs/ntfs/aops.c +3 -6
@@ -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); } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (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; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);/* * 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
@@ -142,8 +140,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)unlock_page (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }
include/linux/buffer_head.h +3 -3
@@ -22,9 +22,6 @@ enum bh_state_bits { BH_Dirty,/* Is dirty */ BH_Lock,/* Is locked */ 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_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 associated with */ atomic_t b_count;/* users using this buffer_head */ +spinlock_t uptodate_lock;/* Used by the first bh in a page, to +* serialise IO completion of other +* buffers in the page */ };/*
Signature · 1 line
2.24.0
Quoted 26 lines · Sebastian Siewior
From: Thomas Gleixner <[email protected]>
Bit spinlocks are problematic if
PREEMPT_RTis enabled, because they disable preemption, which is undesired for latency reasons and breaks when regular spinlocks are taken within thebit_spinlocklocked region because regular spinlocks are converted to 'sleeping spinlocks' on RT. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.Substitute the
BH_Uptodate_Lockbit spinlock with a regular spinlock.Signed-off-by Thomas Gleixner <[email protected]>[bigeasy: remove the wrapper and use always
spinlock_tand move it into
the padding hole]Signed-off-by Sebastian Andrzej Siewior <[email protected]>---
v1…v2: Move the
spinlock_tto the padding hole as per Jan Kara. pahole says its total size remained unchanged, before| atomic_t b_count; /* 96 4 */ | | /* size: 104, cachelines: 2, members: 12 */ | /* padding: 4 */ | /* last cacheline: 40 bytes */
Quoted 7 lines
after
| atomic_t b_count; /* 96 4 */ | spinlock_t uptodate_lock; /* 100 4 */ | | /* size: 104, cachelines: 2, members: 13 */ | /* last cacheline: 40 bytes */
To follow the naming of other members in struct buffer_head, please name this b_uptodate_lock (note the b_ prefix). Otherwise the patch looks good to me so feel free to add:
after fixing this.
Honza
Quoted 165 lines
fs/buffer.c | 19 +++++++------------ fs/ext4/page-io.c | 8 +++----- fs/ntfs/aops.c | 9 +++------ include/linux/buffer_head.h | 6 +++--- 4 files changed, 16 insertions(+), 26 deletions(-)fs/buffer.c +7
-12@@ -277,8 +277,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)* decide that the page is now completely done. */ first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (bh); tmp = bh;@@ -291,8 +290,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);/* * If none of the buffers had errors and they are all @@ -304,8 +302,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }@@ -333,8 +330,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_write (bh);unlock_buffer (bh);@@ -346,14 +342,12 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; } -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);end_page_writeback (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }EXPORT_SYMBOL (end_buffer_async_write);@@ -3422,6 +3416,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)struct buffer_head *ret =kmem_cache_zalloc (bh_cachep, gfp_flags);if (ret) {INIT_LIST_HEAD (&ret->b_assoc_buffers); +spin_lock_init (&ret->uptodate_lock);preempt_disable ();__this_cpu_inc (bh_accounting.nr);recalc_bh_state ();fs/ext4/page-io.c +3
-5@@ -125,11 +125,10 @@ static void ext4_finish_bio(struct bio *bio) } bh = head =page_buffers (page);/* -* We check all buffers in the page under BH_Uptodate_Lock +* We check all buffers in the page under uptodate_lock * to avoid races with other end io clearing async_write flags */ -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &head->b_state); +spin_lock_irqsave (&head->uptodate_lock, flags); do { if (bh_offset(bh) < bio_start || bh_offset(bh) + bh->b_size > bio_end) {@@ -141,8 +140,7 @@ static void ext4_finish_bio(struct bio *bio)if (bio->bi_status)buffer_io_error (bh); }while ((bh = bh->b_this_page) != head); -bit_spin_unlock (BH_Uptodate_Lock, &head->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&head->uptodate_lock, flags);if (!under_io) {fscrypt_free_bounce_page (bounce_page);end_page_writeback (page);fs/ntfs/aops.c +3
-6@@ -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); } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (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; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);/* * 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 @@ -142,8 +140,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)unlock_page (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->uptodate_lock, flags);return ; }include/linux/buffer_head.h +3
-3@@ -22,9 +22,6 @@ enum bh_state_bits { BH_Dirty,/* Is dirty */ BH_Lock,/* Is locked */ 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_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 associated with */ atomic_t b_count;/* users using this buffer_head */ +spinlock_t uptodate_lock;/* Used by the first bh in a page, to +* serialise IO completion of other +* buffers in the page */ };/* Signature · 1 line
2.24.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v3 1/1 fs/buffer: Make BH_Uptodate_Lock bit_spin_lock a regular spinlock_t
From: Thomas Gleixner <[email protected]>
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. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.
Substitute the BH_Uptodate_Lock bit spinlock with a regular spinlock.
[bigeasy: remove the wrapper and use always spinlock_t and move it into
the padding hole]
---
v2…v3: rename uptodate_lock to b_uptodate_lock.
v1…v2: Move the spinlock_t to the padding hole as per Jan Kara. pahole says its total size remained unchanged, before
| atomic_t b_count; /* 96 4 */ | | /* size: 104, cachelines: 2, members: 12 */ | /* padding: 4 */ | /* last cacheline: 40 bytes */
after
| atomic_t b_count; /* 96 4 */ | spinlock_t uptodate_lock; /* 100 4 */ | | /* size: 104, cachelines: 2, members: 13 */ | /* last cacheline: 40 bytes */
fs/buffer.c | 19 +++++++------------ fs/ext4/page-io.c | 8 +++----- fs/ntfs/aops.c | 9 +++------ include/linux/buffer_head.h | 6 +++--- 4 files changed, 16 insertions(+), 26 deletions(-)
fs/buffer.c +7 -12
@@ -275,8 +275,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)* decide that the page is now completely done. */ first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (bh); tmp = bh;
@@ -289,8 +288,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);/* * If none of the buffers had errors and they are all
@@ -302,8 +300,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }
@@ -331,8 +328,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_write (bh);unlock_buffer (bh);
@@ -344,14 +340,12 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; } -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);end_page_writeback (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }EXPORT_SYMBOL (end_buffer_async_write);
@@ -3368,6 +3362,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)struct buffer_head *ret =kmem_cache_zalloc (bh_cachep, gfp_flags);if (ret) {INIT_LIST_HEAD (&ret->b_assoc_buffers); +spin_lock_init (&ret->b_uptodate_lock);preempt_disable ();__this_cpu_inc (bh_accounting.nr);recalc_bh_state ();
fs/ext4/page-io.c +3 -5
@@ -87,11 +87,10 @@ static void ext4_finish_bio(struct bio *bio) } 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 */ -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &head->b_state); +spin_lock_irqsave (&head->b_uptodate_lock, flags); do { if (bh_offset(bh) < bio_start || bh_offset(bh) + bh->b_size > bio_end) {
@@ -103,8 +102,7 @@ static void ext4_finish_bio(struct bio *bio)if (bio->bi_status)buffer_io_error (bh); }while ((bh = bh->b_this_page) != head); -bit_spin_unlock (BH_Uptodate_Lock, &head->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&head->b_uptodate_lock, flags);if (!under_io) {fscrypt_free_bounce_page (bounce_page);end_page_writeback (page);
fs/ntfs/aops.c +3 -6
@@ -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); } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (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; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);/* * 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
@@ -142,8 +140,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)unlock_page (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }
include/linux/buffer_head.h +3 -3
@@ -22,9 +22,6 @@ enum bh_state_bits { BH_Dirty,/* Is dirty */ BH_Lock,/* Is locked */ 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_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 associated with */ 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 */ };/*
Signature · 1 line
2.24.0
Jan Kara
reviewerQuoted 9 lines · Sebastian Siewior
From: Thomas Gleixner <[email protected]>
Bit spinlocks are problematic if
PREEMPT_RTis enabled, because they disable preemption, which is undesired for latency reasons and breaks when regular spinlocks are taken within thebit_spinlocklocked region because regular spinlocks are converted to 'sleeping spinlocks' on RT. So RT replaces the bit spinlocks with regular spinlocks to avoid this problem. Bit spinlocks are also not covered by lock debugging, e.g. lockdep.
Quoted 7 lines
Substitute the
BH_Uptodate_Lockbit spinlock with a regular spinlock.Reviewed-by Jan Kara <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>[bigeasy: remove the wrapper and use always
spinlock_tand move it into
the padding hole]Signed-off-by Sebastian Andrzej Siewior <[email protected]>
OK, how do we push this? Do you plan to push this through tip tree?
Honza
Quoted 184 lines
---
v2…v3: renameuptodate_locktob_uptodate_lock.v1…v2: Move the
spinlock_tto the padding hole as per Jan Kara. pahole says its total size remained unchanged, before| atomic_t b_count; /* 96 4 */ | | /* size: 104, cachelines: 2, members: 12 */ | /* padding: 4 */ | /* last cacheline: 40 bytes */after
| atomic_t b_count; /* 96 4 */ | spinlock_t uptodate_lock; /* 100 4 */ | | /* size: 104, cachelines: 2, members: 13 */ | /* last cacheline: 40 bytes */fs/buffer.c | 19 +++++++------------ fs/ext4/page-io.c | 8 +++----- fs/ntfs/aops.c | 9 +++------ include/linux/buffer_head.h | 6 +++--- 4 files changed, 16 insertions(+), 26 deletions(-)fs/buffer.c +7
-12@@ -275,8 +275,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)* decide that the page is now completely done. */ first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (bh); tmp = bh;@@ -289,8 +288,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);/* * If none of the buffers had errors and they are all @@ -302,8 +300,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }@@ -331,8 +328,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_write (bh);unlock_buffer (bh);@@ -344,14 +340,12 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; } -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);end_page_writeback (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }EXPORT_SYMBOL (end_buffer_async_write);@@ -3368,6 +3362,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)struct buffer_head *ret =kmem_cache_zalloc (bh_cachep, gfp_flags);if (ret) {INIT_LIST_HEAD (&ret->b_assoc_buffers); +spin_lock_init (&ret->b_uptodate_lock);preempt_disable ();__this_cpu_inc (bh_accounting.nr);recalc_bh_state ();fs/ext4/page-io.c +3
-5@@ -87,11 +87,10 @@ static void ext4_finish_bio(struct bio *bio) } 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 */ -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &head->b_state); +spin_lock_irqsave (&head->b_uptodate_lock, flags); do { if (bh_offset(bh) < bio_start || bh_offset(bh) + bh->b_size > bio_end) {@@ -103,8 +102,7 @@ static void ext4_finish_bio(struct bio *bio)if (bio->bi_status)buffer_io_error (bh); }while ((bh = bh->b_this_page) != head); -bit_spin_unlock (BH_Uptodate_Lock, &head->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&head->b_uptodate_lock, flags);if (!under_io) {fscrypt_free_bounce_page (bounce_page);end_page_writeback (page);fs/ntfs/aops.c +3
-6@@ -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); } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (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; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);/* * 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 @@ -142,8 +140,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)unlock_page (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }include/linux/buffer_head.h +3
-3@@ -22,9 +22,6 @@ enum bh_state_bits { BH_Dirty,/* Is dirty */ BH_Lock,/* Is locked */ 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_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 associated with */ 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 */ };/* Signature · 1 line
2.24.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line · Jan Kara
OK, how do we push this? Do you plan to push this through tip tree?
Is it reasonable to push this via the ext4 tree?
Quoted 1 line
Honza
Sebastian
Jan Kara
reviewerQuoted 4 lines · Sebastian Siewior
Quoted 1 line · Jan Kara
OK, how do we push this? Do you plan to push this through tip tree?
Is it reasonable to push this via the ext4 tree?
I don't know and I don't think it largely matters. That code is rarely touched. Lately changes to that code have been flowing through block tree (Jens Axboe) or iomap tree (Darrick Wong) because those were the people needing the changes in...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: f1e67e355c2aafeddf1eac31335709236996d2fe Gitweb: https://git.kernel.org/tip/f1e67e355c2aafeddf1eac31335709236996d2fe Author: Thomas Gleixner <[email protected]> AuthorDate: Mon, 18 Nov 2019 14:28:24 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Sat, 28 Mar 2020 13:21:08 +01:00
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 ]
--- fs/buffer.c | 19 +++++++------------ fs/ext4/page-io.c | 8 +++----- fs/ntfs/aops.c | 9 +++------ include/linux/buffer_head.h | 6 +++--- 4 files changed, 16 insertions(+), 26 deletions(-)
fs/buffer.c +7 -12
@@ -274,8 +274,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)* decide that the page is now completely done. */ first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (bh); tmp = bh;
@@ -288,8 +287,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);/* * 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 ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }
@@ -371,8 +368,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_write (bh);unlock_buffer (bh);
@@ -384,14 +380,12 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) } tmp = tmp->b_this_page; } -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);end_page_writeback (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }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);if (ret) {INIT_LIST_HEAD (&ret->b_assoc_buffers); +spin_lock_init (&ret->b_uptodate_lock);preempt_disable ();__this_cpu_inc (bh_accounting.nr);recalc_bh_state ();
fs/ext4/page-io.c +3 -5
@@ -125,11 +125,10 @@ static void ext4_finish_bio(struct bio *bio) } 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 */ -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &head->b_state); +spin_lock_irqsave (&head->b_uptodate_lock, flags); do { if (bh_offset(bh) < bio_start || bh_offset(bh) + bh->b_size > bio_end) {
@@ -141,8 +140,7 @@ static void ext4_finish_bio(struct bio *bio)if (bio->bi_status)buffer_io_error (bh); }while ((bh = bh->b_this_page) != head); -bit_spin_unlock (BH_Uptodate_Lock, &head->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&head->b_uptodate_lock, flags);if (!under_io) {fscrypt_free_bounce_page (bounce_page);end_page_writeback (page);
fs/ntfs/aops.c +3 -6
@@ -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); } first =page_buffers (page); -local_irq_save (flags); -bit_spin_lock (BH_Uptodate_Lock, &first->b_state); +spin_lock_irqsave (&first->b_uptodate_lock, flags);clear_buffer_async_read (bh);unlock_buffer (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; }while (tmp != bh); -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);/* * 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
@@ -142,8 +140,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)unlock_page (page);return ; still_busy: -bit_spin_unlock (BH_Uptodate_Lock, &first->b_state); -local_irq_restore (flags); +spin_unlock_irqrestore (&first->b_uptodate_lock, flags);return ; }
include/linux/buffer_head.h +3 -3
@@ -22,9 +22,6 @@ enum bh_state_bits { BH_Dirty,/* Is dirty */ BH_Lock,/* Is locked */ 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_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 associated with */ 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 */ };/*