Skip to content

Torn reads of GC statistics from external process via get_gc_stats #155811

Description

@sergey-miryanov

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:

  1. 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.

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions