Commit 4843c69d496a8d2e4caab6182fe016b9a79136e0

Authored by Vivek Goyal
Committed by Jens Axboe
1 parent 5617cbef77

blk-throttle: Free up a group only after one rcu grace period

Soon we will allow accessing a throtl_grp under rcu_read_lock(). Hence
start freeing up throtl_grp after one rcu grace period.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>

Showing 1 changed file with 21 additions and 1 deletions Side-by-side Diff

block/blk-throttle.c
... ... @@ -78,6 +78,8 @@
78 78  
79 79 /* Some throttle limits got updated for the group */
80 80 int limits_changed;
  81 +
  82 + struct rcu_head rcu_head;
81 83 };
82 84  
83 85 struct throtl_data
84 86  
... ... @@ -151,12 +153,30 @@
151 153 return tg;
152 154 }
153 155  
  156 +static void throtl_free_tg(struct rcu_head *head)
  157 +{
  158 + struct throtl_grp *tg;
  159 +
  160 + tg = container_of(head, struct throtl_grp, rcu_head);
  161 + kfree(tg);
  162 +}
  163 +
154 164 static void throtl_put_tg(struct throtl_grp *tg)
155 165 {
156 166 BUG_ON(atomic_read(&tg->ref) <= 0);
157 167 if (!atomic_dec_and_test(&tg->ref))
158 168 return;
159   - kfree(tg);
  169 +
  170 + /*
  171 + * A group is freed in rcu manner. But having an rcu lock does not
  172 + * mean that one can access all the fields of blkg and assume these
  173 + * are valid. For example, don't try to follow throtl_data and
  174 + * request queue links.
  175 + *
  176 + * Having a reference to blkg under an rcu allows acess to only
  177 + * values local to groups like group stats and group rate limits
  178 + */
  179 + call_rcu(&tg->rcu_head, throtl_free_tg);
160 180 }
161 181  
162 182 static void throtl_init_group(struct throtl_grp *tg)