MIME-Version: 1.0 From: arno.odermatt@...1845... Message-ID: Date: Fri, 22 Nov 2013 10:51:27 +0100 Content-Type: multipart/alternative; boundary="=_alternative 003625D8C1257C2B_=" Subject: [Openvpn-devel] Does openvpn 2.3.2 has memory leak? (addendum3 and 4) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gert Doering , openvpn-devel@lists.sourceforge.net Cc: Brad Zhang This is a multipart message in MIME format. --=_alternative 003625D8C1257C2B_= Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Dear Gert, Brad all, as I also had reported to have recognized, that memory was not freed, even= =20 though the openvpn disconnect-script was disconnecting all of the 3400=20 Openvpn-sessions (pls see mail below). Would you think, this is also improved by the change from malloc to=20 calloc, so we could update to 2.3.3 to improve the memory-leak situation? freundlich gr=FCsst, kind regards, _________________________ _________________________ _________________________ _________________________ _________________________ ________________=20 Arno Odermatt=20 Phone +41414454053=20 arno.odermatt@...1845...=20 Schindler Elevator Ltd. | Corporate Research & Development | CRD/CO-BAT=20 Zugerstr. 13 | CH-6030 Ebikon, Switzerland=20 http://www.schindler.com=20 _________________________ _________________________ _________________________ _________________________ _________________________ ________________=20 Please consider your environment.=20 Schindler supports sustainable urban development with safe, reliable and ecologically sound mobility solutions. From: Gert Doering To: Brad Zhang ,=20 Cc: openvpn-devel@lists.sourceforge.net Date: 20.11.2013 19:33 Subject: Re: [Openvpn-devel] Does openvpn 2.3.2 has memory leak? Hi, to bring this discussion to an end... On Thu, Nov 07, 2013 at 06:25:55PM +0800, Brad Zhang wrote: > Thank you so much. I am testing Openvpn 2.3.2 with your patch memory=20 usage > some days. Here is result: Thanks for the exhaustive tests. This is really good to see, and it's impressive how much less memory PolarSSL need! The patch in question has been acked by David, has been pushed to git, and will be in 2.3.3 when we release that. [..] > I noticed your mail said if clients are disconnected, the memory will be > free, but when I tested openvpn + polarssl (no your patch), the memory=20 did > not free completely, for example: > Openvpn 2.3.2 + Polarssl > 62672 55m 1408 S 0.0 2.8 0:06.91 openvpn (Have 200 connections) > 37864 34m 1412 S 0.0 1.7 0:06.84 openvpn (disconnect all=20 connections) [..] > It is odd that memory do not free completely because I saw all the=20 clients > disconnect correctly from Openvpn server logs. > I tried to disable the option "persist-key" and "persist-tun", it did=20 not > make better when clients disconnected. Finding the reason for that is not trivial. What comes into play here is how the "malloc()" and "free()" functions works on that particular=20 operating system - usually, not all malloc() requests fetch memory from=20 the kernel directly, but usually malloc() will request a larger block (with sbrk() or mmap()), and maintain that locally in the process, saving on=20 syscall overhead. free() will also work only locally first, and only if the library decides "it's worth returing something to the kernel" it will actually do so - so it's not unusual to never see memory usage actually go down if your library just keeps the memory chunks around... So it might be that in this case, there's a memory allocation right in the middle of a larger area which is still in use, so the larger area cannot be returned (but the memory might be re-used when the clients connect again, so is not "lost") - but without very extensive debugging, including fully understanding the way the local malloc()/free()=20 implementations work, this is impossible to give a definite answer to. What we know, and this is good :-), is that openvpn *does* call free() on everything it allocates - this we can learn from valgrind, but it will only tell us how the situation is at program end, not how the memory layout looks like while it runs (I think it can be told to do so, but there are *many* short-lived malloc()/free() uses in OpenVPN, so looking at the log files would be a huge amount of work). Anyway. I think what we have is "good enough" given the amount of work we can invest here, and that there are so many other areas where we need to fix bugs... Thanks for bringing this up, and making us reconsider the buffer changes we did in best faith :-) gert --=20 USENET is *not* the non-clickable part of WWW! //www.muc.de/~gert/ Gert Doering - Munich, Germany gert@...1296... fax: +49-89-35655025 gert@...1297... [attachment "att77ku7.dat" deleted by Arno Odermatt/R&D/SCH/SCHINDLER]=20 ---------------------------------------------------------------------------= --- Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing=20 conversations that shape the rapidly evolving mobile landscape. Sign up=20 now.=20 http://pubads.g.doubleclick.net/gampad/clk?id=3D63431311&iu=3D/4140/ostg.cl= ktrk _________________________ ______________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel ----- Forwarded by Arno Odermatt/R&D/SCH/SCHINDLER on 22.11.2013 10:48=20 ----- From: arno.odermatt@...1845... To: Gert Doering ,=20 Cc: openvpn-devel@lists.sourceforge.net Date: 08.11.2013 11:56 Subject: Re: [Openvpn-devel] Does openvpn 2.3.2 has memory leak? Dear Gert,=20 after having been able to spend a smooth operating time of the around 3400= =20 permanent connected O-VPN clients (after having attached memory in form of= =20 a 10Gb swap partition), we just recognized a hickout, where all clients=20 got disconnected.=20 Unfortunately, after around 3270 disconnected clients, memory was'nt freed= =20 at all: 3270 /etc/openvpn/cgwvpn/persipoff=20 top - 10:31:58 up 31 days, 20:10, 2 users, load average: 0.78, 0.70,=20 0.69=20 Tasks: 71 total, 2 running, 69 sleeping, 0 stopped, 0 zombie=20 Cpu(s): 0.3%us, 23.2%sy, 0.0%ni, 50.0%id, 0.0%wa, 14.4%hi, 0.0%si,=20 12.0%st=20 Mem: 7629920k total, 5073576k used, 2556344k free, 159504k buffers=20 Swap: 10485756k total, 0k used, 10485756k free, 192536k cached=20 PID USER PR NI VIRT RES SHR S %CPU %MEM= =20=20 TIME+ COMMAND=20 22810 root 20 0 4481m 4.2g 1996 S 62.5 58.1 5102:38= =20 openvpn=20 12619 root 20 0 8 4 0 R 3.0= =20 0.0 0:00.09 openvpn=20 12222 root 20 0 15228 1216 932 R 0.3 0.0 0:00.02=20 top Unfortunately, this is not something, we had expected.=20 We have not applied the patch yet, which brings back the "2.1" behavior.=20 freundlich gr=FCsst, kind regards, _________________________ _________________________=20 _________________________ _________________________=20 _________________________ ________________=20 Arno Odermatt=20 Phone +41414454053=20 arno.odermatt@...1845...=20 Schindler Elevator Ltd. | Corporate Research & Development | CRD/CO-BAT=20 Zugerstr. 13 | CH-6030 Ebikon, Switzerland=20 http://www.schindler.com=20 _________________________ _________________________=20 _________________________ _________________________=20 _________________________ ________________=20 Please consider your environment.=20 Schindler supports sustainable urban development with safe, reliable and ecologically sound mobility solutions. From: Gert Doering =20 To: Brad Zhang ,=20 Cc: openvpn-devel@lists.sourceforge.net=20 Date: 23.10.2013 16:20=20 Subject: Re: [Openvpn-devel] Does openvpn 2.3.2 has memory leak?=20 Hi, On Sun, Oct 06, 2013 at 09:21:46PM +0800, Brad Zhang wrote: > Do you have some idea about this issue? Looking forward to your reply. Coming back to *this* thread, after some debugging in the other thread with Arno, I think what I can say so far is that we're observing two different things: - the first renegotiation brings a big jump in memory, but this is to be expected, because the new keying material needs extra memory, and the memory for the old key is not released right away (it seems to be released at the next renegotiation, or at client disconnect - I've=20 seen VSZ/RSS go down(!) when clients disconnect, so that seems to work right). This is the "big" jump in memory consumption which is actually killing Arno's setup, because there is not enough virtual memory available to hold all that is needed for 3000 clients (but that can be fixed by increasing max-memory limits if there is enough=20 RAM). - each further renegotiation leaks "a few kbyte" of memory per client, which should also be fully returned when the client disconnects - this is the issue I discovered earlier, with the GC handling of the=20 per-client environment set, and I'll send a patch for that "soon" (as soon as I have fully understood the code involved). Now, what I do not really understand is why the memory consumption on the 3rd, 4th, 5th renegotiation seems to slow down - there seems to be some additional memory fragmentation involved in the 2nd+3rd renegotiation, which leads to memory re-use later on. Or so. Testing this with "reneg-sec 60" is actually quite interesting... here's *disconnect* of a client: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 19892 0.0 0.0 7052 4304 pts/7 SN+ 17:48 0:01 openvpn=20 ../serv USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 19892 0.0 0.0 6300 3740 pts/7 SN+ 17:48 0:01 openvpn=20 ../serv ... so you can see that memory is returned to the OS. (I think this will not be visible if many clients are connected as the free()ed memory will be "somewhere in the middle" - but disconnecting *all* clients should also show memory being returned) Now going to stare more at the code... :-) gert --=20 USENET is *not* the non-clickable part of WWW! //www.muc.de/~gert/ Gert Doering - Munich, Germany gert@...1296... fax: +49-89-35655025 gert@...1297... [attachment "attxgxs6.dat" deleted by Arno Odermatt/R&D/SCH/SCHINDLER]=20 ---------------------------------------------------------------------------= --- October Webinars: Code for Performance Free Intel webinars can help you accelerate application performance. Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most=20 from=20 the latest Intel processors and coprocessors. See abstracts and register > http://pubads.g.doubleclick.net/gampad/clk?id=3D60135991&iu=3D/4140/ostg.cl= ktrk __________________ _________________________ ____ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel ****************************************************** Notice: The information contained in this message is intended only for use= =20 of the individual(s) named above and may contain confidential, proprietary= =20 or legally privileged information. No confidentiality or privilege is=20 waived or lost by any mistransmission. If you are not the intended=20 recipient of this message you are hereby notified that you must not use,=20 disseminate , copy it in any form or take any action in reliance of it. If= =20 you have received this message in error please delete it and any copies of= =20 it and notify the sender immediately. ******************************************************* ---------------------------------------------------------------------------= --- November Webinars for C, C++, Fortran Developers Accelerate application performance with scalable programming models.=20 Explore techniques for threading, error checking, porting, and tuning. Get the=20 most=20 from the latest Intel processors and coprocessors. See abstracts and=20 register http://pubads.g.doubleclick.net/gampad/clk?id=3D60136231&iu=3D/4140/ostg.cl= ktrk _________________________ ______________________ Openvpn-devel mailing list Openvpn-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openvpn-devel ****************************************************** Notice: The information contained in this message is intended only for use = of the individual(s) named above and may contain confidential, proprietary = or legally privileged information. No confidentiality or privilege is waive= d or lost by any mistransmission. If you are not the intended recipient of = this message you are hereby notified that you must not use, disseminate , c= opy it in any form or take any action in reliance of it. If you have receiv= ed this message in error please delete it and any copies of it and notify t= he sender immediately. *******************************************************= --=_alternative 003625D8C1257C2B_= Content-Type: text/html; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Dear Gert, Brad all,

