~/talk

The Bug that Forced Me to Understand Memory Compaction

Talkat RubyConf 2020 · 2020-11-17..11-19· [ruby, linux-and-operating-systems]
links:none on file
slides:none on file

A segfault occurs when calling gc.compact on Ruby 2.7 because a C extension keeps a long‑lived Ruby object unmarked so it moves during compaction; Ruby 2.7 pins marked objects during the initial GC pass. The bug is in an unregistered global (rb_bson_registry), fixed by calling rb_gc_register_mark_object to pin it, or by using rb_gc_mark_no_pin plus compaction callbacks and rb_gc_new_location to update pointers; the registration fix stops the crashes and restores correct behavior.

AI-written summary · about

  1. 0:00Intro
  2. 2:31BSON gem
  3. 4:42Ruby heap
  4. 5:27Allocating memory
  5. 6:19Mark and sweep
  6. 8:25The heap after GC
  7. 8:46Reality check
  8. 9:04Memory bloat
  9. 10:34What I'd learned so far
  10. 12:28Ruby objects in C
  11. 14:09Declaring new Ruby types
  12. 15:33Memory compaction and C extensions
  13. 17:23Garbage collection and C extensions
  14. 18:39Mark callbacks
  15. 19:27Garbage collection with mark callback
  16. 19:49Marking long-lived objects Extension VALUE greeting
  17. 21:50Mark and pin
  18. 23:57Elementary, my dear
  19. 24:23The suspects
  20. 24:45The culprit
  21. 25:32The solution
  22. 25:43Moving forward
  23. 26:29rb_gc_mark_no_pin()
  24. 26:53Compaction callback
  25. 27:35What I learned
  26. 28:44Sources
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.