Skip to content

Commit 04a6b51

Browse files
rhvgoyalJens Axboe
authored andcommitted
blk-throttle: Correct the placement of smp_rmb()
o I was discussing what are the variable being updated without spin lock and why do we need barriers and Oleg pointed out that location of smp_rmb() should be between read of td->limits_changed and tg->limits_changed. This patch fixes it. o Following is one possible sequence of events. Say cpu0 is executing throtl_update_blkio_group_read_bps() and cpu1 is executing throtl_process_limit_change(). cpu0 cpu1 tg->limits_changed = true; smp_mb__before_atomic_inc(); atomic_inc(&td->limits_changed); if (!atomic_read(&td->limits_changed)) return; if (tg->limits_changed) do_something; If cpu0 has updated tg->limits_changed and td->limits_changed, we want to make sure that if update to td->limits_changed is visible on cpu1, then update to tg->limits_changed should also be visible. Oleg pointed out to ensure that we need to insert an smp_rmb() between td->limits_changed read and tg->limits_changed read. o I had erroneously put smp_rmb() before atomic_read(&td->limits_changed). This patch fixes it. Reported-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent d1ae8ff commit 04a6b51

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

‎block/blk-throttle.c‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -725,26 +725,21 @@ static void throtl_process_limit_change(struct throtl_data *td)
725725
struct throtl_grp *tg;
726726
struct hlist_node *pos, *n;
727727

728-
/*
729-
* Make sure atomic_inc() effects from
730-
* throtl_update_blkio_group_read_bps(), group of functions are
731-
* visible.
732-
* Is this required or smp_mb__after_atomic_inc() was suffcient
733-
* after the atomic_inc().
734-
*/
735-
smp_rmb();
736728
if (!atomic_read(&td->limits_changed))
737729
return;
738730

739731
throtl_log(td, "limit changed =%d", atomic_read(&td->limits_changed));
740732

741-
hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
742-
/*
743-
* Do I need an smp_rmb() here to make sure tg->limits_changed
744-
* update is visible. I am relying on smp_rmb() at the
745-
* beginning of function and not putting a new one here.
746-
*/
733+
/*
734+
* Make sure updates from throtl_update_blkio_group_read_bps() group
735+
* of functions to tg->limits_changed are visible. We do not
736+
* want update td->limits_changed to be visible but update to
737+
* tg->limits_changed not being visible yet on this cpu. Hence
738+
* the read barrier.
739+
*/
740+
smp_rmb();
747741

742+
hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
748743
if (throtl_tg_on_rr(tg) && tg->limits_changed) {
749744
throtl_log_tg(td, tg, "limit change rbps=%llu wbps=%llu"
750745
" riops=%u wiops=%u", tg->bps[READ],

0 commit comments

Comments
 (0)