as I also had reported to have recog= nized, that memory was not freed, even though the openvpn disconnect-script was disconnecting all of the 3400 Openvpn-sessions (pls see mail below).
Would you think, this is also improv= ed by the change from malloc to calloc, so we could update to 2.3.3 to improve the memory-leak situation?


freundlich gr=FCsst,
kind regards,

_________________________ _________________________ _________________________ _________________________ _________________________ ________________

Arno Odermatt
Phone +41414454053
arno.odermatt@...1845...

Schindler Elevator Ltd. | Corporate Research & Development | CRD/CO-BAT
Zugerstr. 13 | CH-6030 Ebikon, Switzerland
http://www.schindler.com
_________________________ _________________________ _________________________ _________________________ _________________________ ________________

Please consider your environment.

Schindler supports sustainable urban development with
safe, reliable and ecologically sound mobility solutions.





From:     =    Gert Doering <gert@...1711...= 96...>
To:     &n= bsp;  Brad Zhang <hebei5000@...1186...= .277...>,
Cc:     &n= bsp;  openvpn-devel@...1535...= orge.net
Date:     =    20.11.2013 19:33
Subject:   &nbs= p;    Re: [Openvpn-devel] Does openvpn 2.3.2 has memory leak?




Hi,

to bring this discussion to an end...

