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

Take xmalloc into account #7

Closed
wks opened this issue Aug 4, 2022 · 2 comments
Closed

Take xmalloc into account #7

wks opened this issue Aug 4, 2022 · 2 comments

Comments

@wks
Copy link
Collaborator

wks commented Aug 4, 2022

Ruby wrapped malloc into xmalloc, recording the number of bytes allocated, and use it to guide GC. When using MMTk, we currently do not report the number of bytes allocated by malloc to mmtk-core. As a result, mmtk-core will not trigger GC even when there are significant amount of objects that have part allocated with malloc (such as strings and arrays with the payload allocated with xmalloc). Instead, malloc will fail when running out of memory, and the program will crash. Sometimes (especially when running make install -j while MMTk is enabled) it will exhaust the memory of the entire system. When that happens, the system will become unresponsive, and the OOM killer will start randomly killing processes.

mmtk-core recently gained the ability to count the number of bytes allocated by malloc into the allocated size, via the malloc_counted_size feature. We can make use of it so that we can trigger GC more promptly.

@wks
Copy link
Collaborator Author

wks commented Aug 4, 2022

The easiest way to test is

./miniruby --mmtk -e '(1..100).each do |i| 100.times do "a"*10_000_000 end; puts "#{i}GB" end'

It will be killed by SIGKILL. However, since all long strings allocated in the loop are garbage, each GC should free up sufficient memory so the program could continue.

@wks
Copy link
Collaborator Author

wks commented Aug 29, 2022

#8
mmtk/ruby#21

These two PRs added support for obj_free using MMTk's Java-style resurrecting finalization mechanism. We now manually trigger GC when allocated too much memory via xmalloc, using the same heuristics as vanilla Ruby.

@wks wks closed this as completed Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant