# Poll Memory Utilization

**URL:** <https://discourse.julialang.org/t/poll-memory-utilization/103815>\
**Category:** General Usage\
**Created:** [September 13, 2023, 2:03pm UTC](https://discourse.julialang.org/t/poll-memory-utilization/103815 "2023-09-13T14:03:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [September 13, 2023, 2:03pm UTC](https://discourse.julialang.org/t/poll-memory-utilization/103815/1 "2023-09-13T14:03:20Z")

</div>

Is there a way for me to poll system memory utilization? I am working in an AWS container that will crash out if I allocate more than my allotted memory (no swap), so I’m hoping to add some throttles to my pipeline if I am getting too close to the limit.

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [September 13, 2023, 2:07pm UTC](https://discourse.julialang.org/t/poll-memory-utilization/103815/2 "2023-09-13T14:07:03Z")

</div>

There is `Sys.total_memory()`:

> Get the total memory in RAM (including that which is currently used) in bytes.

and `Sys.free_memory()`:

> Get the total free memory in RAM in bytes.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [September 13, 2023, 2:13pm UTC](https://discourse.julialang.org/t/poll-memory-utilization/103815/3 "2023-09-13T14:13:08Z")

</div>

Ideally Julia would just not use too much memory, but you could use new in 1.10:

```julia
--heap-size-hint=<size> Forces garbage collection if memory usage is higher than that value.
                            The memory hint might be specified in megabytes(500M) or gigabytes(1G)

```

It seems like that option should be redundant, maybe it will be, or at least you can ask Julia to try harder. Julia’s GC is getting better in 1.10 already (and on master) and I believe it will be released soon.

You can also set hard memory limits with Linux tools, but then your Julia will well crash if going over… That might be ok if you restart (automatically), and software should try to live up to that ideal:

> **[Crash-only software](https://en.wikipedia.org/wiki/Crash-only_software)**
>
> Crash-only software refers to computer programs that handle failures by simply restarting, without attempting any sophisticated recovery. Correctly written components of crash-only software can microreboot to a known-good state without the help of a user. Since failure-handling and normal startup use the same methods, this can increase the chance that bugs in failure-handling code will be noticed,\[clarification needed\] except when there are leftover artifacts, such as data corruption from a Cr...

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [September 13, 2023, 4:48pm UTC](https://discourse.julialang.org/t/poll-memory-utilization/103815/4 "2023-09-13T16:48:34Z")

</div>

Thanks @Palli! I’m aware of the GC hint, but I’m concerned with having too much memory in use, not so much cleaning up unneeded memory. And while it would be okay to let Julia crash, I’d like to avoid failure states to begin with using defensive checks and throttles, not dying completely from an avoidable issue.

Those Sys calls look perfect @barucden!
