# Does the GC respond based on memory pressure?

**URL:** <https://discourse.julialang.org/t/does-the-gc-respond-based-on-memory-pressure/64592>\
**Category:** Internals & Design\
**Created:** [July 13, 2021, 4:32pm UTC](https://discourse.julialang.org/t/does-the-gc-respond-based-on-memory-pressure/64592 "2021-07-13T16:32:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [July 13, 2021, 4:32pm UTC](https://discourse.julialang.org/t/does-the-gc-respond-based-on-memory-pressure/64592/1 "2021-07-13T16:32:32Z")

</div>

I.e. is it more or less aggressive depending on what the OS tells it about available memory? Or does it do the same things regardless of the memory pressure. I’m asking because I’m not sure how to communicate that memory pressure in a containerized environment-- or if there is even a need to do so.

(Asking in the context of some OOMs I’m experiencing and trying to figure out how to respond-- increase memory limits, call `GC.gc()` manually more, or something else).

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [July 13, 2021, 7:55pm UTC](https://discourse.julialang.org/t/does-the-gc-respond-based-on-memory-pressure/64592/2 "2021-07-13T19:55:02Z")

</div>

Related post: [Memory consumption growth with many large MILP's in JuMP](https://discourse.julialang.org/t/memory-consumption-growth-with-many-large-milps-in-jump/61895)

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [July 13, 2021, 8:04pm UTC](https://discourse.julialang.org/t/does-the-gc-respond-based-on-memory-pressure/64592/3 "2021-07-13T20:04:44Z")

</div>

To add a few details to my question: (cross-posted from #helpdesk on Slack):

in this case I can just bump the memory limit on my kuberbetes pod, but my question is more about the semantics of how Julia’s GC works with regards to memory pressure. E.g. if I set a memory limit of 16 Gb in kubernetes, it will kill the pod if it exceeds 16 Gb of memory used. But the processes run in a node that might have 60 Gb of memory-- and Sys.free\_memory() will show plenty of free memory.

So my question is basically: is that a problem. I.e. if Julia’s GC works based on available memory, it might say: hey, there’s plenty of free memory, no need to waste time on a GC run now. But actually there’s this hidden limit of X amount and it will get killed if it exceeds it-- and raising the memory limit isn’t helping much bc maybe Julia will just GC even less.

If Julia’s GC is agnostic to what the system says, then the lack of communicating memory pressure to Julia is not the problem, and I need to either get GC to run more often or make less garbage or increase the memory limit etc.

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [July 13, 2021, 8:52pm UTC](https://discourse.julialang.org/t/does-the-gc-respond-based-on-memory-pressure/64592/4 "2021-07-13T20:52:50Z")

</div>

It scales the GC rate with the available memory, yes. I think people who have studied memory allocators usually suggest a maximum ratio of about 1:5 for expected maximum memory to maximum physical memory. Beyond that, it starts to taking exponentially longer to allocate and free memory.

There is an open issue to improve uv\_get\_constrained\_memory to support cgroup2, such that it works better on containerized systems.
