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 behavior when memory is almost full #6103

Closed
danielcdcj opened this issue Mar 10, 2014 · 8 comments
Closed

GC behavior when memory is almost full #6103

danielcdcj opened this issue Mar 10, 2014 · 8 comments
Labels
GC Garbage collector performance Must go faster

Comments

@danielcdcj
Copy link

Refer to this example
https://groups.google.com/forum/#!topic/julia-users/eYCwT6o4UlM

A = a big matrix. After A is defined, there would be 1.1 GB free memory left
B = a random matrix of 500 MB

C = a random matrix of 500 MB
so now there's only 100 MB free on the memory

C = 0
still 100MB free.... Julia not cleaning up Memory. MATLAB would free the memory at this point

B = a random matrix of 500 MB
run out of RAM, now stuff get written to disk

This example was ran in Julia v0.2.1 on Mac OS 10.8.5.

@vtjnash
Copy link
Member

vtjnash commented Mar 10, 2014

Good garbage collection is a tradeoff of time and memory allocation. I recommend you save time and buy enough memory to contain your data.

MATLAB has a rather poor memory management configuration which requires it to call gc() whenever you leave a function call. They have since improved it quite a bit in the last few years, but I'm stuck with an older version of MATLAB for other reasons, and so it is not uncommon for me to wait several minutes for gc to run after running small functions. That is not a good model to copy.

(btw, the GC /did/ run on the next allocation, however, the old matrix hadn't yet been unreferenced at that point, so it couldn't free it. perhaps julia could speculatively dereference LHS variables before calling the RHS function, but that would break if the RHS threw an error, and it probably would only help in artificial tests anyways)

@vtjnash vtjnash closed this as completed Mar 10, 2014
@JeffBezanson
Copy link
Member

Perhaps one thing to say here is that the GC currently doesn't take memory-almost-full conditions into account. It could potentially try harder to collect if physical memory is getting full.

@timholy
Copy link
Member

timholy commented Mar 11, 2014

But shouldn't it run after the C=0 line when you're allocating memory for B? That's the first moment in which you could delete anything; I thought the threshold-trigger was tested any time you allocate memory.

@JeffBezanson
Copy link
Member

True, but we also grow the threshold. The nastiness here is that at a certain point we do a single allocation that's bigger than the whole threshold. Before that allocation we don't appear to need GC. Perhaps this should be a special case of some kind.

@timholy timholy reopened this Mar 11, 2014
@timholy
Copy link
Member

timholy commented Mar 11, 2014

Possible strategies? (Separately or in combination?)

  • If you grow the threshold, don't let it be bigger than the previous largest reclamation (if that's smaller than the current setting, keep the current setting)
  • Grow the threshold to a value no bigger than half of TOTAL_MACHINE_MEMORY-ALLOCATED_MEMORY

@vtjnash
Copy link
Member

vtjnash commented Mar 12, 2014

We do have libuv functions uv_get_free_memory and uv_get_total_memory available

@PallHaraldsson
Copy link
Contributor

This issue was last updated long before v0.4.0-rc2. Is it still an issue after many changes, e.g. to an incremental GC?

Yes, RAM can of course still get full.. but was this about accumulated garbage? [I only scanned thread.. Will not look into much if you think someone just forgot to close the issue.]

@vtjnash: "Good garbage collection is a tradeoff of time and memory allocation. I recommend you save time and buy enough memory to contain your data."

[Yes and no, garbage be allowed to accumulate to much for cache reasons, and you can't buy that easily, but it's a different issue to memory running out.] In the case stated, the memory didn't really run out.

Does Julia ever return memory to the OS? Maybe allocated garbage memory, not used, isn't too big of a problem.. for the current process or for all combined, so I'm not too worried, on Android without VM, it would however be more of an issue.

@yuyichao
Copy link
Contributor

Close as dup of #17987. (Really the other way around but it's better to discuss there.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GC Garbage collector performance Must go faster
Projects
None yet
Development

No branches or pull requests

7 participants