I’m trying to add a custom error message for a package if the user inputs data such that the memory of the system will explode. For such, I use:
if required_memory > 0.8 * Sys.free_memory()
throw(.... appropriate error message... )
end
The problem is that after adding this to the package, CI tests started to fail, because in MacOS with Julia 1.9, it seems that free_memory() is returning way too small values. For instance, the error message says something like free_memory being 0.1Mb.
Those tests are small and do not fail normally, so it is not the case that that is the true free memory of the node running the CI test.
Are there any known issues associated to Sys.free_memory(), particularly in MacOS?
Ps: The error occurred in Julia 1.9 but not in 1.10.4, thus it might be a fixed bug somewhere in between.
Anyway I would like to know if that use of free_memory is reasonable one (I don’t want my users getting Killed for no apparent reason).
I’m definitely not an expert on this, but I think there’s a difference between “free memory” and “available memory”, where the latter includes OS caches which can be quickly freed. I think “free memory” is kinda wasted (since it could be caching something, as long as the OS can quickly dump the cache when the memory is needed for something else), and MacOS tends to not have much of it. And Julia doesn’t seem to expose a Sys.available_memory() or similar.
so I guess I am using a large % of my memory but have available more than the tiny bit Sys.free_memory() says. I for one would be disappointed if a Julia package refused to allocate more than that to me; I can allocate it without an issue or noticeable slowdown:
Thanks for the feedback. I decided then to issue a warning if the memory exceeds a fraction of the total memory, and only error if the required memory is larger than the total memory.