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.

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

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.

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.

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

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

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

Validate that the kernel successfully registered our synthetic block device:

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.

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

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.

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.

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.

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

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.

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.

5. Teardown and Resource Reclamation
Before unmounting virtual layers, reset metrics across every registered region to leave clean counters.

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

Dismantle the virtual block mapping from the Device Mapper framework.

Detach the loopback binding associated with the backing file.

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

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.