Patchwork [2/2,take2] jbd2: delete spin_lock(t_handle_lock) inside wirte_lock(j_state_lock)

login
register
mail settings
Submitter Toshiyuki Okajima
Date Dec. 26, 2011, 1:17 a.m.
Message ID <20111226101727.1ca09119.toshi.okajima@jp.fujitsu.com>
Download mbox | patch
Permalink /patch/133203/
State New
Headers show

Comments

Toshiyuki Okajima - Dec. 26, 2011, 1:17 a.m.
Delete all spin_lock(t_handle_lock) statements inside write_lock(j_state_lock) 
because the critical code sections can be protected by write_lock(j_state_lock)
only.

Signed-off-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
Reported-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
---
 fs/jbd2/commit.c      |    4 ----
 fs/jbd2/transaction.c |    6 +-----
 2 files changed, 1 insertions(+), 9 deletions(-)
Yongqiang Yang - Dec. 31, 2011, 6:35 a.m.
Looks good to me.

Thanks,
Yongqiang.
On Mon, Dec 26, 2011 at 9:17 AM, Toshiyuki Okajima
<toshi.okajima@jp.fujitsu.com> wrote:
> Delete all spin_lock(t_handle_lock) statements inside write_lock(j_state_lock)
> because the critical code sections can be protected by write_lock(j_state_lock)
> only.
>
> Signed-off-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
> Reported-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
> ---
>  fs/jbd2/commit.c      |    4 ----
>  fs/jbd2/transaction.c |    6 +-----
>  2 files changed, 1 insertions(+), 9 deletions(-)
>
> diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
> index 68d704d..1030d47 100644
> --- a/fs/jbd2/commit.c
> +++ b/fs/jbd2/commit.c
> @@ -364,22 +364,18 @@ void jbd2_journal_commit_transaction(journal_t *journal)
>        stats.run.rs_running = jbd2_time_diff(commit_transaction->t_start,
>                                              stats.run.rs_locked);
>
> -       spin_lock(&commit_transaction->t_handle_lock);
>        while (atomic_read(&commit_transaction->t_updates)) {
>                DEFINE_WAIT(wait);
>
>                prepare_to_wait(&journal->j_wait_updates, &wait,
>                                        TASK_UNINTERRUPTIBLE);
>                if (atomic_read(&commit_transaction->t_updates)) {
> -                       spin_unlock(&commit_transaction->t_handle_lock);
>                        write_unlock(&journal->j_state_lock);
>                        schedule();
>                        write_lock(&journal->j_state_lock);
> -                       spin_lock(&commit_transaction->t_handle_lock);
>                }
>                finish_wait(&journal->j_wait_updates, &wait);
>        }
> -       spin_unlock(&commit_transaction->t_handle_lock);
>
>        J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <=
>                        journal->j_max_transaction_buffers);
> diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
> index 76f2eca..c418ed9 100644
> --- a/fs/jbd2/transaction.c
> +++ b/fs/jbd2/transaction.c
> @@ -516,14 +516,10 @@ void jbd2_journal_lock_updates(journal_t *journal)
>                if (!transaction)
>                        break;
>
> -               spin_lock(&transaction->t_handle_lock);
> -               if (!atomic_read(&transaction->t_updates)) {
> -                       spin_unlock(&transaction->t_handle_lock);
> +               if (!atomic_read(&transaction->t_updates))
>                        break;
> -               }
>                prepare_to_wait(&journal->j_wait_updates, &wait,
>                                TASK_UNINTERRUPTIBLE);
> -               spin_unlock(&transaction->t_handle_lock);
>                write_unlock(&journal->j_state_lock);
>                schedule();
>                finish_wait(&journal->j_wait_updates, &wait);
> --
> 1.5.5.6
Jan Kara - Jan. 3, 2012, 3:35 p.m.
On Mon 26-12-11 10:17:27, Toshiyuki Okajima wrote:
> Delete all spin_lock(t_handle_lock) statements inside write_lock(j_state_lock) 
> because the critical code sections can be protected by write_lock(j_state_lock)
> only.
> 
> Signed-off-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
> Reported-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
  The patch looks good. You can add:
Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/jbd2/commit.c      |    4 ----
>  fs/jbd2/transaction.c |    6 +-----
>  2 files changed, 1 insertions(+), 9 deletions(-)
> 
> diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
> index 68d704d..1030d47 100644
> --- a/fs/jbd2/commit.c
> +++ b/fs/jbd2/commit.c
> @@ -364,22 +364,18 @@ void jbd2_journal_commit_transaction(journal_t *journal)
>  	stats.run.rs_running = jbd2_time_diff(commit_transaction->t_start,
>  					      stats.run.rs_locked);
>  
> -	spin_lock(&commit_transaction->t_handle_lock);
>  	while (atomic_read(&commit_transaction->t_updates)) {
>  		DEFINE_WAIT(wait);
>  
>  		prepare_to_wait(&journal->j_wait_updates, &wait,
>  					TASK_UNINTERRUPTIBLE);
>  		if (atomic_read(&commit_transaction->t_updates)) {
> -			spin_unlock(&commit_transaction->t_handle_lock);
>  			write_unlock(&journal->j_state_lock);
>  			schedule();
>  			write_lock(&journal->j_state_lock);
> -			spin_lock(&commit_transaction->t_handle_lock);
>  		}
>  		finish_wait(&journal->j_wait_updates, &wait);
>  	}
> -	spin_unlock(&commit_transaction->t_handle_lock);
>  
>  	J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <=
>  			journal->j_max_transaction_buffers);
> diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
> index 76f2eca..c418ed9 100644
> --- a/fs/jbd2/transaction.c
> +++ b/fs/jbd2/transaction.c
> @@ -516,14 +516,10 @@ void jbd2_journal_lock_updates(journal_t *journal)
>  		if (!transaction)
>  			break;
>  
> -		spin_lock(&transaction->t_handle_lock);
> -		if (!atomic_read(&transaction->t_updates)) {
> -			spin_unlock(&transaction->t_handle_lock);
> +		if (!atomic_read(&transaction->t_updates))
>  			break;
> -		}
>  		prepare_to_wait(&journal->j_wait_updates, &wait,
>  				TASK_UNINTERRUPTIBLE);
> -		spin_unlock(&transaction->t_handle_lock);
>  		write_unlock(&journal->j_state_lock);
>  		schedule();
>  		finish_wait(&journal->j_wait_updates, &wait);
> -- 
> 1.5.5.6
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o - Jan. 5, 2012, 3:27 a.m.
On Mon, Dec 26, 2011 at 10:17:27AM +0900, Toshiyuki Okajima wrote:
> Delete all spin_lock(t_handle_lock) statements inside write_lock(j_state_lock) 
> because the critical code sections can be protected by write_lock(j_state_lock)
> only.
> 
> Signed-off-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com>
> Reported-by: Yongqiang Yang <xiaoqiangnk@gmail.com>

