Monitoring Linux Device Mapper I/O with dmstats on Ubuntu

Overview

Storage subsystems backed by the Linux Device Mapper—such as LVM logical volumes, dm-crypt drives, and multipath topologies—often require fine-grained visibility to isolate performance bottlenecks. This hands-on walkthrough demonstrates how to profile and inspect granular block-layer I/O using the dmstats utility on Ubuntu, covering everything from region partitioning to real-time metric extraction.

1. Verifying Tooling and Core dmstats Syntax

Before configuring monitoring profiles, verify that the Device Mapper management suite is present on your host, pulling in dmsetup from the standard repositories if missing.

Verify installation of dmsetup and dmstats packages

Confirming version compatibility ensures the kernel driver and user-space management library communicate reliably:

Inspecting Device Mapper library and driver versions with dmstats –version

At its foundation, dmstats instruments kernel-level event counters across target virtual block devices.
⚙️ [Primary Subcommands and Switches]

create : Initializes a new I/O monitoring region over a specified Device Mapper target.
delete : Tears down active telemetry collection regions from the target.
list : Enumerates configured statistical regions across registered devices.
print : Dumps raw kernel metrics, including sector transfers and tick counts.
clear : Flushes active counter accumulators back to baseline zeroes.
--areas : Segments the total block span into multiple discrete monitoring subdivisions.
--programid : Tags regions with an arbitrary string identifier for multi-tenant tracking.
-o, --options : Customizes the emitted reporting columns with comma-separated field selectors.
-v, --verbose : Produces detailed diagnostics regarding internal configuration actions.

Listing available command options with dmstats –help

2. Assembling an Isolated Loopback Target for Testing

To experiment without risking production data or needing raw physical disks, allocate a clean temporary working environment.

Setting up an isolated workspace under /tmp/dmstats_lab

Generate a blank 64MB backing image using dd to emulate our raw disk volume.

Allocating a 64MB backing image file with dd

Bind this raw file to the first unoccupied loopback interface, storing the resulting path in an environment variable for subsequent steps.

Attaching the image file to an available loopback interface

Next, feed a 131,072-sector (64MB) linear translation table into dmsetup to instantiate the virtual target test-linear-dev.

Constructing a linear Device Mapper target via dmsetup

Validate that the kernel successfully registered our synthetic block device:

Querying active Device Mapper targets using dmsetup ls

3. Provisioning and Inspecting I/O Telemetry Regions

Begin by creating a global monitoring boundary across the full volume. Executing dmstats create test-linear-dev establishes Region 0, treating the entire 64MB address space as a solitary metric aggregation zone.

Initializing default full-span monitoring region with dmstats create

Query the active configuration to verify registration, sector range coverage, and designated region identifiers.

Confirming registered region details with dmstats list

For workload profiling, global aggregates often obscure localized hotspots. To monitor offset-specific read/write contention, deploy a segmented profile dividing the target into four equal subdivisions via --areas 4.

Partitioning device monitoring into four discrete quadrants

Invoking dmstats list -v unveils the granular division: each sub-area covers exactly 16MB (32,768 sectors), enabling targeted spatial I/O analysis across the volume.

Detailed inspection of segmented areas with verbose listing flags

4. Driving Synthetic Workloads and Analyzing Telemetry

To observe statistics accumulation, bypass the Linux page cache using direct I/O (oflag=direct), issuing 1,024 write operations of 4KB random payloads directly to /dev/mapper/test-linear-dev.

Injecting direct write load into the mapped target

Follow up by triggering a matching read workload, streaming unbuffered blocks into /dev/null to exercise input counters.

Triggering direct sequential read transactions with dd

The raw telemetry data emitted by the kernel driver—covering raw request counts, sector tallies, and elapsed execution ticks—can be retrieved directly via dmstats print.

Displaying unformatted kernel counters with dmstats print

For operational analysis, dmstats report transforms raw counters into human-readable throughput rates, wait times, and utilization percentages, clearly contrasting global performance against sub-area activity.

Generating formatted performance metrics report with dmstats report

5. Teardown and Resource Reclamation

Before unmounting virtual layers, reset metrics across every registered region to leave clean counters.

Flushing recorded metric counters using dmstats clear

Deregister and purge all telemetry monitoring zones configured on the virtual device.

Purging all active monitoring regions with dmstats delete

Dismantle the virtual block mapping from the Device Mapper framework.

Removing the synthetic Device Mapper target

Detach the loopback binding associated with the backing file.

Detaching loop device associations using losetup

Finally, purge the staging folder and scrap artifacts from the host filesystem.

Cleaning up the test laboratory directory

By mastering dmstats, systems administrators gain high-resolution visibility into virtual block devices, transforming ambiguous storage delays into actionable, offset-precise performance insights across Ubuntu deployments.