Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tracking global block usage statistics in the block allocator, by assigning a purpose to each block and keeping track of how many blocks have been allocated/freed for that purpose.
Command-line args
To see block usage statistics at runtime, you can do this:
The default is to sample every 1 second and log the output. To control the sample rate, use the
block-usage-sample-interval
parameter:Here, we pass a time
T
, which has a time unit suffix:s
for seconds,m
for milliseconds,u
for microseconds, andn
for nanoseconds. For example,150m
will sample every 150 milliseconds,2500u
will sample every 2500 microseconds, etc.Logging control. This mechanism currently reuses the existing logger. Note that it can be helpful to use
@mpl log-file <FILENAME> --
to output to a file rather than interleaving log messages with normal output.Example and output description
Example output with
log-level block-allocator:info block-usage-sample-interval 200m
which samples every 200 milliseconds:Timestamp. The log message begins with
block-allocator(T)
whereT
is the elapsed time (in seconds) since the beginning of the program. In this example, 7.2 seconds have elapsed so far.Current num blocks mapped. The second line shows how many blocks are currently mapped from the OS; this number increases and decreases as blocks are mapped and unmapped. The format is
<num currently mapped> (= <cumulative mapped> - <cumulative unmapped>)
; when blocks are released back to the OS, this will be shown in the cumulative unmapped count.Blocks allocated/freed. The remaining lines each have the form:
<purpose> <count> <percent of currently mapped> (= <cumulative allocated> - <cumulative freed>)
For example, in the above log, there are currently ~111K blocks in use for heap chunks, which is 66% of all blocks currently mapped from the OS; cumulatively, the program has allocated ~502K blocks for heap chunks and has freed 390K of those.
Other notes
This PR includes a general-purpose "sampler" mechanism which allows for running an arbitrary function periodically. It was very helpful for sampling block usage statistics, and seems really nice in general. I think we could start using it for other purposes.
The implementation strategy is
lock-freewait-free, and relies on hijacking failed limit checks (to enter the runtime system).See
runtime/gc/sampler.{c,h}
for more info.