On Thu, Nov 07, 2013 at 06:25:55PM +0800, Brad Zhang wrote:
> Thank you so much. I am testing Openvpn 2.3.2 with your patch memory usage
> some days. Here is result:

Thanks for the exhaustive tests.  This is really good to see, and it's
impressive how much less memory PolarSSL need!

The patch in question has been acked by David, has been pushed to git,
and will be in 2.3.3 when we release that.

[..]
> I noticed your mail said if clients are disconnected, the memory will be
> free, but when I tested openvpn + polarssl (no your patch), the memory did
> not free completely, for example:
> Openvpn 2.3.2 + Polarssl
> 62672  55m 1408 S  0.0  2.8   0:06.91 openvpn  (Have 200 connections)
> 37864  34m 1412 S  0.0  1.7   0:06.84 openvpn  (disconnect all connections)
[..]
> It is odd that memory do not free completely because I saw all the clients
> disconnect correctly from Openvpn server logs.
> I tried to disable the option "persist-key" and "persis= t-tun", it did not
> make better when clients disconnected.

Finding the reason for that is not trivial.  What comes into play here is
how the "malloc()" and "free()" functions works on that particular
operating system - usually, not all malloc() requests fetch memory from the
kernel directly, but usually malloc() will request a larger block (with
sbrk() or mmap()), and maintain that locally in the process, saving on
syscall overhead.  free() will also work only locally first, and only if
the library decides "it's worth returing something to the kernel" it will
actually do so - so it's not unusual to never see memory usage actually
go down if your library just keeps the memory chunks around...

