Browse Source

[core] clear request,connection pools every 64 sec (#3084)

x-ref:
  "Memory fragmentation with HTTP/2 enabled"
  https://redmine.lighttpd.net/issues/3084
master
Glenn Strauss 3 months ago
parent
commit
62a9d5b78f
  1. 2
      src/connections.c
  2. 28
      src/reqpool.c
  3. 3
      src/reqpool.h
  4. 3
      src/server.c

2
src/connections.c

@ -57,8 +57,6 @@ static connection *connections_get_new_connection(server *srv) {
else {
con = connection_init(srv);
connection_reset(con);
if (srv->srvconf.h2proto)
request_pool_extend(srv, 8);
}
/*con->prev = NULL;*//*(already set)*/
if ((con->next = srv->conns))

28
src/reqpool.c

@ -232,21 +232,6 @@ request_free_data (request_st * const r)
/* linked list of (request_st *) cached for reuse */
static request_st *reqpool;
/* max num of (request_st *) to cache */
static uint32_t reqspace;
void
request_pool_extend (server *srv, const uint32_t sz)
{
for (uint32_t i = 0; i < sz; ++i) {
request_st * const x = calloc(1, sizeof(request_st));
force_assert(x);
request_init_data(x, NULL, srv);
x->con = (connection *)reqpool; /*(reuse r->con as next ptr)*/
reqpool = x;
}
}
void
@ -257,7 +242,6 @@ request_pool_free (void)
reqpool = (request_st *)r->con; /*(reuse r->con as next ptr)*/
request_free_data(r);
free(r);
++reqspace;
}
}
@ -279,15 +263,8 @@ request_release (request_st * const r)
request_reset_ex(r);
r->state = CON_STATE_CONNECT;
if (reqspace) {
--reqspace;
r->con = (connection *)reqpool; /*(reuse r->con as next ptr)*/
reqpool = r;
}
else {
request_free_data(r);
free(r);
}
r->con = (connection *)reqpool; /*(reuse r->con as next ptr)*/
reqpool = r;
}
@ -297,7 +274,6 @@ request_acquire (connection * const con)
request_st *r = reqpool;
if (r) {
reqpool = (request_st *)r->con; /*(reuse r->con as next ptr)*/
++reqspace;
}
else {
r = calloc(1, sizeof(request_st));

3
src/reqpool.h

@ -22,9 +22,6 @@ request_st * request_acquire (connection *con);
__attribute_cold__
void request_free_data (request_st *r);
__attribute_cold__
void request_pool_extend (server *srv, uint32_t sz);
__attribute_cold__
void request_pool_free (void);

3
src/server.c

@ -1882,6 +1882,9 @@ static void server_handle_sigalrm (server * const srv, unix_time64_t mono_ts, un
if (0 == (mono_ts & 0x3f)) { /*(once every 64 secs)*/
/* free excess chunkqueue buffers every 64 secs */
chunkqueue_chunk_pool_clear();
/* clear request and connection pools every 64 secs */
request_pool_free();
connections_pool_clear(srv);
/* attempt to restart dead piped loggers every 64 secs */
if (0 == srv->srvconf.max_worker)
fdevent_restart_logger_pipes(mono_ts);

Loading…
Cancel
Save