Re: ffi.new intermittent failures

  • From: Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 14 Nov 2013 08:35:02 +0000

On 14 Nov 2013 08:30, "Alexander Gladysh" <agladysh@xxxxxxxxx> wrote:
>
> Hi, list!
>
> We observe intermittent failures in ff.new, when attempting to
> allocate a largeish chunk of memory on Linux (see below). C calls like
> calloc work fine.
>
> Any clues?

Look at the allocation code. For x64 it uses mmap with hints and needs to
get low 2G addresses which can fail. Best to call mmap yourself for huge
allocations and allocate over 2G.

Judtin

> Thanks,
> Alexander.
>
> dvv@pk:~$ rlwrap luajit2
> LuaJIT 2.0.2 -- Copyright (C) 2005-2013 Mike Pall. http://luajit.org/
> JIT: ON CMOV SSE2 SSE3 fold cse dce fwd dse narrow loop abc sink fuse
> > ffi=require('ffi')
> > =ffi.typeof('char[1000000000]')()
> cdata<char [1000000000]>: 0x41800018
> > =ffi.typeof('char[1000000000]')()
> not enough memory
> > =ffi.typeof('char[1000000000]')()
> cdata<char [1000000000]>: 0x41c96018
> > =ffi.typeof('char[1000000000]')()
> not enough memory
>
> >dvv@pk:~$ uname -a
> Linux pk 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013
> x86_64 x86_64 x86_64 GNU/Linux
>
> dvv@pk:~$ lsb_release -a
> No LSB modules are available.
> Distributor ID:    Ubuntu
> Description:    Ubuntu 13.10
> Release:    13.10
> Codename:    saucy
>
> git clone http://luajit.org/git/luajit-2.0.git
> #5a25a735f589d6fafbaa3c234c59fbfe8920a102
>
> dvv@pk:~$ free
>              total       used       free     shared    buffers     cached
> Mem:       2049692     999172    1050520          0      16652     298216
> -/+ buffers/cache:     684304    1365388
> Swap:      1046524     472364     574160
>

Other related posts: