Various block throttling fixes
Subsystems (2)
PATCH 1/1 Various block throttling fixes
Hi Jens,
During testing of block device throttling, I found few issues. Here are the fixes for those issues.
[PATCH 1/4] blkio: Do not export throttle files if CONFIG_BLK_DEV_THROTTLING=n [PATCH 2/4] blkio: deletion of a cgroup was causes oops
[PATCH 3/4] blkio: Add root group to td->tg_list
[PATCH 4/4] blkio: Recalculate the throttled bio dispatch time upon throttle limit change
Overall diff
block/blk-cgroup.c | 121 +++++++++++++++++++++------------------ block/blk-cgroup.h | 21 ++++--- block/blk-throttle.c | 151 ++++++++++++++++++++++++++++++++++++++++++------- block/cfq-iosched.c | 4 +- 4 files changed, 207 insertions(+), 90 deletions(-)
Thanks
Vivek
PATCH 1/4 blkio: Do not export throttle files if CONFIG_BLK_DEV_THROTTLING=n
Currently throttling related files were visible even if user had disabled throttling using config options. It was switching off background throttling of bio but not the cgroup files. This patch fixes it.
--- block/blk-cgroup.c | 97 +++++++++++++++++++++++++++------------------------- 1 files changed, 50 insertions(+), 47 deletions(-)
block/blk-cgroup.c +50 -47
@@ -1242,41 +1242,6 @@ struct cftype blkio_files[] = { .write_u64 = blkiocg_file_write_u64, }, { - .name = "throttle.read_bps_device", - .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, - BLKIO_THROTL_read_bps_device), - .read_seq_string = blkiocg_file_read, - .write_string = blkiocg_file_write, - .max_write_len = 256, - }, - - { - .name = "throttle.write_bps_device", - .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, - BLKIO_THROTL_write_bps_device), - .read_seq_string = blkiocg_file_read, - .write_string = blkiocg_file_write, - .max_write_len = 256, - }, - - { - .name = "throttle.read_iops_device", - .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, - BLKIO_THROTL_read_iops_device), - .read_seq_string = blkiocg_file_read, - .write_string = blkiocg_file_write, - .max_write_len = 256, - }, - - { - .name = "throttle.write_iops_device", - .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, - BLKIO_THROTL_write_iops_device), - .read_seq_string = blkiocg_file_read, - .write_string = blkiocg_file_write, - .max_write_len = 256, - }, - { .name = "time", .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP, BLKIO_PROP_time),
@@ -1295,24 +1260,12 @@ struct cftype blkio_files[] = { .read_map = blkiocg_file_read_map, }, { - .name = "throttle.io_service_bytes", - .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, - BLKIO_THROTL_io_service_bytes), - .read_map = blkiocg_file_read_map, - }, - { .name = "io_serviced", .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP, BLKIO_PROP_io_serviced), .read_map = blkiocg_file_read_map, }, { - .name = "throttle.io_serviced", - .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, - BLKIO_THROTL_io_serviced), - .read_map = blkiocg_file_read_map, - }, - { .name = "io_service_time", .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP, BLKIO_PROP_io_service_time),
@@ -1340,6 +1293,56 @@ struct cftype blkio_files[] = { .name = "reset_stats", .write_u64 = blkiocg_reset_stats, }, +#ifdef CONFIG_BLK_DEV_THROTTLING + { + .name = "throttle.read_bps_device", + .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, + BLKIO_THROTL_read_bps_device), + .read_seq_string = blkiocg_file_read, + .write_string = blkiocg_file_write, + .max_write_len = 256, + }, + + { + .name = "throttle.write_bps_device", + .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, + BLKIO_THROTL_write_bps_device), + .read_seq_string = blkiocg_file_read, + .write_string = blkiocg_file_write, + .max_write_len = 256, + }, + + { + .name = "throttle.read_iops_device", + .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, + BLKIO_THROTL_read_iops_device), + .read_seq_string = blkiocg_file_read, + .write_string = blkiocg_file_write, + .max_write_len = 256, + }, + + { + .name = "throttle.write_iops_device", + .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, + BLKIO_THROTL_write_iops_device), + .read_seq_string = blkiocg_file_read, + .write_string = blkiocg_file_write, + .max_write_len = 256, + }, + { + .name = "throttle.io_service_bytes", + .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, + BLKIO_THROTL_io_service_bytes), + .read_map = blkiocg_file_read_map, + }, + { + .name = "throttle.io_serviced", + .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL, + BLKIO_THROTL_io_serviced), + .read_map = blkiocg_file_read_map, + }, +#endif /* CONFIG_BLK_DEV_THROTTLING */ + #ifdef CONFIG_DEBUG_BLK_CGROUP { .name = "avg_queue_size",
Signature · 1 line
1.7.2.3
PATCH 2/4 blkio: deletion of a cgroup was causes oops
In reply to Vivek Goyalo Now a cgroup list of blkg elements can contain blkg from multiple policies. Before sending an unlink event, make sure blkg belongs to they policy. If policy does not own the blkg, do not send update for this blkg.
--- block/blk-cgroup.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
block/blk-cgroup.c +5 -4
@@ -1411,13 +1411,14 @@ static void blkiocg_destroy(struct cgroup_subsys *subsys, struct cgroup *cgroup)/* * This blkio_group is being unlinked as associated cgroup is * going away. Let all the IO controlling policies know about -* this event. Currently this is static call to one io -* controlling policy. Once we have more policies in place, we -* need some dynamic registration of callback function. +* this event. */ spin_lock (&blkio_list_lock); -list_for_each_entry (blkiop, &blkio_list, list) +list_for_each_entry (blkiop, &blkio_list, list) { +if (blkiop->plid != blkg->plid) +continue ; blkiop->ops.blkio_unlink_group_fn (key, blkg); + }spin_unlock (&blkio_list_lock); }while (1 );
Signature · 1 line
1.7.2.3
PATCH 3/4 blkio: Add root group to td->tg_list
In reply to Vivek Goyalo Currently all the dynamically allocated groups, except root grp is added to td->tg_list. This was not a problem so far but in next patch I will travel through td->tg_list to process any updates of limits on the group. If root group is not in tg_list, then root group's updates are not processed.
o It is better to root group also to tg_list instead of doing special processing for it during limit updates.
--- block/blk-throttle.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)
block/blk-throttle.c +13 -4
@@ -87,7 +87,7 @@ struct throtl_dataunsigned int nr_queued[2 ];/* -* number of total undestroyed groups (excluding root group) +* number of total undestroyed groups */ unsigned int nr_undestroyed_grps;
@@ -940,7 +940,17 @@ int blk_throtl_init(struct request_queue *q)/* Practically unlimited BW */ tg->bps[0 ] = tg->bps[1 ] =-1 ; tg->iops[0 ] = tg->iops[1 ] =-1 ; -atomic_set (&tg->ref,1 ); + +/* +* Set root group reference to 2. One reference will be dropped when +* all groups on tg_list are being deleted during queue exit. Other +* reference will remain there as we don't want to delete this group +* as it is statically allocated and gets destroyed when throtl_data +* goes away. +*/ +atomic_set (&tg->ref,2 ); +hlist_add_head (&tg->tg_node, &td->tg_list); + td->nr_undestroyed_grps++;INIT_DELAYED_WORK (&td->throtl_work, blk_throtl_work);
@@ -966,10 +976,9 @@ void blk_throtl_exit(struct request_queue *q)spin_lock_irq (q->queue_lock);throtl_release_tgs (td); -blkiocg_del_blkio_group (&td->root_tg.blkg);/* If there are other groups */ -if (td->nr_undestroyed_grps >=1 ) +if (td->nr_undestroyed_grps >0 ) wait = true;spin_unlock_irq (q->queue_lock);
Signature · 1 line
1.7.2.3
PATCH 4/4 blkio: Recalculate the throttled bio dispatch time upon throttle limit change
In reply to Vivek Goyalo Currently any cgroup throttle limit changes are processed asynchronousy and the change does not take affect till a new bio is dispatched from same group.
o It might happen that a user sets a redicuously low limit on throttling. Say 1 bytes per second on reads. In such cases simple operations like mount a disk can wait for a very long time.
o Once bio is throttled, there is no easy way to come out of that wait even if user increases the read limit later.
o This patch fixes it. Now if a user changes the cgroup limits, we recalculate the bio dispatch time according to new limits.
o Can't take queueu lock under blkcg_lock, hence after the change I wake up the dispatch thread again which recalculates the time. So there are some variables being synchronized across two threads without lock and I had to make use of barriers. Hoping I have used barriers correctly. Any review of memory barrier code especially will help.
--- block/blk-cgroup.c | 15 ++++-- block/blk-cgroup.h | 21 ++++---- block/blk-throttle.c | 134 +++++++++++++++++++++++++++++++++++++++++++------- block/cfq-iosched.c | 4 +- 4 files changed, 139 insertions(+), 35 deletions(-)
block/blk-cgroup.c +10 -5
@@ -124,7 +124,8 @@ blkio_update_group_weight(struct blkio_group *blkg, unsigned int weight)if (blkiop->plid != blkg->plid)continue ;if (blkiop->ops.blkio_update_group_weight_fn) - blkiop->ops.blkio_update_group_weight_fn (blkg, weight); + blkiop->ops.blkio_update_group_weight_fn (blkg->key, + blkg, weight); } }
@@ -141,11 +142,13 @@ static inline void blkio_update_group_bps(struct blkio_group *blkg, u64 bps,if (fileid == BLKIO_THROTL_read_bps_device && blkiop->ops.blkio_update_group_read_bps_fn) - blkiop->ops.blkio_update_group_read_bps_fn (blkg, bps); + blkiop->ops.blkio_update_group_read_bps_fn (blkg->key, + blkg, bps);if (fileid == BLKIO_THROTL_write_bps_device && blkiop->ops.blkio_update_group_write_bps_fn) - blkiop->ops.blkio_update_group_write_bps_fn (blkg, bps); + blkiop->ops.blkio_update_group_write_bps_fn (blkg->key, + blkg, bps); } }
@@ -162,11 +165,13 @@ static inline void blkio_update_group_iops(struct blkio_group *blkg,if (fileid == BLKIO_THROTL_read_iops_device && blkiop->ops.blkio_update_group_read_iops_fn) - blkiop->ops.blkio_update_group_read_iops_fn (blkg, iops); + blkiop->ops.blkio_update_group_read_iops_fn (blkg->key, + blkg, iops);if (fileid == BLKIO_THROTL_write_iops_device && blkiop->ops.blkio_update_group_write_iops_fn) - blkiop->ops.blkio_update_group_write_iops_fn (blkg,iops); + blkiop->ops.blkio_update_group_write_iops_fn (blkg->key, + blkg,iops); } }
block/blk-cgroup.h +11 -10
@@ -186,16 +186,17 @@ extern unsigned int blkcg_get_write_iops(struct blkio_cgroup *blkcg, dev_t dev);typedef void (blkio_unlink_group_fn ) (void *key,struct blkio_group *blkg); -typedef void (blkio_update_group_weight_fn ) (struct blkio_group *blkg, -unsigned int weight); -typedef void (blkio_update_group_read_bps_fn ) (struct blkio_group *blkg, -u64 read_bps); -typedef void (blkio_update_group_write_bps_fn ) (struct blkio_group *blkg, -u64 write_bps); -typedef void (blkio_update_group_read_iops_fn ) (struct blkio_group *blkg, -unsigned int read_iops); -typedef void (blkio_update_group_write_iops_fn ) (struct blkio_group *blkg, -unsigned int write_iops); + +typedef void (blkio_update_group_weight_fn ) (void *key, +struct blkio_group *blkg,unsigned int weight); +typedef void (blkio_update_group_read_bps_fn ) (void * key, +struct blkio_group *blkg,u64 read_bps); +typedef void (blkio_update_group_write_bps_fn ) (void *key, +struct blkio_group *blkg,u64 write_bps); +typedef void (blkio_update_group_read_iops_fn ) (void *key, +struct blkio_group *blkg,unsigned int read_iops); +typedef void (blkio_update_group_write_iops_fn ) (void *key, +struct blkio_group *blkg,unsigned int write_iops);struct blkio_policy_ops {blkio_unlink_group_fn *blkio_unlink_group_fn;
block/blk-throttle.c +116 -18
203 lines not on this page · raw message
block/cfq-iosched.c +2 -2
@@ -976,8 +976,8 @@ static inline struct cfq_group *cfqg_of_blkg(struct blkio_group *blkg)return NULL ; } -void -cfq_update_blkio_group_weight (struct blkio_group *blkg,unsigned int weight) +void cfq_update_blkio_group_weight (void *key,struct blkio_group *blkg, +unsigned int weight) {cfqg_of_blkg (blkg)->weight = weight; }
Signature · 1 line
1.7.2.3
Re: [PATCH 4/4] blkio: Recalculate the throttled bio dispatch time upon throttle limit change
Quoted 10 lines · On Tue, 28 Sep 2010 13:10:59 -0400 Vivek Goyal wrote:
o Currently any cgroup throttle limit changes are processed asynchronousy and the change does not take affect till a new bio is dispatched from same group.
o It might happen that a user sets a redicuously low limit on throttling. Say 1 bytes per second on reads. In such cases simple operations like mount a disk can wait for a very long time.
o Once bio is throttled, there is no easy way to come out of that wait even if user increases the read limit later.
Quoted 8 lines
o This patch fixes it. Now if a user changes the cgroup limits, we recalculate the bio dispatch time according to new limits.
o Can't take queueu lock under
blkcg_lock, hence after the change I wake up the dispatch thread again which recalculates the time. So there are some variables being synchronized across two threads without lock and I had to make use of barriers. Hoping I have used barriers correctly. Any review of memory barrier code especially will help.
Hi,
Has this report been addressed/fixed?
on i386:
blk-throttle.c:(.text+0x1abb8): undefined reference to __udivdi3' blk-throttle.c:(.text+0x1b1dc): undefined reference to __udivdi3'
on linux-next 2010-0924 and 2010-0927.
---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***
Re: [PATCH 4/4] blkio: Recalculate the throttled bio dispatch time upon throttle limit change
Quoted 22 lines · Randy Dunlap
Quoted 10 lines · On Tue, 28 Sep 2010 13:10:59 -0400 Vivek Goyal wrote:
o Currently any cgroup throttle limit changes are processed asynchronousy and the change does not take affect till a new bio is dispatched from same group.
o It might happen that a user sets a redicuously low limit on throttling. Say 1 bytes per second on reads. In such cases simple operations like mount a disk can wait for a very long time.
o Once bio is throttled, there is no easy way to come out of that wait even if user increases the read limit later.
Quoted 8 lines
o This patch fixes it. Now if a user changes the cgroup limits, we recalculate the bio dispatch time according to new limits.
o Can't take queueu lock under
blkcg_lock, hence after the change I wake up the dispatch thread again which recalculates the time. So there are some variables being synchronized across two threads without lock and I had to make use of barriers. Hoping I have used barriers correctly. Any review of memory barrier code especially will help.
Quoted 3 lines
Hi,
Has this report been addressed/fixed?
Hi Randy,
No. I was not aware of it. Thanks for bringing it to my notice. I will look into it.
Vivek
Quoted 12 lines
on i386:
blk-throttle.c:(.text+0x1abb8): undefined reference to
__udivdi3' blk-throttle.c:(.text+0x1b1dc): undefined reference to__udivdi3'on linux-next 2010-0924 and 2010-0927.
---
~Randy
*** Remember to useDocumentation/SubmitChecklistwhen testing your code ***