Skip to content

CA-432861: Re-map a plugin's shared file when it grows - #7370

Merged
MarkSymsCtx merged 2 commits into
xapi-project:masterfrom
MarkSymsCtx:CA-432861
Nov 2, 2026
Merged

MarkSymsCtx merged 2 commits into
xapi-project:masterfrom
MarkSymsCtx:CA-432861

Conversation

@MarkSymsCtx

Copy link
Copy Markdown
Contributor

The v2 protocol has rrdd re-read all of a plugin's data when its metadata checksum changes, but the file reader maps the file once, at the length it had on first read. A plugin that adds datasources extends the file in place, as the Python rrdd library does, so the re-read runs off the end of the old mapping and fails on every tick: the plugin's datasources go dark until it re-registers. A plugin whose datasource set follows the VMs on a host hits this on the first VM start.

The v2 protocol has rrdd re-read all of a plugin's data when its
metadata checksum changes, but the file reader maps the file once, at
the length it had on first read. A plugin that adds datasources
extends the file in place, as the Python rrdd library does, so the
re-read runs off the end of the old mapping and fails on every tick:
the plugin's datasources go dark until it re-registers. A plugin whose
datasource set follows the VMs on a host hits this on the first VM
start.

Signed-off-by: Mark Syms <mark.syms@citrix.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
let size =
try (Unix.stat state.path).Unix.st_size with Unix.Unix_error _ -> 0
in
if size > Cstruct.length state.mapping then state.mapping <- map state.path ;

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.

This shouldn't leak memory, the memory reserved by map is held by a bigarray which installs a finalizer. Although this isn't made explicit in the documentation, it's present in the implementation:
https://github.com/ocaml/ocaml/blob/trunk/otherlibs/unix/mmap_ba.c#L74
https://github.com/ocaml/ocaml/blob/trunk/otherlibs/unix/mmap_ba.c#L28-L56

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.

Thanks for that @psafont , I'm reading that as the change being OK wrt. memory.

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.

I'm reading that as the change being OK wrt. memory.

That's exactly it.
We've had problems in rrrds with memory leaks, and bigarrays are not generally garbage-collected, so I had to check it.

Re-mapping a grown file makes File.expose stat the file, so the two
calls per read that were free before now cost two syscalls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Mark Syms <mark.syms@citrix.com>
@MarkSymsCtx
MarkSymsCtx added this pull request to the merge queue Nov 2, 2026
Merged via the queue into xapi-project:master with commit caf4d43 Nov 2, 2026
16 checks passed
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.

4 participants