dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 6/4] gc.c: allow disabling sleepy GC
Date: Wed, 2 May 2018 04:52:49 +0000	[thread overview]
Message-ID: <20180502045248.GA3949@80x24.org> (raw)
In-Reply-To: <20180501080844.22751-1-e@80x24.org>

* internal.h: remove prototypes
* gc.h: define macros and static inlines for disabling functionality
  moved prototypes from internal.h
* gc.c: adjust for switches, update comments
---
 gc.c       | 12 +++++++-----
 gc.h       | 25 +++++++++++++++++++++++++
 internal.h |  4 ----
 3 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/gc.c b/gc.c
index 61b5e24f094..f7a3cd9eb43 100644
--- a/gc.c
+++ b/gc.c
@@ -6518,14 +6518,15 @@ gc_rest(rb_objspace_t *objspace)
     }
 }
 
+#if RUBY_GC_SLEEPY_SWEEP || RUBY_GC_SLEEPY_MARK
+/* this is just a hint, TOCTOU race may happen */
 int
 rb_gc_inprogress(const rb_execution_context_t *ec)
 {
     rb_objspace_t *objspace = rb_ec_vm_ptr(ec)->objspace;
 
-    /* TODO: should this check is_incremental_marking() ? */
-    return is_lazy_sweeping(&objspace->eden_heap) ||
-           is_incremental_marking(objspace);
+    return (RUBY_GC_SLEEPY_SWEEP && is_lazy_sweeping(&objspace->eden_heap)) ||
+           (RUBY_GC_SLEEPY_MARK && is_incremental_marking(objspace));
 }
 
 /* returns true if there is more work to do, false if not */
@@ -6534,12 +6535,12 @@ rb_gc_step(const rb_execution_context_t *ec)
 {
     rb_objspace_t *objspace = rb_ec_vm_ptr(ec)->objspace;
 
-    if (is_lazy_sweeping(&objspace->eden_heap)) {
+    if (RUBY_GC_SLEEPY_SWEEP && is_lazy_sweeping(&objspace->eden_heap)) {
 #if GC_ENABLE_LAZY_SWEEP
 	gc_sweep_continue(objspace, &objspace->eden_heap);
 #endif
     }
-    else if (is_incremental_marking(objspace)) {
+    else if (RUBY_GC_SLEEPY_MARK && is_incremental_marking(objspace)) {
 #if GC_ENABLE_INCREMENTAL_MARK
 	gc_marks_continue(objspace, &objspace->eden_heap);
 #endif
@@ -6547,6 +6548,7 @@ rb_gc_step(const rb_execution_context_t *ec)
 
     return rb_gc_inprogress(ec);
 }
+#endif /* RUBY_GC_SLEEPY_SWEEP || RUBY_GC_SLEEPY_MARK */
 
 struct objspace_and_reason {
     rb_objspace_t *objspace;
diff --git a/gc.h b/gc.h
index 2c91e06620a..1f8a06cdc7e 100644
--- a/gc.h
+++ b/gc.h
@@ -91,6 +91,31 @@ const char *rb_raw_obj_info(char *buff, const int buff_size, VALUE obj);
 void rb_obj_info_dump(VALUE obj);
 
 struct rb_thread_struct;
+struct rb_execution_context_struct;
+
+#ifndef RUBY_GC_SLEEPY_SWEEP
+#  define RUBY_GC_SLEEPY_SWEEP 1
+#endif
+#ifndef RUBY_GC_SLEEPY_MARK
+#  define RUBY_GC_SLEEPY_MARK 1
+#endif
+
+#if RUBY_GC_SLEEPY_SWEEP || RUBY_GC_SLEEPY_MARK
+int rb_gc_inprogress(const struct rb_execution_context_struct *);
+int rb_gc_step(const struct rb_execution_context_struct *);
+#else /* (RUBY_GC_SLEEPY_SWEEP|RUBY_GC_SLEEPY_MARK) == 0 */
+static inline int
+rb_gc_inprogress(const struct rb_execution_context_struct *ec)
+{
+	return 0;
+}
+
+static inline int
+rb_gc_step(const struct rb_execution_context_struct *ec)
+{
+    return 0;
+}
+#endif /* (RUBY_GC_SLEEPY_SWEEP|RUBY_GC_SLEEPY_MARK) == 0 */
 
 RUBY_SYMBOL_EXPORT_BEGIN
 
diff --git a/internal.h b/internal.h
index 43043e6601d..85370ec0d7f 100644
--- a/internal.h
+++ b/internal.h
@@ -1290,10 +1290,6 @@ void rb_gc_writebarrier_remember(VALUE obj);
 void ruby_gc_set_params(int safe_level);
 void rb_copy_wb_protected_attribute(VALUE dest, VALUE obj);
 
-struct rb_execution_context_struct;
-int rb_gc_inprogress(const struct rb_execution_context_struct *);
-int rb_gc_step(const struct rb_execution_context_struct *);
-
 #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(_WIN32)
 #define ruby_sized_xrealloc(ptr, new_size, old_size) ruby_xrealloc(ptr, new_size)
 #define ruby_sized_xrealloc2(ptr, new_count, element_size, old_count) ruby_xrealloc(ptr, new_count, element_size)
-- 
EW

  parent reply	other threads:[~2018-05-02  4:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-01  8:08 [WIP v2 0/4] sleepy GC Eric Wong
2018-05-01  8:08 ` [WIP v2 1/4] thread.c (timeout_prepare): common function Eric Wong
2018-05-01  8:08 ` [WIP v2 2/4] gc: rb_wait_for_single_fd performs GC if idle (Linux) Eric Wong
2018-05-01  8:08 ` [WIP v2 3/4] thread.c (do_select): perform GC if idle Eric Wong
2018-05-01  8:08 ` [WIP v2 4/4] thread.c: native_sleep callers may perform GC Eric Wong
2018-05-02  4:42   ` [PATCH 5/4] thread_sync.c (mutex_lock): add missing else Eric Wong
2018-05-02  4:52 ` Eric Wong [this message]
2018-05-02  4:57 ` [PATCH] benchmark: add benchmarks for sleepy GC Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180502045248.GA3949@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).