Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Ostanevich <sergos@tarantool.org>
To: Igor Munkin <imun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org,
	Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: Re: [Tarantool-patches] [PATCH 1/2] test: disable JIT for Lua Fun totable function
Date: Thu, 25 Jun 2020 12:43:51 +0300	[thread overview]
Message-ID: <20200625094351.GC16381@tarantool.org> (raw)
In-Reply-To: <20200621202459.GE3503@tarantool.org>

Hi!

Thanks for explanation!

My question was about hypothetic solution - as you mentioned for a
trace with wrong RENAME - how long will it take to implement such a
workaround?

It whould affect only traces with such problem, and next approach can
be to retry the trace with less optimizations, not just abort it?

Regards,
Sergos

On 21 Jun 23:24, Igor Munkin wrote:
> Sergos,
> 
> On 21.06.20, Sergey Ostanevich wrote:
> > Hi!
> > 
> > Thanks for the patch!
> > 
> > AFAIU you just fix one of our test. Is it make sence to fix the library
> > code in fun.lua to bring the fix for all cutomers?
> 
> Yes, I "fixed" the test (i.e. made it non-flaky) that reproduces the
> mentioned issue.
> 
> We have already discussed it offline with Sasha Tu. Of course it makes
> sense to fix the "source" of the bug, but what exactly we need to fix?
> 
> Assume there is exactly the chunk in client's code making JIT to emit an
> invalid RENAME. So there is no option to fix it in scope of the platform
> except turning JIT off by default. The same issue is with Lua Fun: it's
> just a "third party" Lua code leading to invalid traces assembling.
> 
> Furthermore, we have lots of code in the platform using Lua Fun methods
> with not a single JIT-related problem (at least I don't know any). Lua
> Fun is a high-performance functional programming library for Lua
> designed with LuaJIT's trace compiler in mind (I copied this from GitHub
> repo), ergo disabling JIT for the whole library will nerf performance
> for the well-compiled Lua code.
> 
> As a result I see two solutions (besides fixing the root cause):
> * Turn JIT engine off for the whole platform (or even disable JIT
>   machinery at all). It definitely will lead to dramatic performance
>   drop and might also lead to further dramatic source code changes,
>   since some Tarantool parts are tuned a lot regarding JIT specifics.
> * Provide a recipe for ones facing the similar problem, so they can use
>   Lua Fun until the fix is ready. I guess the way the patch is done can
>   be shared with all customers.
> 
> > 
> > Also, as soon as we know the #584 essence - how hard will it be to test
> > all Tarantool libs for this bug?
> 
> Since JIT tries to optimize and narrow Lua dynamic specifics, it's like
> finding a needle in a haystack. As you can see in my reproducer[1] I
> just reduce register pressure via enabling sink optimization and amiss
> RENAME is emitted. With disabled sink optimization everything works
> fine.
> 
> It would be nice to enrich our suite with such tests for other Tarantool
> libs, but even this single case is way too complex to find: we need to
> emit destructive x86 op with the different "source" and "destination"
> registers allocated between two side exits related to the same snapshot
> -- I'm not sure I didn't missed something.
> 
> It looks like we can add a trace abort (or even assert) for a RENAME
> emitted between two side exits with the same snapno. As a result broken
> traces are not compiled. Thoughts? I need some time to think about it.
> 
> Long story short: the stars were aligned and the failure occurred. For
> now I have no idea how to catch such traces without patching assembling
> machinery.
> 
> > 
> > Regards,
> > Sergos
> > 
> > 
> > On 19 Jun 23:40, Igor Munkin wrote:
> > > JIT compiler can generate invalid trace for <totable> function breaking
> > > its semantics (see LuaJIT/LuaJIT#584). Since interpreter works fine and
> > > produces right results, disabling JIT for this function (and all its
> > > subfunctions) stops execution failures.
> > > 
> > > Relates to LuaJIT/LuaJIT#584
> > > Fixes #4252
> > > 
> > > Signed-off-by: Igor Munkin <imun@tarantool.org>
> > > ---
> > >  test/box-tap/key_def.test.lua | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > > 
> > > diff --git a/test/box-tap/key_def.test.lua b/test/box-tap/key_def.test.lua
> > > index d7dbf5b88..ce7a3cb63 100755
> > > --- a/test/box-tap/key_def.test.lua
> > > +++ b/test/box-tap/key_def.test.lua
> > > @@ -4,6 +4,14 @@ local tap = require('tap')
> > >  local ffi = require('ffi')
> > >  local json = require('json')
> > >  local fun = require('fun')
> > > +
> > > +-- Fix for gh-4252: to prevent invalid trace assembling (see
> > > +-- LuaJIT/LuaJIT#584) disable JIT for fun.totable function and
> > > +-- method (these functions are different GCfunc objects) and all
> > > +-- their subfunctions.
> > > +jit.off(fun.totable, true)
> > > +jit.off(fun.iter({}).totable, true)
> > > +
> > >  local key_def_lib = require('key_def')
> > >  
> > >  local usage_error = 'Bad params, use: key_def.new({' ..
> > > -- 
> > > 2.25.0
> > > 
> 
> [1]: https://gist.github.com/igormunkin/18cb6afe5a495bce31f772d453f3117e#file-4252-lua
> 
> -- 
> Best regards,
> IM

  reply	other threads:[~2020-06-25  9:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19 20:50 [Tarantool-patches] [PATCH 0/2] Reduce Lua GC pressure in Tarantool Igor Munkin
2020-06-19 20:40 ` [Tarantool-patches] [PATCH 1/2] test: disable JIT for Lua Fun totable function Igor Munkin
2020-06-21 10:26   ` Sergey Ostanevich
2020-06-21 20:24     ` Igor Munkin
2020-06-25  9:43       ` Sergey Ostanevich [this message]
2020-06-26 11:11         ` Igor Munkin
2020-06-26 13:11           ` Igor Munkin
2020-06-23 18:04   ` Igor Munkin
2020-06-23 18:45     ` Alexander V. Tikhonov
2020-06-23 21:58       ` Igor Munkin
2020-06-19 20:40 ` [Tarantool-patches] [PATCH 2/2] box: reduce box_process_lua Lua GC memory usage Igor Munkin
2020-06-20 17:42   ` Vladislav Shpilevoy
2020-06-20 21:24     ` Igor Munkin
2020-06-21 10:27       ` Sergey Ostanevich
2020-06-21 10:40         ` Igor Munkin
2020-06-21 15:35       ` Vladislav Shpilevoy
2020-06-21 19:09         ` Igor Munkin
2020-06-22 22:54 ` [Tarantool-patches] [PATCH 0/2] Reduce Lua GC pressure in Tarantool Vladislav Shpilevoy
2020-06-23 21:06 ` Vladislav Shpilevoy
2020-06-23 21:58   ` Igor Munkin
2020-06-23 21:59 ` Igor Munkin
2020-06-27 13:22   ` Igor Munkin

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=20200625094351.GC16381@tarantool.org \
    --to=sergos@tarantool.org \
    --cc=imun@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/2] test: disable JIT for Lua Fun totable function' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox