Skip to content

[hist] Pause filling during snapshot - #23093

Open
hahnjo wants to merge 1 commit into
root-project:masterfrom
hahnjo:hist-snapshot-pause
Open

[hist] Pause filling during snapshot#23093
hahnjo wants to merge 1 commit into
root-project:masterfrom
hahnjo:hist-snapshot-pause

Conversation

@hahnjo

@hahnjo hahnjo commented Aug 18, 2026

Copy link
Copy Markdown
Member

FillAtomic is much faster than SnapshotAtomic, so in case of heavy contention it would starve the snapshot. By adding a new atomic flag FillAtomic can pause while a Snapshot is running. The successful double collect is still needed if a thread is already in FillAtomic.

If SnapshotAtomic is not used, the performance impact of the added check is minimal / not measurable because fSnapshot is always false and already in the cache line of the RHistEngine.

@hahnjo
hahnjo requested review from hageboeck and jblomer August 18, 2026 11:48
@hahnjo hahnjo self-assigned this Aug 18, 2026
@hahnjo hahnjo added the in:Hist label Aug 18, 2026
@github-actions

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 4h 53m 53s ⏱️
 3 834 tests  3 833 ✅ 0 💤 1 ❌
71 578 runs  71 575 ✅ 0 💤 3 ❌

For more details on these failures, see this check.

Results for commit a14b914.

Comment thread hist/histv7/inc/ROOT/RHistEngine.hxx

std::atomic_flag snapshotter;
StressInParallel(NThreads, [&] {
if (!snapshotter.test_and_set()) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I understand correctly, this means that the first thread to run will start N consecutive snapshots and lead all the other thread to all do Fills.

Should we also test when a second thread is attempting to do a snapshot (to exercise the while loop on line 873)?

The time taken by the snapshot-ing thread between the end of a snapshot and the start of another one is smallish (2 GetBinContent), is there a risk that with this PR the execution now mostly does all the snapshots before (most of) the Fills? (i.e. not quite but almost executing the whole snapshot-ing threads before the other)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should we also test when a second thread is attempting to do a snapshot (to exercise the while loop on line 873)?

That's exactly what the "new" test StressSnapshotAtomic does, calling SnapshotAtomic from 4 threads, no? The renamed StressFillSnapshotAtomic then tests the interaction between FillAtomic and SnapshotAtomic, but here we can never have two SnapshotAtomic interacting.

is there a risk that with this PR the execution now mostly does all the snapshots before (most of) the Fills

I don't think so, it also has to destruct the snapshot histogram.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's exactly what the "new" test StressSnapshotAtomic does,

Indeed.

The renamed StressFillSnapshotAtomic ... but here we can never have two SnapshotAtomic interacting.

It 'could' (straightforwardly) be extended to have 2 Snapshot threads hence testing the 3 ways interactions.

I don't think so, it also has to destruct the snapshot histogram.

Fair enough.

FillAtomic is much faster than SnapshotAtomic, so in case of heavy
contention it would starve the snapshot. By adding a new atomic flag
FillAtomic can pause while a Snapshot is running. The successful
double collect is still needed if a thread is already in FillAtomic.

If SnapshotAtomic is not used, the performance impact of the added
check is minimal / not measurable because fSnapshot is always false
and already in the cache line of the RHistEngine.
@hahnjo
hahnjo force-pushed the hist-snapshot-pause branch from a14b914 to 313652f Compare August 19, 2026 12:01
{
ROOT::TestSupport::CheckDiagsRAII diagRAII;
diagRAII.optionalDiag(kWarning, "TKey::TKey", "no public constructor", /*matchFullMessage=*/false);
diagRAII.optionalDiag(kWarning, "TStreamerInfo::Build", "data member \"fSnapshot\" will not be saved",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In which configuration did that appears? (Since fSnapshot is marked transient, we should not be issuing this message)

@pcanal pcanal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants