[ruby-dev:48708] [ruby-trunk - Bug #10431] Can't sweep garbage object immediatly when GC_ENABLE_LAZY_SWEEP=0

From: nobu@...
Date: 2014-10-27 04:18:50 UTC
List: ruby-dev #48708
Issue #10431 has been updated by Nobuyoshi Nakada.

Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: DONTNEED, 2.1:=
 DONTNEED

----------------------------------------
Bug #10431: Can't sweep garbage object immediatly when GC_ENABLE_LAZY_SWEEP=
=3D0
https://bugs.ruby-lang.org/issues/10431#change-49654

* Author: Masahiro Ide
* Status: Open
* Priority: Normal
* Assignee:=20
* Category: core
* Target version: current: 2.2.0
* ruby -v: ruby 2.2.0dev (2014-10-26 trunk 48073) [x86_64-darwin14]
* Backport: 2.0.0: DONTNEED, 2.1: DONTNEED
----------------------------------------
GC_ENABLE_LAZY_SWEEP=3D0=E3=81=A8=E8=A8=AD=E5=AE=9A=E3=81=97=E3=81=A6ruby=
=E3=82=92=E3=83=93=E3=83=AB=E3=83=89=E3=81=97=EF=BC=8C=E4=BB=A5=E4=B8=8B=E3=
=81=AE=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92
=E5=AE=9F=E8=A1=8C=E3=81=97=E3=81=9F=E5=A0=B4=E5=90=88=EF=BC=8CGC=E6=99=82=
=E3=81=AB=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88=E3=81=8C=E8=
=A7=A3=E6=94=BE=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E3=82=
=88=E3=81=86=E3=81=AB=E8=A6=8B=E3=81=88=E3=81=BE=E3=81=99=EF=BC=8E

~~~
$ ../configure  CFLAGS=3D"-DGC_ENABLE_LAZY_SWEEP=3D0" && make miniruby
$ cat bug2.rb
GC.disable
10000.times { Object.new }
total_freed_objects1 =3D GC.stat[:total_freed_objects]
GC.enable
GC.start(full_mark: true, immediate_sweep: true)
total_freed_objects2 =3D GC.stat[:total_freed_objects]
puts "freed object : #{total_freed_objects2 - total_freed_objects1}"

$ ./miniruby -v
ruby 2.2.0dev (2014-10-26 trunk 48073) [x86_64-darwin14]
$ ./miniruby bug2.rb
freed object : 0

~~~

=E3=81=BE=E3=81=9F=EF=BC=8Cruby=E3=81=AE=E3=82=B3=E3=83=B3=E3=83=91=E3=82=
=A4=E3=83=AB=E3=83=95=E3=83=A9=E3=82=B0=E3=82=92GC_ENABLE_LAZY_SWEEP=3D0,
RGENGC_CHECK_MODE=3D1=E3=81=A8=E8=A8=AD=E5=AE=9A=E3=81=97=E3=81=9F=E4=B8=8A=
=E3=81=A7=E3=83=93=E3=83=AB=E3=83=89=E3=81=97=EF=BC=8C=E4=BB=A5=E4=B8=8B=E3=
=81=AE=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E5=AE=9F=E8=A1=8C=E3=81=99=E3=82=
=8B=E3=81=A8
assert=E3=81=A7=E8=90=BD=E3=81=A1=E3=81=BE=E3=81=99=EF=BC=8E

~~~
$ ./miniruby -e '10000.times { Object.new }'
Assertion failed: (objspace->flags.stat =3D=3D gc_stat_none), function gc_s=
tart, file ../gc.c, line 5802.
[1]    91336 abort      ./miniruby -e '10000.times { Object.new }'
~~~

sweep=E3=83=95=E3=82=A7=E3=83=BC=E3=82=BA=E3=81=AB=E3=81=A6GC_ENABLE_LAZY_S=
WEEP!=3D1=E3=81=AE=E6=99=82=E3=81=AE=E3=81=BFsweep=E3=81=8C=E5=AE=9F=E8=A1=
=8C=E3=81=95=E3=82=8C=E3=82=8B=E3=81=AE=E3=81=8C
=E5=8E=9F=E5=9B=A0=E3=81=AE=E3=82=88=E3=81=86=E3=81=A7=E3=81=99=E3=81=AE=E3=
=81=A7=EF=BC=8C=E3=81=93=E3=82=8C=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=99=E3=82=
=8B=E3=83=91=E3=83=83=E3=83=81=E3=82=92=E4=BD=9C=E3=82=8A=E3=81=BE=E3=81=97=
=E3=81=9F=EF=BC=8E

~~~diff
diff --git a/gc.c b/gc.c
index a27cc01..979e2e0 100644
--- a/gc.c
+++ b/gc.c
@@ -3314,9 +3314,8 @@ static void
 gc_sweep_rest(rb_objspace_t *objspace)
 {
     rb_heap_t *heap =3D heap_eden; /* lazy sweep only for eden */
-
-    if (is_lazy_sweeping(heap)) {
-       while (is_lazy_sweeping(heap)) {
+    if ((heap)->sweep_pages !=3D NULL) {
+       while ((heap)->sweep_pages !=3D NULL) {
            gc_sweep_step(objspace, heap);
        }
     }
~~~

English:

When I tried to compile ruby with GC_ENABLE_LAZY_SWEEP=3D0,
Ruby does not sweep objects immediatly.

~~~
$ ../configure  CFLAGS=3D"-DGC_ENABLE_LAZY_SWEEP=3D0" && make miniruby
$ cat bug2.rb
GC.disable
10000.times { Object.new }
total_freed_objects1 =3D GC.stat[:total_freed_objects]
GC.enable
GC.start(full_mark: true, immediate_sweep: true)
total_freed_objects2 =3D GC.stat[:total_freed_objects]
puts "freed object : #{total_freed_objects2 - total_freed_objects1}"

$ ./miniruby -v
ruby 2.2.0dev (2014-10-26 trunk 48073) [x86_64-darwin14]
$ ./miniruby bug2.rb
freed object : 0
~~~

In addition, when I set GC_ENABLE_LAZY_SWEEP=3D0 and RGENGC_CHECK_MODE=3D1
ruby gives me assertion error like this:

~~~
$ ./miniruby -e '10000.times { Object.new }'
Assertion failed: (objspace->flags.stat =3D=3D gc_stat_none), function gc_s=
tart, file ../gc.c, line 5802.
[1]    91336 abort      ./miniruby -e '10000.times { Object.new }'
~~~

The following patch fix this problem.

~~~diff
diff --git a/gc.c b/gc.c
index a27cc01..979e2e0 100644
--- a/gc.c
+++ b/gc.c
@@ -3314,9 +3314,8 @@ static void
 gc_sweep_rest(rb_objspace_t *objspace)
 {
     rb_heap_t *heap =3D heap_eden; /* lazy sweep only for eden */
-
-    if (is_lazy_sweeping(heap)) {
-       while (is_lazy_sweeping(heap)) {
+    if ((heap)->sweep_pages !=3D NULL) {
+       while ((heap)->sweep_pages !=3D NULL) {
            gc_sweep_step(objspace, heap);
        }
     }

~~~



--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next