So it might be that in this case, there's a memory allocation right in
the middle of a larger area which is still in use, so the larger area
cannot be returned (but the memory might be re-used when the clients
connect again, so is not "lost") - but without very extensive debugging,
including fully understanding the way the local malloc()/free()
implementations work, this is impossible to give a definite answer to.

What we know, and this is good :-), is that openvpn *does* call free()
on everything it allocates - this we can learn from valgrind, but it
will only tell us how the situation is at program end, not how the
memory layout looks like while it runs (I think it can be told to do
so, but there are *many* short-lived malloc()/free() uses in OpenVPN,
so looking at the log files would be a huge amount of work).

Anyway.  I think what we have is "good enough" given the amount of
work we can invest here, and that there are so many other areas where
we need to fix bugs...

Thanks for bringing this up, and making us reconsider the buffer changes
we did in best faith :-)

gert
--
USENET is *not* the non-clickable part of WWW!
                                                          //www.muc.de/~gert/=
Gert Doering - Munich, Germany                             gert@...1296...
fax: +49-89-35655025                        gert@...1297...
[attachment "att77ku7.dat" deleted by Arno Odermatt/R&D/SCH/S= CHINDLER] ---------------------------------------------------------------------------= ---
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing
conversations that shape the rapidly evolving mobile landscape. Sign up now.
http://pubads.g.doublec= lick.net/gampad/clk?id=3D63431311&iu=3D/4140/ostg.clktrk__________________ _________________________ ____
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ope= nvpn-devel




----- Forwarded by A= rno Odermatt/R&D/SCH/SCHINDLER on 22.11.2013 10:48 -----

From:     =    arno.odermatt@...1845...
To:     &n= bsp;  Gert Doering <gert@...1711...= 96...>,
Cc:     &n= bsp;  openvpn-devel@...1535...= orge.net
Date:     =    08.11.2013 11:56
Subject:   &nbs= p;    Re: [Openvpn-devel] Does openvpn 2.3.2 has memory leak?




Dear Gert,

after having been able to spend a smooth operating time of the around 3400 permanent connected O-VPN clients (after having attached memory in form of a 10Gb swap partition), we just recognized a hickout, where all clients got disconnected.


Unfortunately, after around 3270 disconnected clients, memory was'nt freed at all:


3270 /etc/openvpn/cgwvpn/persipoff


top - 10:31:58 up 31 days, 20:10,  2 users,  load average: 0.78, 0.70, 0.69

Tasks:  71 total,   2 running,  69 sleeping,   0 stoppe= d,   0 zombie

Cpu(s):  0.3%us, 23.2%sy,  0.0= %ni, 50.0%id,  0.0%wa, 14.4%hi,  0.0%si, 12.0%st

Mem:   7629920k total,  507357= 6k used,  2556344k free,   159504k buffers

Swap: 10485756k total,     &nb= sp;  0k used, 10485756k free,   192536k cached

PID USER         &nb= sp;PR  NI  VIRT      RES     SHR      S      %CPU     %MEM    TIME+       COMMAND

22810 root      20   0     4481m=   4.2g    1996   S      62.5            58.1       5102:38      o= penvpn

12619 root      20   0       8             4           0        R      3.0              0.0          0:00.09      openvpn

12222 root      20   0    15228   1216    932       R  0.3  0.0   0:00.02 top

Unfortunately, this is not something, we had expected.

We have not applied the patch yet, which brings back the "2.1" behavior.



freundlich gr=FCsst,
kind regards,


_________________________ _________________________ _______________________= __ _________________________ _________________________ ________________
Arno Odermatt
Phone +41414454053
arno.odermatt@...1845...

