Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GC may not leave any memory for C #17472

Open
dlangBugzillaToGithub opened this issue Jan 11, 2024 · 0 comments
Open

GC may not leave any memory for C #17472

dlangBugzillaToGithub opened this issue Jan 11, 2024 · 0 comments
Labels
Druntime:GC Issues relating the Garbage Collector Druntime Specific to druntime OS:Linux P1 Severity:normal

Comments

@dlangBugzillaToGithub
Copy link

Vladimir Panteleev (@CyberShadow) reported this on 2024-01-11T10:58:04Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24329

Description

When the GC tries to allocate some memory and has none available in the pools it already acquired from the OS, it uses a heuristic to decide whether to trigger a collection cycle or to just request more memory from the OS.

There are some allocation patterns that may cause it to request the last bit of memory from the OS, even though a collection could otherwise satisfy that demand for memory. When this happens, no more memory can be allocated from anywhere in the program, including from C code using malloc.

Though programs generally do not "run out of memory" on modern systems, due to the prevalence of virtual memory, it can still happen if the virtual memory size is limited by `ulimit -v`, or the program runs in a container/cgroup which imposes a memory limit.

This becomes a problem when trying to interoperate with C libraries (as most D programs ultimately do). For example, one symptom of this is std.net.curl requests failing with "Out of memory on handle XXXXXXXXX".

Ideally, the GC should stop allocating (if it can avoid doing so) when the total program memory usage approaches the total program memory limit, though querying these two figures may not be straight-forward on all platforms.

https://github.com/dlang/dmd/blob/4fc086b0c9d08a5bcdabecdec441ec779462181e/druntime/src/core/internal/gc/os.d#L213-L215
@thewilsonator thewilsonator added Druntime Specific to druntime Druntime:GC Issues relating the Garbage Collector and removed Arch:x86_64 Issues specific to x86_64 labels Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Druntime:GC Issues relating the Garbage Collector Druntime Specific to druntime OS:Linux P1 Severity:normal
Projects
None yet
Development

No branches or pull requests

2 participants