From: "plaisthos (Code Review)" Date: Thu, 19 Mar 2026 14:55:47 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., antonio@...2726... Message-ID: <72e7bcfa6df27ed97daba855be7652740cff4e85-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="8pzt8w4+djs="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Increase default size of internal hash maps to 4 * --max-clients List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --8pzt8w4+djs= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, ordex, plaisthos. Hello flichtenheld, ordex, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1563?usp=3Demail to look at the new patch set (#7). The following approvals got outdated and were removed: Code-Review+2 by flichtenheld, Code-Review+2 by ordex The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. Change subject: Increase default size of internal hash maps to 4 * --max-cl= ients ...................................................................... Increase default size of internal hash maps to 4 * --max-clients The default of 256 seems quite low as with (at least) 1024 possible entries (the --max-clients default setting) we have a guaranteed collisions. Using 4 times the number of possible entries for real addresses should reduce collisions quite a bit while also leaving some headroom for the virtual addresses hash where a client might have more than one address. A reason to keep the limit so low are the memory requirements. Each bucket has the size of one linked-list pointer (4 byte or 32 bit and 8 byte for 64 bit). So 256 buckets use 1 or 2 kB while 4096 will use 16 kB or 32 kB. When the current limit was set 20 years ago this might have been a meaningful memory saving but today the collision probability is more important. Change-Id: Ia699b0dfa407ac377970bb130434298eaaec592b Signed-off-by: Arne Schwabe --- M doc/man-sections/advanced-options.rst M doc/man-sections/server-options.rst M src/openvpn/options.c 3 files changed, 24 insertions(+), 4 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/63/1563/7 diff --git a/doc/man-sections/advanced-options.rst b/doc/man-sections/advan= ced-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 =3D VLAN_ALL; o->vlan_pvid =3D 1; - o->real_hash_size =3D 256; - o->virtual_hash_size =3D 256; o->n_bcast_buf =3D 256; o->tcp_queue_limit =3D 64; o->max_clients =3D 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 =3D 4 * o->max_clients; + } + if (!o->virtual_hash_size) + { + o->virtual_hash_size =3D 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 =3D=3D MODE_SERVER) + { + helper_hashmap_sizes(o); + } + options_postprocess_setdefault_ncpciphers(o); options_set_backwards_compatible_options(o); options_process_mutate_prf(o); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1563?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ia699b0dfa407ac377970bb130434298eaaec592b Gerrit-Change-Number: 1563 Gerrit-PatchSet: 7 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: ordex Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: ordex --8pzt8w4+djs= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld, ordex, plaisthos.

plaisthos uploaded patch set #7 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1563?usp=3Demail">View Chan= ge

The following approvals got outdated and were removed: Code-Review+2 by flichtenheld, Code-Review+2 by ordex

The change is n= o longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfi= ed now.

Increase default size of internal hash maps to 4 *=
 --max-clients

The default of 256 seems quite low as with (at least)= 1024 possible
entries (the --max-clients default setting) we have a gua= ranteed
collisions. Using 4 times the number of possible entries for rea= l
addresses should reduce collisions quite a bit while also leaving
s= ome headroom for the virtual addresses hash where a client might
have mo= re than one address.

A reason to keep the limit so low are the memor= y requirements. Each
bucket has the size of one linked-list pointer (4 b= yte or 32 bit and
8 byte for 64 bit). So 256 buckets use 1 or 2 kB while= 4096 will use
16 kB or 32 kB.

When the current limit was set 20 = years ago this might have been a
meaningful memory saving but today the = collision probability is
more important.

Change-Id: Ia699b0dfa407= ac377970bb130434298eaaec592b
Signed-off-by: Arne Schwabe <arne@...2068...= 7...>
---
M doc/man-sections/advanced-options.rst
M doc/man-sec= tions/server-options.rst
M src/openvpn/options.c
3 files changed, 24 = insertions(+), 4 deletions(-)

git pull ssh://ger=
rit.openvpn.net:29418/openvpn refs/changes/63/1563/7
diff --git a/d=
oc/man-sections/advanced-options.rst b/doc/man-sections/advanced-options.rs=
t
index e1115e4..73ca44a 100644
--- a/doc/m= an-sections/advanced-options.rst
+++ b/doc/man-sections/adv= anced-options.rst
@@ -36,7 +36,8 @@

hash-size r v

- By default, both tables are sized at 256 bucke= ts.
+ By default, bo= th tables are sized at 4 times ``--max-clients`` buckets.
+ With the default of 1024 of ``--max= -clients`` this gives 4096 buckets.

--bc= ast-buffers n
Allocate ``n`` buffers for broadcast datag= rams (default :code:`256`).
diff --git a/doc/man-sections/s= erver-options.rst b/doc/man-sections/server-options.rst
ind= ex 03ce651..eb8e273 100644
--- a/doc/man-sections/server-op= tions.rst
+++ b/doc/man-sections/server-options.rst<= br>@@ -414,7 +414,7 @@
iroute-ipv6 ipv6addr/bit= s

--max-clients n
- Limit server to a maximum of ``n`` concur= rent clients.
+ Limi= t server to a maximum of ``n`` concurrent clients. Defaults to 1024.=

--max-routes-per-client n
A= llow 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<= /span>
+++ b/src/openvpn/options.c
@@ -849,8 +849,= 6 @@
#endif
o->vlan_accept =3D VLA= N_ALL;
o->vlan_pvid =3D 1;
- o->real_hash_size =3D 256;
- o->virtual_hash_size =3D 25= 6;

o->n_bcast_buf =3D 256;
o-&= gt;tcp_queue_limit =3D 64;
o->max_clients =3D 1024;=
@@ -3724,6 +3722,22 @@
gc_free(&g= c);
}
#endif /* if defined(_WIN32) || def= ined(TARGET_ANDROID) */
+/**
+ * Sets the = internal hash maps sizes according to the max_clients
+ *
+ */
= +static void
+helper_= hashmap_sizes(struct options *o)
+{
+ i= f (!o->real_hash_size)
+ {
+ = o->real_hash_size =3D 4 * o->max_clients;
+ }
+ if (!o->virtual_hash_size)
+ {
+ o->virtual_hash_size =3D 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 =3D=3D MODE_SERVER)
+ {
+ = helper_hashmap_sizes(o);
+ }
+
options_postprocess_setdefault_ncpciphers(o); options_set_backwards_compatible_options(o);
= options_process_mutate_prf(o);

To vi= ew, visit change 1563. To unsubscribe, or for help writing mail filters, visit = settings.

=
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ia699b0dfa407ac377970bb13043= 4298eaaec592b
Gerrit-Change-Number: 1563
Gerrit-PatchSet: 7
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: ordex <antonio@...2726...&= gt;
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: ordex <antonio@...2726...= >
= --8pzt8w4+djs=--