dm: add statistics support
Subsystems (3)
PATCH v2 1/1 dm: add statistics support
From: Mikulas Patocka <[email protected]>
Support the collection of I/O statistics on user-defined regions of a DM device. Only bio-based DM devices are currently supported.
Each user-defined region specifies a starting sector, ending sector and step. Individual statistics will be collected for each step-sized area between the starting and ending sector.
The I/O statistics counters for each step-sized area of a region are in the same format as /sys/block/*/stat or /proc/diskstats but extra counters (12 and 13) are provided: total time spent reading and writing in milliseconds. These counters may be accessed by sending the @stats_print message to the appropriate DM device via dmsetup.
DM statistics creation will allocate memory via kmalloc or fallback to using vmalloc space. At most, 1/4 of the overall system memory may be allocated by DM statistics. The admin can see how much memory is used by reading /sys/module/dm_mod/parameters/stats_current_allocated_bytes
See Documentation/device-mapper/statistics.txt for more details.
--- Documentation/device-mapper/statistics.txt | 121 ++++ drivers/md/Makefile | 2 +- drivers/md/dm-ioctl.c | 22 +- drivers/md/dm-stats.c | 946 ++++++++++++++++++++++++++++ drivers/md/dm-stats.h | 40 ++ drivers/md/dm.c | 63 ++- drivers/md/dm.h | 17 + 7 files changed, 1200 insertions(+), 11 deletions(-)
Documentation/device-mapper/statistics.txt new file +121 -0
@@ -0,0 +1,121 @@ +DM statistics +============= + +Device Mapper supporta the collection of I/O statistics on user-defined +regions of a DM device. Only bio-based DM devices are currently +supported. + +Each user-defined region specifies a starting sector, ending sector +and step. Individual statistics will be collected for each step-sized +area between the starting and ending sector. + +The I/O statistics counters for each step-sized area of a region are +in the same format as /sys/block/*/stat or /proc/diskstats but extra +counters (12 and 13) are provided: total time spent reading and +writing in milliseconds. These counters may be accessed by sending the +@stats_print message to the appropriate DM device via dmsetup. + +Each region has a corresponding unique identifier that is assigned when +the region is created. The region id must be supplied when querying +statistics about the region, deleting the region, etc. Unique region +ids enable multiple userspace programs to request and process statistics +for the same DM device without stepping over each other's data. + +DM statistics creation will allocate memory via kmalloc or fallback to +using vmalloc space. At most, 1/4 of the overall system memory may be +allocated by DM statistics. The admin can see how much memory is used +by reading /sys/module/dm_mod/parameters/stats_current_allocated_bytes + +Messages +======== + + @stats_create <range> <step> [<program_id> [<program_params>]] + + Create a new region and return the region id. + <range> + "-" - whole device + "<start>-<end>" - a specified range in 512-byte sectors + <step> + "<number>" - the number of sectors in each area + "/<number>" - the range is subdivided into the specified + number of areas + <program_id> + An optional parameter. The string that identifies a program + that created this range. The kernel returns this string back + in the output of @stats_list message, but it doesn't use this + value for anything. + <program_params> + An optional parameter. The string that identifies parameters + for a program that created this range. The kernel returns this + string back in the output of @stats_list message, but it + doesn't use this value for anything. + + @stats_clear <region id> + + Clear all the counters except the in-flight i/o counters. + <region id> + region id returned from @stats_create + + @stats_print <region id> [<starting_line> <number_of_lines>] + + Print counters for each step-sized area of a region. + <region id> + region id returned from @stats_create + <starting_line> + The index of the starting line in the output. If omitted, all + lines are returned. + <number_of_lines> + The number of lines in the output. If omitted, all lines are + returned. + Output format for each step-sized area of a region: + <starting sector>-<ending sector> counters + The first 11 counters have the same meaning as + /sys/block/*/stat or /proc/diskstats. + Additional counters: + 12. the total time spent reading in milliseconds + 13. the total time spent writing in milliseconds + + @stats_print_clear <region id> [<starting_line> <number_of_lines>] + + Atomically print and then clear all the counters except the + in-flight i/o counters. Useful when client consuming the + statistics does not want to lose any statistics (those updated + between printing and clearing). + <region id> + region id returned from @stats_create + <starting_line> + The index of the starting line in the output. If omitted, all + lines are returned/cleared. + <number_of_lines> + The number of lines in the output. If omitted, all lines are + returned/cleared. + + @stats_delete <region id> + + Delete the region with the specified id. + <region id> + region id returned from @stats_create + + @stats_list [<program_id>] + + List all regions registered with @stats_create. + <program_id> + An optional parameter specifying the program that queries the + parameters. If this parameter is specified, only region + belonging to this program are returned. If it is not + specified, all regions are returned. + Output format: + <id>: <start>-<end> <step size> <program_id> <program_params> + +Examples +======== + +Subdivide the DM device 'vol' into 100 pieces and start collecting +statistics on them: +dmsetup message vol 0 @stats_create - /100 + +Print the statistics: +dmsetup message vol 0 @stats_print 0 + +Delete the statistics: +dmsetup message vol 0 @stats_delete 0
drivers/md/Makefile +1 -1
@@ -3,7 +3,7 @@ # dm-mod-y += dm.o dm-table.o dm-target.o dm-linear.o dm-stripe.o \ - dm-ioctl.o dm-io.o dm-kcopyd.o dm-sysfs.o + dm-ioctl.o dm-io.o dm-kcopyd.o dm-sysfs.o dm-stats.o dm-multipath-y += dm-path-selector.o dm-mpath.o dm-snapshot-y += dm-snap.o dm-exception-store.o dm-snap-transient.o \ dm-snap-persistent.o
drivers/md/dm-ioctl.c +14 -8
@@ -1455,20 +1455,26 @@ static int table_status(struct dm_ioctl *param, size_t param_size)return 0 ; } -static bool buffer_test_overflow (char *result,unsigned maxlen) -{ -return !maxlen ||strlen (result) +1 >= maxlen; -} -/* -* Process device-mapper dependent messages. +* Process device-mapper dependent messages. Messages prefixed with '@' +* are processed by the DM core. All others are delivered to the target. * Returns a number <= 1 if message was processed by device mapper. * Returns 2 if message should be delivered to the target. */ static int message_for_md (struct mapped_device *md,unsigned argc,char **argv,char *result,unsigned maxlen) { -return 2 ; +int r; + +if (**argv !='@' ) +return 2 ;/* no '@' prefix, deliver to target */ + + r =dm_stats_message (md, argc, argv, result, maxlen); +if (r <2 ) +return r; + +DMERR ("Unsupported message sent to DM core: %s" , argv[0 ]); +return -EINVAL ; }/*
@@ -1542,7 +1548,7 @@ static int target_message(struct dm_ioctl *param, size_t param_size)if (r ==1 ) { param->flags |=DM_DATA_OUT_FLAG ; -if (buffer_test_overflow (result, maxlen)) +if (dm_message_test_buffer_overflow (result, maxlen)) param->flags |=DM_BUFFER_FULL_FLAG ;else param->data_size = param->data_start +strlen (result) +1 ;
drivers/md/dm-stats.c new file +946 -0
946 lines not on this page · raw message
drivers/md/dm-stats.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef DM_STATS_H +#define DM_STATS_H + +#include <linux/types.h> +#include <linux/mutex.h> +#include <linux/list.h> + +int dm_statistics_init (void ); +void dm_statistics_exit (void ); + +struct dm_stats { +struct mutex mutex; +struct list_head list;/* list of struct dm_stat */ +struct dm_stats_last_position __percpu *last; +sector_t last_sector; +unsigned last_rw; +}; + +struct dm_stats_aux { +bool merged; +}; + +void dm_stats_init (struct dm_stats *st); +void dm_stats_cleanup (struct dm_stats *st); + +struct mapped_device ; + +int dm_stats_message (struct mapped_device *md,unsigned argc,char **argv, +char *result,unsigned maxlen); + +void dm_stats_account_io (struct dm_stats *stats,unsigned long bi_rw, +sector_t bi_sector,unsigned bi_sectors,bool end, +unsigned long duration,struct dm_stats_aux *aux); + +static inline bool dm_stats_used (struct dm_stats *st) +{ +return !list_empty (&st->list); +} + +#endif
drivers/md/dm.c +61 -2
136 lines not on this page · raw message
drivers/md/dm.h +17 -0
@@ -16,6 +16,8 @@#include <linux/blkdev.h> #include <linux/hdreg.h> +#include "dm-stats.h" +/* * Suspend feature flags */
@@ -146,10 +148,16 @@ void dm_destroy(struct mapped_device *md);void dm_destroy_immediate (struct mapped_device *md);int dm_open_count (struct mapped_device *md);int dm_lock_for_deletion (struct mapped_device *md); +int dm_request_based (struct mapped_device *md); +sector_t dm_get_size (struct mapped_device *md); +struct dm_stats *dm_get_stats (struct mapped_device *md);int dm_kobject_uevent (struct mapped_device *md,enum kobject_action action,unsigned cookie); +void dm_internal_suspend (struct mapped_device *md); +void dm_internal_resume (struct mapped_device *md); +int dm_io_init (void );void dm_io_exit (void );
@@ -162,4 +170,13 @@ void dm_kcopyd_exit(void);struct dm_md_mempools *dm_alloc_md_mempools (unsigned type,unsigned integrity,unsigned per_bio_data_size);void dm_free_md_mempools (struct dm_md_mempools *pools); + +/* +* Helpers that are used by DM core +*/ +static inline bool dm_message_test_buffer_overflow (char *result,unsigned maxlen) +{ +return !maxlen ||strlen (result) +1 >= maxlen; +} +#endif