Skip to contentSkip to conversation

Require at least 20MB of mlock()-able memory if --mlock is used.

PATCH Superseded Gert Doering 5 participants 23 messages Mar 7, 2021 – Mar 11, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Require at least 20MB of mlock()-able memory if --mlock is used.

If --mlock is used, the amount of memory OpenVPN can use is guarded by the RLIMIT_MEMLOCK value (see mlockall(2)). The OS default for this is usually 64 Kbyte, which is enough for OpenVPN to initialize, but as soon as the first TLS handshake comes it, OpenVPN will crash due to "ouf of memory", and might even end up in a crash loop.

Steady-state OpenVPN requires between 8 MB and 30-50 MB (servers with many concurrent clients) of memory.

So: with this patch, we check if getrlimit() is available, and if yes, log the amount of mlock'able memory. If the amount is below 20 MB, which is an arbitrary value "large enough for most smaller deployments", we abort.

Trac: #1390

---
 configure.ac                         |  2 +-
 doc/man-sections/generic-options.rst |  6 ++++++
 src/openvpn/platform.c               | 18 ++++++++++++++++++
 src/openvpn/platform.h               |  4 ++++
 4 files changed, 29 insertions(+), 1 deletion(-)
configure.ac +1 -1
index 1ab8fe59..c65df3e2 100644
@@ -645,7 +645,7 @@ AC_FUNC_FORK
 
 AC_CHECK_FUNCS([ \
 	daemon chroot getpwnam setuid nice system getpid dup dup2 \
-	getpass syslog openlog mlockall getgrnam setgid \
+	getpass syslog openlog mlockall getrlimit getgrnam setgid \
 	setgroups stat flock readv writev time gettimeofday \
 	ctime memset vsnprintf strdup \
 	setsid chdir putenv getpeername unlink \
doc/man-sections/generic-options.rst +6 -0
index d5f08839..0a7d3caf 100644
@@ -237,6 +237,12 @@ which mode OpenVPN is configured as.
   likely fail. The limit can be increased using ulimit or systemd
   directives depending on how OpenVPN is started.
 
+  If the platform has the getrlimit(2) system call, OpenVPN will check
+  for the amount of mlock-able memory before calling mlockall(2), and 
+  abort if less than 20 Mb are available.  20 Mb is somewhat arbitrary -
+  it is enough for a moderately-sized OpenVPN deployment, but the memory
+  usage will go beyond that if the number of concurrent clients is high.
+
 --nice n
   Change process priority after initialization (``n`` greater than 0 is
   lower priority, ``n`` less than zero is higher priority).
src/openvpn/platform.c +18 -0
index ef688c23..67a69748 100644
@@ -193,6 +193,24 @@ void
 platform_mlockall(bool print_msg)
 {
 #ifdef HAVE_MLOCKALL
+
+#ifdef HAVE_GETRLIMIT
+    struct rlimit rl;
+    if (getrlimit(RLIMIT_MEMLOCK,&rl)<0)
+    {
+        msg(M_WARN | M_ERRNO, "WARNING: getrlimit(RLIMIT_MEMLOCK) failed");
+    }
+    else
+    {
+	msg(M_INFO, "mlock: MEMLOCK limit: soft=%ldkb, hard=%dkb",
+	    ((long int) rl.rlim_cur)/1024, ((long int) rl.rlim_max)/1024);
+	if (rl.rlim_cur < 20*1024*1024)
+	{
+	    msg(M_FATAL, "mlock: RLIMIT_MEMLOCK < 20 MByte, increase limit");
+	}
+    }
+#endif
+
     if (mlockall(MCL_CURRENT | MCL_FUTURE))
     {
         msg(M_WARN | M_ERRNO, "WARNING: mlockall call failed");
src/openvpn/platform.h +4 -0
index 01f3200c..02c23e38 100644
@@ -48,6 +48,10 @@
 #include <stdio.h>
 #endif
 
+#ifdef HAVE_GETRLIMIT
+#include <sys/resource.h>
+#endif
+
 #include "basic.h"
 #include "buffer.h"
 
Signature · 1 line
2.26.2
#1 lore raw

Hi,

Quoted 6 lines · Gert Doering

If --mlock is used, the amount of memory OpenVPN can use is guarded by the RLIMIT_MEMLOCK value (see mlockall(2)). The OS default for this is usually 64 Kbyte, which is enough for OpenVPN to initialize, but as soon as the first TLS handshake comes it, OpenVPN will crash due to "ouf of memory", and might even end up in a crash loop.

Quoted 8 lines

Steady-state OpenVPN requires between 8 MB and 30-50 MB (servers with many concurrent clients) of memory.

So: with this patch, we check if getrlimit() is available, and if yes, log the amount of mlock'able memory. If the amount is below 20 MB, which is an arbitrary value "large enough for most smaller deployments", we abort.

This is required only if privileges are dropped, isn't it? Could be made conditional
on o->username is set.

Quoted 29 lines

Trac: #1390

---
 configure.ac                         |  2 +-
 doc/man-sections/generic-options.rst |  6 ++++++
 src/openvpn/platform.c               | 18 ++++++++++++++++++
 src/openvpn/platform.h               |  4 ++++
 4 files changed, 29 insertions(+), 1 deletion(-)
configure.ac +1 -1
index 1ab8fe59..c65df3e2 100644
@@ -645,7 +645,7 @@ AC_FUNC_FORK
 
 AC_CHECK_FUNCS([ \
        daemon chroot getpwnam setuid nice system getpid dup dup2 \
-       getpass syslog openlog mlockall getgrnam setgid \
+       getpass syslog openlog mlockall getrlimit getgrnam setgid \
        setgroups stat flock readv writev time gettimeofday \
        ctime memset vsnprintf strdup \
        setsid chdir putenv getpeername unlink \
doc/man-sections/generic-options.rst +0 -0
index d5f08839..0a7d3caf 100644

doc/man-sections/generic-options.rst which mode OpenVPN is configured as. · line 241

Quoted 5 lines
doc/man-sections/generic-options.rst +2 -0
@@ -237,6 +237,12 @@ which mode OpenVPN is configured as.
   likely fail. The limit can be increased using ulimit or systemd
   directives depending on how OpenVPN is started.
 
+  If the platform has the getrlimit(2) system call, OpenVPN will check
+  for the amount of mlock-able memory before calling mlockall(2), and

white space at end of line

doc/man-sections/generic-options.rst which mode OpenVPN is configured as. · line 243

Quoted 3 lines
doc/man-sections/generic-options.rst +1 -0
+  abort if less than 20 Mb are available.  20 Mb is somewhat arbitrary -
 

Mb -> MB

Quoted 11 lines
doc/man-sections/generic-options.rst +3 -0
+  it is enough for a moderately-sized OpenVPN deployment, but the memory
+  usage will go beyond that if the number of concurrent clients is high.
+
 --nice n
   Change process priority after initialization (``n`` greater than 0 is

lower priority, ``n`` less than zero is higher priority).

src/openvpn/platform.c +0 -0
index ef688c23..67a69748 100644

src/openvpn/platform.c void · line 200

Quoted 8 lines
src/openvpn/platform.c +4 -0
@@ -193,6 +193,24 @@ void
 platform_mlockall(bool print_msg)
 {
 #ifdef HAVE_MLOCKALL
+
+#ifdef HAVE_GETRLIMIT
+    struct rlimit rl;
+    if (getrlimit(RLIMIT_MEMLOCK,&rl)<0)
 

spaces after "," and around "<" :)

src/openvpn/platform.c void

Quoted 8 lines
src/openvpn/platform.c +6 -0
+    {
+        msg(M_WARN | M_ERRNO, "WARNING: getrlimit(RLIMIT_MEMLOCK)
 failed");
+    }
+    else
+    {
+       msg(M_INFO, "mlock: MEMLOCK limit: soft=%ldkb, hard=%dkb",
 

%dkb --> %ldkb

src/openvpn/platform.c void · line 206

Quoted 2 lines
src/openvpn/platform.c +1 -0
+           ((long int) rl.rlim_cur)/1024, ((long int) rl.rlim_max)/1024);

Some may argue that our style is to put space around "/"

Quoted 5 lines
src/openvpn/platform.c +3 -0
+       if (rl.rlim_cur < 20*1024*1024)
+       {
+           msg(M_FATAL, "mlock: RLIMIT_MEMLOCK < 20 MByte, increase

limit");

Mbyte -> MB or megabytes

Quoted 12 lines
src/openvpn/platform.c +4 -0
+       }
+    }
+#endif
+
     if (mlockall(MCL_CURRENT | MCL_FUTURE))
     {
         msg(M_WARN | M_ERRNO, "WARNING: mlockall call failed");
src/openvpn/platform.h +0 -0
index 01f3200c..02c23e38 100644

src/openvpn/platform.h line 57

Quoted 10 lines
src/openvpn/platform.h +4 -0
@@ -48,6 +48,10 @@
 #include <stdio.h>
 #endif
 
+#ifdef HAVE_GETRLIMIT
+#include <sys/resource.h>
+#endif
+
 #include "basic.h"
 #include "buffer.h"
 

Selva

#2 lore raw

Hi,

thanks for the review.

Quoted 17 lines · Selva Nair
Quoted 6 lines · Gert Doering

If --mlock is used, the amount of memory OpenVPN can use is guarded by the RLIMIT_MEMLOCK value (see mlockall(2)). The OS default for this is usually 64 Kbyte, which is enough for OpenVPN to initialize, but as soon as the first TLS handshake comes it, OpenVPN will crash due to "ouf of memory", and might even end up in a crash loop.

Quoted 8 lines

Steady-state OpenVPN requires between 8 MB and 30-50 MB (servers with many concurrent clients) of memory.

So: with this patch, we check if getrlimit() is available, and if yes, log the amount of mlock'able memory. If the amount is below 20 MB, which is an arbitrary value "large enough for most smaller deployments", we abort.

Quoted 3 lines

This is required only if privileges are dropped, isn't it? Could be made conditional
on o->username is set.

"I'm not sure", TBH. rlimit handling in unix is a bit of an unknown territory for me.

What I understand is that root can *increment* the rlimit at will, but I'd assume that the rlimit value "in existance right now" (specifically, the soft limit) applies to root processes as well. Sort of a voluntary protection against processes running away.

But I can test this. Just malloc() until it does...

[..]

Quoted 8 lines

doc/man-sections/generic-options.rst which mode OpenVPN is configured as. · line 241

Quoted 6 lines
doc/man-sections/generic-options.rst +2 -0
@@ -237,6 +237,12 @@ which mode OpenVPN is configured as.
   likely fail. The limit can be increased using ulimit or systemd
   directives depending on how OpenVPN is started.
 
+  If the platform has the getrlimit(2) system call, OpenVPN will check
+  for the amount of mlock-able memory before calling mlockall(2), and

white space at end of line

Yeah, the whitespace-and-typing force wasn't strong with me today :-)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#3 lore raw
Quoted 28 lines · Gert Doering

Hi,

thanks for the review.

Quoted 1 line · Selva Nair

On Sun, Mar 7, 2021 at 11:31 AM Gert Doering <[email protected]...>

Quoted 7 lines · wrote:
Quoted 7 lines

If --mlock is used, the amount of memory OpenVPN can use is guarded by the RLIMIT_MEMLOCK value (see mlockall(2)). The OS default for this is usually 64 Kbyte, which is enough for OpenVPN to initialize, but as soon as the first TLS handshake comes it, OpenVPN will crash due to "ouf of memory", and might even end up in a crash loop.

Quoted 6 lines
Quoted 6 lines

Steady-state OpenVPN requires between 8 MB and 30-50 MB (servers with many concurrent clients) of memory.

So: with this patch, we check if getrlimit() is available, and if yes, log the amount of mlock'able memory. If the amount is below 20 MB, which is an arbitrary value "large enough for most smaller

deployments",

Quoted 6 lines
Quoted 2 lines

we abort.

This is required only if privileges are dropped, isn't it? Could be made conditional
on o->username is set.

Quoted 8 lines

"I'm not sure", TBH. rlimit handling in unix is a bit of an unknown territory for me.

What I understand is that root can *increment* the rlimit at will, but I'd assume that the rlimit value "in existance right now" (specifically, the soft limit) applies to root processes as well. Sort of a voluntary protection against processes running away.

On modern linux kernels (since some 2.6.x..) RLIMIT_MEMLOCK applies only to unprivileged processes -- privileged processes allowed to lock "unlimited" amount of memory as documented in man mlock. We updated the man page based on that sometime ago.

We could also consider using setrlimit to increase the limit before dropping privileges.

But I haven't checked how other "unix"-like OSes behave.

Selva

#4 lore raw

Hi,

Quoted 8 lines · Selva Nair
Quoted 7 lines

"I'm not sure", TBH. rlimit handling in unix is a bit of an unknown territory for me.

What I understand is that root can *increment* the rlimit at will, but I'd assume that the rlimit value "in existance right now" (specifically, the soft limit) applies to root processes as well. Sort of a voluntary protection against processes running away.

Quoted 4 lines

On modern linux kernels (since some 2.6.x..) RLIMIT_MEMLOCK applies only to unprivileged processes -- privileged processes allowed to lock "unlimited" amount of memory as documented in man mlock. We updated the man page based on that sometime ago.

Indeed, "man mlock" says something about "privileged processes" on Linux (it doesn't say that on FreeBSD).

Quoted 2 lines

We could also consider using setrlimit to increase the limit before dropping privileges.

That's another possible angle... just up soft+hard to "something" (how much would that be? :-) ) and log the fact.

David, Arne, any opinion on this? Where do we want to go?

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#5 lore raw

Hi,

Quoted 20 lines · Gert Doering

Hi,

Quoted 5 lines · Selva Nair
Quoted 5 lines

"I'm not sure", TBH. rlimit handling in unix is a bit of an unknown territory for me.

What I understand is that root can *increment* the rlimit at will, but I'd assume that the rlimit value "in existance right now"

(specifically,

Quoted 4 lines
Quoted 2 lines

the soft limit) applies to root processes as well. Sort of a voluntary protection against processes running away.

On modern linux kernels (since some 2.6.x..) RLIMIT_MEMLOCK applies only

to

Quoted 1 line

unprivileged processes -- privileged processes allowed to lock

"unlimited"

Quoted 1 line

amount of memory as documented in man mlock. We updated the man page

based

Quoted 1 line

on that sometime ago.

Quoted 9 lines

Indeed, "man mlock" says something about "privileged processes" on Linux (it doesn't say that on FreeBSD).

Quoted 2 lines

We could also consider using setrlimit to increase the limit before dropping privileges.

That's another possible angle... just up soft+hard to "something" (how much would that be? :-) ) and log the fact.

Rereading my comment on Trac #1059 I recall testing this and concluding 100MB enough for clients. On modern machines that's a low amount of memory --- not allowing swapout of 100MB should be acceptable. For servers, I think there is no reliable limit that we could come up with.

Selva

#6 lore raw
Quoted 7 lines · Selva Nair

Rereading my comment on Trac #1059 I recall testing this and concluding 100MB enough for clients. On modern machines that's a low amount of memory --- not allowing swapout of 100MB should be acceptable. For servers, I think there is no reliable limit that we could come up with.

Selva

I recall, when testing with EC the min. required was 89MB.

R

#7 lore raw
In reply to Selva Nair

Hi,

Quoted 7 lines · Selva Nair
Quoted 2 lines

That's another possible angle... just up soft+hard to "something" (how much would that be? :-) ) and log the fact.

Rereading my comment on Trac #1059 I recall testing this and concluding 100MB enough for clients. On modern machines that's a low amount of memory --- not allowing swapout of 100MB should be acceptable. For servers, I think there is no reliable limit that we could come up with.

This is interesting. My machines, including servers, have a way lower memory usage - but I'm not using EC.

Here's a linux server with 3 peers and a client (arm32):

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     14569  0.0  0.5   5704  2980 ?        Ss    2020  12:31 openvpn
root     21020  0.1  0.5   5568  3040 ?        Ss    2020 454:45 openvpn

Here's a FreeBSD server that serves 5 clients right now, but has peaks up to 150 concurrent clients (amd64)

USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 5023 0.3 0.1 30924 23172 - Ss 20Dec20 1945:07.12 /usr/local/sbin/openvpn --cd /usr/local/etc/openvpn --daemon

... and another two Linux server instances...

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1138  2.1  1.3  26732 10628 ?        Ss    2019 21678:18 /usr/sbin/openvpn
root      2897  0.8  0.9  29548  7080 ?        Ss    2019 8596:15 /usr/sbin/openvpn

the last 3 see a high number of clients during work time, and quite some churn (especially due to iOS/android connecting and disconnecting frequently), but long-term memory usage is not high.

So there must be some massive transient usage due to EC at reconnection time...

But anyway. 100M seems to be a good value, then.

I'll send a v2 of that patch, with setrlimit().

thanks,

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#17 lore raw

PATCH v2 1/1 Require at least 100MB of mlock()-able memory if --mlock is used.

In reply to Gert Doering

If --mlock is used, the amount of memory OpenVPN can use is guarded by the RLIMIT_MEMLOCK value (see mlockall(2)). The OS default for this is usually 64 Kbyte, which is enough for OpenVPN to initialize, but as soon as the first TLS handshake comes it, OpenVPN will crash due to "ouf of memory", and might even end up in a crash loop.

Steady-state OpenVPN requires between 8 MB and 30-50 MB (servers with many concurrent clients) of memory. TLS renegotiation with EC keys requires up to 90 MB of transient memory.

So: with this patch, we check if getrlimit() is available, and if yes, log the amount of mlock'able memory. If the amount is below 100 MB, which is an arbitrary value "large enough for most smaller deployments", we try to increase the limits to 100 MB, and abort if this fails.

v2:
change arbitrary number to 100 MB, introduce #define for it not only check but also increase with setrlimit() uncrustify fixes

Trac: #1390

---
 configure.ac                         |  2 +-
 doc/man-sections/generic-options.rst |  7 +++++++
 src/openvpn/platform.c               | 29 ++++++++++++++++++++++++++++
 src/openvpn/platform.h               |  4 ++++
 4 files changed, 41 insertions(+), 1 deletion(-)
configure.ac +1 -1
index 1ab8fe59..c65df3e2 100644
@@ -645,7 +645,7 @@ AC_FUNC_FORK
 
 AC_CHECK_FUNCS([ \
 	daemon chroot getpwnam setuid nice system getpid dup dup2 \
-	getpass syslog openlog mlockall getgrnam setgid \
+	getpass syslog openlog mlockall getrlimit getgrnam setgid \
 	setgroups stat flock readv writev time gettimeofday \
 	ctime memset vsnprintf strdup \
 	setsid chdir putenv getpeername unlink \
doc/man-sections/generic-options.rst +7 -0
index d5f08839..c026529e 100644
@@ -237,6 +237,13 @@ which mode OpenVPN is configured as.
   likely fail. The limit can be increased using ulimit or systemd
   directives depending on how OpenVPN is started.
 
+  If the platform has the getrlimit(2) system call, OpenVPN will check
+  for the amount of mlock-able memory before calling mlockall(2), and
+  tries to increase the limit to 100 MB if less than this is configured.
+  100 Mb is somewhat arbitrary - it is enough for a moderately-sized
+  OpenVPN deployment, but the memory usage might go beyond that if the
+  number of concurrent clients is high.
+
 --nice n
   Change process priority after initialization (``n`` greater than 0 is
   lower priority, ``n`` less than zero is higher priority).
src/openvpn/platform.c +29 -0
index ef688c23..dfbf50c0 100644
@@ -193,6 +193,35 @@ void
 platform_mlockall(bool print_msg)
 {
 #ifdef HAVE_MLOCKALL
+
+#ifdef HAVE_GETRLIMIT
+#define MIN_LOCKED_MEM_MB 100
+    struct rlimit rl;
+    if (getrlimit(RLIMIT_MEMLOCK, &rl) < 0)
+    {
+        msg(M_WARN | M_ERRNO, "WARNING: getrlimit(RLIMIT_MEMLOCK) failed");
+    }
+    else
+    {
+        msg(M_INFO, "mlock: MEMLOCK limit: soft=%ld KB, hard=%ld KB",
+            ((long int) rl.rlim_cur) / 1024, ((long int) rl.rlim_max) / 1024);
+        if (rl.rlim_cur < MIN_LOCKED_MEM_MB*1024*1024)
+        {
+            msg(M_INFO, "mlock: RLIMIT_MEMLOCK < %d MB, increase limit",
+                MIN_LOCKED_MEM_MB);
+            rl.rlim_cur = MIN_LOCKED_MEM_MB*1024*1024;
+            if (rl.rlim_max < rl.rlim_cur)
+            {
+                rl.rlim_max = rl.rlim_cur;
+            }
+            if (setrlimit(RLIMIT_MEMLOCK, &rl) < 0)
+            {
+                msg(M_FATAL | M_ERRNO, "ERROR: setrlimit() failed");
+            }
+        }
+    }
+#endif
+
     if (mlockall(MCL_CURRENT | MCL_FUTURE))
     {
         msg(M_WARN | M_ERRNO, "WARNING: mlockall call failed");
src/openvpn/platform.h +4 -0
index 01f3200c..02c23e38 100644
@@ -48,6 +48,10 @@
 #include <stdio.h>
 #endif
 
+#ifdef HAVE_GETRLIMIT
+#include <sys/resource.h>
+#endif
+
 #include "basic.h"
 #include "buffer.h"
 
Signature · 1 line
2.26.2
#9 lore raw
In reply to Gert Doering

Am 07.03.21 um 19:44 schrieb Gert Doering:

Quoted 19 lines

Hi,

Quoted 8 lines · Selva Nair
Quoted 7 lines

"I'm not sure", TBH. rlimit handling in unix is a bit of an unknown territory for me.

What I understand is that root can *increment* the rlimit at will, but I'd assume that the rlimit value "in existance right now" (specifically, the soft limit) applies to root processes as well. Sort of a voluntary protection against processes running away.

Quoted 4 lines

On modern linux kernels (since some 2.6.x..) RLIMIT_MEMLOCK applies only to unprivileged processes -- privileged processes allowed to lock "unlimited" amount of memory as documented in man mlock. We updated the man page based on that sometime ago.

Indeed, "man mlock" says something about "privileged processes" on Linux (it doesn't say that on FreeBSD).

Quoted 7 lines
Quoted 2 lines

We could also consider using setrlimit to increase the limit before dropping privileges.

That's another possible angle... just up soft+hard to "something" (how much would that be? :-) ) and log the fact.

David, Arne, any opinion on this? Where do we want to go?

Looking at this feature from today's perspective, it feels like one of OpenVPN's boutique features. Was probably useful at some point but doesn't really make much sense today anymore. Esepcially with what is written in the manpage. Today you rather would use full disk encryption or disable swapping rather than to rely on OpenVPN's --mlock.

That being said I am against your patch, I am just wondering if that is a feature we need to keep at all.

Arne

#10 lore raw
Quoted 9 lines · Arne Schwabe

Looking at this feature from today's perspective, it feels like one of OpenVPN's boutique features. Was probably useful at some point but doesn't really make much sense today anymore. Esepcially with what is written in the manpage. Today you rather would use full disk encryption or disable swapping rather than to rely on OpenVPN's --mlock.

That being said I am against your patch, I am just wondering if that is a feature we need to keep at all.

Having all openvpn data remain permanently in memory also offers a (small) performance boost.

Your alternative offers would impact performance and be system wide.

Therefore, I for one disagree.

--

#8 lore raw
In reply to Gert Doering
Quoted 33 lines · Gert Doering

Hi,

Quoted 7 lines · Selva Nair
Quoted 2 lines

That's another possible angle... just up soft+hard to "something" (how much would that be? :-) ) and log the fact.

Rereading my comment on Trac #1059 I recall testing this and concluding 100MB enough for clients. On modern machines that's a low amount of memory --- not allowing swapout of 100MB should be acceptable. For servers, I think there is no reliable limit that we could come up with.

This is interesting. My machines, including servers, have a way lower memory usage - but I'm not using EC.

Here's a linux server with 3 peers and a client (arm32):

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     14569  0.0  0.5   5704  2980 ?        Ss    2020  12:31 openvpn
root     21020  0.1  0.5   5568  3040 ?        Ss    2020 454:45 openvpn

Here's a FreeBSD server that serves 5 clients right now, but has peaks up to 150 concurrent clients (amd64)

USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 5023 0.3 0.1 30924 23172 - Ss 20Dec20 1945:07.12 /usr/local/sbin/openvpn --cd /usr/local/etc/openvpn --daemon

... and another two Linux server instances...

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1138  2.1  1.3  26732 10628 ?        Ss    2019 21678:18 /usr/sbin/openvpn
root      2897  0.8  0.9  29548  7080 ?        Ss    2019 8596:15 /usr/sbin/openvpn
Quoted 7 lines

the last 3 see a high number of clients during work time, and quite some churn (especially due to iOS/android connecting and disconnecting frequently), but long-term memory usage is not high.

So there must be some massive transient usage due to EC at reconnection time...

FWIW .... A couple of my CentOS 8.3 servers with 2 client connections running 24/7.

* Server 1

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
openvpn  3437979  0.0  0.1  76360  2924 ?        Ss   Feb25   2:19 /usr/sbin/openvpn

* Server 2

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
openvpn  2805670  0.0  0.8  76624  6896 ?        Ss   Feb25   7:08 /usr/sbin/openvpn

The start date is from when openvpn-2.5.1 got released and updated. OpenSSL 1.1.1g-12 is used on both hosts.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#11 lore raw
In reply to tincanteksup
Quoted 14 lines · tincanteksup
Quoted 9 lines · Arne Schwabe

Looking at this feature  from today's perspective, it feels like one of OpenVPN's boutique features. Was probably useful at some point but doesn't really make much sense today anymore. Esepcially with what is written in the manpage. Today you rather would use full disk encryption or disable swapping rather than to rely on OpenVPN's --mlock.

That being said I am against your patch, I am just wondering if that is a feature we need to keep at all.

Quoted 6 lines

Having all openvpn data remain permanently in memory also offers a (small) performance boost.

Your alternative offers would impact performance and be system wide.

Therefore, I for one disagree.

mlock() itself does not really have any impact your these arguments.

Yes, mlock() is about ensuring that OpenVPN can allocate a certain amount of memory which will stay entirely in RSS the memory pool as long as the memory pages has been locked. But it is not a system wide knob; it's a per process knob and applications can even turn this on and off at will (given they have the needed privileges for it) during the lifetime of the process.

Due to this flexibility to when you can enable and disable memory locking, it is also clear it is not intended to be used as a performance knob. It is designed to be more a security related feature, which in OpenVPN's context is there to avoid getting memory containing keying material being swapped out to disk.

On today's hardware even telling the kernel to not swap out a few hundred megabytes will also not result in much noticeable performance improvements. To feel the difference, you would need to have some really ancient hardware.

If you care or have issues with performance related to swapping, you need to revisit your swap setup - or add more RAM. A few hundred megabyte related to OpenVPN will not make things better or worse system wide on your system. Fixing the real reason you have swapping issues will.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#12 lore raw
Quoted 24 lines · David Sommerseth
Quoted 14 lines · tincanteksup
Quoted 9 lines · Arne Schwabe

Looking at this feature  from today's perspective, it feels like one of OpenVPN's boutique features. Was probably useful at some point but doesn't really make much sense today anymore. Esepcially with what is written in the manpage. Today you rather would use full disk encryption or disable swapping rather than to rely on OpenVPN's --mlock.

That being said I am against your patch, I am just wondering if that is a feature we need to keep at all.

Quoted 6 lines

Having all openvpn data remain permanently in memory also offers a (small) performance boost.

Your alternative offers would impact performance and be system wide.

Therefore, I for one disagree.

mlock() itself does not really have any impact your these arguments.

Quoted 9 lines

Yes, mlock() is about ensuring that OpenVPN can allocate a certain amount of memory which will stay entirely in RSS the memory pool as long as the memory pages has been locked.  But it is not a system wide knob; it's a per process knob and applications can even turn this on and off at will (given they have the needed privileges for it) during the lifetime of the process.

Due to this flexibility to when you can enable and disable memory locking, it is also clear it is not intended to be used as a performance knob.  It is designed to be more a security related feature, which in OpenVPN's context is there to avoid getting memory containing keying material being swapped out to disk.

On today's hardware even telling the kernel to not swap out a few hundred megabytes will also not result in much noticeable performance improvements.  To feel the difference, you would need to have some really ancient hardware.

If you care or have issues with performance related to swapping, you need to revisit your swap setup - or add more RAM.  A few hundred megabyte related to OpenVPN will not make things better or worse system wide on your system.  Fixing the real reason you have swapping issues will.

I have swapping issues all the time and I can't add more RAM. I don't want system wide disk encryption.
And I don't want an SSD either.

I do not have the money to keep up with modern hardware.

Having openvpn --mlock is exactly the right choice for my home system.

Please, do not remove --mlock from openvpn.

Please try to put yourselves in the place of the average user, for once.

R

#16 lore raw
In reply to Gert Doering
Quoted 19 lines · Gert Doering

Hi,

Quoted 8 lines · Selva Nair
Quoted 7 lines

"I'm not sure", TBH. rlimit handling in unix is a bit of an unknown territory for me.

What I understand is that root can *increment* the rlimit at will, but I'd assume that the rlimit value "in existance right now" (specifically, the soft limit) applies to root processes as well. Sort of a voluntary protection against processes running away.

Quoted 4 lines

On modern linux kernels (since some 2.6.x..) RLIMIT_MEMLOCK applies only to unprivileged processes -- privileged processes allowed to lock "unlimited" amount of memory as documented in man mlock. We updated the man page based on that sometime ago.

Indeed, "man mlock" says something about "privileged processes" on Linux (it doesn't say that on FreeBSD).

Quoted 7 lines
Quoted 2 lines

We could also consider using setrlimit to increase the limit before dropping privileges.

That's another possible angle... just up soft+hard to "something" (how much would that be? :-) ) and log the fact.

David, Arne, any opinion on this? Where do we want to go?

I do think mlock serves a purpose in ensuring where memory pages are kept, from a general perspective. But does it really make sense in today's virtualized world? Where we're mostly having several GiBs of RAM available. I'm not sure it matters that much either way. But for those who care about memory security, it is a useful feature.

Since the code to enable this shouldn't be enormous (since we use mlockall()), I don't see much winning in code complexity by tearing it out when it may provide some security related features.

The unprivileged vs privileged process on Linux kernels change happened in 2.6.9, according to "Linux Programming Interface" (LPI) [Michael Kerrisk, chapter 50)]. I do not consider that an issue at all; I can't think of any still fully supported Linux distributions with such an ancient Linux kernel. It should really not run security related tasks (from a general perspective).

If I've understood the LPI book correctly, the default (RLIMIT_MEMLOCK) is set to 32KiB for both hard and soft limits. Clearly not enough for our use case.

setrlimit() by itself isn't really that magical. Basically you populate struct rlimit with the limits you want and call setrlimit(RLIMIT_MEMLOCK, &new_limits); Plus error checking and all that.

But we should look into if we should acquire CAP_IPC_LOCK capability as well, otherwise we need to completely ensure that mlockall() is really called before privileges have been dropped. I know I had to kick out --mlock on a few configs a long while ago, related to lack of privileges - but that could have been SELinux restrictions as well. Need to revisit this.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#13 lore raw
In reply to tincanteksup
Quoted 5 lines · tincanteksup

I have swapping issues all the time and I can't add more RAM. I don't want system wide disk encryption.
And I don't want an SSD either.

Quoted 7 lines

I do not have the money to keep up with modern hardware.

Having openvpn --mlock is exactly the right choice for my home system.

Please, do not remove --mlock from openvpn.

How much memory does your OpenVPN process consume? And if the process (or task in kernel lingo) is active (not idling), it generally will not be swapped out. If it does, you are already running way to much on your host. So you need to prioritize what that host should really run.

OpenVPN's --mlock does not save you.

And in fact, the kernel may as well swap out the memory pages containing the program itself and just keep the data pages allocated by the program in memory. Which will result in a sluggish OpenVPN performance regardless.

This gives a brief overview which might help you see what happens:
<https://scoutapm.com/blog/understanding-page-faults-and-memory-swap-in-outs-when-should-you-worry>

And even though you don't want SSD. At least consider if you can get hold of a reasonably performing SSD with not too many GB and activate that device as a swap device on your host. It will not be optimal, but at least the general swapping can go faster if you have a decent SATA/SAS controller.

Quoted 2 lines

Please try to put yourselves in the place of the average user, for once.

The average users I know does not push their hardware beyond its limits so much it hurts the overall performance. Those I know would start planning for an upgrade. Or get an RPi4 and run OpenVPN on it, as it got a reasonable network performance: <https://notenoughtech.com/raspberry-pi/2019-raspberry-pi-network-speed-test/>

But openvpn --mlock is never the solution to performance and swapping. Never ever.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#14 lore raw
Quoted 26 lines · David Sommerseth
Quoted 5 lines · tincanteksup

I have swapping issues all the time and I can't add more RAM. I don't want system wide disk encryption.
And I don't want an SSD either.

Quoted 7 lines

I do not have the money to keep up with modern hardware.

Having openvpn --mlock is exactly the right choice for my home system.

Please, do not remove --mlock from openvpn.

How much memory does your OpenVPN process consume?  And if the process (or task in kernel lingo) is active (not idling), it generally will not be swapped out.  If it does, you are already running way to much on your host.  So you need to prioritize what that host should really run.

OpenVPN's --mlock does not save you.

And in fact, the kernel may as well swap out the memory pages containing the program itself and just keep the data pages allocated by the program in memory.  Which will result in a sluggish OpenVPN performance regardless.

This gives a brief overview which might help you see what happens:
<https://scoutapm.com/blog/understanding-page-faults-and-memory-swap-in-outs-when-should-you-worry>

And even though you don't want SSD.  At least consider if you can get hold of a reasonably performing SSD with not too many GB and activate that device as a swap device on your host.  It will not be optimal, but at least the general swapping can go faster if you have a decent SATA/SAS controller.

Quoted 9 lines
Quoted 2 lines

Please try to put yourselves in the place of the average user, for once.

The average users I know does not push their hardware beyond its limits so much it hurts the overall performance.  Those I know would start planning for an upgrade.  Or get an RPi4 and run OpenVPN on it, as it got a reasonable network performance: <https://notenoughtech.com/raspberry-pi/2019-raspberry-pi-network-speed-test/>

But openvpn --mlock is never the solution to performance and swapping. Never ever.

As I Initially clarified, there *may* be a Small performance tweak by using --mlock.

The problem here is that by removing --mlock you shift the burden of securing ephemeral key data to the under lying OS.

You may as well print the full private keys in the log (again) and expect the user to delete them all and shred their disk.

As for how I must spend my money, that is no business of yours.

my2c

#15 lore raw
In reply to Arne Schwabe

Hi,

Quoted 2 lines · Arne Schwabe

That being said I am against your patch, I am just wondering if that is a feature we need to keep at all.

Just for clarification: is there a "not" missing in that sentence?

(Code-wise, mlock / *rlimit is just ~40-50 lines of code, isolated to init time, so it really doesn't cost/save us much either way)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
Acked-by on v2 1/1
#18 lore raw

Re: [Openvpn-devel] [PATCH v2] Require at least 100MB of mlock()-able memory if --mlock is used.

In reply to Gert Doering

Hi,

Quoted 120 lines · Gert Doering

If --mlock is used, the amount of memory OpenVPN can use is guarded by the RLIMIT_MEMLOCK value (see mlockall(2)). The OS default for this is usually 64 Kbyte, which is enough for OpenVPN to initialize, but as soon as the first TLS handshake comes it, OpenVPN will crash due to "ouf of memory", and might even end up in a crash loop.

Steady-state OpenVPN requires between 8 MB and 30-50 MB (servers with many concurrent clients) of memory. TLS renegotiation with EC keys requires up to 90 MB of transient memory.

So: with this patch, we check if getrlimit() is available, and if yes, log the amount of mlock'able memory. If the amount is below 100 MB, which is an arbitrary value "large enough for most smaller deployments", we try to increase the limits to 100 MB, and abort if this fails.

v2:
change arbitrary number to 100 MB, introduce #define for it not only check but also increase with setrlimit() uncrustify fixes

Trac: #1390

---
 configure.ac                         |  2 +-
 doc/man-sections/generic-options.rst |  7 +++++++
 src/openvpn/platform.c               | 29 ++++++++++++++++++++++++++++
 src/openvpn/platform.h               |  4 ++++
 4 files changed, 41 insertions(+), 1 deletion(-)
configure.ac +1 -1
index 1ab8fe59..c65df3e2 100644
@@ -645,7 +645,7 @@ AC_FUNC_FORK
 
 AC_CHECK_FUNCS([ \
        daemon chroot getpwnam setuid nice system getpid dup dup2 \
-       getpass syslog openlog mlockall getgrnam setgid \
+       getpass syslog openlog mlockall getrlimit getgrnam setgid \
        setgroups stat flock readv writev time gettimeofday \
        ctime memset vsnprintf strdup \
        setsid chdir putenv getpeername unlink \
doc/man-sections/generic-options.rst +7 -0
index d5f08839..c026529e 100644
@@ -237,6 +237,13 @@ which mode OpenVPN is configured as.
   likely fail. The limit can be increased using ulimit or systemd
   directives depending on how OpenVPN is started.
 
+  If the platform has the getrlimit(2) system call, OpenVPN will check
+  for the amount of mlock-able memory before calling mlockall(2), and
+  tries to increase the limit to 100 MB if less than this is configured.
+  100 Mb is somewhat arbitrary - it is enough for a moderately-sized
+  OpenVPN deployment, but the memory usage might go beyond that if the
+  number of concurrent clients is high.
+
 --nice n
   Change process priority after initialization (``n`` greater than 0 is
   lower priority, ``n`` less than zero is higher priority).
src/openvpn/platform.c +29 -0
index ef688c23..dfbf50c0 100644
@@ -193,6 +193,35 @@ void
 platform_mlockall(bool print_msg)
 {
 #ifdef HAVE_MLOCKALL
+
+#ifdef HAVE_GETRLIMIT
+#define MIN_LOCKED_MEM_MB 100
+    struct rlimit rl;
+    if (getrlimit(RLIMIT_MEMLOCK, &rl) < 0)
+    {
+        msg(M_WARN | M_ERRNO, "WARNING: getrlimit(RLIMIT_MEMLOCK)
 failed");
+    }
+    else
+    {
+        msg(M_INFO, "mlock: MEMLOCK limit: soft=%ld KB, hard=%ld KB",
+            ((long int) rl.rlim_cur) / 1024, ((long int) rl.rlim_max) /
 1024);
+        if (rl.rlim_cur < MIN_LOCKED_MEM_MB*1024*1024)
+        {
+            msg(M_INFO, "mlock: RLIMIT_MEMLOCK < %d MB, increase limit",
+                MIN_LOCKED_MEM_MB);
+            rl.rlim_cur = MIN_LOCKED_MEM_MB*1024*1024;
+            if (rl.rlim_max < rl.rlim_cur)
+            {
+                rl.rlim_max = rl.rlim_cur;
+            }
+            if (setrlimit(RLIMIT_MEMLOCK, &rl) < 0)
+            {
+                msg(M_FATAL | M_ERRNO, "ERROR: setrlimit() failed");
+            }
+        }
+    }
+#endif
+
     if (mlockall(MCL_CURRENT | MCL_FUTURE))
     {
         msg(M_WARN | M_ERRNO, "WARNING: mlockall call failed");
src/openvpn/platform.h +4 -1
index 01f3200c..02c23e38 100644
@@ -48,6 +48,10 @@
 #include <stdio.h>
 #endif
 
+#ifdef HAVE_GETRLIMIT
+#include <sys/resource.h>
+#endif
+
 #include "basic.h"
 #include "buffer.h"
 
--
Quoted 2 lines

2.26.2

Looks good to me. We call mlockall (and now setrlimit) early before dropping privileges, so this should take care of at least the naive user error of running with "--mlock --user foo" and the default low memlock limit.

Selva

#19 lore raw

PATCH v3 1/1 Require at least 100MB of mlock()-able memory if --mlock is used.

In reply to Gert Doering

If --mlock is used, the amount of memory OpenVPN can use is guarded by the RLIMIT_MEMLOCK value (see mlockall(2)). The OS default for this is usually 64 Kbyte, which is enough for OpenVPN to initialize, but as soon as the first TLS handshake comes it, OpenVPN will crash due to "ouf of memory", and might even end up in a crash loop.

Steady-state OpenVPN requires between 8 MB and 30-50 MB (servers with many concurrent clients) of memory. TLS renegotiation with EC keys requires up to 90 MB of transient memory.

So: with this patch, we check if getrlimit() is available, and if yes, log the amount of mlock'able memory. If the amount is below 100 MB, which is an arbitrary value "large enough for most smaller deployments", we try to increase the limits to 100 MB, and abort if this fails.

v2:
change arbitrary number to 100 MB, introduce #define for it not only check but also increase with setrlimit() uncrustify fixes

v3:
OpenSolaris has mlockall() and getrlimit(), but no RLIMIT_MEMLOCK -
make code conditional on HAVE_GETRLIMIT *and* RLIMIT_MEMLOCK
add Changes.rst entry

Trac: #1390

---
 Changes.rst                          |  5 +++++
 configure.ac                         |  2 +-
 doc/man-sections/generic-options.rst |  7 +++++++
 src/openvpn/platform.c               | 29 ++++++++++++++++++++++++++++
 src/openvpn/platform.h               |  4 ++++
 5 files changed, 46 insertions(+), 1 deletion(-)
Changes.rst +5 -0
index 62008e8d..d6be1050 100644
@@ -15,6 +15,11 @@ Compatibility with OpenSSL in FIPS mode
     requirements/recommendation of FIPS 140-2. This just allows OpenVPN
     to be run on a system that be configured OpenSSL in FIPS mode.
 
+``mlock`` will now check if enough memlock-able memory has been reserved,
+    and if less than 100MB RAM are available, use setrlimit() to upgrade
+    the limit.  See Trac #1390.  Not available on OpenSolaris.
+
+
 Deprecated features
 -------------------
 ``inetd`` has been removed
configure.ac +1 -1
index 1ab8fe59..c65df3e2 100644
@@ -645,7 +645,7 @@ AC_FUNC_FORK
 
 AC_CHECK_FUNCS([ \
 	daemon chroot getpwnam setuid nice system getpid dup dup2 \
-	getpass syslog openlog mlockall getgrnam setgid \
+	getpass syslog openlog mlockall getrlimit getgrnam setgid \
 	setgroups stat flock readv writev time gettimeofday \
 	ctime memset vsnprintf strdup \
 	setsid chdir putenv getpeername unlink \
doc/man-sections/generic-options.rst +7 -0
index d5f08839..c026529e 100644
@@ -237,6 +237,13 @@ which mode OpenVPN is configured as.
   likely fail. The limit can be increased using ulimit or systemd
   directives depending on how OpenVPN is started.
 
+  If the platform has the getrlimit(2) system call, OpenVPN will check
+  for the amount of mlock-able memory before calling mlockall(2), and
+  tries to increase the limit to 100 MB if less than this is configured.
+  100 Mb is somewhat arbitrary - it is enough for a moderately-sized
+  OpenVPN deployment, but the memory usage might go beyond that if the
+  number of concurrent clients is high.
+
 --nice n
   Change process priority after initialization (``n`` greater than 0 is
   lower priority, ``n`` less than zero is higher priority).
src/openvpn/platform.c +29 -0
index ef688c23..3bf95f84 100644
@@ -193,6 +193,35 @@ void
 platform_mlockall(bool print_msg)
 {
 #ifdef HAVE_MLOCKALL
+
+#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_MEMLOCK)
+#define MIN_LOCKED_MEM_MB 100
+    struct rlimit rl;
+    if (getrlimit(RLIMIT_MEMLOCK, &rl) < 0)
+    {
+        msg(M_WARN | M_ERRNO, "WARNING: getrlimit(RLIMIT_MEMLOCK) failed");
+    }
+    else
+    {
+        msg(M_INFO, "mlock: MEMLOCK limit: soft=%ld KB, hard=%ld KB",
+            ((long int) rl.rlim_cur) / 1024, ((long int) rl.rlim_max) / 1024);
+        if (rl.rlim_cur < MIN_LOCKED_MEM_MB*1024*1024)
+        {
+            msg(M_INFO, "mlock: RLIMIT_MEMLOCK < %d MB, increase limit",
+                MIN_LOCKED_MEM_MB);
+            rl.rlim_cur = MIN_LOCKED_MEM_MB*1024*1024;
+            if (rl.rlim_max < rl.rlim_cur)
+            {
+                rl.rlim_max = rl.rlim_cur;
+            }
+            if (setrlimit(RLIMIT_MEMLOCK, &rl) < 0)
+            {
+                msg(M_FATAL | M_ERRNO, "ERROR: setrlimit() failed");
+            }
+        }
+    }
+#endif
+
     if (mlockall(MCL_CURRENT | MCL_FUTURE))
     {
         msg(M_WARN | M_ERRNO, "WARNING: mlockall call failed");
src/openvpn/platform.h +4 -0
index 01f3200c..02c23e38 100644
@@ -48,6 +48,10 @@
 #include <stdio.h>
 #endif
 
+#ifdef HAVE_GETRLIMIT
+#include <sys/resource.h>
+#endif
+
 #include "basic.h"
 #include "buffer.h"
 
Signature · 1 line
2.26.2
#20 lore raw

[Openvpn-devel] [PATCH applied] Re: Require at least 100MB of mlock()-able memory if --mlock is used.

Thanks, Selva.

v3 has actually been buildbot-tested on all the platforms (I tested v2 after the ACK, and it failed OpenSolaris, so I grumbled and adjusted the #ifdef's...). It has been "tested for real" on Linux, which has "prlimit" to tell you the currently-active limits for *other* processes
- haven't found something equivalent on the BSDs, so only "it will report the right value(s) and not explode"-tested (+ buildbot compile).

Patch has been applied to the master branch.

commit b0bff5590152fbcc5b4d47c18817838fd00c58c3

Author: Gert Doering
Date:   Wed Mar 10 13:48:08 2021 +0100
     Require at least 100MB of mlock()-able memory if --mlock is used.

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Selva Nair <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg21657.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#21 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: Require at least 100MB of mlock()-able memory if --mlock is used.

Hi,

Quoted 9 lines · Gert Doering

Thanks, Selva.

v3 has actually been buildbot-tested on all the platforms (I tested v2 after the ACK, and it failed OpenSolaris, so I grumbled and adjusted the #ifdef's...). It has been "tested for real" on Linux, which has "prlimit" to tell you the currently-active limits for *other* processes
- haven't found something equivalent on the BSDs, so only "it will report the right value(s) and not explode"-tested (+ buildbot compile).

prlimit on Linux is handy as it can change the limits of a running process as well.
On FreeBSD probably "limits -P pid ... " can do the same?

Selva

Quoted 29 lines

Patch has been applied to the master branch.

commit b0bff5590152fbcc5b4d47c18817838fd00c58c3

Author: Gert Doering
Date:   Wed Mar 10 13:48:08 2021 +0100
     Require at least 100MB of mlock()-able memory if --mlock is used.

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Selva Nair <[email protected]...>
     Message-Id: <[email protected]...>
     URL:
https://www.mail-archive.com/[email protected]/msg21657.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

#22 lore raw

Re: [Openvpn-devel] [PATCH applied] Re: Require at least 100MB of mlock()-able memory if --mlock is used.

HI,

Quoted 2 lines · Selva Nair

prlimit on Linux is handy as it can change the limits of a running process as well.

Yes :-) - my week is full of exciting discoveries.

Quoted 1 line

On FreeBSD probably "limits -P pid ... " can do the same?

Indeed! Thanks, didn't follow the right references, it seems...

[email protected]...:/tmp$ limits -P 13222
Resource limits (current):
[..]
  memorylocked           102400 kB

... so, the claim of OpenVPN pid 13222 "I have set this to 100M" is true :-)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...