]> git.kaiwu.me - njs.git/commit
Modules: improved shared dict eviction strategy.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 27 Mar 2026 00:16:25 +0000 (17:16 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 30 Mar 2026 23:53:46 +0000 (16:53 -0700)
commit983427973b96a3c6293a6aa6ace7c859b28f35aa
tree347327dd24307231269dbaf22d5517d9d6611890
parent754771984a7f1d017f80e1c3a602a4c9dc64cc56
Modules: improved shared dict eviction strategy.

Previously, when a slab allocation failed in evict mode, only 16
entries were evicted with a single retry.  This could still result
in SharedMemoryError when the freed slab slots did not match the
requested allocation size class, even though the zone had plenty
of evictable entries.

In practice, it might happen when the following conditions are met:
    - The shared zone is full
    - evict flag is enabled
    - key/value entries differ in size

The allocation now retries in a loop, evicting 16 entries at a time,
until the allocation succeeds or no more entries remain in the expire
tree.

After this change, allocation with evict enabled can only fail when:
    - the value is larger than the zone's usable space
    - the expire tree has no entries left to evict
    - zone metadata overhead leaves insufficient room
nginx/ngx_js_shared_dict.c
nginx/t/js_shared_dict_evict.t