mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-24 00:54:02 +00:00
Rewrite the cache on a fixed slab without per-entry allocation
cache.cpp keeps its C API but replaces uthash and the two mallocs per entry with one slab of nodes holding their keys inline, linked in last-use order, and an open-addressing index of node ids that hashes through the slab with a per-cache random seed. Both blocks are reserved by cache_create() and touched only as entries are used, so a large, mostly empty cache costs no resident memory. Semantics are unchanged: an insert evicts the least recently used entry once the cache holds capacity entries (the AEAD-2022 session table's 4095/4096 boundary), lookups refresh recency and age, cache_clear() drops stale entries, and free_cb may re-enter the cache. Re-inserting a key now replaces its data instead of shadowing it. cache_create_keyed() sizes keys per cache; the AEAD-2022 salt pool and session table use it. test_cache_cpp covers the boundary, ordering, replacement, ageing, re-entrant callbacks and limits; alloc_steady_cache requires zero allocations across 100,000 inserts on a full cache. AEAD-2022 ss-server drops from 84 to 80 allocations per relayed connection.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
src/aead.cpp 4
|
||||
src/aead2022.cpp 3
|
||||
src/aead2022_udp.cpp 5
|
||||
src/cache.cpp 3
|
||||
src/crypto.cpp 4
|
||||
src/ipset.cpp 3
|
||||
src/jconf.cpp 16
|
||||
|
||||
Reference in New Issue
Block a user