<feed xmlns='http://www.w3.org/2005/Atom'>
<title>redis.git/src/function_lua.c, branch master</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.</subtitle>
<id>http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/atom/src/function_lua.c?h=master</id>
<link rel='self' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/atom/src/function_lua.c?h=master'/>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/'/>
<updated>2025-10-30T05:02:49Z</updated>
<entry>
<title>Lua script can be executed in the context of another user (CVE-2025-46818)</title>
<updated>2025-10-30T05:02:49Z</updated>
<author>
<name>Ozan Tezcan</name>
<email>ozantezcan@gmail.com</email>
</author>
<published>2025-06-23T09:10:12Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=a3ae6cb0d6e7acf9b5f4c9a1f0943913140d7527'/>
<id>urn:sha1:a3ae6cb0d6e7acf9b5f4c9a1f0943913140d7527</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Adding AGPLv3 as a license option to Redis! (#13997)</title>
<updated>2025-05-01T13:04:22Z</updated>
<author>
<name>Pieter Cailliau</name>
<email>pieter@redis.com</email>
</author>
<published>2025-05-01T13:04:22Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=d65102861f51af48241f607afa678c4c2a0f894c'/>
<id>urn:sha1:d65102861f51af48241f607afa678c4c2a0f894c</id>
<content type='text'>
Read more about [the new license option](http://redis.io/blog/agplv3/)
and [the Redis 8 release](http://redis.io/blog/redis-8-ga/).</content>
</entry>
<entry>
<title>Fix LUA garbage collector (CVE-2024-46981)</title>
<updated>2025-01-13T19:20:19Z</updated>
<author>
<name>YaacovHazan</name>
<email>yaacov.hazan@redis.com</email>
</author>
<published>2024-12-15T19:41:45Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=342ee426ad0d0731b2272553bd4db2cd78e24772'/>
<id>urn:sha1:342ee426ad0d0731b2272553bd4db2cd78e24772</id>
<content type='text'>
Reset GC state before closing the lua VM to prevent user data
to be wrongly freed while still might be used on destructor callbacks.
</content>
</entry>
<entry>
<title>Fix memory leak of jemalloc tcache on function flush command (#13661)</title>
<updated>2024-11-21T11:12:58Z</updated>
<author>
<name>Ozan Tezcan</name>
<email>ozantezcan@gmail.com</email>
</author>
<published>2024-11-21T11:12:58Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=9ebf80a28c3ba12e9aedc7cee145637d1ed2ab5a'/>
<id>urn:sha1:9ebf80a28c3ba12e9aedc7cee145637d1ed2ab5a</id>
<content type='text'>
Starting from https://github.com/redis/redis/pull/13133, we allocate a
jemalloc thread cache and use it for lua vm.
On certain cases, like `script flush` or `function flush` command, we
free the existing thread cache and create a new one.

Though, for `function flush`, we were not actually destroying the
existing thread cache itself. Each call creates a new thread cache on
jemalloc and we leak the previous thread cache instances. Jemalloc
allows maximum 4096 thread cache instances. If we reach this limit,
Redis prints "Failed creating the lua jemalloc tcache" log and abort.

There are other cases that can cause this memory leak, including
replication scenarios when emptyData() is called.

The implication is that it looks like redis `used_memory` is low, but
`allocator_allocated` and RSS remain high.

Co-authored-by: debing.sun &lt;debing.sun@redis.com&gt;</content>
</entry>
<entry>
<title>Trigger Lua GC after script loading (#13407)</title>
<updated>2024-07-16T01:28:47Z</updated>
<author>
<name>debing.sun</name>
<email>debing.sun@redis.com</email>
</author>
<published>2024-07-16T01:28:47Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=88af96c7a2548013273d0be2bcb3690328e52a24'/>
<id>urn:sha1:88af96c7a2548013273d0be2bcb3690328e52a24</id>
<content type='text'>
Nowdays we do not trigger LUA GC after loading lua script. This means
that when a large number of scripts are loaded, such as when functions
are propagating from the master to the replica, if the LUA scripts are
never touched on the replica, the garbage might remain there
indefinitely.

Before this PR, we would share a gc_count between scripts and functions.
This means that, under certain circumstances, the GC trigger for scripts
and functions was not fair.
For example, loading a large number of scripts followed by a small
number of functions could result in the functions triggering GC.
In this PR, we assign a unique `gc_count` to each of them, so the GC
triggers between them will no longer affect each other.

on the other hand, this PR will to bring regession for script loading
commands(`FUNCTION LOAD` and `SCRIPT LOAD`), but they are not hot path,
we can ignore it, and it will be replaced
https://github.com/redis/redis/pull/13375 in the future.

---------

Co-authored-by: Oran Agra &lt;oran@redislabs.com&gt;</content>
</entry>
<entry>
<title>Rebuild function engines for function flush command (#13383)</title>
<updated>2024-07-10T09:35:36Z</updated>
<author>
<name>debing.sun</name>
<email>debing.sun@redis.com</email>
</author>
<published>2024-07-10T09:35:36Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=ffff7fea7cd98e1573db000c51f4d80af89c453c'/>
<id>urn:sha1:ffff7fea7cd98e1573db000c51f4d80af89c453c</id>
<content type='text'>
### Issue
The current implementation of `FUNCTION FLUSH` command uses
`lua_unref()` to unreference script closures in Lua vm. However,
invoking `lua_unref()` during lazy free (`ASYNC` argument) is risky
since it is not thread-safe.

Another issue is that using `lua_unref()` to unreference references does
not trigger GC, This can result in the Lua VM leaves a significant
amount of garbage, which may never be cleaned up if not properly GC.

### Solution
The proposed solution is to completely rebuild the engines, resulting in
a brand new Lua VM.

---------

Co-authored-by: meir &lt;meir@redis.com&gt;</content>
</entry>
<entry>
<title>Allocate Lua VM code with jemalloc instead of libc, and count it used memory (#13133)</title>
<updated>2024-04-16T09:43:33Z</updated>
<author>
<name>Binbin</name>
<email>binloveplay1314@qq.com</email>
</author>
<published>2024-04-16T09:43:33Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=804110a487f048669aa9d9412e5789ec43f4fe39'/>
<id>urn:sha1:804110a487f048669aa9d9412e5789ec43f4fe39</id>
<content type='text'>
## Background
1. Currently Lua memory control does not pass through Redis's zmalloc.c.
Redis maxmemory cannot limit memory problems caused by users abusing lua
since these lua VM memory is not part of used_memory.

2. Since jemalloc is much better (fragmentation and speed), and also we
know it and trust it. we are
going to use jemalloc instead of libc to allocate the Lua VM code and
count it used memory.

## Process:
In this PR, we will use jemalloc in lua. 
1. Create an arena for all lua vm (script and function), which is
shared, in order to avoid blocking defragger.
2. Create a bound tcache for the lua VM, since the lua VM and the main
thread are by default in the same tcache, and if there is no isolated
tcache, lua may request memory from the tcache which has just been freed
by main thread, and vice versa
On the other hand, since lua vm might be release in bio thread, but
tcache is not thread-safe, we need to recreate
    the tcache every time we recreate the lua vm.
3. Remove lua memory statistics from memory fragmentation statistics to
avoid the effects of lua memory fragmentation

## Other
Add the following new fields to `INFO DEBUG` (we may promote them to
INFO MEMORY some day)
1. allocator_allocated_lua: total number of bytes allocated of lua arena
2. allocator_active_lua: total number of bytes in active pages allocated
in lua arena
3. allocator_resident_lua: maximum number of bytes in physically
resident data pages mapped in lua arena
4. allocator_frag_bytes_lua: fragment bytes in lua arena

This is oranagra's idea, and i got some help from sundb.

This solves the third point in #13102.

---------

Co-authored-by: debing.sun &lt;debing.sun@redis.com&gt;
Co-authored-by: Oran Agra &lt;oran@redislabs.com&gt;</content>
</entry>
<entry>
<title>Change license from BSD-3 to dual RSALv2+SSPLv1 (#13157)</title>
<updated>2024-03-20T22:38:24Z</updated>
<author>
<name>Pieter Cailliau</name>
<email>pieter@redis.com</email>
</author>
<published>2024-03-20T22:38:24Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=0b34396924eca4edc524469886dc5be6c77ec4ed'/>
<id>urn:sha1:0b34396924eca4edc524469886dc5be6c77ec4ed</id>
<content type='text'>
[Read more about the license change
here](https://redis.com/blog/redis-adopts-dual-source-available-licensing/)
Live long and prosper 🖖</content>
</entry>
<entry>
<title>Ensure that the function load timeout is disabled during loading from RDB/AOF and on replicas. (#12451)</title>
<updated>2023-08-02T08:43:31Z</updated>
<author>
<name>Meir Shpilraien (Spielrein)</name>
<email>meir@redis.com</email>
</author>
<published>2023-08-02T08:43:31Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=2ee1bbb53baea26b442d602b0b3335176170736d'/>
<id>urn:sha1:2ee1bbb53baea26b442d602b0b3335176170736d</id>
<content type='text'>
When loading a function from either RDB/AOF or a replica, it is essential not to
fail on timeout errors. The loading time may vary due to various factors, such as
hardware specifications or the system's workload during the loading process.
Once a function has been successfully loaded, it should be allowed to load from
persistence or on replicas without encountering a timeout failure.

To maintain a clear separation between the engine and Redis internals, the
implementation refrains from directly checking the state of Redis within the
engine itself. Instead, the engine receives the desired timeout as part of the
library creation and duly respects this timeout value. If Redis wishes to disable
any timeout, it can simply send a value of 0.</content>
</entry>
<entry>
<title>Remove prototypes with empty declarations (#12020)</title>
<updated>2023-05-03T00:31:32Z</updated>
<author>
<name>Madelyn Olson</name>
<email>34459052+madolson@users.noreply.github.com</email>
</author>
<published>2023-05-03T00:31:32Z</published>
<link rel='alternate' type='text/html' href='http://dangofactory.net/cgit/cgit.cgi/Server/redis.git/commit/?id=5e3be1be09c947810732e7be2a4bb1b0ed75de4a'/>
<id>urn:sha1:5e3be1be09c947810732e7be2a4bb1b0ed75de4a</id>
<content type='text'>
Technically declaring a prototype with an empty declaration has been deprecated since the early days of C, but we never got a warning for it. C2x will apparently be introducing a breaking change if you are using this type of declarator, so Clang 15 has started issuing a warning with -pedantic. Although not apparently a problem for any of the compiler we build on, if feels like the right thing is to properly adhere to the C standard and use (void).</content>
</entry>
</feed>
