MINOR: server: move idle tree insert in a dedicated function

Define a new function _srv_add_idle(). This is a simple wrapper to
insert a connection in the server idle tree. This is reserved for simple
usage and require to idle_conns lock. In most cases,
srv_add_to_idle_list() should be used.

This patch does not have any functional change. However, it will help
with the next patch as idle connection will be always inserted in a list
as secondary storage along with idle/safe trees.
This commit is contained in:
Amaury Denoyelle 2023-08-25 15:48:39 +02:00
parent 77ac8eb4a6
commit 61fc9568fb
7 changed files with 25 additions and 23 deletions

View File

@ -85,6 +85,7 @@ void srv_release_conn(struct server *srv, struct connection *conn);
struct connection *srv_lookup_conn(struct eb_root *tree, uint64_t hash);
struct connection *srv_lookup_conn_next(struct connection *conn);
void _srv_add_idle(struct server *srv, struct connection *conn, int is_safe);
int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_safe);
struct task *srv_cleanup_toremove_conns(struct task *task, void *context, unsigned int state);

View File

@ -177,12 +177,8 @@ int conn_notify_mux(struct connection *conn, int old_flags, int forced_wake)
goto done;
if (conn_in_list) {
struct eb_root *root = (conn_in_list == CO_FL_SAFE_LIST) ?
&srv->per_thr[tid].safe_conns :
&srv->per_thr[tid].idle_conns;
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
eb64_insert(root, &conn->hash_node->node);
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
}
}

View File

@ -2986,10 +2986,7 @@ struct task *fcgi_io_cb(struct task *t, void *ctx, unsigned int state)
struct server *srv = objt_server(conn->target);
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
if (conn_in_list == CO_FL_SAFE_LIST)
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
else
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
}
return t;

View File

@ -3701,10 +3701,7 @@ struct task *h1_io_cb(struct task *t, void *ctx, unsigned int state)
struct server *srv = objt_server(conn->target);
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
if (conn_in_list == CO_FL_SAFE_LIST)
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
else
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
}
return t;

View File

@ -4123,10 +4123,7 @@ struct task *h2_io_cb(struct task *t, void *ctx, unsigned int state)
struct server *srv = objt_server(conn->target);
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
if (conn_in_list == CO_FL_SAFE_LIST)
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
else
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
}

View File

@ -5986,6 +5986,23 @@ struct connection *srv_lookup_conn_next(struct connection *conn)
return next_conn;
}
/* Add <conn> in <srv> idle trees. Set <is_safe> if connection is deemed safe
* for reuse.
*
* This function is a simple wrapper for tree insert. It should only be used
* for internal usage or when removing briefly the connection to avoid takeover
* on it before reinserting it with this function. In other context, prefer to
* use the full feature srv_add_to_idle_list().
*
* Must be called with idle_conns_lock.
*/
void _srv_add_idle(struct server *srv, struct connection *conn, int is_safe)
{
struct eb_root *tree = is_safe ? &srv->per_thr[tid].safe_conns :
&srv->per_thr[tid].idle_conns;
eb64_insert(tree, &conn->hash_node->node);
}
/* This adds an idle connection to the server's list if the connection is
* reusable, not held by any owner anymore, but still has available streams.
*/
@ -6022,11 +6039,11 @@ int srv_add_to_idle_list(struct server *srv, struct connection *conn, int is_saf
if (is_safe) {
conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_SAFE_LIST;
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
_srv_add_idle(srv, conn, 1);
_HA_ATOMIC_INC(&srv->curr_safe_nb);
} else {
conn->flags = (conn->flags & ~CO_FL_LIST_MASK) | CO_FL_IDLE_LIST;
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
_srv_add_idle(srv, conn, 0);
_HA_ATOMIC_INC(&srv->curr_idle_nb);
}
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);

View File

@ -6345,10 +6345,7 @@ struct task *ssl_sock_io_cb(struct task *t, void *context, unsigned int state)
struct server *srv = objt_server(conn->target);
HA_SPIN_LOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
if (conn_in_list == CO_FL_SAFE_LIST)
eb64_insert(&srv->per_thr[tid].safe_conns, &conn->hash_node->node);
else
eb64_insert(&srv->per_thr[tid].idle_conns, &conn->hash_node->node);
_srv_add_idle(srv, conn, conn_in_list == CO_FL_SAFE_LIST);
HA_SPIN_UNLOCK(IDLE_CONNS_LOCK, &idle_conns[tid].idle_conns_lock);
}
return t;