md: optimize barrier usage for Rmw atomic bitops
PATCH 1/1 md: optimize barrier usage for Rmw atomic bitops
For both set and clear_bit, we can avoid the unnecessary barrier on non LL/SC architectures, such as x86. Instead, use the smp_mb__{before,after}_atomic() calls.
--- drivers/md/md.c | 2 +- drivers/md/raid10.c | 7 ++++--- drivers/md/raid5.c | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-)
drivers/md/md.c +1 -1
@@ -2561,7 +2561,7 @@ static bool set_in_sync(struct mddev *mddev)* Ensure ->in_sync is visible before we clear * ->sync_checkers. */ -smp_mb (); +smp_mb__before_atomic ();set_bit (MD_SB_CHANGE_CLEAN , &mddev->sb_flags);sysfs_notify_dirent_safe (mddev->sysfs_state); }
drivers/md/raid10.c +4 -3
@@ -1865,9 +1865,10 @@ static int raid10_remove_disk(struct mddev *mddev, struct md_rdev *rdev)/* We must have just cleared 'rdev' */ p->rdev = p->replacement;clear_bit (Replacement, &p->replacement->flags); -smp_mb ();/* Make sure other CPUs may see both as identical -* but will never see neither -- if they are careful. -*/ +/* Make sure other CPUs may see both as identical +* but will never see neither -- if they are careful. +*/ +smp_mb__after_atomic (); p->replacement =NULL ; }
drivers/md/raid5.c +5 -4
@@ -364,7 +364,7 @@ static int release_stripe_list(struct r5conf *conf,int hash;/* sh could be readded after STRIPE_ON_RELEASE_LIST is cleard */ -smp_mb (); +smp_mb__before_atomic ();clear_bit (STRIPE_ON_RELEASE_LIST , &sh->state);/* * Don't worry the bit is set here, because if the bit is set
@@ -7654,9 +7654,10 @@ static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev)/* We must have just cleared 'rdev' */ p->rdev = p->replacement;clear_bit (Replacement, &p->replacement->flags); -smp_mb ();/* Make sure other CPUs may see both as identical -* but will never see neither - if they are careful -*/ +/* Make sure other CPUs may see both as identical +* but will never see neither - if they are careful +*/ +smp_mb__after_atomic (); p->replacement =NULL ;if (!err)
Signature · 1 line
2.16.4
Quoted 29 lines · Davidlohr Bueso
For both set and
clear_bit, we can avoid the unnecessary barrier on non LL/SC architectures, such as x86. Instead, use the smp_mb__{before,after}_atomic() calls.Signed-off-by Davidlohr Bueso <[email protected]>--- drivers/md/md.c | 2 +- drivers/md/raid10.c | 7 ++++--- drivers/md/raid5.c | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-)drivers/md/md.c +1
-1@@ -2561,7 +2561,7 @@ static bool set_in_sync(struct mddev *mddev)* Ensure ->in_sync is visible before we clear * ->sync_checkers. */ -smp_mb (); +smp_mb__before_atomic ();set_bit (MD_SB_CHANGE_CLEAN , &mddev->sb_flags);sysfs_notify_dirent_safe (mddev->sysfs_state); }drivers/md/raid10.c +0
-0
drivers/md/raid10.c static int raid10_remove_disk(struct mddev *mddev, struct md_rdev *rdev) · line 1870
Quoted 9 lines
drivers/md/raid10.c +3
-3@@ -1865,9 +1865,10 @@ static int raid10_remove_disk(struct mddev *mddev, struct md_rdev *rdev)/* We must have just cleared 'rdev' */ p->rdev = p->replacement;clear_bit (Replacement, &p->replacement->flags); -smp_mb ();/* Make sure other CPUs may see both as identical -* but will never see neither -- if they are careful. -*/ +/* Make sure other CPUs may see both as identical +* but will never see neither -- if they are careful. +*/
Since we are here, it is better to change the comment style to
/*
* ...
*/
Quoted 18 lines
drivers/md/raid10.c +1
-0+smp_mb__after_atomic (); p->replacement =NULL ; }drivers/md/raid5.c +1
-1@@ -364,7 +364,7 @@ static int release_stripe_list(struct r5conf *conf,int hash;/* sh could be readded after STRIPE_ON_RELEASE_LIST is cleard */ -smp_mb (); +smp_mb__before_atomic ();clear_bit (STRIPE_ON_RELEASE_LIST , &sh->state);/* * Don't worry the bit is set here, because if the bit is set
drivers/md/raid5.c static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev) · line 7659
Quoted 6 lines
drivers/md/raid5.c +0
-3@@ -7654,9 +7654,10 @@ static int raid5_remove_disk(struct mddev *mddev, struct md_rdev *rdev)/* We must have just cleared 'rdev' */ p->rdev = p->replacement;clear_bit (Replacement, &p->replacement->flags); -smp_mb ();/* Make sure other CPUs may see both as identical -* but will never see neither - if they are careful -*/
Ditto.
Thanks,
Guoqing
Song Liu
maintainerQuoted 9 lines · Guoqing Jiang
Quoted 5 lines · Davidlohr Bueso
For both set and
clear_bit, we can avoid the unnecessary barrier on non LL/SC architectures, such as x86. Instead, use the smp_mb__{before,after}_atomic() calls.Signed-off-by Davidlohr Bueso <[email protected]>
./scripts/checkpatch.pl reports the following:
=============== 8< =================
WARNING: memory barrier without comment
#81: FILE: drivers/md/md.c:2564:
+ smp_mb__before_atomic();
WARNING: memory barrier without comment
#112: FILE: drivers/md/raid5.c:367:
+ smp_mb__before_atomic();
WARNING: Missing Signed-off-by: line by nominal patch author 'Davidlohr Bueso <[email protected]>'
total: 0 errors, 3 warnings, 42 lines checked
=============== 8< =================
Since we are on it, let's add comments for the barriers. Also, please double check the email
is correct.
Thanks,
Song