Schindler Elevator Ltd. | Corporate Research & Development | CRD/CO-BAT
Zugerstr. 13 | CH-6030 Ebikon, Switzerland

http://www.schindler.com
_________________________ _________________________ _______________________= __ _________________________ _________________________ ________________
Please consider your environment.


Schindler supports sustainable urban development with
safe, reliable and ecologically sound mobility solutions.






From:        
= Gert Doering <gert@...1296...>
To:        
Br= ad Zhang <hebei5000@...277...>,
Cc:        
op= envpn-devel@lists.sourceforge.net
Date:        
= 23.10.2013 16:20
Subject:        
Re: [Openvpn-devel] Does openvpn 2.3.2 has memory leak?





Hi,

On Sun, Oct 06, 2013 at 09:21:46PM +0800, Brad Zhang wrote:
> Do you have some idea about this issue?  Looking forward to your reply.

Coming back to *this* thread, after some debugging in the other thread
with Arno, I think what I can say so far is that we're observing two
different things:

- the first renegotiation brings a big jump in memory, but this is to
 be expected, because the new keying material needs extra memory, and
 the memory for the old key is not released right away (it seems to be
 released at the next renegotiation, or at client disconnect - I've
 seen VSZ/RSS go down(!) when clients disconnect, so that seems to
 work right).  This is the "big" jump in memory consum= ption which is
 actually killing Arno's setup, because there is not enough virtual  memory available to hold all that is needed for 3000 clients (but
 that can be fixed by increasing max-memory limits if there is enough
 RAM).

- each further renegotiation leaks "a few kbyte" of memory per client,
 which should also be fully returned when the client disconnects - this
 is the issue I discovered earlier, with the GC handling of the per-c= lient
 environment set, and I'll send a patch for that "soon" (as soon as I
 have fully understood the code involved).

Now, what I do not really understand is why the memory consumption on the 3rd, 4th, 5th renegotiation seems to slow down - there seems to be some
additional memory fragmentation involved in the 2nd+3rd renegotiation,
which leads to memory re-use later on.  Or so.

Testing this with "reneg-sec 60" is actually quite interesting...  here's
*disconnect* of a client:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     19892  0.0  0.0   7052  4304 pts/7    SN+  17:48   0:01 openvpn ../serv
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     19892  0.0  0.0   6300  3740 pts/7    SN+  17:48   0:01 openvpn ../serv

... so you can see that memory is returned to the OS.  (I think this will
not be visible if many clients are connected as the free()ed memory will
be "somewhere in the middle" - but disconnecting *all* clients should also
show memory being returned)

Now going to stare more at the code... :-)

gert


--
USENET is *not* the non-clickable part of WWW!
                                                         //www.muc.de/~gert/<= br> Gert Doering - Munich, Germany                             gert@...1296...
fax: +49-89-35655025                        gert@...1297...
[attachment "attxgxs6.dat" deleted by Arno Odermatt/R&D/SCH/S= CHINDLER] ---------------------------------------------------------------------------= ---
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >

http://p= ubads.g.doubleclick.net/gampad/clk?id=3D60135991&iu=3D/4140/ostg.clktrk= ____________ ______ _________________________ ____
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
=
https://lists.sourceforge.net/lis= ts/listinfo/openvpn-devel


******************************************************
Notice: The information contained in this message is intended only for use of the individual(s) named above and may contain confidential, propriet= ary or legally privileged information. No confidentiality or privilege is waived or lost by any mistransmission. If you are not the intended recipient of this message you are hereby notified that you must not use, disseminate , copy it in any form or take any action in reliance of it. If you have received this message in error please delete it and any copies of it and notify the sender immediately.
*******************************************************
---------------------------------------------------------------------= ---------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explor= e
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and regist= er
http://pubads.g.doublec= lick.net/gampad/clk?id=3D60136231&iu=3D/4140/ostg.clktrk__________________ _________________________ ____
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ope= nvpn-devel

******************************************************
Notice: The information contained in this message is intended only for use = of the individual(s) named above and may contain confidential, proprietary = or legally privileged information. No confidentiality or privilege is waive= d or lost by any mistransmission. If you are not the intended recipient of = this message you are hereby notified that you must not use, disseminate , c= opy it in any form or take any action in reliance of it. If you have receiv= ed this message in error please delete it and any copies of it and notify t= he sender immediately.
*******************************************************
--=_alternative 003625D8C1257C2B_=--