[lkml]   [2020]   [Aug]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subject[RFC PATCH 0/7] metricfs metric file system and examples
To try to restart the discussion of kernel statistics started by the
statsfs patchsets (, I wanted
to share the following set of patches which are Google's 'metricfs'
implementation and some example uses. Google has been using metricfs
internally since 2012 as a way to export various statistics to our
telemetry systems (similar to OpenTelemetry), and we have over 200
statistics exported on a typical machine.

These patches have been cleaned up and modernized v.s. the versions
in production; I've included notes under the fold in the patches.
They're based on v5.8-rc6.

The statistics live under debugfs, in a tree rooted at:


Each metric is a directory, with four files in it. For example, the '
core/metricfs: Create metricfs, standardized files under debugfs.' patch
includes a simple 'metricfs_presence' metric, whose files look like:
DESCRIPTION A\ basic\ presence\ metric.

(The "version" field always says '1', and is kind of vestigial)

An example of a more complicated stat is the networking stats.
For example, the tx_bytes stat looks like:

DESCRIPTION net\ device\ transmited\ bytes\ count
interface value
str int
lo 4394430608
eth0 33353183843
eth1 16228847091

The per-cpu statistics show up in the schedulat stat info and x86
IRQ counts. For example:

DESCRIPTION time\ in\ user\ mode\ (nsec)
cpu value
int int
0 1183486517734
1 1038284237228

The full set of example metrics I've included are:

core/metricfs: Create metricfs, standardized files under debugfs.
core/metricfs: metric for kernel warnings
core/metricfs: expose scheduler stat information through metricfs
net-metricfs: Export /proc/net/dev via metricfs.
core/metricfs: expose x86-specific irq information through metricfs

The general approach is called out in kernel/metricfs.c:

The kernel provides:
- A description of the metric
- The subsystem for the metric (NULL is ok)
- Type information about the metric, and
- A callback function which supplies metric values.

- "values" files are at MOST 64K. We truncate the file at that point.
- The list of fields and types is at most 1K.
- Metrics may have at most 2 fields.

Best Practices:
- Emit the most important data first! Once the 64K per-metric buffer
is full, the emit* functions won't do anything.
- In userspace, open(), read(), and close() the file quickly! The kernel
allocation for the metric is alive as long as the file is open. This
permits users to seek around the contents of the file, while
permitting an atomic view of the data.

Note that since the callbacks are called and the data is generated at
file open() time, the relative consistency is only between members of
a given metric; the rx_bytes stat for every network interface will
be read at almost the same time, but if you want to get rx_bytes
and rx_packets, there could be a bunch of slew between the two file
opens. (So this doesn't entirely address Andrew Lunn's comments in

This also doesn't address one of the basic parts of the statsfs work:
moving the statistics out of debugfs to avoid lockdown interactions.

Google has found a lot of value in having a generic interface for adding
these kinds of statistics with reasonably low overhead (reading them
is O(number of statistics), not number of objects in each statistic).
There are definitely warts in the interface, but does the basic approach
make sense to folks?

- Jonathan

Jonathan Adams (5):
core/metricfs: add support for percpu metricfs files
core/metricfs: metric for kernel warnings
core/metricfs: expose softirq information through metricfs
core/metricfs: expose scheduler stat information through metricfs
core/metricfs: expose x86-specific irq information through metricfs

Justin TerAvest (1):
core/metricfs: Create metricfs, standardized files under debugfs.

Laurent Chavey (1):
net-metricfs: Export /proc/net/dev via metricfs.

arch/x86/kernel/irq.c | 80 ++++
fs/proc/stat.c | 57 +++
include/linux/metricfs.h | 131 +++++++
kernel/Makefile | 2 +
kernel/metricfs.c | 775 +++++++++++++++++++++++++++++++++++++
kernel/metricfs_examples.c | 151 ++++++++
kernel/panic.c | 131 +++++++
kernel/softirq.c | 45 +++
lib/Kconfig.debug | 18 +
net/core/Makefile | 1 +
net/core/net_metricfs.c | 194 ++++++++++
11 files changed, 1585 insertions(+)
create mode 100644 include/linux/metricfs.h
create mode 100644 kernel/metricfs.c
create mode 100644 kernel/metricfs_examples.c
create mode 100644 net/core/net_metricfs.c


 \ /
  Last update: 2020-08-06 02:15    [W:0.060 / U:0.560 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site