This may be true today, but I'm worried this is going to make the code
more fragile.  The header file include/linux/jbd2.h defines which
fields are protected by which lock.  This patch is going to make those
comments partially obsolete.  We need to make sure the locking
protocol is clearly defined before we go around removing locks.

This is something I would like to do, but we need to make sure the
code remains maintainable in the long run.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 68d704d..1030d47 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -364,22 +364,18 @@  void jbd2_journal_commit_transaction(journal_t *journal)
 	stats.run.rs_running = jbd2_time_diff(commit_transaction->t_start,
 					      stats.run.rs_locked);
 
-	spin_lock(&commit_transaction->t_handle_lock);
 	while (atomic_read(&commit_transaction->t_updates)) {
 		DEFINE_WAIT(wait);
 
 		prepare_to_wait(&journal->j_wait_updates, &wait,
 					TASK_UNINTERRUPTIBLE);
 		if (atomic_read(&commit_transaction->t_updates)) {
-			spin_unlock(&commit_transaction->t_handle_lock);
 			write_unlock(&journal->j_state_lock);
 			schedule();
 			write_lock(&journal->j_state_lock);
-			spin_lock(&commit_transaction->t_handle_lock);
 		}
 		finish_wait(&journal->j_wait_updates, &wait);
 	}
-	spin_unlock(&commit_transaction->t_handle_lock);
 
 	J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <=
 			journal->j_max_transaction_buffers);
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index 76f2eca..c418ed9 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -516,14 +516,10 @@  void jbd2_journal_lock_updates(journal_t *journal)
 		if (!transaction)
 			break;
 
-		spin_lock(&transaction->t_handle_lock);
-		if (!atomic_read(&transaction->t_updates)) {
-			spin_unlock(&transaction->t_handle_lock);
+		if (!atomic_read(&transaction->t_updates))
 			break;
-		}
 		prepare_to_wait(&journal->j_wait_updates, &wait,
 				TASK_UNINTERRUPTIBLE);
-		spin_unlock(&transaction->t_handle_lock);
 		write_unlock(&journal->j_state_lock);
 		schedule();
 		finish_wait(&journal->j_wait_updates, &wait);