Skip to content

Commit fd2ed4d

Browse files
Mikulas Patockasnitm
authored andcommitted
dm: add statistics support
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>
1 parent 94563ba commit fd2ed4d

9 files changed

Lines changed: 1299 additions & 14 deletions

File tree

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
DM statistics
2+
=============
3+
4+
Device Mapper supports the collection of I/O statistics on user-defined
5+
regions of a DM device. If no regions are defined no statistics are
6+
collected so there isn't any performance impact. Only bio-based DM
7+
devices are currently supported.
8+
9+
Each user-defined region specifies a starting sector, length and step.
10+
Individual statistics will be collected for each step-sized area within
11+
the range specified.
12+
13+
The I/O statistics counters for each step-sized area of a region are
14+
in the same format as /sys/block/*/stat or /proc/diskstats (see:
15+
Documentation/iostats.txt). But two extra counters (12 and 13) are
16+
provided: total time spent reading and writing in milliseconds. All
17+
these counters may be accessed by sending the @stats_print message to
18+
the appropriate DM device via dmsetup.
19+
20+
Each region has a corresponding unique identifier, which we call a
21+
region_id, that is assigned when the region is created. The region_id
22+
must be supplied when querying statistics about the region, deleting the
23+
region, etc. Unique region_ids enable multiple userspace programs to
24+
request and process statistics for the same DM device without stepping
25+
on each other's data.
26+
27+
The creation of DM statistics will allocate memory via kmalloc or
28+
fallback to using vmalloc space. At most, 1/4 of the overall system
29+
memory may be allocated by DM statistics. The admin can see how much
30+
memory is used by reading
31+
/sys/module/dm_mod/parameters/stats_current_allocated_bytes
32+
33+
Messages
34+
========
35+
36+
@stats_create <range> <step> [<program_id> [<aux_data>]]
37+
38+
Create a new region and return the region_id.
39+
40+
<range>
41+
"-" - whole device
42+
"<start_sector>+<length>" - a range of <length> 512-byte sectors
43+
starting with <start_sector>.
44+
45+
<step>
46+
"<area_size>" - the range is subdivided into areas each containing
47+
<area_size> sectors.
48+
"/<number_of_areas>" - the range is subdivided into the specified
49+
number of areas.
50+
51+
<program_id>
52+
An optional parameter. A name that uniquely identifies
53+
the userspace owner of the range. This groups ranges together
54+
so that userspace programs can identify the ranges they
55+
created and ignore those created by others.
56+
The kernel returns this string back in the output of
57+
@stats_list message, but it doesn't use it for anything else.
58+
59+
<aux_data>
60+
An optional parameter. A word that provides auxiliary data
61+
that is useful to the client program that created the range.
62+
The kernel returns this string back in the output of
63+
@stats_list message, but it doesn't use this value for anything.
64+
65+
@stats_delete <region_id>
66+
67+
Delete the region with the specified id.
68+
69+
<region_id>
70+
region_id returned from @stats_create
71+
72+
@stats_clear <region_id>
73+
74+
Clear all the counters except the in-flight i/o counters.
75+
76+
<region_id>
77+
region_id returned from @stats_create
78+
79+
@stats_list [<program_id>]
80+
81+
List all regions registered with @stats_create.
82+
83+
<program_id>
84+
An optional parameter.
85+
If this parameter is specified, only matching regions
86+
are returned.
87+
If it is not specified, all regions are returned.
88+
89+
Output format:
90+
<region_id>: <start_sector>+<length> <step> <program_id> <aux_data>
91+
92+
@stats_print <region_id> [<starting_line> <number_of_lines>]
93+
94+
Print counters for each step-sized area of a region.
95+
96+
<region_id>
97+
region_id returned from @stats_create
98+
99+
<starting_line>
100+
The index of the starting line in the output.
101+
If omitted, all lines are returned.
102+
103+
<number_of_lines>
104+
The number of lines to include in the output.
105+
If omitted, all lines are returned.
106+
107+
Output format for each step-sized area of a region:
108+
109+
<start_sector>+<length> counters
110+
111+
The first 11 counters have the same meaning as
112+
/sys/block/*/stat or /proc/diskstats.
113+
114+
Please refer to Documentation/iostats.txt for details.
115+
116+
1. the number of reads completed
117+
2. the number of reads merged
118+
3. the number of sectors read
119+
4. the number of milliseconds spent reading
120+
5. the number of writes completed
121+
6. the number of writes merged
122+
7. the number of sectors written
123+
8. the number of milliseconds spent writing
124+
9. the number of I/Os currently in progress
125+
10. the number of milliseconds spent doing I/Os
126+
11. the weighted number of milliseconds spent doing I/Os
127+
128+
Additional counters:
129+
12. the total time spent reading in milliseconds
130+
13. the total time spent writing in milliseconds
131+
132+
@stats_print_clear <region_id> [<starting_line> <number_of_lines>]
133+
134+
Atomically print and then clear all the counters except the
135+
in-flight i/o counters. Useful when the client consuming the
136+
statistics does not want to lose any statistics (those updated
137+
between printing and clearing).
138+
139+
<region_id>
140+
region_id returned from @stats_create
141+
142+
<starting_line>
143+
The index of the starting line in the output.
144+
If omitted, all lines are printed and then cleared.
145+
146+
<number_of_lines>
147+
The number of lines to process.
148+
If omitted, all lines are printed and then cleared.
149+
150+
@stats_set_aux <region_id> <aux_data>
151+
152+
Store auxiliary data aux_data for the specified region.
153+
154+
<region_id>
155+
region_id returned from @stats_create
156+
157+
<aux_data>
158+
The string that identifies data which is useful to the client
159+
program that created the range. The kernel returns this
160+
string back in the output of @stats_list message, but it
161+
doesn't use this value for anything.
162+
163+
Examples
164+
========
165+
166+
Subdivide the DM device 'vol' into 100 pieces and start collecting
167+
statistics on them:
168+
169+
dmsetup message vol 0 @stats_create - /100
170+
171+
Set the auxillary data string to "foo bar baz" (the escape for each
172+
space must also be escaped, otherwise the shell will consume them):
173+
174+
dmsetup message vol 0 @stats_set_aux 0 foo\\ bar\\ baz
175+
176+
List the statistics:
177+
178+
dmsetup message vol 0 @stats_list
179+
180+
Print the statistics:
181+
182+
dmsetup message vol 0 @stats_print 0
183+
184+
Delete the statistics:
185+
186+
dmsetup message vol 0 @stats_delete 0

