All Projects → shdown → lua-shm-state-poc

shdown / lua-shm-state-poc

Licence: MIT license
Lua state in shared memory: a proof of concept

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects
lua
6591 projects
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to lua-shm-state-poc

libjio
[mirror] A library for Journaled I/O
Stars: ✭ 17 (-22.73%)
Mutual labels:  posix
tupai
Tupai is a multi-tasking operating system I wrote for my degree that focuses on safety and design, targeting a variety of platforms.
Stars: ✭ 21 (-4.55%)
Mutual labels:  posix
fusell-seed
FUSE (the low-level interface) file system boilerplate 📂 🔌 💾
Stars: ✭ 13 (-40.91%)
Mutual labels:  posix
onionjuggler
Manage your Onion Services via CLI or TUI on Unix-like operating system with a POSIX compliant shell.
Stars: ✭ 31 (+40.91%)
Mutual labels:  posix
coderun
⏯️ Code runner CLI that can run any languages
Stars: ✭ 23 (+4.55%)
Mutual labels:  posix
Onyx
UNIX-like operating system written in C and C++
Stars: ✭ 52 (+136.36%)
Mutual labels:  posix
sh
Collection Of My Sh Scripts.
Stars: ✭ 109 (+395.45%)
Mutual labels:  posix
expand-brackets
Expand POSIX bracket expressions (character classes) in glob patterns.
Stars: ✭ 26 (+18.18%)
Mutual labels:  posix
cccc
Source code counter and metrics tool for C++, C, and Java
Stars: ✭ 39 (+77.27%)
Mutual labels:  posix
boxtree
Quad/octree building for FMMs in Python and OpenCL
Stars: ✭ 52 (+136.36%)
Mutual labels:  shared-memory
cubefs
CubeFS is a cloud native distributed storage platform.
Stars: ✭ 3,062 (+13818.18%)
Mutual labels:  posix
InitKit
Neo-InitWare is a modular, cross-platform reimplementation of the systemd init system. It is experimental.
Stars: ✭ 364 (+1554.55%)
Mutual labels:  posix
init
KISS Linux - Init Framework
Stars: ✭ 85 (+286.36%)
Mutual labels:  posix
lustre-release
Mirror of official Lustre development repository http://git.whamcloud.com/
Stars: ✭ 35 (+59.09%)
Mutual labels:  posix
timebox
A timer script for Windows/Linux/Unix/macOS to practice timeboxing (the time management technique)
Stars: ✭ 42 (+90.91%)
Mutual labels:  posix
dotfiles skeleton
robust and beginner friendly dotfile skeleton
Stars: ✭ 14 (-36.36%)
Mutual labels:  posix
reactor-aeron
A reactive driver for Aeron transport (https://github.com/real-logic/aeron)
Stars: ✭ 43 (+95.45%)
Mutual labels:  shared-memory
genspio
Generate Shell Phrases In OCaml
Stars: ✭ 46 (+109.09%)
Mutual labels:  posix
MPSC Queue
A multi-producer single consumer queue C++ template suitable for async logging with SHM IPC support
Stars: ✭ 51 (+131.82%)
Mutual labels:  shared-memory
oursh
Your comrade through the perilous world of UNIX.
Stars: ✭ 59 (+168.18%)
Mutual labels:  posix

PoC of sharing Lua interpreter memory between multiple processes.

It features two processes that take turns calling functions f() and g() in the same Lua state (loaded from demo.lua).

Screenshot

How?

There’s nothing new in Lua being flexible: it allows to override all the memory management by passing a custom allocator to lua_newstate. The only things left are to create a shared memory mapping and implement an allocator working in it.

This is more or less safe as long as Lua knows nothing about parallelism. Some things in the standard library do know, though; see the “Caveats” section.

On systems other that Linux, shared memory mappings have to be of fixed size; by default, this PoC allocates 16 Mb on these systems.

In fact, Linux shared memory mappings also have to be of fixed “size” — of fixed virtual size: thanks to the overcommit feature and the MAP_NORESERVE mmap flag, which tells Linux to only allocate physical pages on demand (this does not depend on which overcommit policy your system is configured to use), we can only pay for what we use, and not a page more. And with madvise(..., MADV_REMOVE), we can reclaim the pages we don’t need anymore. Yay!

On Linux, this PoC goes on to allocate 16 Gb of virtual memory (1 Gb on 32-bit systems). Because this ought to be enough for anybody. If your virtual memory is, in some reason, limited, run it as ./main -p, which forces it to fall back to a portable 16 Mb mapping.

Caveats

  • Some functions in Lua’s standard library really don’t expect being called with such a setup. These functions are os.execute, io.popen, os.exit and os.setlocale.

  • All actions on files (including opening and closing) are local to the current process.

  • My memory allocator sucks. Implementing a better one — possibly leveraging the aforementioned Linux features — is left as an exercise for the reader.

  • Does not work with LuaJIT.

  • Be careful with external modules.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].