multiload: fix hang when per-thread load bandwidth is below 1 MiB/s - #60
Merged
Merged
Conversation
Load threads published (uint64_t)mibps in x.count, which is also the sample-ready handshake polled by main. Below 1 MiB/s the cast truncated to 0, so main waited forever. Publish bytes/s instead and convert back to MiB/s in main. Also print per-thread values with %.3f.
seranian
approved these changes
Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
multiload hangs forever, with every worker thread spinning at 100% CPU, when any memory-load thread measures less than 1 MiB/s during a sample window.
In
LOAD_MEMORY_SAMPLE_MIBPS, each load thread publishes its bandwidth as (uint64_t)mibps into t->x.count. That field is also the handshake:mainpollsuntil x.count != 0to know the thread finished the sample. When mibps < 1.0, the cast truncates to 0, so:the thread sets
cur_sample = nxt_sampleand never reports this sample again;mainspins forever inwhile (ready == 0)waiting for a non-zero count.This can happen in practice when many threads share a memory node with very low bandwidth. For example, 80 threads on a node degraded to about 60 MiB/s works out to about 0.76 MiB/s per thread. It can also be triggered with a large injection delay:
Fix
Load threads now publish bytes/s instead of MiB/s in
x.count, andmainconverts the value back to MiB/s before aggregating.x.countis 64 bits wide, so there is no overflow risk at any real bandwidth. A value of 0 would require a single pass over the load buffer to take millions of seconds, so the handshake no longer depends on bandwidth being at least 1 MiB/s.The fix also removes the per-thread truncation error (previously up to 1 MiB/s per thread, summed across all load threads in Total(MiB/s)).
The per-thread values (
ML(n)at-v -v, andPerThread=at-v) are now printed with %.3f, so bandwidth below 1 MiB/s is visible instead of rounding to 0 or 1.Chase threads are unchanged. Their
x.countremains an iteration counter.Testing
Injection-delay repro above: before the fix it hangs; after the fix it exits 0 and reports Total(MiB/s) of about 0.58.