| Message ID | 20260325124526.124049-1-frank@lichtenheld.com |
|---|---|
| State | New |
| Headers | show |
| Series | [Openvpn-devel,v7] Increase default size of internal hash maps to 4 * --max-clients | expand |
Stared at the code for a bit, and spent some thoughts on it. Makes sense.
I haven't actually tested this beyond "BB is green". The server testbed
will give it a bit of testing, but this is not really meaningful either
(because I have 3 clients connected at maximum)...
If the environment is very tight on memory, reducing --max-clients is
way more effective (and shrinks the hash map accordingly).
Your patch has been applied to the master and release/2.7 branch
(scalability, low impact).
commit 7b5ebf7c447db16953c9541fdd00c7aa56124fc5 (master)
commit 216c76324d2ee9221346cdfb25891e634aff2b9e (release/2.7)
Author: Arne Schwabe
Date: Wed Mar 25 13:45:26 2026 +0100
Increase default size of internal hash maps to 4 * --max-clients
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Antonio Quartulli <antonio@mandelbit.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1563
Message-Id: <20260325124526.124049-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36268.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
--
kind regards,
Gert Doering
diff --git a/doc/man-sections/advanced-options.rst b/doc/man-sections/advanced-options.rst index e1115e4..73ca44a 100644 --- a/doc/man-sections/advanced-options.rst +++ b/doc/man-sections/advanced-options.rst @@ -36,7 +36,8 @@ hash-size r v - By default, both tables are sized at 256 buckets. + By default, both tables are sized at 4 times ``--max-clients`` buckets. + With the default of 1024 of ``--max-clients`` this gives 4096 buckets. --bcast-buffers n Allocate ``n`` buffers for broadcast datagrams (default :code:`256`). diff --git a/doc/man-sections/server-options.rst b/doc/man-sections/server-options.rst index 03ce651..eb8e273 100644 --- a/doc/man-sections/server-options.rst +++ b/doc/man-sections/server-options.rst @@ -414,7 +414,7 @@ iroute-ipv6 ipv6addr/bits --max-clients n - Limit server to a maximum of ``n`` concurrent clients. + Limit server to a maximum of ``n`` concurrent clients. Defaults to 1024. --max-routes-per-client n Allow a maximum of ``n`` internal routes per client (default diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 1db781d..24f2407 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -849,8 +849,6 @@ #endif o->vlan_accept = VLAN_ALL; o->vlan_pvid = 1; - o->real_hash_size = 256; - o->virtual_hash_size = 256; o->n_bcast_buf = 256; o->tcp_queue_limit = 64; o->max_clients = 1024; @@ -3724,6 +3722,22 @@ gc_free(&gc); } #endif /* if defined(_WIN32) || defined(TARGET_ANDROID) */ +/** + * Sets the internal hash maps sizes according to the max_clients + * + */ +static void +helper_hashmap_sizes(struct options *o) +{ + if (!o->real_hash_size) + { + o->real_hash_size = 4 * o->max_clients; + } + if (!o->virtual_hash_size) + { + o->virtual_hash_size = 4 * o->max_clients; + } +} static void options_postprocess_mutate(struct options *o, struct env_set *es) @@ -3739,6 +3753,11 @@ helper_keepalive(o); helper_tcp_nodelay(o); + if (o->mode == MODE_SERVER) + { + helper_hashmap_sizes(o); + } + options_postprocess_setdefault_ncpciphers(o); options_set_backwards_compatible_options(o); options_process_mutate_prf(o);