From: "tmm1 (Aman Gupta)" Date: 2013-10-04T10:53:43+09:00 Subject: [ruby-core:57653] [ruby-trunk - Bug #8983] [PATCH] GC.stat[:heap_free_num] returns number of unused slots on heap Issue #8983 has been updated by tmm1 (Aman Gupta). > (2) count zombie_num > > (objspace->heap.limit - > (objspace_live_num(objspace) - zombie_num) I like this approach. This will be useful also for debugging finalizer leaks. Once we replace heap_free_num with this formula, I would like to rename the existing heap.free_num counter. Do you have any suggestion for a better name? Maybe heap.reused_num or heap.swept_num ---------------------------------------- Bug #8983: [PATCH] GC.stat[:heap_free_num] returns number of unused slots on heap https://bugs.ruby-lang.org/issues/8983#change-42271 Author: tmm1 (Aman Gupta) Status: Assigned Priority: Normal Assignee: ko1 (Koichi Sasada) Category: Target version: current: 2.1.0 ruby -v: ruby 2.1.0dev (2013-10-03 trunk 43129) [x86_64-darwin12.4.1] Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN In ruby 1.9 and 2.0, gc_stat() used to call rest_sweep() so heap_free_num always equals the number of free slots (ObjectSpace.count_objects[:FREE]). In 2.1 the rest_sweep() was removed, so free_num is not always accurate. This patch fixes compatibility with the previous behavior. With this patch, it is also easier to perform "out-of-band" GC in unicorn and passenger. For example: if your application requires 100k objects per request, then you can run the following in-between every request: GC.start if GC.stat[:heap_free_num] < 100_000 I also added a objspace->heap.limit because HEAP_OBJ_LIMIT*heap_used is not accurate due to memory re-alignment in heap_assign_slot. https://github.com/tmm1/ruby/compare/gc-stat-free-num https://github.com/tmm1/ruby/compare/gc-stat-free-num.patch -- http://bugs.ruby-lang.org/