lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Saturday 03, Bogdan Marinescu wrote:
> now it runs happily with 39k, which is quite an improvement. I'm
> having some problems making it run with TLSF; for some reason, Lua
> segfaults with this allocator when your patch is applied and I don't
> understand why (it runs fine with TLSF without the patch). Which is
Try it with my new patch, to see if you get the same segfaults.  Also can you 
provide a stack trace of where the segfault happens?

> not nice, since TLSF gave some very good results when used with Lua,
> and I'm very curious about the TLFS + patch combination. In any case,
> I think your patch would be useful in any resource constrained
> embedded system (and most of them are resource constrained). People on
> desktops will probably be reluctant to use this, since they generally
> don't have problems related to memory consumption and the patch would
> only slow down Lua, but I consider this to be an important step
> towards making Lua embedded-friendly.
I am working on a script engine that will run scripts sandboxed with a 
memlimit set at around 64-128K.  So I think an emergency GC can be helpful 
outside embedded devices.

> On thing that I've noticed is that setting the limit to 64k (which is
> the maximum internal memory of many ARM cores out there) doesn't
> really help, as the allocator is likely to return NULL because
> reaching this limit. However, setting the limit to 3/4 of the actual
> available memory changes the situation dramatically.
the allocator most likely has some overhead for managing allocated blocks.  
Try running the GC when the allocator returns NULL and only return NULL back 
to the Lua core if the allocator returns NULL twice.

example:
void *gc_allocator(void *ud, void *ptr, size_t osize, size_t nsize) {
  lua_State *L=(lua_State *)ud;
  ptr = wrapped_allocator(ud, ptr, osize, nsize);
  if(ptr == NULL && nsize > 0) {
    lua_gc(L, LUA_GCCOLLECT, 0);
    ptr = wrapped_allocator(ud, ptr, osize, nsize);
  }
  return ptr;
}

-- 
Robert G. Jakabosky