Bug report
Bug description:
If an external tool sampling GC statistics does not pause the target process (and we designed get_gc_stats not to pause), it can read torn data under certain circumstances.
There are two distinct problems:
-
Weakly ordered platforms: The stores of ts_start and ts_stop may be reordered by the CPU/optimizer. We need to add memory barriers to mitigate this.
-
Large memcpy window: We are copying a sufficiently large memory region via memcpy. If two or more GC cycles occur during this copy, we can end up with inconsistent data spanning multiple GC states.
@maurycy has an idea to use a sequence counter for consistency checks — I think he should definitely give it a try.
cc @pablogsal
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Bug report
Bug description:
If an external tool sampling GC statistics does not pause the target process (and we designed
get_gc_statsnot to pause), it can read torn data under certain circumstances.There are two distinct problems:
Weakly ordered platforms: The stores of
ts_startandts_stopmay be reordered by the CPU/optimizer. We need to add memory barriers to mitigate this.Large memcpy window: We are copying a sufficiently large memory region via
memcpy. If two or more GC cycles occur during this copy, we can end up with inconsistent data spanning multiple GC states.@maurycy has an idea to use a sequence counter for consistency checks — I think he should definitely give it a try.
cc @pablogsal
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response