mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Buffers: a pool of mapped pages, buffers of 16384 bytes
A connection's buffers came from malloc(), which keeps what it is given back: a buffer let go while the connection waits (HTTP keep-alive, an idle relay) left its memory with the process. They now come from a pool of memory mapped for them, in chunks aligned to their size, the first unit of a chunk its header. A unit is a page, or a buffer if pages are smaller: with pages of 4 or 16 KB a buffer is a unit of its own, with pages of 64 KB a unit holds four. Free units are kept for the next buffer, the most recently freed first; more than 64 and an eighth of those in use, and the least recently freed are given back to the system (MADV_DONTNEED on Linux, MADV_FREE_REUSABLE on macOS, MADV_FREE elsewhere, MEM_RESET on Windows), and a chunk given back whole is unmapped. Built for AddressSanitizer the buffers stay malloc()'s, which it checks for overruns, unless WITHBUFPOOL is defined; the pool then poisons the free ones. Buffers are 16384 bytes, not 16384 + 64: a size of pages. The 64 bytes were room for a TLS record's header, which tlspr needs to have a record whole; tlspr now takes a larger buffer when a record does not fit, up to TLS's largest (5 + 16384 + 2048), given back once it is emptied, and relays read the whole buffer again, a record at most as before. A record larger than the buffer set with -b is no longer refused. HTTP proxy, 2000 idle keep-alive connections, after a request (Linux container): 39.6 KB a connection before, 19.5 KB now; a thread a connection, 44.2 KB before, 24.1 KB now; a TCP relay, 13.0 KB before, 11.6 KB now. Incompatible for plugins: CLIENTBUFSIZE is 16384; clibufdata and srvbufdata are the pool's, never to be passed to free() or realloc(). bufpoolinit() is called before any service starts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a6402010a4
commit
5de7ae2dac
8 files changed
+326
-22
No files matched your search
@@ -426,6 +426,7 @@ int main(int argc, char * argv[]) {
|
||||
_3proxy_mutex_init(&tc_mutex);
|
||||
_3proxy_mutex_init(&loops_mutex);
|
||||
_3proxy_mutex_init(&tpool.mutex);
|
||||
bufpoolinit();
|
||||
#ifndef NORADIUS
|
||||
_3proxy_mutex_init(&rad_mutex);
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user