[#61424] [REJECT?] xmalloc/xfree: reduce atomic ops w/ thread-locals — Eric Wong <normalperson@...>

I'm unsure about this. I _hate_ the extra branches this adds;

13 messages 2014/03/12

[ruby-core:61508] Re: [REJECT?] xmalloc/xfree: reduce atomic ops w/ thread-locals

From: SASADA Koichi <ko1@...>
Date: 2014-03-15 07:15:29 UTC
List: ruby-core #61508
(2014/03/14 2:12), Eric Wong wrote:
> How about only using thread local and remove the process-wide globals?

I doubt

> Underflow from race conditions might cause too many GC runs.

Let the counter(s) change addition only.

separate then into:
  malloc_increase (increase only)
  free_increase   (increase only)

and use like that:
  if (malloc_incraese > free_increase &&
      malloc_incraese - free_increase > malloc_limit) {
    do_gc();
  }

There are no underflow.

In fact, I started this strategy just before releasing 2.1. However,
"free_increase" is bigger than malloc_increase.  Maybe this is someone's
bug (for example, xfree for a malloced block) or my misunderstanding.


>> > # basically, GVL protects multi-threads parallel update of such values.
>> > # this atomic operations only for call_without_gvl().
>> > # so it is minor case.
> Right.  I am looking into using GVL less :)
> For example, much of sweep phase may be done without GVL.

I see. It is problem.

# But parallel sweep on my exepriment doesn't show impressive speedup.


BTW,

> +    rb_thread_t *th = ruby_thread_from_native();

`th' can be NULL because no Ruby threads can call this code.

-- 
// SASADA Koichi at atdot dot net

In This Thread