Skip to content

expose free space histograms in /proc#14013

Open
cleverca22 wants to merge 1 commit intoopenzfs:masterfrom
cleverca22:fragmentation
Open

expose free space histograms in /proc#14013
cleverca22 wants to merge 1 commit intoopenzfs:masterfrom
cleverca22:fragmentation

Conversation

@cleverca22
Copy link

Motivation and Context

this allows graphing zdb -MM without any performance costs

Description

adds a new kstat in /proc with free space fragmentation
example output:

[root@nixos:~]# cat /proc/spl/kstat/zfs/vm/fragmentation
normal{power="9",pool="vm"} 14
normal{power="10",pool="vm"} 75
normal{power="11",pool="vm"} 16
normal{power="12",pool="vm"} 37

How Has This Been Tested?

booting a vm and comparing the output to zdb -MM vm

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Copy link
Contributor

@ryao ryao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These really should be destroyed in the reverse order that they were initialized, but that is a pre-existing problem that merits its own patch.

Copy link
Contributor

@ryao ryao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good in my cursory review.

@cleverca22 cleverca22 force-pushed the fragmentation branch 2 times, most recently from 22ddc3a to fdd6a2c Compare October 11, 2022 00:38
@rincebrain
Copy link
Contributor

"fragmentation" seems like an awkward name, to me, for this /proc entry. Maybe something about it being the free space (or the histogram thereof)?

@ghost
Copy link

ghost commented Oct 11, 2022

I don't think we need the pool name repeated on every line when it is already known. Is that formatted for influxdb? Nope not quite.

@ryao
Copy link
Contributor

ryao commented Oct 11, 2022

@freqlabs It is formatted for prometheus.

@ghost
Copy link

ghost commented Oct 11, 2022

I'd prefer a format that is easier to manipulate for anyone not using prometheus.

@cleverca22
Copy link
Author

the pool name was repeated, so it could easily just be dumped right into prometheus

but if the prometheus format is being removed, and its just 9 14, then the pool name isnt really needed, something has to convert it to prometheus, and can add the pool name back in as it does so

@rincebrain what about just histogram maybe? or metaclass_histogram?
i could also break it up, and so normal_histogram and special_histogram, which is sort of needed if the prometheus metric names are going away

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Oct 12, 2022
@cleverca22
Copy link
Author

cleverca22 commented Oct 20, 2022

[root@nixos:/proc/spl/kstat/zfs/vm]# ls fragmentation_*
fragmentation_dedup	    fragmentation_log	  fragmentation_special
fragmentation_embedded_log  fragmentation_normal

[root@nixos:/proc/spl/kstat/zfs/vm]# cat fragmentation_normal 
9 19
10 49
11 24
12 38
13 21
14 17
15 12
16 2
17 2
27 15

[root@nixos:/proc/spl/kstat/zfs/vm]# 

removed all of the redundant info, so its just a list of numbers now
also changed it to have one metaclass per file, and filled in all of them

open to suggestions on renaming the stat files

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it because the checkstyle workflow didn't run and it's hard to judge whitespace on github, but this doesn't pass cstyle. Generally try to match the style of the existing code, make cstyle will be more specific.

@cleverca22
Copy link
Author

fixed the code to agree with cstyle

@ghost
Copy link

ghost commented Oct 21, 2022

Please also sign off on the commit with your next update: https://github.com/openzfs/zfs/blob/master/.github/CONTRIBUTING.md#signed-off-by

@ghost
Copy link

ghost commented Nov 2, 2022

All the commits need to be signed off, and the last two should be squashed into one.

@behlendorf
Copy link
Contributor

@cleverca22 if you're still interested in pursuing this change please address the outstanding feedback and rebase this PR on the latest master.

@cleverca22
Copy link
Author

i do want to get this merged, i'll take a look at rebasing and addressing the comments when i get some free time

i have been running this branch on 3 machines since i made it, and need to update them anyways

@behlendorf behlendorf added the Status: Revision Needed Changes are required for the PR to be accepted label Dec 5, 2023
@behlendorf behlendorf removed the Status: Revision Needed Changes are required for the PR to be accepted label Dec 11, 2023
@behlendorf
Copy link
Contributor

@cleverca22 great. We can tacklie this in parts if you want to open a new PR with just a singed off version of c0bd9ca. Then this can be squashed rebased on top of that change.

@cleverca22 cleverca22 force-pushed the fragmentation branch 2 times, most recently from 6460516 to 9a97022 Compare September 9, 2025 14:35
@cleverca22 cleverca22 force-pushed the fragmentation branch 2 times, most recently from c35b37b to 9cf94a0 Compare September 12, 2025 03:03
@amotin
Copy link
Member

amotin commented Sep 12, 2025

The checkstyle is unhappy: error: missing "Signed-off-by". Please add it to the commit message.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last addition and this should be good. Can you rebase it and force update the PR while making the change.

case 2:
return (spa_embedded_log_class(stat->spa));
case 3:
return (spa_special_class(stat->spa));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 6th metaslab class called spa_special_embedded_log_class was added by be1e991. Please add this one in too.

example output:
```
[root@nixos:~]# cat /proc/spl/kstat/zfs/vm/fragmentation_normal
9 19
10 49
11 24
12 38
13 21
14 17
15 12
16 2
17 2
27 15
```

this allows graphing `zdb -MM` without any performance costs

Signed-off-by: Michael Bishop <cleverca22@gmail.com>
@behlendorf
Copy link
Contributor

@ryan-moeller recently added allocation class metrics as pool properties in #18238. They don't include the free space histograms, but the other key metrics are there including fragmentation. Providing the full histograms in /proc I think is still useful but let's align the names with the pool properties. I'd suggest.

class_normal_free_histogram
class_special_free_histogram
class_dedup_free_histogram
class_log_free_histogram
class_elog_free_histogram
class_special_elog_free_histogram

I'd also suggest adding a header to the kstat output. That's easy enough to strip off for tools automatically consuming this output and helpful for us humans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Code Review Needed Ready for review and testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants