jbd2: Bit spinlock conversions
Subsystems (2)
cover jbd2: Bit spinlock conversions
Hello,
This series is derived from Thomas' series to get rid of bit spinlocks in buffer head code. These patches convert BH_State bit spinlock to an ordinary spinlock inside struct journal_head and somewhat reduce the critical section under BH_JournalHead bit spinlock so that it is fine for RT.
Motivation from original Thomas' series:
Bit spinlocks are problematic if PREEMPT_RT is enabled. 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.
Bit spinlocks are also not covered by lock debugging, e.g. lockdep. With the spinlock substitution in place, they can be exposed via a new config
switch: CONFIG_DEBUG_BIT_SPINLOCKS.
WRT patch routing: Since these are non-trivial changes to JBD2 and independent of the rest of the series from Thomas, I think it would be safest to route them through ext4 tree where they get most testing. Thoughts?
Honza
PATCH 4/7 jbd2: Drop unnecessary branch from jbd2_journal_forget()
We have cleared both dirty & jbddirty bits from the bh. So there's no difference between bforget() and brelse(). Thus there's no point jumping to no_jbd branch.
--- fs/jbd2/transaction.c | 4 ---- 1 file changed, 4 deletions(-)
fs/jbd2/transaction.c +0 -4
@@ -1596,10 +1596,6 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh) }else {__jbd2_journal_unfile_buffer (jh);jbd2_journal_put_journal_head (jh); -if (!buffer_jbd (bh)) { -spin_unlock (&journal->j_list_lock); - goto not_jbd; - } }spin_unlock (&journal->j_list_lock); }else if (jh->b_transaction) {
Signature · 1 line
2.16.4
PATCH 1/7 jbd2: Simplify journal_unmap_buffer()
In reply to Jan KaraFrom: Thomas Gleixner <[email protected]>
journal_unmap_buffer() checks first whether the buffer head is a journal. If so it takes locks and then invokes jbd2_journal_grab_journal_head() followed by another check whether this is journal head buffer.
The double checking is pointless.
Replace the initial check with jbd2_journal_grab_journal_head() which alredy checks whether the buffer head is actually a journal.
Allows also early access to the journal head pointer for the upcoming conversion of state lock to a regular spinlock.
--- fs/jbd2/transaction.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
fs/jbd2/transaction.c +2 -6
@@ -2196,7 +2196,8 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh,* holding the page lock. --sct */ -if (!buffer_jbd (bh)) + jh =jbd2_journal_grab_journal_head (bh); +if (!jh) goto zap_buffer_unlocked;/* OK, we have data buffer in journaled mode */
@@ -2204,10 +2205,6 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh,jbd_lock_bh_state (bh);spin_lock (&journal->j_list_lock); - jh =jbd2_journal_grab_journal_head (bh); -if (!jh) - goto zap_buffer_no_jh; -/* * We cannot remove the buffer from checkpoint lists until the * transaction adding inode to orphan list (let's call it T)
@@ -2329,7 +2326,6 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh,*/ jh->b_modified =0 ;jbd2_journal_put_journal_head (jh); -zap_buffer_no_jh:spin_unlock (&journal->j_list_lock);jbd_unlock_bh_state (bh);write_unlock (&journal->j_state_lock);
Signature · 1 line
2.16.4
PATCH 5/7 jbd2: Don't call __bforget() unnecessarily
In reply to Jan Karajbd2_journal_forget() jumps to 'not_jbd' branch which calls __bforget() in cases where the buffer is clean which is pointless. In case of failed assertion, it can be even argued that it is safer not to touch buffer's dirty bits. Also logically it makes more sense to just jump to 'drop' and that will make logic also simpler when we switch bh_state_lock to a spinlock.
--- fs/jbd2/transaction.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
fs/jbd2/transaction.c +4 -5
@@ -1547,7 +1547,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)if (!J_EXPECT_JH (jh, !jh->b_committed_data,"inconsistent data on disk" )) { err = -EIO ; - goto not_jbd; + goto drop; }/* keep track of whether or not this transaction modified us */
@@ -1637,7 +1637,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)if (!jh->b_cp_transaction) {JBUFFER_TRACE (jh,"belongs to none transaction" );spin_unlock (&journal->j_list_lock); - goto not_jbd; + goto drop; }/*
@@ -1647,7 +1647,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)if (!buffer_dirty (bh)) {__jbd2_journal_remove_checkpoint (jh);spin_unlock (&journal->j_list_lock); - goto not_jbd; + goto drop; }/*
@@ -1660,10 +1660,9 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)__jbd2_journal_file_buffer (jh, transaction, BJ_Forget);spin_unlock (&journal->j_list_lock); } - +drop:jbd_unlock_bh_state (bh);__brelse (bh); -drop:if (drop_reserve) {/* no need to reserve log space for this block -bzzz */ handle->h_buffer_credits++;
Signature · 1 line
2.16.4
PATCH 7/7 jbd2: Free journal head outside of locked region
In reply to Jan KaraFrom: Thomas Gleixner <[email protected]>
On PREEMPT_RT bit-spinlocks have the same semantics as on PREEMPT_RT=n, i.e. they disable preemption. That means functions which are not safe to be called in preempt disabled context on RT trigger a might_sleep() assert.
The journal head bit spinlock is mostly held for short code sequences with trivial RT safe functionality, except for one place:
jbd2_journal_put_journal_head() invokes __journal_remove_journal_head() with the journal head bit spinlock held. __journal_remove_journal_head() invokes kmem_cache_free() which must not be called with preemption disabled on RT.
Jan suggested to rework the removal function so the actual free happens outside the bit-spinlocked region.
Split it into two parts:
- Do the sanity checks and the buffer head detach under the lock
- Do the actual free after dropping the lock
There is error case handling in the free part which needs to dereference the b_size field of the now detached buffer head. Due to paranoia (caused by ignorance) the size is retrieved in the detach function and handed into the free function. Might be over-engineered, but better safe than sorry.
This makes the journal head bit-spinlock usage RT compliant and also avoids nested locking which is not covered by lockdep.
--- fs/jbd2/journal.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
fs/jbd2/journal.c +14 -6
@@ -2533,17 +2533,23 @@ static void __journal_remove_journal_head(struct buffer_head *bh)J_ASSERT_BH (bh,buffer_jbd (bh));J_ASSERT_BH (bh,jh2bh (jh) == bh);BUFFER_TRACE (bh,"remove journal_head" ); + +/* Unlink before dropping the lock */ + bh->b_private =NULL ; + jh->b_bh =NULL ;/* debug, really */ +clear_buffer_jbd (bh); +} + +static void journal_release_journal_head (struct journal_head *jh,size_t b_size) +{if (jh->b_frozen_data) {printk (KERN_WARNING "%s: freeing b_frozen_data\n" , __func__); -jbd2_free (jh->b_frozen_data, bh->b_size); +jbd2_free (jh->b_frozen_data, b_size); }if (jh->b_committed_data) {printk (KERN_WARNING "%s: freeing b_committed_data\n" , __func__); -jbd2_free (jh->b_committed_data, bh->b_size); +jbd2_free (jh->b_committed_data, b_size); } - bh->b_private =NULL ; - jh->b_bh =NULL ;/* debug, really */ -clear_buffer_jbd (bh);journal_free_journal_head (jh); }
@@ -2561,9 +2567,11 @@ void jbd2_journal_put_journal_head(struct journal_head *jh)if (!jh->b_jcount) {__journal_remove_journal_head (bh);jbd_unlock_bh_journal_head (bh); +journal_release_journal_head (jh, bh->b_size);__brelse (bh); - }else + }else {jbd_unlock_bh_journal_head (bh); + } }/*
Signature · 1 line
2.16.4
PATCH 3/7 jbd2: Move dropping of jh reference out of un/re-filing functions
In reply to Jan Kara__jbd2_journal_unfile_buffer() and __jbd2_journal_refile_buffer() drop transaction's jh reference when they remove jh from a transaction. This will be however inconvenient once we move state lock into journal_head itself as we still need to unlock it and we'd need to grab jh reference just for that. Move dropping of jh reference out of these functions into the few callers.
--- fs/jbd2/commit.c | 5 ++++- fs/jbd2/transaction.c | 23 +++++++++++++++-------- include/linux/jbd2.h | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-)
fs/jbd2/commit.c +4 -1
@@ -918,6 +918,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)transaction_t *cp_transaction;struct buffer_head *bh;int try_to_free =0 ; +bool drop_ref; jh = commit_transaction->t_forget;spin_unlock (&journal->j_list_lock);
@@ -1022,8 +1023,10 @@ void jbd2_journal_commit_transaction(journal_t *journal) try_to_free =1 ; }JBUFFER_TRACE (jh,"refile or unfile buffer" ); -__jbd2_journal_refile_buffer (jh); + drop_ref =__jbd2_journal_refile_buffer (jh);jbd_unlock_bh_state (bh); +if (drop_ref) +jbd2_journal_put_journal_head (jh);if (try_to_free)release_buffer_page (bh);/* Drops bh reference */ else
fs/jbd2/transaction.c +15 -8
@@ -1595,6 +1595,7 @@ int jbd2_journal_forget (handle_t *handle, struct buffer_head *bh)__jbd2_journal_file_buffer (jh, transaction, BJ_Forget); }else {__jbd2_journal_unfile_buffer (jh); +jbd2_journal_put_journal_head (jh);if (!buffer_jbd (bh)) {spin_unlock (&journal->j_list_lock); goto not_jbd;
@@ -1968,17 +1969,15 @@ static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh) }/* -* Remove buffer from all transactions. +* Remove buffer from all transactions. The caller is responsible for dropping +* the jh reference that belonged to the transaction. * * Called with bh_state lock and j_list_lock -* -* jh and bh may be already freed when this function returns. */ static void __jbd2_journal_unfile_buffer (struct journal_head *jh) {__jbd2_journal_temp_unlink_buffer (jh); jh->b_transaction =NULL ; -jbd2_journal_put_journal_head (jh); }void jbd2_journal_unfile_buffer (journal_t *journal,struct journal_head *jh)
@@ -1992,6 +1991,7 @@ void jbd2_journal_unfile_buffer(journal_t *journal, struct journal_head *jh)__jbd2_journal_unfile_buffer (jh);spin_unlock (&journal->j_list_lock);jbd_unlock_bh_state (bh); +jbd2_journal_put_journal_head (jh);__brelse (bh); }
@@ -2130,6 +2130,7 @@ static int __dispose_buffer(struct journal_head *jh, transaction_t *transaction) }else {JBUFFER_TRACE (jh,"on running transaction" );__jbd2_journal_unfile_buffer (jh); +jbd2_journal_put_journal_head (jh); }return may_free; }
@@ -2493,9 +2494,11 @@ void jbd2_journal_file_buffer(struct journal_head *jh,* Called under j_list_lock * Called under jbd_lock_bh_state(jh2bh(jh)) * -* jh and bh may be already free when this function returns +* When this function returns true, there's no next transaction to refile to +* and the caller has to drop jh reference through +* jbd2_journal_put_journal_head(). */ -void __jbd2_journal_refile_buffer (struct journal_head *jh) +bool __jbd2_journal_refile_buffer (struct journal_head *jh) {int was_dirty, jlist;struct buffer_head *bh =jh2bh (jh);
@@ -2507,7 +2510,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)/* If the buffer is now unused, just drop it. */ if (jh->b_next_transaction ==NULL ) {__jbd2_journal_unfile_buffer (jh); -return ; +return true; }/*
@@ -2535,6 +2538,7 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)if (was_dirty)set_buffer_jbddirty (bh); +return false; }/*
@@ -2546,15 +2550,18 @@ void __jbd2_journal_refile_buffer(struct journal_head *jh)void jbd2_journal_refile_buffer (journal_t *journal,struct journal_head *jh) {struct buffer_head *bh =jh2bh (jh); +bool drop;/* Get reference so that buffer cannot be freed before we unlock it */ get_bh (bh);jbd_lock_bh_state (bh);spin_lock (&journal->j_list_lock); -__jbd2_journal_refile_buffer (jh); + drop =__jbd2_journal_refile_buffer (jh);jbd_unlock_bh_state (bh);spin_unlock (&journal->j_list_lock);__brelse (bh); +if (drop) +jbd2_journal_put_journal_head (jh); }/*
include/linux/jbd2.h +1 -1
@@ -1252,7 +1252,7 @@ JBD2_FEATURE_INCOMPAT_FUNCS(csum3, CSUM_V3)/* Filing buffers */ extern void jbd2_journal_unfile_buffer (journal_t *,struct journal_head *); -extern void __jbd2_journal_refile_buffer (struct journal_head *); +extern bool __jbd2_journal_refile_buffer (struct journal_head *);extern void jbd2_journal_refile_buffer (journal_t *,struct journal_head *);extern void __jbd2_journal_file_buffer (struct journal_head *,transaction_t *,int );extern void __journal_free_buffer (struct journal_head *bh);
Signature · 1 line
2.16.4
PATCH 6/7 jbd2: Make state lock a spinlock
In reply to Jan KaraFrom: Thomas Gleixner <[email protected]>
Bit-spinlocks are problematic on PREEMPT_RT if functions which might sleep on RT, e.g. spin_lock(), alloc/free(), are invoked inside the lock held region because bit spinlocks disable preemption even on RT.
A first attempt was to replace state lock with a spinlock placed in struct buffer_head and make the locking conditional on PREEMPT_RT and DEBUG_BIT_SPINLOCKS.
Jan pointed out that there is a 4 byte hole in struct journal_head where a regular spinlock fits in and he would not object to convert the state lock to a spinlock unconditionally.
Aside of solving the RT problem, this also gains lockdep coverage for the journal head state lock (bit-spinlocks are not covered by lockdep as it's hard to fit a lockdep map into a single bit).
The trivial change would have been to convert the jbd_*lock_bh_state() inlines, but that comes with the downside that these functions take a buffer head pointer which needs to be converted to a journal head pointer which adds another level of indirection.
As almost all functions which use this lock have a journal head pointer readily available, it makes more sense to remove the lock helper inlines and write out spin_*lock() at all call sites.
Fixup all locking comments as well.
--- fs/jbd2/commit.c | 8 ++-- fs/jbd2/journal.c | 10 +++-- fs/jbd2/transaction.c | 100 ++++++++++++++++++++----------------------- fs/ocfs2/suballoc.c | 19 ++++---- include/linux/jbd2.h | 20 +-------- include/linux/journal-head.h | 19 +++++--- 6 files changed, 82 insertions(+), 94 deletions(-)
fs/jbd2/commit.c +4 -4
@@ -482,10 +482,10 @@ void jbd2_journal_commit_transaction(journal_t *journal)if (jh->b_committed_data) {struct buffer_head *bh =jh2bh (jh); -jbd_lock_bh_state (bh); +spin_lock (&jh->b_state_lock);jbd2_free (jh->b_committed_data, bh->b_size); jh->b_committed_data =NULL ; -jbd_unlock_bh_state (bh); +spin_unlock (&jh->b_state_lock); }jbd2_journal_refile_buffer (journal, jh); }
@@ -928,7 +928,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)* done with it. */ get_bh (bh); -jbd_lock_bh_state (bh); +spin_lock (&jh->b_state_lock);J_ASSERT_JH (jh, jh->b_transaction == commit_transaction);/*
@@ -1024,7 +1024,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) }JBUFFER_TRACE (jh,"refile or unfile buffer" ); drop_ref =__jbd2_journal_refile_buffer (jh); -jbd_unlock_bh_state (bh); +spin_unlock (&jh->b_state_lock);if (drop_ref)jbd2_journal_put_journal_head (jh);if (try_to_free)
fs/jbd2/journal.c +6 -4
@@ -365,7 +365,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,/* keep subsequent assertions sane */ atomic_set (&new_bh->b_count,1 ); -jbd_lock_bh_state (bh_in); +spin_lock (&jh_in->b_state_lock); repeat:/* * If a new transaction has already done a buffer copy-out, then
@@ -407,13 +407,13 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,if (need_copy_out && !done_copy_out) {char *tmp; -jbd_unlock_bh_state (bh_in); +spin_unlock (&jh_in->b_state_lock); tmp =jbd2_alloc (bh_in->b_size,GFP_NOFS );if (!tmp) {brelse (new_bh);return -ENOMEM ; } -jbd_lock_bh_state (bh_in); +spin_lock (&jh_in->b_state_lock);if (jh_in->b_frozen_data) {jbd2_free (tmp, bh_in->b_size); goto repeat;
@@ -466,7 +466,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,__jbd2_journal_file_buffer (jh_in, transaction, BJ_Shadow);spin_unlock (&journal->j_list_lock);set_buffer_shadow (bh_in); -jbd_unlock_bh_state (bh_in); +spin_unlock (&jh_in->b_state_lock);return do_escape | (done_copy_out <<1 ); }
@@ -2412,6 +2412,8 @@ static struct journal_head *journal_alloc_journal_head(void) ret =kmem_cache_zalloc (jbd2_journal_head_cache,GFP_NOFS | __GFP_NOFAIL); } +if (ret) +spin_lock_init (&ret->b_state_lock);return ret; }
fs/jbd2/transaction.c +47 -53
323 lines not on this page · raw message
fs/ocfs2/suballoc.c +11 -8
@@ -1252,6 +1252,7 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh, int nr) {struct ocfs2_group_desc *bg = (struct ocfs2_group_desc *) bg_bh->b_data; +struct journal_head *jh;int ret;if (ocfs2_test_bit (nr, (unsigned long *)bg->bg_bitmap))
@@ -1260,13 +1261,14 @@ static int ocfs2_test_bg_bit_allocatable(struct buffer_head *bg_bh,if (!buffer_jbd (bg_bh))return 1 ; -jbd_lock_bh_state (bg_bh); - bg = (struct ocfs2_group_desc *)bh2jh (bg_bh)->b_committed_data; + jh =bh2jh (bg_bh); +spin_lock (&jh->b_state_lock); + bg = (struct ocfs2_group_desc *) jh->b_committed_data;if (bg) ret = !ocfs2_test_bit (nr, (unsigned long *)bg->bg_bitmap);else ret =1 ; -jbd_unlock_bh_state (bg_bh); +spin_unlock (&jh->b_state_lock);return ret; }
@@ -2387,6 +2389,7 @@ static int ocfs2_block_group_clear_bits(handle_t *handle,int status;unsigned int tmp;struct ocfs2_group_desc *undo_bg =NULL ; +struct journal_head *jh;/* The caller got this descriptor from * ocfs2_read_group_descriptor(). Any corruption is a code bug. */
@@ -2405,10 +2408,10 @@ static int ocfs2_block_group_clear_bits(handle_t *handle, goto bail; } + jh =bh2jh (group_bh);if (undo_fn) { -jbd_lock_bh_state (group_bh); - undo_bg = (struct ocfs2_group_desc *) -bh2jh (group_bh)->b_committed_data; +spin_lock (&jh->b_state_lock); + undo_bg = (struct ocfs2_group_desc *) jh->b_committed_data;BUG_ON (!undo_bg); }
@@ -2423,7 +2426,7 @@ static int ocfs2_block_group_clear_bits(handle_t *handle,le16_add_cpu (&bg->bg_free_bits_count, num_bits);if (le16_to_cpu (bg->bg_free_bits_count) >le16_to_cpu (bg->bg_bits)) {if (undo_fn) -jbd_unlock_bh_state (group_bh); +spin_unlock (&jh->b_state_lock); return ocfs2_error(alloc_inode->i_sb, "Group descriptor # %llu has bit count %u but claims %u are freed. num_bits %d\n", (unsigned long long)le64_to_cpu(bg->bg_blkno), le16_to_cpu(bg->bg_bits),
@@ -2432,7 +2435,7 @@ static int ocfs2_block_group_clear_bits(handle_t *handle, }if (undo_fn) -jbd_unlock_bh_state (group_bh); +spin_unlock (&jh->b_state_lock);ocfs2_journal_dirty (handle, group_bh); bail:
include/linux/jbd2.h +2 -18
@@ -313,7 +313,6 @@ enum jbd_state_bits { BH_Revoked,/* Has been revoked from the log */ BH_RevokeValid,/* Revoked flag is valid */ BH_JBDDirty,/* Is dirty but journaled */ - BH_State,/* Pins most journal_head state */ BH_JournalHead,/* Pins bh->b_private and jh->b_bh */ BH_Shadow,/* IO on shadow buffer is running */ BH_Verified, /* Metadata block has been verified ok */
@@ -342,21 +341,6 @@ static inline struct journal_head *bh2jh(struct buffer_head *bh)return bh->b_private; } -static inline void jbd_lock_bh_state (struct buffer_head *bh) -{ -bit_spin_lock (BH_State, &bh->b_state); -} - -static inline int jbd_is_locked_bh_state (struct buffer_head *bh) -{ -return bit_spin_is_locked (BH_State, &bh->b_state); -} - -static inline void jbd_unlock_bh_state (struct buffer_head *bh) -{ -bit_spin_unlock (BH_State, &bh->b_state); -} -static inline void jbd_lock_bh_journal_head (struct buffer_head *bh) {bit_spin_lock (BH_JournalHead, &bh->b_state);
@@ -551,9 +535,9 @@ struct transaction_chp_stats_s {* ->jbd_lock_bh_journal_head() (This is "innermost") * * j_state_lock -* ->jbd_lock_bh_state() +* ->b_state_lock * -* jbd_lock_bh_state() +* b_state_lock * ->j_list_lock * * j_state_lock
include/linux/journal-head.h +12 -7
@@ -23,6 +23,11 @@ struct journal_head {*/ struct buffer_head *b_bh; +/* +* Protect the buffer head state +*/ +spinlock_t b_state_lock; +/* * Reference count - see description in journal.c * [jbd_lock_bh_journal_head()]
@@ -30,7 +35,7 @@ struct journal_head {int b_jcount;/* -* Journalling list for this buffer [jbd_lock_bh_state()] +* Journalling list for this buffer [b_state_lock] * NOTE: We *cannot* combine this with b_modified into a bitfield * as gcc would then (which the C standard allows but which is * very unuseful) make 64-bit accesses to the bitfield and clobber
@@ -41,20 +46,20 @@ struct journal_head {/* * This flag signals the buffer has been modified by * the currently running transaction -* [jbd_lock_bh_state()] +* [b_state_lock] */ unsigned b_modified;/* * Copy of the buffer data frozen for writing to the log. -* [jbd_lock_bh_state()] +* [b_state_lock] */ char *b_frozen_data;/* * Pointer to a saved copy of the buffer containing no uncommitted * deallocation references, so that allocations can avoid overwriting -* uncommitted deletes. [jbd_lock_bh_state()] +* uncommitted deletes. [b_state_lock] */ char *b_committed_data;
@@ -63,7 +68,7 @@ struct journal_head {* metadata: either the running transaction or the committing * transaction (if there is one). Only applies to buffers on a * transaction's data or metadata journaling list. -* [j_list_lock] [jbd_lock_bh_state()] +* [j_list_lock] [b_state_lock] * Either of these locks is enough for reading, both are needed for * changes. */
@@ -73,13 +78,13 @@ struct journal_head {* Pointer to the running compound transaction which is currently * modifying the buffer's metadata, if there was already a transaction * committing it when the new transaction touched it. -* [t_list_lock] [jbd_lock_bh_state()] +* [t_list_lock] [b_state_lock] */ transaction_t *b_next_transaction;/* * Doubly-linked list of buffers on a transaction's data, metadata or -* forget queue. [t_list_lock] [jbd_lock_bh_state()] +* forget queue. [t_list_lock] [b_state_lock] */ struct journal_head *b_tnext, *b_tprev;
Signature · 1 line
2.16.4
PATCH 2/7 jbd2: Remove jbd_trylock_bh_state()
In reply to Jan KaraFrom: Thomas Gleixner <[email protected]>
No users.
--- include/linux/jbd2.h | 5 ----- 1 file changed, 5 deletions(-)
include/linux/jbd2.h +0 -5
@@ -347,11 +347,6 @@ static inline void jbd_lock_bh_state(struct buffer_head *bh)bit_spin_lock (BH_State, &bh->b_state); } -static inline int jbd_trylock_bh_state (struct buffer_head *bh) -{ -return bit_spin_trylock (BH_State, &bh->b_state); -} -static inline int jbd_is_locked_bh_state (struct buffer_head *bh) {return bit_spin_is_locked (BH_State, &bh->b_state);
Signature · 1 line
2.16.4
Jan,
Quoted 4 lines · Jan Kara
This series is derived from Thomas' series to get rid of bit spinlocks in buffer head code. These patches convert
BH_Statebit spinlock to an ordinary spinlock inside structjournal_headand somewhat reduce the critical section underBH_JournalHeadbit spinlock so that it is fine for RT.
Thanks a lot for cleaning this up!
Quoted 7 lines
Motivation from original Thomas' series:
Bit spinlocks are problematic if
PREEMPT_RTis enabled. 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.
Quoted 7 lines
Bit spinlocks are also not covered by lock debugging, e.g. lockdep. With the spinlock substitution in place, they can be exposed via a new config
switch:CONFIG_DEBUG_BIT_SPINLOCKS.WRT patch routing: Since these are non-trivial changes to JBD2 and independent of the rest of the series from Thomas, I think it would be safest to route them through ext4 tree where they get most testing. Thoughts?
Yes, there is no dependency, so feel free to route it through ext4.
Thanks,
tglx
kbuild test robot
build botRe: [PATCH 6/7] jbd2: Make state lock a spinlock
In reply to Jan KaraI love your patch! Yet something to improve:
Hi Jan,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc3 next-20190807]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Jan-Kara/jbd2-Bit-spinlock-conversions/20190804-170656
config: i386-randconfig-h002-201931 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:
# save the attached .config to linux build tree
make ARCH=i386 If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
In file included from <command-line>:0:0:
>> include/linux/journal-head.h:29:2: error: unknown type name 'spinlock_t'
spinlock_t b_state_lock;
^~~~~~~~~~vim +/spinlock_t +29 include/linux/journal-head.h
19
20 struct journal_head {
21 /*
22 * Points back to our buffer_head. [jbd_lock_bh_journal_head()]
23 */
24 struct buffer_head *b_bh;
25
26 /*
27 * Protect the buffer head state
28 */
> 29 spinlock_t b_state_lock;
30
31 /*
32 * Reference count - see description in journal.c
33 * [jbd_lock_bh_journal_head()]
34 */
35 int b_jcount;
36
37 /*
38 * Journalling list for this buffer [b_state_lock]
39 * NOTE: We *cannot* combine this with b_modified into a bitfield
40 * as gcc would then (which the C standard allows but which is
41 * very unuseful) make 64-bit accesses to the bitfield and clobber
42 * b_jcount if its update races with bitfield modification.
43 */
44 unsigned b_jlist;
45
46 /*
47 * This flag signals the buffer has been modified by
48 * the currently running transaction
49 * [b_state_lock]
50 */
51 unsigned b_modified;
52
53 /*
54 * Copy of the buffer data frozen for writing to the log.
55 * [b_state_lock]
56 */
57 char *b_frozen_data;
58
59 /*
60 * Pointer to a saved copy of the buffer containing no uncommitted
61 * deallocation references, so that allocations can avoid overwriting
62 * uncommitted deletes. [b_state_lock]
63 */
64 char *b_committed_data;
65
66 /*
67 * Pointer to the compound transaction which owns this buffer's
68 * metadata: either the running transaction or the committing
69 * transaction (if there is one). Only applies to buffers on a
70 * transaction's data or metadata journaling list.
71 * [j_list_lock] [b_state_lock]
72 * Either of these locks is enough for reading, both are needed for
73 * changes.
74 */
75 transaction_t *b_transaction;
76
77 /*
78 * Pointer to the running compound transaction which is currently
79 * modifying the buffer's metadata, if there was already a transaction
80 * committing it when the new transaction touched it.
81 * [t_list_lock] [b_state_lock]
82 */
83 transaction_t *b_next_transaction;
84
85 /*
86 * Doubly-linked list of buffers on a transaction's data, metadata or
87 * forget queue. [t_list_lock] [b_state_lock]
88 */
89 struct journal_head *b_tnext, *b_tprev;
90
91 /*
92 * Pointer to the compound transaction against which this buffer
93 * is checkpointed. Only dirty buffers can be checkpointed.
94 * [j_list_lock]
95 */
96 transaction_t *b_cp_transaction;
97
98 /*
99 * Doubly-linked list of buffers still remaining to be flushed 100 * before an old transaction can be checkpointed.
101 * [j_list_lock]
102 */
103 struct journal_head *b_cpnext, *b_cpprev;
104
105 /* Trigger type */
106 struct jbd2_buffer_trigger_type *b_triggers;
107
108 /* Trigger type for the committing transaction's frozen data */
109 struct jbd2_buffer_trigger_type *b_frozen_triggers;
110 };
111
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH 6/7] jbd2: Make state lock a spinlock
Quoted 7 lines · kbuild test robot
Hi Jan,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc3 next-20190807]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
Yeah, missing include of linux/spinlock.h. I'll send V2 of the series.
Honza
Quoted 117 lines
url: https://github.com/0day-ci/linux/commits/Jan-Kara/jbd2-Bit-spinlock-conversions/20190804-170656
config: i386-randconfig-h002-201931 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-10) 7.4.0 reproduce:# save the attached .config to linux build tree make ARCH=i386If you fix the issue, kindly add following tag
Reported-by kbuild test robot <[email protected]>All errors (new ones prefixed by >>):
In file included from <command-line>:0:0:
Quoted 1 line
Quoted 1 line
include/linux/journal-head.h:29:2: error: unknown type name 'spinlock_t'spinlock_t b_state_lock; ^~~~~~~~~~vim +/spinlock_t +29
include/linux/journal-head.h19 20 struct journal_head { 21 /* 22 * Points back to our buffer_head. [jbd_lock_bh_journal_head()] 23 */ 24 struct buffer_head *b_bh; 25 26 /* 27 * Protect the buffer head state 28 */Quoted 1 line
29
spinlock_tb_state_lock;30 31 /* 32 * Reference count - see description in journal.c 33 * [jbd_lock_bh_journal_head()] 34 */ 35 int b_jcount; 36 37 /* 38 * Journalling list for this buffer [b_state_lock] 39 * NOTE: We *cannot* combine this with b_modified into a bitfield 40 * as gcc would then (which the C standard allows but which is 41 * very unuseful) make 64-bit accesses to the bitfield and clobber 42 * b_jcount if its update races with bitfield modification. 43 */ 44 unsigned b_jlist; 45 46 /* 47 * This flag signals the buffer has been modified by 48 * the currently running transaction 49 * [b_state_lock] 50 */ 51 unsigned b_modified; 52 53 /* 54 * Copy of the buffer data frozen for writing to the log. 55 * [b_state_lock] 56 */ 57 char *b_frozen_data; 58 59 /* 60 * Pointer to a saved copy of the buffer containing no uncommitted 61 * deallocation references, so that allocations can avoid overwriting 62 * uncommitted deletes. [b_state_lock] 63 */ 64 char *b_committed_data; 65 66 /* 67 * Pointer to the compound transaction which owns this buffer's 68 * metadata: either the running transaction or the committing 69 * transaction (if there is one). Only applies to buffers on a 70 * transaction's data or metadata journaling list. 71 * [j_list_lock] [b_state_lock] 72 * Either of these locks is enough for reading, both are needed for 73 * changes. 74 */ 75 transaction_t *b_transaction; 76 77 /* 78 * Pointer to the running compound transaction which is currently 79 * modifying the buffer's metadata, if there was already a transaction 80 * committing it when the new transaction touched it. 81 * [t_list_lock] [b_state_lock] 82 */ 83 transaction_t *b_next_transaction; 84 85 /* 86 * Doubly-linked list of buffers on a transaction's data, metadata or 87 * forget queue. [t_list_lock] [b_state_lock] 88 */ 89 struct journal_head *b_tnext, *b_tprev; 90 91 /* 92 * Pointer to the compound transaction against which this buffer 93 * is checkpointed. Only dirty buffers can be checkpointed. 94 * [j_list_lock] 95 */ 96 transaction_t *b_cp_transaction; 97 98 /* 99 * Doubly-linked list of buffers still remaining to be flushed 100 * before an old transaction can be checkpointed. 101 * [j_list_lock] 102 */ 103 struct journal_head *b_cpnext, *b_cpprev; 104 105 /* Trigger type */ 106 struct jbd2_buffer_trigger_type *b_triggers; 107 108 /* Trigger type for the committing transaction's frozen data */ 109 struct jbd2_buffer_trigger_type *b_frozen_triggers; 110 }; 111---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR