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
+7
-3
@@ -155,7 +155,10 @@ typedef struct _3proxy_sem_s {
|
||||
|
||||
#define MAX_HASH_SIZE (64)
|
||||
#define UDPBUFSIZE 16384
|
||||
#define CLIENTBUFSIZE (16384 + 64)
|
||||
/* A connection's data buffer, either side's: a page or pages of the buffer
|
||||
pool (bufget()). A TLS record does not always fit: tlspr takes a larger
|
||||
one for it. */
|
||||
#define CLIENTBUFSIZE 16384
|
||||
#define CLIENTTMPBUFSIZE 8192
|
||||
/* The defaults of minlogqueue and maxlogqueue: the lines a log's queue
|
||||
keeps slots for, and holds at most; -D at build time sets others. */
|
||||
@@ -914,8 +917,9 @@ struct clientparam {
|
||||
something done at once, never for what has to outlive a call into
|
||||
anything that could log. */
|
||||
unsigned char tmpbuf[CLIENTTMPBUFSIZE];
|
||||
/* Each side's data buffer, CLIENTBUFSIZE of malloc's, which clibuf and
|
||||
srvbuf point to unless a filter needed a bigger one. Made with the
|
||||
/* Each side's data buffer, CLIENTBUFSIZE from the buffer pool, which
|
||||
clibuf and srvbuf point to unless a filter or a TLS record needed a
|
||||
bigger one. Made with the
|
||||
connection (bufalloc()); a loop's relay gives an empty one back while
|
||||
nothing but the relay can use it, and makes it again to read. */
|
||||
unsigned char *clibufdata,
|
||||
|
||||
Reference in new issue
Block a user