Skip to content

Commit

Permalink
dm: add statistics support
Browse files Browse the repository at this point in the history
Support the collection of I/O statistics on user-defined regions of
a DM device.  If no regions are defined no statistics are collected so
there isn't any performance impact.  Only bio-based DM devices are
currently supported.

Each user-defined region specifies a starting sector, length and step.
Individual statistics will be collected for each step-sized area within
the range specified.

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.  All these counters may be accessed by sending
the @stats_print message to the appropriate DM device via dmsetup.

The creation of DM statistics 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.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
  • Loading branch information
Mikulas Patocka authored and snitm committed Sep 6, 2013
1 parent 94563ba commit fd2ed4d
Show file tree
Hide file tree
Showing 9 changed files with 1,299 additions and 14 deletions.
186 changes: 186 additions & 0 deletions Documentation/device-mapper/statistics.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
DM statistics
=============

Device Mapper supports the collection of I/O statistics on user-defined
regions of a DM device. If no regions are defined no statistics are
collected so there isn't any performance impact. Only bio-based DM
devices are currently supported.

Each user-defined region specifies a starting sector, length and step.
Individual statistics will be collected for each step-sized area within
the range specified.

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 (see:
Documentation/iostats.txt). But two extra counters (12 and 13) are
provided: total time spent reading and writing in milliseconds. All
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, which we call a
region_id, 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
on each other's data.

The creation of DM statistics 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> [<aux_data>]]

Create a new region and return the region_id.

<range>
"-" - whole device
"<start_sector>+<length>" - a range of <length> 512-byte sectors
starting with <start_sector>.

<step>
"<area_size>" - the range is subdivided into areas each containing
<area_size> sectors.
"/<number_of_areas>" - the range is subdivided into the specified
number of areas.

<program_id>
An optional parameter. A name that uniquely identifies
the userspace owner of the range. This groups ranges together
so that userspace programs can identify the ranges they
created and ignore those created by others.
The kernel returns this string back in the output of
@stats_list message, but it doesn't use it for anything else.

<aux_data>
An optional parameter. A word that provides auxiliary data
that is useful to the client program that created the range.
The kernel returns this string back in the output of
@stats_list message, but it doesn't use this value for anything.

@stats_delete <region_id>

Delete the region with the specified id.

<region_id>
region_id returned from @stats_create

@stats_clear <region_id>

Clear all the counters except the in-flight i/o counters.

<region_id>
region_id returned from @stats_create

@stats_list [<program_id>]

List all regions registered with @stats_create.

<program_id>
An optional parameter.
If this parameter is specified, only matching regions
are returned.
If it is not specified, all regions are returned.

Output format:
<region_id>: <start_sector>+<length> <step> <program_id> <aux_data>

@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 to include in the output.
If omitted, all lines are returned.

Output format for each step-sized area of a region:

<start_sector>+<length> counters

The first 11 counters have the same meaning as
/sys/block/*/stat or /proc/diskstats.

Please refer to Documentation/iostats.txt for details.

1. the number of reads completed
2. the number of reads merged
3. the number of sectors read
4. the number of milliseconds spent reading
5. the number of writes completed
6. the number of writes merged
7. the number of sectors written
8. the number of milliseconds spent writing
9. the number of I/Os currently in progress
10. the number of milliseconds spent doing I/Os
11. the weighted number of milliseconds spent doing I/Os

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 the 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 printed and then cleared.

<number_of_lines>
The number of lines to process.
If omitted, all lines are printed and then cleared.

@stats_set_aux <region_id> <aux_data>

Store auxiliary data aux_data for the specified region.

<region_id>
region_id returned from @stats_create

<aux_data>
The string that identifies data which is useful to the client
program that created the range. The kernel returns this
string back in the output of @stats_list message, but it
doesn't use this value for anything.

Examples
========

Subdivide the DM device 'vol' into 100 pieces and start collecting
statistics on them:

dmsetup message vol 0 @stats_create - /100

Set the auxillary data string to "foo bar baz" (the escape for each
space must also be escaped, otherwise the shell will consume them):

dmsetup message vol 0 @stats_set_aux 0 foo\\ bar\\ baz

List the statistics:

dmsetup message vol 0 @stats_list

Print the statistics:

dmsetup message vol 0 @stats_print 0

Delete the statistics:

dmsetup message vol 0 @stats_delete 0
2 changes: 1 addition & 1 deletion drivers/md/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions drivers/md/dm-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit fd2ed4d

Please sign in to comment.