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
Expose heap size information to the user #3275
Conversation
Thank you for this contribution! It would be great if you could provide an unit test just to ensure it links correctly and return sane results (probably check returned size to be matching |
Thanks for the feedback! I added a unit test to check whether the returned results are indeed within sound bounderies. I am still unsure about how to get the initial and maximum heap sizes for the boehm gc. If anyone has suggestions, please feel free to share them. I also tried 'guarding' the results that are returned from boehm gc when environment variables are used (i.e., if the user has set environment variables, return those instead of the retrieved results from boehm gc). However, I will be opening a follow up PR soon to integrate the new functionalities with javalib. |
The problem with not available scala-native/tools/src/main/scala/scala/scalanative/build/GC.scala Lines 43 to 44 in 940b812
I've taken a glance at Boehm GC and probably we can start with env variable |
Thanks a lot, it makes sense 😅. Hm, some checks seem to fail. Is this maybe from another commit not related to this PR? Failing tests seem to be from runtimes with immix and commix on Linux, though those were not modified in the latest commit to this PR. For Boehm, if no environment variables are set, the initial heap size will be 0 and the maximum heap size will be |
I think these are problems of GitHub infrastructure, I'll restart them later |
* [WIP] first iteration of exposing heap size info * Exposed heap size information that the GC utilizes to the user * updated getMinHeapSize name to getInitHeapSize name * fixed clangfmt * fixed gone bracket * added unit test for the heap size information retrieval * fixed scalafmt :) * fixed linking boehm with shared. updated boehm to guard heap size information (cherry picked from commit 89f8ed5)
* [WIP] first iteration of exposing heap size info * Exposed heap size information that the GC utilizes to the user * updated getMinHeapSize name to getInitHeapSize name * fixed clangfmt * fixed gone bracket * added unit test for the heap size information retrieval * fixed scalafmt :) * fixed linking boehm with shared. updated boehm to guard heap size information (cherry picked from commit 89f8ed5)
This PR aims at exposing heap size information to the end user of Scala Native. Concretely, the initial heap size and the maximum heap size should be accessed by the end user using
scalanative.runtime.GC.getInitHeapSize()
andscalanative.runtime.GC.getMaxHeapSize()
which will both return the results in bytes. This is similar toRuntime.getRuntime().maxMemory()
in the Java library.Motivation
In some cases, the user may be interested in knowing the initial and maximum heap size the garbage collector is using at runtime. For example, if the user sets the initial and maximum heap size using environment variables, the user may want to do a sanity check in their program to make sure that the variables are correctly set. This is useful in some (automated) benchmarking infrastructures, where the heap size is often limited, and it may come in handy to check that the heap size settings are correcly set and well understood by the Scala Native program.
Implementation
Immix and Commix
For the immix and commix garbage collectors, accessing the initial heap size is achieved by using the
Settings_MinHeapSize()
function. As for the maximum heap size, if the user has set a maximum heap size using the corresponding environment variable, then this variable will be returned. Otherwise, the total amount of the available phyiscal memory on the machine will be returned.None
For the none gc, if the user did not change the heap size settings, the initial heap size will be 0, and the maximum heap size will be the total amount of physical memory.
Boehm
Unfortuantely, I was not able to get the initial heap size using the public interface of the Boehm GC. I was able to locate it in the codebase of BDWGC Line 928 bdwgc/misc.c, but I could not find directly any public interface to retrieve these results.
As for the maximum heap size, the
GC_get_prof_stats
function may be used. However when I was testing on my machine (Ubuntu 22.04) with a manually set maximum heap size,GC_prof_stats_s.heapsize_full
did not seem to change, which makes me think that I probably misunderstood its usage, and it is perhaps not the maximum heap size.