blkio: IO controller stats
Subsystems (3)
v3 cover blkio: IO controller stats
The following series implements some additional stats for IO controller.
These stats have helped us debug issues with earlier IO controller versions and should be useful now as well.
We've been using these stats for monitoring and debugging problems after the fact as these stats can be collected and stored for later use.
One might argue that most of this information can be exported using blktrace when debugging. However, blktrace has non-trivial performance impact and cannot be always turned on. These stats provide a way for continuous monitoring without losing much performance on rotational disks. We've been able to look at these stats and debug issues after problems have been reported in the wild and understand the IO pattern of the affected workloads.
Some of these stats are also a good data source for high-level analysis and capacity planning.
This patchset adds 4 stats and I will send out another patchset later for stats like io_merged and some stats that can be turned on only for debugging - idle_time (total time spent idling for this blkio_group), wait_time (total time spent by the blkio_group waiting before any one of its queues got a timeslice). I've tried to breakdown the stats and sent the most basic ones here.
Changelog from v2 (most based on Vivek Goyal's comments):
o Initialize blkg->stats_lock
o rename io_add_stat to blkio_add_stat and declare it static
o use bool for direction and sync
o derive direction and sync info from existing rq methods
o use 12 for major:minor string length
o define io_service_time better to cover the NCQ case
o add a separate reset_stats interface
o make the indexed stats a 2d array to simplify macro and function pointer code
Changelog from v1 (most based on Vivek Goyal's comments):
o blkio.time now exports in jiffies as before
o Added stats description in patch description and Documentation/cgroup/blkio-controller.txt
o Prefix all stats functions with blkio and make them static as applicable
o replace IO_TYPE_MAX with IO_TYPE_TOTAL
o Moved #define constant to top of blk-cgroup.c
o Pass dev_t around instead of char *
o Add note to documentation file about resetting stats
o use BLK_CGROUP_MODULE in addition to BLK_CGROUP config option in #ifdef statements
o Avoid struct request specific knowledge in blk-cgroup. blk-cgroup.h now has rq_direction() and rq_sync() functions which are used by CFQ and when using io-controller at a higher level, bio_* functions can be added.
---
Divyesh Shah (3):
Increment the blkio cgroup stats for real now.
Add io controller stats like
Remove per-cfqq nr_sectors as we'll be passing that info at request dispatch
Documentation/cgroups/blkio-controller.txt | 40 +++++ block/blk-cgroup.c | 225 ++++++++++++++++++++++++++-- block/blk-cgroup.h | 79 ++++++++-- block/blk-core.c | 6 - block/cfq-iosched.c | 18 +- include/linux/blkdev.h | 38 +++++ 6 files changed, 356 insertions(+), 50 deletions(-)
Signature · 1 line
Divyesh
PATCH v3 1/3 blkio: Remove per-cfqq nr_sectors as we'll be passing
that info at request dispatch with other stats now. This patch removes the existing support for accounting sectors for a blkio_group. This will be added back differently in the next two patches.
---
block/blk-cgroup.c | 3 +-- block/blk-cgroup.h | 6 ++---- block/cfq-iosched.c | 10 ++-------- 3 files changed, 5 insertions(+), 14 deletions(-)
block/blk-cgroup.c +1 -2
@@ -56,10 +56,9 @@ struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)EXPORT_SYMBOL_GPL (cgroup_to_blkio_cgroup);void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, -unsigned long time,unsigned long sectors) +unsigned long time) { blkg->time += time; - blkg->sectors += sectors; }EXPORT_SYMBOL_GPL (blkiocg_update_blkio_group_stats);
block/blk-cgroup.h +2 -4
@@ -106,7 +106,7 @@ extern int blkiocg_del_blkio_group(struct blkio_group *blkg);extern struct blkio_group *blkiocg_lookup_group (struct blkio_cgroup *blkcg,void *key);void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, -unsigned long time,unsigned long sectors); +unsigned long time);#else struct cgroup ; static inline struct blkio_cgroup *
@@ -123,8 +123,6 @@ blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }static inline struct blkio_group *blkiocg_lookup_group (struct blkio_cgroup *blkcg,void *key) {return NULL ; }static inline void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, -unsigned long time,unsigned long sectors) -{ -} +unsigned long time) {}#endif #endif /* _BLK_CGROUP_H */
block/cfq-iosched.c +2 -8
@@ -141,8 +141,6 @@ struct cfq_queue {struct cfq_queue *new_cfqq;struct cfq_group *cfqg;struct cfq_group *orig_cfqg; -/* Sectors dispatched in current dispatch round */ -unsigned long nr_sectors; };/*
@@ -882,8 +880,7 @@ static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq) slice_used = cfqq->allocated_slice; } -cfq_log_cfqq (cfqq->cfqd, cfqq,"sl_used=%u sect=%lu" , slice_used, - cfqq->nr_sectors); +cfq_log_cfqq (cfqq->cfqd, cfqq,"sl_used=%u" , slice_used);return slice_used; }
@@ -917,8 +914,7 @@ static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,cfq_log_cfqg (cfqd, cfqg,"served: vt=%llu min_vt=%llu" , cfqg->vdisktime, st->min_vdisktime); -blkiocg_update_blkio_group_stats (&cfqg->blkg, used_sl, - cfqq->nr_sectors); +blkiocg_update_blkio_group_stats (&cfqg->blkg, used_sl); }#ifdef CONFIG_CFQ_GROUP_IOSCHED
@@ -1524,7 +1520,6 @@ static void __cfq_set_active_queue(struct cfq_data *cfqd, cfqq->allocated_slice =0 ; cfqq->slice_end =0 ; cfqq->slice_dispatch =0 ; - cfqq->nr_sectors =0 ;cfq_clear_cfqq_wait_request (cfqq);cfq_clear_cfqq_must_dispatch (cfqq);
@@ -1869,7 +1864,6 @@ static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)elv_dispatch_sort (q, rq); cfqd->rq_in_flight[cfq_cfqq_sync (cfqq)]++; - cfqq->nr_sectors +=blk_rq_sectors (rq); }/*
Re: [PATCH 1/3][v3] blkio: Remove per-cfqq nr_sectors as we'll be passing
Quoted 5 lines · Divyesh Shah
that info at request dispatch with other stats now. This patch removes the existing support for accounting sectors for a
blkio_group. This will be added back differently in the next two patches.Signed-off-by Divyesh Shah<[email protected]>
Vivek
Quoted 95 lines
---
block/blk-cgroup.c | 3 +-- block/blk-cgroup.h | 6 ++---- block/cfq-iosched.c | 10 ++-------- 3 files changed, 5 insertions(+), 14 deletions(-)block/blk-cgroup.c +1
-2@@ -56,10 +56,9 @@ struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)EXPORT_SYMBOL_GPL (cgroup_to_blkio_cgroup);void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, -unsigned long time,unsigned long sectors) +unsigned long time) { blkg->time += time; - blkg->sectors += sectors; }EXPORT_SYMBOL_GPL (blkiocg_update_blkio_group_stats);block/blk-cgroup.h +2
-4@@ -106,7 +106,7 @@ extern int blkiocg_del_blkio_group(struct blkio_group *blkg);extern struct blkio_group *blkiocg_lookup_group (struct blkio_cgroup *blkcg,void *key);void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, -unsigned long time,unsigned long sectors); +unsigned long time);#else struct cgroup ; static inline struct blkio_cgroup *@@ -123,8 +123,6 @@ blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }static inline struct blkio_group *blkiocg_lookup_group (struct blkio_cgroup *blkcg,void *key) {return NULL ; }static inline void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, -unsigned long time,unsigned long sectors) -{ -} +unsigned long time) {}#endif #endif /* _BLK_CGROUP_H */ block/cfq-iosched.c +2
-8@@ -141,8 +141,6 @@ struct cfq_queue {struct cfq_queue *new_cfqq;struct cfq_group *cfqg;struct cfq_group *orig_cfqg; -/* Sectors dispatched in current dispatch round */ -unsigned long nr_sectors; };/* @@ -882,8 +880,7 @@ static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq) slice_used = cfqq->allocated_slice; } -cfq_log_cfqq (cfqq->cfqd, cfqq,"sl_used=%u sect=%lu" , slice_used, - cfqq->nr_sectors); +cfq_log_cfqq (cfqq->cfqd, cfqq,"sl_used=%u" , slice_used);return slice_used; }@@ -917,8 +914,7 @@ static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,cfq_log_cfqg (cfqd, cfqg,"served: vt=%llu min_vt=%llu" , cfqg->vdisktime, st->min_vdisktime); -blkiocg_update_blkio_group_stats (&cfqg->blkg, used_sl, - cfqq->nr_sectors); +blkiocg_update_blkio_group_stats (&cfqg->blkg, used_sl); }#ifdef CONFIG_CFQ_GROUP_IOSCHED @@ -1524,7 +1520,6 @@ static void __cfq_set_active_queue(struct cfq_data *cfqd, cfqq->allocated_slice =0 ; cfqq->slice_end =0 ; cfqq->slice_dispatch =0 ; - cfqq->nr_sectors =0 ;cfq_clear_cfqq_wait_request (cfqq);cfq_clear_cfqq_must_dispatch (cfqq);@@ -1869,7 +1864,6 @@ static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)elv_dispatch_sort (q, rq); cfqd->rq_in_flight[cfq_cfqq_sync (cfqq)]++; - cfqq->nr_sectors +=blk_rq_sectors (rq); }/*
PATCH v3 2/3 blkio: Add io controller stats like
In reply to Divyesh Shah- io_service_time (the time between request dispatch and completion for IOs in the cgroup)
- io_wait_time (the time spent waiting in the IO shceduler queues before getting serviced)
- io_serviced (number of IOs serviced from this blkio_group)
- io_service_bytes (Number of bytes served for this cgroup)
These stats are accumulated per operation type helping us to distinguish between read and write, and sync and async IO. This patch does not increment any of these stats.
---
Documentation/cgroups/blkio-controller.txt | 40 +++++++ block/blk-cgroup.c | 166 +++++++++++++++++++++++++--- block/blk-cgroup.h | 60 ++++++++-- block/cfq-iosched.c | 3 - 4 files changed, 239 insertions(+), 30 deletions(-)
Documentation/cgroups/blkio-controller.txt +39 -1
@@ -77,7 +77,6 @@ Details of cgroup files ======================= - blkio.weight - Specifies per cgroup weight. - Currently allowed range of weights is from 100 to 1000. - blkio.time
@@ -92,6 +91,41 @@ Details of cgroup files third field specifies the number of sectors transferred by the group to/from the device. +- blkio.io_service_bytes + - Number of bytes transferred to/from the disk by the group. These + are further divided by the type of operation - read or write, sync + or async. First two fields specify the major and minor number of the + device, third field specifies the operation type and the fourth field + specifies the number of bytes. + +- blkio.io_serviced + - Number of IOs completed to/from the disk by the group. These + are further divided by the type of operation - read or write, sync + or async. First two fields specify the major and minor number of the + device, third field specifies the operation type and the fourth field + specifies the number of IOs. + +- blkio.io_service_time + - Total amount of time between request dispatch and request completion + for the IOs done by this cgroup. This is in nanoseconds to make it + meaningful for flash devices too. For devices with queue depth of 1, + this time represents the actual service time. When queue_depth > 1, + that is no longer true as requests may be served out of order. + This time is further divided by the type of operation - + read or write, sync or async. First two fields specify the major and + minor number of the device, third field specifies the operation type + and the fourth field specifies the io_service_time in ns. + +- blkio.io_wait_time + - Total amount of time the IO spent waiting in the scheduler queues for + service. This can be greater than the total time elapsed since it is + cumulative io_wait_time for all IOs. This is in nanoseconds to make it + meaningful for flash devices too. This time is further divided by the + type of operation - read or write, sync or async. First two fields + specify the major and minor number of the device, third field + specifies the operation type and the fourth field specifies the + io_wait_time in ns. + - blkio.dequeue - Debugging aid only enabled if CONFIG_DEBUG_CFQ_IOSCHED=y. This gives the statistics about how many a times a group was dequeued
@@ -99,6 +133,10 @@ Details of cgroup files and minor number of the device and third field specifies the number of times a group was dequeued from a particular device. +- blkio.reset_stats + - Writing an int to this file will result in resetting all the stats + for that cgroup. + CFQ sysfs tunable ================= /sys/block/<disk>/queue/iosched/group_isolation
block/blk-cgroup.c +150 -16
223 lines not on this page · raw message
block/blk-cgroup.h +48 -12
99 lines not on this page · raw message
block/cfq-iosched.c +2 -1
@@ -914,7 +914,7 @@ static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,cfq_log_cfqg (cfqd, cfqg,"served: vt=%llu min_vt=%llu" , cfqg->vdisktime, st->min_vdisktime); -blkiocg_update_blkio_group_stats (&cfqg->blkg, used_sl); +blkiocg_update_timeslice_used (&cfqg->blkg, used_sl); }#ifdef CONFIG_CFQ_GROUP_IOSCHED
@@ -954,6 +954,7 @@ cfq_find_alloc_cfqg(struct cfq_data *cfqd, struct cgroup *cgroup, int create)for_each_cfqg_st (cfqg, i, j, st) *st =CFQ_RB_ROOT ;RB_CLEAR_NODE (&cfqg->rb_node); +blkio_group_init (&cfqg->blkg);/* * Take the initial reference that will be released on destroy
Re: [PATCH 2/3][v3] blkio: Add io controller stats like
Quoted 40 lines · Divyesh Shah
-
io_service_time(the time between request dispatch and completion for IOs in the cgroup)
-io_wait_time(the time spent waiting in the IO shceduler queues before getting serviced)
-io_serviced(number of IOs serviced from thisblkio_group)
-io_service_bytes(Number of bytes served for this cgroup)These stats are accumulated per operation type helping us to distinguish between read and write, and sync and async IO. This patch does not increment any of these stats.
Signed-off-by Divyesh Shah<[email protected]>---
Documentation/cgroups/blkio-controller.txt | 40 +++++++ block/blk-cgroup.c | 166 +++++++++++++++++++++++++--- block/blk-cgroup.h | 60 ++++++++-- block/cfq-iosched.c | 3 - 4 files changed, 239 insertions(+), 30 deletions(-)Documentation/cgroups/blkio-controller.txt +4
-1@@ -77,7 +77,6 @@ Details of cgroup files ======================= - blkio.weight - Specifies per cgroup weight. - Currently allowed range of weights is from 100 to 1000. - blkio.time@@ -92,6 +91,41 @@ Details of cgroup files third field specifies the number of sectors transferred by the group to/from the device. +- blkio.io_service_bytes + - Number of bytes transferred to/from the disk by the group. These + are further divided by the type of operation - read or write, sync + or async. First two fields specify the major and minor number of the
Documentation/cgroups/blkio-controller.txt Details of cgroup files · line 107
Quoted 10 lines
Documentation/cgroups/blkio-controller.txt +10
-0+ device, third field specifies the operation type and the fourth field + specifies the number of bytes. + +- blkio.io_serviced + - Number of IOs completed to/from the disk by the group. These + are further divided by the type of operation - read or write, sync + or async. First two fields specify the major and minor number of the + device, third field specifies the operation type and the fourth field + specifies the number of IOs. +
Hi Divyesh,
V3 looks much better. Just couple of minor nits.
Documentation/cgroups/blkio-controller.txt Details of cgroup files · line 113
Quoted 6 lines
Documentation/cgroups/blkio-controller.txt +6
-0+- blkio.io_service_time + - Total amount of time between request dispatch and request completion + for the IOs done by this cgroup. This is in nanoseconds to make it + meaningful for flash devices too. For devices with queue depth of 1, + this time represents the actual service time. When queue_depth > 1, + that is no longer true as requests may be served out of order.
Like io_wait_time, can you also mention here that this time is cumulative time and on NCQ disks it can be more than actual time elapsed.
I did a quick run with your patches. I ran a sequential workload for 30s in two groups of weight 100 and 200. Following is the output of blkio.io_service_time (I have kept stats for only disk 253:3 in output).
# cat test1/blkio.io_service_time 253:3 Read 18019970625 253:3 Write 0 253:3 Sync 18019970625 253:3 Async 0 253:3 Total 18019970625
# cat test2/blkio.io_service_time 253:3 Read 35479070171 253:3 Write 0 253:3 Sync 35479070171 253:3 Async 0
This storage supports NCQ. We see that though I ran test only for 30 seconds, total service ime for cgroup is close to 18+35=53 seconds.
Quoted 19 lines
Documentation/cgroups/blkio-controller.txt +15
-0+ This time is further divided by the type of operation - + read or write, sync or async. First two fields specify the major and + minor number of the device, third field specifies the operation type + and the fourth field specifies the io_service_time in ns. + +- blkio.io_wait_time + - Total amount of time the IO spent waiting in the scheduler queues for + service. This can be greater than the total time elapsed since it is + cumulative io_wait_time for all IOs. This is in nanoseconds to make it + meaningful for flash devices too. This time is further divided by the + type of operation - read or write, sync or async. First two fields + specify the major and minor number of the device, third field + specifies the operation type and the fourth field specifies the + io_wait_time in ns. + - blkio.dequeue - Debugging aid only enabled if CONFIG_DEBUG_CFQ_IOSCHED=y. This gives the statistics about how many a times a group was dequeued
Documentation/cgroups/blkio-controller.txt Details of cgroup files · line 139
Quoted 7 lines
Documentation/cgroups/blkio-controller.txt +4
-0@@ -99,6 +133,10 @@ Details of cgroup files and minor number of the device and third field specifies the number of times a group was dequeued from a particular device. +- blkio.reset_stats + - Writing an int to this file will result in resetting all the stats + for that cgroup. +
Personally, I like adding a separate file to reset the stats. Now one does not get surprised by the fact that writting to blkio.io_service_time, also reset rest of the stats.
Quoted 43 lines
Documentation/cgroups/blkio-controller.txt +0
-0CFQ sysfs tunable ================= /sys/block/<disk>/queue/iosched/group_isolationblock/blk-cgroup.c +15
-4@@ -17,6 +17,8 @@#include <linux/err.h> #include "blk-cgroup.h" +#define MAX_KEY_LEN 100 +static DEFINE_SPINLOCK (blkio_list_lock);static LIST_HEAD (blkio_list);@@ -55,12 +57,21 @@ struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup) }EXPORT_SYMBOL_GPL (cgroup_to_blkio_cgroup); -void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, -unsigned long time) +void blkio_group_init (struct blkio_group *blkg) +{ +spin_lock_init (&blkg->stats_lock); +} +EXPORT_SYMBOL_GPL (blkio_group_init); + +void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time) { - blkg->time += time; +unsigned long flags; + +spin_lock_irqsave (&blkg->stats_lock, flags); + blkg->stats.time += time; +spin_unlock_irqrestore (&blkg->stats_lock, flags); } -EXPORT_SYMBOL_GPL (blkiocg_update_blkio_group_stats); +EXPORT_SYMBOL_GPL (blkiocg_update_timeslice_used);void blkiocg_add_blkio_group (struct blkio_cgroup *blkcg,struct blkio_group *blkg,void *key,dev_t dev)
block/blk-cgroup.c blkiocg_weight_write(struct cgroup *cgroup, struct cftype *cftype, u64 val) · line 186
Quoted 7 lines
block/blk-cgroup.c +3
-1@@ -170,13 +181,107 @@ blkiocg_weight_write(struct cgroup *cgroup, struct cftype *cftype, u64 val)return 0 ; } -#define SHOW_FUNCTION_PER_GROUP (__VAR) \ +static int +blkiocg_reset_write (struct cgroup *cgroup,struct cftype *cftype,u64 val) +{
I guess we can rename this function to blkiocg_reset_stats().
[..]
Quoted 21 lines
block/blk-cgroup.c +12
-2@@ -217,16 +331,36 @@ struct cftype blkio_files[] = { }, { .name = "time", - .read_seq_string = blkiocg_time_read, + .read_map = blkiocg_time_read, }, { .name = "sectors", - .read_seq_string = blkiocg_sectors_read, + .read_map = blkiocg_sectors_read, + }, + { + .name = "io_service_bytes", + .read_map = blkiocg_io_service_bytes_read, + }, + { + .name = "io_serviced", + .read_map = blkiocg_io_serviced_read, + }, + {
block/blk-cgroup.c struct cftype blkio_files[] = { · line 358
Quoted 10 lines
block/blk-cgroup.c +10
-0+ .name = "io_service_time", + .read_map = blkiocg_io_service_time_read, + }, + { + .name = "io_wait_time", + .read_map = blkiocg_io_wait_time_read, + }, + { + .name = "reset_stats", + .write_u64 = blkiocg_reset_write,
use blkiocg_reset_stats?
Thanks
Vivek
Re: [PATCH 2/3][v3] blkio: Add io controller stats like
Vivek,
I'll send out a v3.1 only for this patch since you've Acked the
other 2 patches. Thanks a lot for the detailed reviews again!
Quoted 63 lines · Vivek Goyal
Quoted 42 lines · Divyesh Shah
-
io_service_time(the time between request dispatch and completion for IOs in the cgroup)
-io_wait_time(the time spent waiting in the IO shceduler queues before getting serviced)
-io_serviced(number of IOs serviced from thisblkio_group)
-io_service_bytes(Number of bytes served for this cgroup)These stats are accumulated per operation type helping us to distinguish between read and write, and sync and async IO. This patch does not increment any of these stats.
Signed-off-by Divyesh Shah<[email protected]>---
Documentation/cgroups/blkio-controller.txt | 40 +++++++
block/blk-cgroup.c | 166 +++++++++++++++++++++++++--- block/blk-cgroup.h | 60 ++++++++-- block/cfq-iosched.c | 3 - 4 files changed, 239 insertions(+), 30 deletions(-)Documentation/cgroups/blkio-controller.txt +0
-0@@ -77,7 +77,6 @@ Details of cgroup files=======================
- blkio.weight
- Specifies per cgroup weight.
-
Currently allowed range of weights is from 100 to 1000.- blkio.time
Documentation/cgroups/blkio-controller.txt +0
-0@@ -92,6 +91,41 @@ Details of cgroup filesthird field specifies the number of sectors transferred by the group to/from the device.
+- blkio.io_service_bytes
+ - Number of bytes transferred to/from the disk by the group. These
+ are further divided by the type of operation - read or write, sync
+ or async. First two fields specify the major and minor number of the
+ device, third field specifies the operation type and the fourth field
+ specifies the number of bytes.Documentation/cgroups/blkio-controller.txt Details of cgroup files · line 107
Quoted 8 lines
Documentation/cgroups/blkio-controller.txt +8
-0+ +- blkio.io_serviced + - Number of IOs completed to/from the disk by the group. These + are further divided by the type of operation - read or write, sync + or async. First two fields specify the major and minor number of the + device, third field specifies the operation type and the fourth field + specifies the number of IOs. +Hi Divyesh,
V3 looks much better. Just couple of minor nits.
Quoted 6 lines
+- blkio.io_service_time
+ - Total amount of time between request dispatch and request completion
+ for the IOs done by this cgroup. This is in nanoseconds to make it
+ meaningful for flash devices too. For devices with queue depth of 1,
+ this time represents the actual service time. Whenqueue_depth> 1,
+ that is no longer true as requests may be served out of order.
Quoted 2 lines
Like
io_wait_time, can you also mention here that this time is cumulative time and on NCQ disks it can be more than actual time elapsed.
Will do.
Quoted 12 lines
I did a quick run with your patches. I ran a sequential workload for 30s in two groups of weight 100 and 200. Following is the output of blkio.io_service_time (I have kept stats for only disk 253:3 in output).
# cat test1/blkio.io_service_time 253:3 Read 18019970625 253:3 Write 0 253:3 Sync 18019970625 253:3 Async 0 253:3 Total 18019970625
Quoted 8 lines
# cat test2/blkio.io_service_time 253:3 Read 35479070171 253:3 Write 0 253:3 Sync 35479070171 253:3 Async 0This storage supports NCQ. We see that though I ran test only for 30 seconds, total service ime for cgroup is close to 18+35=53 seconds.
Yes that is expected as from our discussion about NCQ as any IO can have the service time of multiple IOs coupled together when serviced out of order.
Quoted 78 lines
Quoted 23 lines
+ This time is further divided by the type of operation -
+ read or write, sync or async. First two fields specify the major and
+ minor number of the device, third field specifies the operation type
+ and the fourth field specifies theio_service_timein ns.Documentation/cgroups/blkio-controller.txt +11
-0+ +- blkio.io_wait_time + - Total amount of time the IO spent waiting in the scheduler queues for + service. This can be greater than the total time elapsed since it is + cumulative io_wait_time for all IOs. This is in nanoseconds to make it + meaningful for flash devices too. This time is further divided by the + type of operation - read or write, sync or async. First two fields + specify the major and minor number of the device, third field + specifies the operation type and the fourth field specifies the + io_wait_time in ns. +- blkio.dequeue
- Debugging aid only enabled ifCONFIG_DEBUG_CFQ_IOSCHED=y. This gives the statistics about how many a times a group was dequeuedDocumentation/cgroups/blkio-controller.txt +0
-0@@ -99,6 +133,10 @@ Details of cgroup filesand minor number of the device and third field specifies the number of times a group was dequeued from a particular device.
Quoted 4 lines
+- blkio.reset_stats
+ - Writing an int to this file will result in resetting all the stats
+ for that cgroup.
+Personally, I like adding a separate file to reset the stats. Now one does not get surprised by the fact that writting to blkio.io_service_time, also reset rest of the stats.
Quoted 46 lines
CFQ sysfs tunable
=================
/sys/block/<disk>/queue/iosched/group_isolationblock/blk-cgroup.c +15
-4@@ -17,6 +17,8 @@ #include <linux/err.h> #include "blk-cgroup.h" +#define MAX_KEY_LEN 100 + static DEFINE_SPINLOCK(blkio_list_lock); static LIST_HEAD(blkio_list);@@ -55,12 +57,21 @@ struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup) } EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup); -void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, - unsigned long time) +void blkio_group_init (struct blkio_group *blkg) +{ + spin_lock_init(&blkg->stats_lock); +} +EXPORT_SYMBOL_GPL (blkio_group_init); + +void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time) { - blkg->time += time; + unsigned long flags; + + spin_lock_irqsave(&blkg->stats_lock, flags); + blkg->stats.time += time; + spin_unlock_irqrestore(&blkg->stats_lock, flags); } -EXPORT_SYMBOL_GPL (blkiocg_update_blkio_group_stats); +EXPORT_SYMBOL_GPL (blkiocg_update_timeslice_used); void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, struct blkio_group *blkg, void *key, dev_t dev)@@ -170,13 +181,107 @@ blkiocg_weight_write(struct cgroup *cgroup, struct cftype *cftype, u64 val) return 0; }
Quoted 6 lines
block/blk-cgroup.c blkiocg_weight_write(struct cgroup *cgroup, struct cftype *cftype, u64 val) · line 186
Quoted 4 lines
block/blk-cgroup.c +3
-1-#define SHOW_FUNCTION_PER_GROUP (__VAR) \ +static int +blkiocg_reset_write (struct cgroup *cgroup,struct cftype *cftype,u64 val) +{I guess we can rename this function to
blkiocg_reset_stats().
Will do
Quoted 27 lines
[..]
Quoted 25 lines
block/blk-cgroup.c +16
-2@@ -217,16 +331,36 @@ struct cftype blkio_files[] = { }, { .name = "time", - .read_seq_string = blkiocg_time_read, + .read_map = blkiocg_time_read, }, { .name = "sectors", - .read_seq_string = blkiocg_sectors_read, + .read_map = blkiocg_sectors_read, + }, + { + .name = "io_service_bytes", + .read_map = blkiocg_io_service_bytes_read, + }, + { + .name = "io_serviced", + .read_map = blkiocg_io_serviced_read, + }, + { + .name = "io_service_time", + .read_map = blkiocg_io_service_time_read, + }, + {
Quoted 8 lines
block/blk-cgroup.c struct cftype blkio_files[] = { · line 358
Quoted 6 lines
block/blk-cgroup.c +6
-0+ .name = "io_wait_time", + .read_map = blkiocg_io_wait_time_read, + }, + { + .name = "reset_stats", + .write_u64 = blkiocg_reset_write,use
blkiocg_reset_stats?
Will do
Quoted 4 lines
Thanks
Vivek
Re: [PATCH 2/3][v3] blkio: Add io controller stats like
Quoted 4 lines · Divyesh Shah
Vivek,
I'll send out a v3.1 only for this patch since you've Acked the
other 2 patches. Thanks a lot for the detailed reviews again!
That's fine. You can just reply to same mail and attach the new patch. Just that we need to explicitly mention to Jens to pick this new patch with minor modifications.
Jens, how should we handle this patchset now? Original patches have already been applied to you for-2.6.35 branch. Should Divyesh, now send cleanup patches on top of these or something else?
Thanks
Vivek
Quoted 220 lines · Vivek Goyal
Quoted 63 lines · Divyesh Shah
Quoted 42 lines
-
io_service_time(the time between request dispatch and completion for IOs in the cgroup)
-io_wait_time(the time spent waiting in the IO shceduler queues before getting serviced)
-io_serviced(number of IOs serviced from thisblkio_group)
-io_service_bytes(Number of bytes served for this cgroup)These stats are accumulated per operation type helping us to distinguish between read and write, and sync and async IO. This patch does not increment any of these stats.
Signed-off-by Divyesh Shah<[email protected]>---
Documentation/cgroups/blkio-controller.txt | 40 +++++++
block/blk-cgroup.c | 166 +++++++++++++++++++++++++--- block/blk-cgroup.h | 60 ++++++++-- block/cfq-iosched.c | 3 - 4 files changed, 239 insertions(+), 30 deletions(-)Documentation/cgroups/blkio-controller.txt +0
-0@@ -77,7 +77,6 @@ Details of cgroup files=======================
- blkio.weight
- Specifies per cgroup weight.
-
Currently allowed range of weights is from 100 to 1000.- blkio.time
Documentation/cgroups/blkio-controller.txt +0
-0@@ -92,6 +91,41 @@ Details of cgroup filesthird field specifies the number of sectors transferred by the group to/from the device.
+- blkio.io_service_bytes
+ - Number of bytes transferred to/from the disk by the group. These
+ are further divided by the type of operation - read or write, sync
+ or async. First two fields specify the major and minor number of the
+ device, third field specifies the operation type and the fourth field
+ specifies the number of bytes.Documentation/cgroups/blkio-controller.txt Details of cgroup files · line 107
Quoted 8 lines
Documentation/cgroups/blkio-controller.txt +8
-0+ +- blkio.io_serviced + - Number of IOs completed to/from the disk by the group. These + are further divided by the type of operation - read or write, sync + or async. First two fields specify the major and minor number of the + device, third field specifies the operation type and the fourth field + specifies the number of IOs. +Hi Divyesh,
V3 looks much better. Just couple of minor nits.
Quoted 6 lines
+- blkio.io_service_time
+ - Total amount of time between request dispatch and request completion
+ for the IOs done by this cgroup. This is in nanoseconds to make it
+ meaningful for flash devices too. For devices with queue depth of 1,
+ this time represents the actual service time. Whenqueue_depth> 1,
+ that is no longer true as requests may be served out of order.Quoted 2 lines
Like
io_wait_time, can you also mention here that this time is cumulative time and on NCQ disks it can be more than actual time elapsed.Will do.
Quoted 12 lines
I did a quick run with your patches. I ran a sequential workload for 30s in two groups of weight 100 and 200. Following is the output of blkio.io_service_time (I have kept stats for only disk 253:3 in output).
# cat test1/blkio.io_service_time 253:3 Read 18019970625 253:3 Write 0 253:3 Sync 18019970625 253:3 Async 0 253:3 Total 18019970625Quoted 8 lines
# cat test2/blkio.io_service_time 253:3 Read 35479070171 253:3 Write 0 253:3 Sync 35479070171 253:3 Async 0This storage supports NCQ. We see that though I ran test only for 30 seconds, total service ime for cgroup is close to 18+35=53 seconds.
Yes that is expected as from our discussion about NCQ as any IO can have the service time of multiple IOs coupled together when serviced out of order.
Quoted 78 lines
Quoted 23 lines
+ This time is further divided by the type of operation -
+ read or write, sync or async. First two fields specify the major and
+ minor number of the device, third field specifies the operation type
+ and the fourth field specifies theio_service_timein ns.Documentation/cgroups/blkio-controller.txt +11
-0+ +- blkio.io_wait_time + - Total amount of time the IO spent waiting in the scheduler queues for + service. This can be greater than the total time elapsed since it is + cumulative io_wait_time for all IOs. This is in nanoseconds to make it + meaningful for flash devices too. This time is further divided by the + type of operation - read or write, sync or async. First two fields + specify the major and minor number of the device, third field + specifies the operation type and the fourth field specifies the + io_wait_time in ns. +- blkio.dequeue
- Debugging aid only enabled ifCONFIG_DEBUG_CFQ_IOSCHED=y. This gives the statistics about how many a times a group was dequeuedDocumentation/cgroups/blkio-controller.txt +0
-0@@ -99,6 +133,10 @@ Details of cgroup filesand minor number of the device and third field specifies the number of times a group was dequeued from a particular device.
Quoted 4 lines
+- blkio.reset_stats
+ - Writing an int to this file will result in resetting all the stats
+ for that cgroup.
+Personally, I like adding a separate file to reset the stats. Now one does not get surprised by the fact that writting to blkio.io_service_time, also reset rest of the stats.
Quoted 46 lines
CFQ sysfs tunable
=================
/sys/block/<disk>/queue/iosched/group_isolationblock/blk-cgroup.c +15
-4@@ -17,6 +17,8 @@ #include <linux/err.h> #include "blk-cgroup.h" +#define MAX_KEY_LEN 100 + static DEFINE_SPINLOCK(blkio_list_lock); static LIST_HEAD(blkio_list);@@ -55,12 +57,21 @@ struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup) } EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup); -void blkiocg_update_blkio_group_stats (struct blkio_group *blkg, - unsigned long time) +void blkio_group_init (struct blkio_group *blkg) +{ + spin_lock_init(&blkg->stats_lock); +} +EXPORT_SYMBOL_GPL (blkio_group_init); + +void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time) { - blkg->time += time; + unsigned long flags; + + spin_lock_irqsave(&blkg->stats_lock, flags); + blkg->stats.time += time; + spin_unlock_irqrestore(&blkg->stats_lock, flags); } -EXPORT_SYMBOL_GPL (blkiocg_update_blkio_group_stats); +EXPORT_SYMBOL_GPL (blkiocg_update_timeslice_used); void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg, struct blkio_group *blkg, void *key, dev_t dev)@@ -170,13 +181,107 @@ blkiocg_weight_write(struct cgroup *cgroup, struct cftype *cftype, u64 val) return 0; }Quoted 6 lines
block/blk-cgroup.c blkiocg_weight_write(struct cgroup *cgroup, struct cftype *cftype, u64 val) · line 186
Quoted 4 lines
block/blk-cgroup.c +3
-1-#define SHOW_FUNCTION_PER_GROUP (__VAR) \ +static int +blkiocg_reset_write (struct cgroup *cgroup,struct cftype *cftype,u64 val) +{I guess we can rename this function to
blkiocg_reset_stats().Will do
Quoted 27 lines
[..]
Quoted 25 lines
block/blk-cgroup.c +16
-2@@ -217,16 +331,36 @@ struct cftype blkio_files[] = { }, { .name = "time", - .read_seq_string = blkiocg_time_read, + .read_map = blkiocg_time_read, }, { .name = "sectors", - .read_seq_string = blkiocg_sectors_read, + .read_map = blkiocg_sectors_read, + }, + { + .name = "io_service_bytes", + .read_map = blkiocg_io_service_bytes_read, + }, + { + .name = "io_serviced", + .read_map = blkiocg_io_serviced_read, + }, + { + .name = "io_service_time", + .read_map = blkiocg_io_service_time_read, + }, + {Quoted 8 lines
block/blk-cgroup.c struct cftype blkio_files[] = { · line 358
Quoted 6 lines
block/blk-cgroup.c +6
-0+ .name = "io_wait_time", + .read_map = blkiocg_io_wait_time_read, + }, + { + .name = "reset_stats", + .write_u64 = blkiocg_reset_write,use
blkiocg_reset_stats?Will do
Quoted 4 lines
Thanks
Vivek
PATCH v3 3/3 blkio: Increment the blkio cgroup stats for real now.
In reply to Divyesh ShahWe also add start_time_ns and io_start_time_ns fields to struct request here to record the time when a request is created and when it is dispatched to device. We use ns uints here as ms and jiffies are not very useful for non-rotational media.
---
block/blk-cgroup.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++-- block/blk-cgroup.h | 15 ++++++++++-- block/blk-core.c | 6 +++-- block/cfq-iosched.c | 7 +++++- include/linux/blkdev.h | 38 +++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 9 deletions(-)
block/blk-cgroup.c +56 -2
@@ -15,6 +15,7 @@#include <linux/kdev_t.h> #include <linux/module.h> #include <linux/err.h> +#include <linux/blkdev.h> #include "blk-cgroup.h" #define MAX_KEY_LEN 100
@@ -63,6 +64,23 @@ void blkio_group_init(struct blkio_group *blkg) }EXPORT_SYMBOL_GPL (blkio_group_init); +/* +* Add to the appropriate stat variable depending on the request type. +* This should be called with the blkg->stats_lock held. +*/ +static void blkio_add_stat (uint64_t *stat,uint64_t add,bool direction, +bool sync) +{ +if (direction) + stat[BLKIO_STAT_WRITE ] += add; +else + stat[BLKIO_STAT_READ ] += add; +if (sync) + stat[BLKIO_STAT_SYNC ] += add; +else + stat[BLKIO_STAT_ASYNC ] += add; +} +void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time) {unsigned long flags;
@@ -73,6 +91,42 @@ void blkiocg_update_timeslice_used(struct blkio_group *blkg, unsigned long time) }EXPORT_SYMBOL_GPL (blkiocg_update_timeslice_used); +void blkiocg_update_dispatch_stats (struct blkio_group *blkg, +uint64_t bytes,bool direction,bool sync) +{ +struct blkio_group_stats *stats; +unsigned long flags; + +spin_lock_irqsave (&blkg->stats_lock, flags); + stats = &blkg->stats; + stats->sectors += bytes >>9 ; +blkio_add_stat (stats->stat_arr[BLKIO_STAT_SERVICED ],1 , direction, + sync); +blkio_add_stat (stats->stat_arr[BLKIO_STAT_SERVICE_BYTES ], bytes, + direction, sync); +spin_unlock_irqrestore (&blkg->stats_lock, flags); +} +EXPORT_SYMBOL_GPL (blkiocg_update_dispatch_stats); + +void blkiocg_update_completion_stats (struct blkio_group *blkg, +uint64_t start_time,uint64_t io_start_time,bool direction,bool sync) +{ +struct blkio_group_stats *stats; +unsigned long flags; +unsigned long long now =sched_clock (); + +spin_lock_irqsave (&blkg->stats_lock, flags); + stats = &blkg->stats; +if (time_after64 (now, io_start_time)) +blkio_add_stat (stats->stat_arr[BLKIO_STAT_SERVICE_TIME ], + now - io_start_time, direction, sync); +if (time_after64 (io_start_time, start_time)) +blkio_add_stat (stats->stat_arr[BLKIO_STAT_WAIT_TIME ], + io_start_time - start_time, direction, sync); +spin_unlock_irqrestore (&blkg->stats_lock, flags); +} +EXPORT_SYMBOL_GPL (blkiocg_update_completion_stats); +void blkiocg_add_blkio_group (struct blkio_cgroup *blkcg,struct blkio_group *blkg,void *key,dev_t dev) {
@@ -315,12 +369,12 @@ SHOW_FUNCTION_PER_GROUP(dequeue, BLKIO_STAT_DEQUEUE, 0);#undef SHOW_FUNCTION_PER_GROUP#ifdef CONFIG_DEBUG_BLK_CGROUP -void blkiocg_update_blkio_group_dequeue_stats (struct blkio_group *blkg, +void blkiocg_update_dequeue_stats (struct blkio_group *blkg,unsigned long dequeue) { blkg->stats.dequeue += dequeue; } -EXPORT_SYMBOL_GPL (blkiocg_update_blkio_group_dequeue_stats); +EXPORT_SYMBOL_GPL (blkiocg_update_dequeue_stats);#endif struct cftype blkio_files[] = {
block/blk-cgroup.h +12 -3
@@ -125,12 +125,12 @@ static inline char *blkg_path(struct blkio_group *blkg) {return blkg->path; } -void blkiocg_update_blkio_group_dequeue_stats (struct blkio_group *blkg, +void blkiocg_update_dequeue_stats (struct blkio_group *blkg,unsigned long dequeue);#else static inline char *blkg_path (struct blkio_group *blkg) {return NULL ; } -static inline void blkiocg_update_blkio_group_dequeue_stats ( -struct blkio_group *blkg,unsigned long dequeue) {} +static inline void blkiocg_update_dequeue_stats (struct blkio_group *blkg, +unsigned long dequeue) {}#endif #if defined(CONFIG_BLK_CGROUP ) || defined(CONFIG_BLK_CGROUP_MODULE )
@@ -144,6 +144,10 @@ extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,void blkio_group_init (struct blkio_group *blkg);void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time); +void blkiocg_update_dispatch_stats (struct blkio_group *blkg,uint64_t bytes, +bool direction,bool sync); +void blkiocg_update_completion_stats (struct blkio_group *blkg, +uint64_t start_time,uint64_t io_start_time,bool direction,bool sync);#else struct cgroup ; static inline struct blkio_cgroup *
@@ -160,5 +164,10 @@ static inline struct blkio_group * blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }static inline void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time) {} +static inline void blkiocg_update_dispatch_stats (struct blkio_group *blkg, +uint64_t bytes,bool direction,bool sync) {} +static inline void blkiocg_update_completion_stats (struct blkio_group *blkg, +uint64_t start_time,uint64_t io_start_time,bool direction, +bool sync) {}#endif #endif /* _BLK_CGROUP_H */
block/blk-core.c +4 -2
@@ -127,6 +127,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq) rq->tag =-1 ; rq->ref_count =1 ; rq->start_time = jiffies; +set_start_time_ns (rq); }EXPORT_SYMBOL (blk_rq_init);
@@ -1855,8 +1856,10 @@ void blk_dequeue_request(struct request *rq)* and to it is freed is accounted as io that is in progress at * the driver side. */ -if (blk_account_rq (rq)) +if (blk_account_rq (rq)) { q->in_flight[rq_is_sync (rq)]++; +set_io_start_time_ns (rq); + } }/**
@@ -2517,4 +2520,3 @@ int __init blk_dev_init(void)return 0 ; } -
block/cfq-iosched.c +6 -1
@@ -854,7 +854,7 @@ cfq_group_service_tree_del(struct cfq_data *cfqd, struct cfq_group *cfqg)if (!RB_EMPTY_NODE (&cfqg->rb_node))cfq_rb_erase (&cfqg->rb_node, st); cfqg->saved_workload_slice =0 ; -blkiocg_update_blkio_group_dequeue_stats (&cfqg->blkg,1 ); +blkiocg_update_dequeue_stats (&cfqg->blkg,1 ); }static inline unsigned int cfq_cfqq_slice_usage (struct cfq_queue *cfqq)
@@ -1865,6 +1865,8 @@ static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)elv_dispatch_sort (q, rq); cfqd->rq_in_flight[cfq_cfqq_sync (cfqq)]++; +blkiocg_update_dispatch_stats (&cfqq->cfqg->blkg,blk_rq_bytes (rq), +rq_data_dir (rq),rq_is_sync (rq)); }/*
@@ -3285,6 +3287,9 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)WARN_ON (!cfqq->dispatched); cfqd->rq_in_driver--; cfqq->dispatched--; +blkiocg_update_completion_stats (&cfqq->cfqg->blkg,rq_start_time_ns (rq), +rq_io_start_time_ns (rq),rq_data_dir (rq), +rq_is_sync (rq)); cfqd->rq_in_flight[cfq_cfqq_sync (cfqq)]--;
include/linux/blkdev.h +37 -1
@@ -193,7 +193,10 @@ struct request {struct gendisk *rq_disk;unsigned long start_time; - +#if defined(CONFIG_BLK_CGROUP ) || defined(CONFIG_BLK_CGROUP_MODULE ) +unsigned long long start_time_ns; +unsigned long long io_start_time_ns;/* when passed to hardware */ +#endif /* Number of scatter-gather DMA addr+len pairs after * physical address coalescing is performed. */
@@ -1219,6 +1222,39 @@ static inline void put_dev_sector(Sector p)struct work_struct ;int kblockd_schedule_work (struct request_queue *q,struct work_struct *work); +#if defined(CONFIG_BLK_CGROUP ) || defined(CONFIG_BLK_CGROUP_MODULE ) +static inline void set_start_time_ns (struct request *req) +{ + req->start_time_ns =sched_clock (); +} + +static inline void set_io_start_time_ns (struct request *req) +{ + req->io_start_time_ns =sched_clock (); +} + +static inline uint64_t rq_start_time_ns (struct request *req) +{ +return req->start_time_ns; +} + +static inline uint64_t rq_io_start_time_ns (struct request *req) +{ +return req->io_start_time_ns; +} +#else +static inline void set_start_time_ns (struct request *req) {} +static inline void set_io_start_time_ns (struct request *req) {} +static inline uint64_t rq_start_time_ns (struct request *req) +{ +return 0 ; +} +static inline uint64_t rq_io_start_time_ns (struct request *req) +{ +return 0 ; +} +#endif +#define MODULE_ALIAS_BLOCKDEV (major,minor) \ MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))#define MODULE_ALIAS_BLOCKDEV_MAJOR (major) \
Re: [PATCH 3/3][v3] blkio: Increment the blkio cgroup stats for real now.
Quoted 6 lines · Divyesh Shah
We also add
start_time_nsandio_start_time_nsfields to struct request here to record the time when a request is created and when it is dispatched to device. We use ns uints here as ms and jiffies are not very useful for non-rotational media.Signed-off-by Divyesh Shah<[email protected]>
Looks good to me.
Vivek
Quoted 262 lines
---
block/blk-cgroup.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++-- block/blk-cgroup.h | 15 ++++++++++-- block/blk-core.c | 6 +++-- block/cfq-iosched.c | 7 +++++- include/linux/blkdev.h | 38 +++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 9 deletions(-)block/blk-cgroup.c +56
-2@@ -15,6 +15,7 @@#include <linux/kdev_t.h> #include <linux/module.h> #include <linux/err.h> +#include <linux/blkdev.h> #include "blk-cgroup.h" #define MAX_KEY_LEN 100@@ -63,6 +64,23 @@ void blkio_group_init(struct blkio_group *blkg) }EXPORT_SYMBOL_GPL (blkio_group_init); +/* +* Add to the appropriate stat variable depending on the request type. +* This should be called with the blkg->stats_lock held. +*/ +static void blkio_add_stat (uint64_t *stat,uint64_t add,bool direction, +bool sync) +{ +if (direction) + stat[BLKIO_STAT_WRITE ] += add; +else + stat[BLKIO_STAT_READ ] += add; +if (sync) + stat[BLKIO_STAT_SYNC ] += add; +else + stat[BLKIO_STAT_ASYNC ] += add; +} +void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time) {unsigned long flags;@@ -73,6 +91,42 @@ void blkiocg_update_timeslice_used(struct blkio_group *blkg, unsigned long time) }EXPORT_SYMBOL_GPL (blkiocg_update_timeslice_used); +void blkiocg_update_dispatch_stats (struct blkio_group *blkg, +uint64_t bytes,bool direction,bool sync) +{ +struct blkio_group_stats *stats; +unsigned long flags; + +spin_lock_irqsave (&blkg->stats_lock, flags); + stats = &blkg->stats; + stats->sectors += bytes >>9 ; +blkio_add_stat (stats->stat_arr[BLKIO_STAT_SERVICED ],1 , direction, + sync); +blkio_add_stat (stats->stat_arr[BLKIO_STAT_SERVICE_BYTES ], bytes, + direction, sync); +spin_unlock_irqrestore (&blkg->stats_lock, flags); +} +EXPORT_SYMBOL_GPL (blkiocg_update_dispatch_stats); + +void blkiocg_update_completion_stats (struct blkio_group *blkg, +uint64_t start_time,uint64_t io_start_time,bool direction,bool sync) +{ +struct blkio_group_stats *stats; +unsigned long flags; +unsigned long long now =sched_clock (); + +spin_lock_irqsave (&blkg->stats_lock, flags); + stats = &blkg->stats; +if (time_after64 (now, io_start_time)) +blkio_add_stat (stats->stat_arr[BLKIO_STAT_SERVICE_TIME ], + now - io_start_time, direction, sync); +if (time_after64 (io_start_time, start_time)) +blkio_add_stat (stats->stat_arr[BLKIO_STAT_WAIT_TIME ], + io_start_time - start_time, direction, sync); +spin_unlock_irqrestore (&blkg->stats_lock, flags); +} +EXPORT_SYMBOL_GPL (blkiocg_update_completion_stats); +void blkiocg_add_blkio_group (struct blkio_cgroup *blkcg,struct blkio_group *blkg,void *key,dev_t dev) {@@ -315,12 +369,12 @@ SHOW_FUNCTION_PER_GROUP(dequeue, BLKIO_STAT_DEQUEUE, 0);#undef SHOW_FUNCTION_PER_GROUP#ifdef CONFIG_DEBUG_BLK_CGROUP -void blkiocg_update_blkio_group_dequeue_stats (struct blkio_group *blkg, +void blkiocg_update_dequeue_stats (struct blkio_group *blkg,unsigned long dequeue) { blkg->stats.dequeue += dequeue; } -EXPORT_SYMBOL_GPL (blkiocg_update_blkio_group_dequeue_stats); +EXPORT_SYMBOL_GPL (blkiocg_update_dequeue_stats);#endif struct cftype blkio_files[] = {block/blk-cgroup.h +12
-3@@ -125,12 +125,12 @@ static inline char *blkg_path(struct blkio_group *blkg) {return blkg->path; } -void blkiocg_update_blkio_group_dequeue_stats (struct blkio_group *blkg, +void blkiocg_update_dequeue_stats (struct blkio_group *blkg,unsigned long dequeue);#else static inline char *blkg_path (struct blkio_group *blkg) {return NULL ; } -static inline void blkiocg_update_blkio_group_dequeue_stats ( -struct blkio_group *blkg,unsigned long dequeue) {} +static inline void blkiocg_update_dequeue_stats (struct blkio_group *blkg, +unsigned long dequeue) {}#endif #if defined(CONFIG_BLK_CGROUP ) || defined(CONFIG_BLK_CGROUP_MODULE )@@ -144,6 +144,10 @@ extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,void blkio_group_init (struct blkio_group *blkg);void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time); +void blkiocg_update_dispatch_stats (struct blkio_group *blkg,uint64_t bytes, +bool direction,bool sync); +void blkiocg_update_completion_stats (struct blkio_group *blkg, +uint64_t start_time,uint64_t io_start_time,bool direction,bool sync);#else struct cgroup ; static inline struct blkio_cgroup *@@ -160,5 +164,10 @@ static inline struct blkio_group * blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }static inline void blkiocg_update_timeslice_used (struct blkio_group *blkg,unsigned long time) {} +static inline void blkiocg_update_dispatch_stats (struct blkio_group *blkg, +uint64_t bytes,bool direction,bool sync) {} +static inline void blkiocg_update_completion_stats (struct blkio_group *blkg, +uint64_t start_time,uint64_t io_start_time,bool direction, +bool sync) {}#endif #endif /* _BLK_CGROUP_H */ block/blk-core.c +4
-2@@ -127,6 +127,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq) rq->tag =-1 ; rq->ref_count =1 ; rq->start_time = jiffies; +set_start_time_ns (rq); }EXPORT_SYMBOL (blk_rq_init);@@ -1855,8 +1856,10 @@ void blk_dequeue_request(struct request *rq)* and to it is freed is accounted as io that is in progress at * the driver side. */ -if (blk_account_rq (rq)) +if (blk_account_rq (rq)) { q->in_flight[rq_is_sync (rq)]++; +set_io_start_time_ns (rq); + } }/** @@ -2517,4 +2520,3 @@ int __init blk_dev_init(void)return 0 ; } -block/cfq-iosched.c +6
-1@@ -854,7 +854,7 @@ cfq_group_service_tree_del(struct cfq_data *cfqd, struct cfq_group *cfqg)if (!RB_EMPTY_NODE (&cfqg->rb_node))cfq_rb_erase (&cfqg->rb_node, st); cfqg->saved_workload_slice =0 ; -blkiocg_update_blkio_group_dequeue_stats (&cfqg->blkg,1 ); +blkiocg_update_dequeue_stats (&cfqg->blkg,1 ); }static inline unsigned int cfq_cfqq_slice_usage (struct cfq_queue *cfqq)@@ -1865,6 +1865,8 @@ static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)elv_dispatch_sort (q, rq); cfqd->rq_in_flight[cfq_cfqq_sync (cfqq)]++; +blkiocg_update_dispatch_stats (&cfqq->cfqg->blkg,blk_rq_bytes (rq), +rq_data_dir (rq),rq_is_sync (rq)); }/* @@ -3285,6 +3287,9 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)WARN_ON (!cfqq->dispatched); cfqd->rq_in_driver--; cfqq->dispatched--; +blkiocg_update_completion_stats (&cfqq->cfqg->blkg,rq_start_time_ns (rq), +rq_io_start_time_ns (rq),rq_data_dir (rq), +rq_is_sync (rq)); cfqd->rq_in_flight[cfq_cfqq_sync (cfqq)]--;include/linux/blkdev.h +37
-1@@ -193,7 +193,10 @@ struct request {struct gendisk *rq_disk;unsigned long start_time; - +#if defined(CONFIG_BLK_CGROUP ) || defined(CONFIG_BLK_CGROUP_MODULE ) +unsigned long long start_time_ns; +unsigned long long io_start_time_ns;/* when passed to hardware */ +#endif /* Number of scatter-gather DMA addr+len pairs after * physical address coalescing is performed. */ @@ -1219,6 +1222,39 @@ static inline void put_dev_sector(Sector p)struct work_struct ;int kblockd_schedule_work (struct request_queue *q,struct work_struct *work); +#if defined(CONFIG_BLK_CGROUP ) || defined(CONFIG_BLK_CGROUP_MODULE ) +static inline void set_start_time_ns (struct request *req) +{ + req->start_time_ns =sched_clock (); +} + +static inline void set_io_start_time_ns (struct request *req) +{ + req->io_start_time_ns =sched_clock (); +} + +static inline uint64_t rq_start_time_ns (struct request *req) +{ +return req->start_time_ns; +} + +static inline uint64_t rq_io_start_time_ns (struct request *req) +{ +return req->io_start_time_ns; +} +#else +static inline void set_start_time_ns (struct request *req) {} +static inline void set_io_start_time_ns (struct request *req) {} +static inline uint64_t rq_start_time_ns (struct request *req) +{ +return 0 ; +} +static inline uint64_t rq_io_start_time_ns (struct request *req) +{ +return 0 ; +} +#endif +#define MODULE_ALIAS_BLOCKDEV (major,minor) \ MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))#define MODULE_ALIAS_BLOCKDEV_MAJOR (major) \