‎drivers/md/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
dm-mod-y += dm.o dm-table.o dm-target.o dm-linear.o dm-stripe.o \
6-
dm-ioctl.o dm-io.o dm-kcopyd.o dm-sysfs.o
6+
dm-ioctl.o dm-io.o dm-kcopyd.o dm-sysfs.o dm-stats.o
77
dm-multipath-y += dm-path-selector.o dm-mpath.o
88
dm-snapshot-y += dm-snap.o dm-exception-store.o dm-snap-transient.o \
99
dm-snap-persistent.o

‎drivers/md/dm-ioctl.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,20 +1455,26 @@ static int table_status(struct dm_ioctl *param, size_t param_size)
14551455
return 0;
14561456
}
14571457

1458-
static bool buffer_test_overflow(char *result, unsigned maxlen)
1459-
{
1460-
return !maxlen || strlen(result) + 1 >= maxlen;
1461-
}
1462-
14631458
/*
1464-
* Process device-mapper dependent messages.
1459+
* Process device-mapper dependent messages. Messages prefixed with '@'
1460+
* are processed by the DM core. All others are delivered to the target.
14651461
* Returns a number <= 1 if message was processed by device mapper.
14661462
* Returns 2 if message should be delivered to the target.
14671463
*/
14681464
static int message_for_md(struct mapped_device *md, unsigned argc, char **argv,
14691465
char *result, unsigned maxlen)
14701466
{
1471-
return 2;
1467+
int r;
1468+
1469+
if (**argv != '@')
1470+
return 2; /* no '@' prefix, deliver to target */
1471+
1472+
r = dm_stats_message(md, argc, argv, result, maxlen);
1473+
if (r < 2)
1474+
return r;
1475+
1476+
DMERR("Unsupported message sent to DM core: %s", argv[0]);
1477+
return -EINVAL;
14721478
}
14731479

14741480
/*
@@ -1542,7 +1548,7 @@ static int target_message(struct dm_ioctl *param, size_t param_size)
15421548

15431549
if (r == 1) {
15441550
param->flags |= DM_DATA_OUT_FLAG;
1545-
if (buffer_test_overflow(result, maxlen))
1551+
if (dm_message_test_buffer_overflow(result, maxlen))
15461552
param->flags |= DM_BUFFER_FULL_FLAG;
15471553
else
15481554
param->data_size = param->data_start + strlen(result) + 1;

0 commit comments

Comments
 (0)