Open peterzhu2118 opened 3 months ago
mmtk_add_obj_free_candidate
will make allocation slow if the object needs obj_free
. But we also need the list of obj_free
candidates during normal GC, too, not just during shutdown. During GC, after the liveness of all objects are determined (i.e. after the transitive closure), we go through the list of obj_free
candidates to free them. So freeing objects at shutdown using heap walking can't eliminate the need of mmtk_add_obj_free_candidate
.
But there is one alternative. We may walk the heap during GC (after transitive closure) to find dying obj_free
candidates. Then we don't need mmtk_add_obj_free_candidate
at allocation sites. I am not sure if it profitable.
obj_free
candidates. And the real bottleneck is free()
itself (because it cannot be parallelized, see https://mmtk.zulipchat.com/#narrow/stream/313365-mmtk-ruby/topic/.60free.60.20doesn't.20scale). Meanwhile, we have made efforts so that String
, Array
and MatchData
are no longer obj_free
candidates. If only a small fraction of all objects need obj_free
, it's better to only register those exceptional objects rather than walking every single object.
Right now, we place objects that need to be freed at shutdown into a weak list that is traversed at shutdown. This makes allocation slower and increases memory used.
Allocation:
https://github.com/mmtk/ruby/blob/9903af45b366238734403ad3b709102e418598d1/gc/mmtk.c#L224
Shutdown:
https://github.com/mmtk/ruby/blob/9903af45b366238734403ad3b709102e418598d1/gc/mmtk.c#L495-L503
Instead, we should use heap walking at shutdown to free these objects.