[PATCHv2 0/9] libnvme: add support for retrieving additional NVMe stat
Nilay Shroff
nilay at linux.ibm.com
Fri Apr 10 00:33:39 PDT 2026
On 4/9/26 2:40 PM, Daniel Wagner wrote:
> Hi Nilay,
>
> On Sat, Apr 04, 2026 at 03:44:50PM +0530, Nilay Shroff wrote:
>> Certain NVMe attributes and statistics can change dynamically at runtime.
>> However, the current libnvme implementation caches attribute values while
>> scanning and building the topology. Subsequent libnvme API calls return
>> these cached values.
>>
>> While this approach works well for one-shot nvme-cli commands, it is not
>> suitable for use cases that require upto date information. In particular,
>> real-time monitoring tools such as nvme-top require access to the latest
>> (non-cached) values of such attributes.
>>
>> To address this, this patchset introduces support for retrieving
>> non-cached values for selected attributes whose values may change
>> dynamically. The first three patches disable auto-generated accessors
>> for ana_state, numa_nodes, and iopolicy using "!accessors:none", and
>> provide custom implementations that always return the latest values.
>>
>> In addition, libnvme lacks support for retrieving gendisk statistics, which
>> provide useful insight into disk activity (e.g., number of I/Os processed,
>> time spent servicing I/O, and in-flight I/O counts). This patchset adds
>> support for retrieving gendisk I/O statistics for both per-path and namespace
>> gendisks.
>>
>> Finally, this series adds support for retrieving diagnostic counters at
>> different levels, including per-path, namespace, nshead, and controller.
>> These counters should improve visibility into NVMe native multipath behavior.
>>
>> All of the above statistics and counters can be leveraged by tools such as
>> nvme-top to provide real-time monitoring and analysis.
>>
>> As usual, feedback and suggestions are welcome!
>
> Looks way better. Thanks!
>
> Unfortunately, the big renaming of the API has happened, thus could I
> ask to rebase (and rename the symbols accordingly)?
>
Yes sure, I will rebase the code and spin a new revision.
> One thing I notices, is the first set of statistic getters have the
> 'bool diffstat' argument, the second one not. To make this a bit more
> consistent I'd say it would be great to have it on all functions. WDYT?
>
The diffstat value is only set during the refresh/update phase (i.e.,
nvme_ns_update_stat() or nvme_path_update_stat()). These refresh APIs
take the diffstat argument so that the caller can specify whether they
want absolute statistics or differential statistics for getters.
In practice, the caller indicates this preference at refresh time—for
example: nvme_path_update_stat(p, diffstat);
After that, the getter APIs rely on the state established during the refresh.
Based on the diffstat setting, they will either:
- return the current absolute values, or
- compute and return the difference between the current and previous statistics.
For example, the following getters:
- nvme_path_get_io_ticks
- nvme_path_get_read_ticks
- nvme_path_get_write_ticks
- nvme_path_get_read_ios
- nvme_path_get_write_ios
- nvme_path_get_read_sectors
- nvme_path_get_write_sectors
Will return differential values if diffstat was set to true during the refresh.
Otherwise, they return absolute values. Does this make sense?
Thanks,
--Nilay
More information about the Linux-nvme
mailing list