cord_buf: introduce cord_buf API
There was a global ibuf object called tarantool_lua_ibuf. It was used in all the places working with Lua which didn't have yields, and where fiber's region could be potentially slower due to not being able to guarantee the allocated memory is contiguous. Yields during the ibuf usage were prohibited because another fiber would take the same ibuf and override its previous content which was still used by another fiber. But it wasn't taken into account that there is Lua GC. It can be invoked from any Lua function in Lua C code, and almost on any line in the Lua scripts. During GC some deleted objects might have GC handlers installed as __gc metamethods. From the handler they could call Tarantool functions, including the ones using the global ibuf. Therefore ibuf could be overridden not only at yields, but almost in any moment. Because with the Lua GC at hand, the multitasking is not strictly "cooperative" anymore. It is necessary to implement ownership for the global buffer. The patch prepares the API for this: the buffer is moved to its own file, and has methods take(), put(), and drop(). Take() is supposed to make the current fiber own the buffer. Put() makes it available again. Drop() does the same but also clears the buffer (frees its memory). The ownership itself is a subject for the next patches. Here only the API is prepared. The patch "hits" performance a little. Previously the get of buffer.IBUF_SHARED cost around 1 ns. Now cord_ibuf_take() + cord_ibuf_put() cost around 5 ns together. The next patches will make it worse, up to 15 ns until #5871 is done. Part of #5632
Showing
- src/box/lua/schema.lua 32 additions, 15 deletionssrc/box/lua/schema.lua
- src/box/lua/tuple.c 14 additions, 14 deletionssrc/box/lua/tuple.c
- src/box/lua/tuple.lua 9 additions, 5 deletionssrc/box/lua/tuple.lua
- src/exports.h 3 additions, 1 deletionsrc/exports.h
- src/lib/core/CMakeLists.txt 1 addition, 0 deletionssrc/lib/core/CMakeLists.txt
- src/lib/core/cord_buf.c 47 additions, 0 deletionssrc/lib/core/cord_buf.c
- src/lib/core/cord_buf.h 45 additions, 0 deletionssrc/lib/core/cord_buf.h
- src/lua/buffer.lua 49 additions, 2 deletionssrc/lua/buffer.lua
- src/lua/iconv.lua 5 additions, 3 deletionssrc/lua/iconv.lua
- src/lua/init.c 0 additions, 3 deletionssrc/lua/init.c
- src/lua/msgpack.c 3 additions, 3 deletionssrc/lua/msgpack.c
- src/lua/msgpackffi.lua 4 additions, 3 deletionssrc/lua/msgpackffi.lua
- src/lua/socket.lua 6 additions, 8 deletionssrc/lua/socket.lua
- src/lua/swim.lua 11 additions, 6 deletionssrc/lua/swim.lua
- src/lua/utf8.c 10 additions, 6 deletionssrc/lua/utf8.c
- src/lua/utils.h 0 additions, 1 deletionsrc/lua/utils.h
- static-build/test/static-build/exports.test.lua 3 additions, 1 deletionstatic-build/test/static-build/exports.test.lua
- test/unit/luaT_tuple_new.c 0 additions, 4 deletionstest/unit/luaT_tuple_new.c
Loading
Please register or sign in to comment