Skip to content

Weaken memory ordering OneToOnRingBuffer#359

Open
pveentjer wants to merge 1 commit intoaeron-io:masterfrom
pveentjer:cleanup/OneToOneRingBuffer-relaxed-memory-ordering
Open

Weaken memory ordering OneToOnRingBuffer#359
pveentjer wants to merge 1 commit intoaeron-io:masterfrom
pveentjer:cleanup/OneToOneRingBuffer-relaxed-memory-ordering

Conversation

@pveentjer
Copy link
Copy Markdown
Contributor

@pveentjer pveentjer commented Apr 14, 2026

The current code has excessive memory ordering and it can be reduced.

@pveentjer pveentjer force-pushed the cleanup/OneToOneRingBuffer-relaxed-memory-ordering branch from 7dc72f8 to a39fce5 Compare April 14, 2026 03:35
return false;
}

buffer.putIntRelease(lengthOffset(recordIndex), -recordLength);
Copy link
Copy Markdown
Contributor Author

@pveentjer pveentjer Apr 14, 2026

Choose a reason for hiding this comment

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

For the actual claim (so writing the negative record length), only opaque is needed. Surrounding loads/stores do not need to be ordered. The content of the record can't be read (apart from the length) until the commit is done. The commit is performed using a release store and will make sure that all writes to the record are visible when the positive length is read by the reader.

return recordIndex;
}

buffer.putIntRelease(lengthOffset(recordIndex), -recordLength);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also an opaque write for the record length. We do not care for any ordering guarantees. Only when the record is committed, a release store is needed which will order the stores to the record before it.

}

buffer.putIntRelease(lengthOffset(recordIndex), -recordLength);
VarHandle.releaseFence();
Copy link
Copy Markdown
Contributor Author

@pveentjer pveentjer Apr 14, 2026

Choose a reason for hiding this comment

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

The VarHandle.releaseFence can be dropped. THe only ordering that is needed is the release store of the (positive) record length when committing. This will order all the stores to the record before it.

if (0 != padding)
{
buffer.putLong(0, 0L);
buffer.putIntRelease(lengthOffset(recordIndex), -padding);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't need to announce the negative length. The reading side will not read the record while the length is not positive. And there won't be any abort in this case.

{
buffer.putLong(0, 0L);
buffer.putIntRelease(lengthOffset(recordIndex), -padding);
VarHandle.releaseFence();
Copy link
Copy Markdown
Contributor Author

@pveentjer pveentjer Apr 14, 2026

Choose a reason for hiding this comment

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

The releaseFence is not needed. The release store of the commit (so writing the positive length) will order the write of the message type, before it.

@pveentjer
Copy link
Copy Markdown
Contributor Author

Once this PR is merged, I'll apply the same changes to the aeron_spsc_rb.c

@pveentjer pveentjer force-pushed the cleanup/OneToOneRingBuffer-relaxed-memory-ordering branch from a39fce5 to dd2b636 Compare April 14, 2026 05:15
@pveentjer pveentjer changed the title [WIP] Minimize memory ordering OneToOnRingBuffer Minimize memory ordering OneToOnRingBuffer Apr 14, 2026
@pveentjer pveentjer changed the title Minimize memory ordering OneToOnRingBuffer Weaken memory ordering OneToOnRingBuffer Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant