COLO: handling of the full primary or secondary queue
v5 cover COLO: handling of the full primary or secondary queue
The series is to handle the full primary or secondary queue in colo-compare.
Fix the "pkt" memory leak in packet_enqueue(). Reproduce steps:
1. Setup PVM and SVM both with NIC e1000 by the steps descripted in the wiki qemu/COLO
2. Run "iperf3 -s" in PVM
3. Run "iperf3 -c <PVM-IP> -t 7200" in client
The memory usage of qemu-system-x86_64 increases as the PVM's QMP shows "qemu-system-x86_64: colo compare secondary queue size too big, drop packet".
Please help to review, thanks.
V5:
- Replace the error_report of full queue with a trace event
- Remove handling of the full primary or secondary queue which hurt network throughput too much
V4:
- Remove redundant flush of packets
V3:
- handling of the full primary or secondary queue according to the suggestion from Zhang Chen
V2:
- Fix incorrect patch format
Derek Su (1):
colo-compare: Fix memory leak in packet_enqueue()
net/colo-compare.c | 23 +++++++++++++++-------- net/trace-events | 1 + 2 files changed, 16 insertions(+), 8 deletions(-)
Signature · 1 line
2.17.1
PATCH v5 1/1 colo-compare: Fix memory leak in packet_enqueue()
The patch is to fix the "pkt" memory leak in packet_enqueue(). The allocated "pkt" needs to be freed if the colo compare primary or secondary queue is too big.
Replace the error_report of full queue with a trace event.
--- net/colo-compare.c | 23 +++++++++++++++-------- net/trace-events | 1 + 2 files changed, 16 insertions(+), 8 deletions(-)
net/colo-compare.c +15 -8
@@ -122,6 +122,10 @@ enum { SECONDARY_IN, }; +static const char *colo_mode[] = { + [PRIMARY_IN ] ="primary" , + [SECONDARY_IN ] ="secondary" , +}; static int compare_chr_send(CompareState *s, const uint8_t *buf,
@@ -217,6 +221,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)ConnectionKey key;Packet *pkt =NULL ;Connection *conn; +int ret;if (mode ==PRIMARY_IN ) { pkt = packet_new(s->pri_rs.buf,
@@ -245,16 +250,18 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) }if (mode ==PRIMARY_IN ) { -if (!colo_insert_packet (&conn->primary_list, pkt, &conn->pack)) { -error_report ("colo compare primary queue size too big," -"drop packet" ); - } + ret =colo_insert_packet (&conn->primary_list, pkt, &conn->pack); }else { -if (!colo_insert_packet (&conn->secondary_list, pkt, &conn->sack)) { -error_report ("colo compare secondary queue size too big," -"drop packet" ); - } + ret =colo_insert_packet (&conn->secondary_list, pkt, &conn->sack); } + +if (!ret) { +trace_colo_compare_drop_packet (colo_mode[mode], +"queue size too big, drop packet" ); +packet_destroy (pkt,NULL ); + pkt =NULL ; + } + *con = conn;return 0 ;
net/trace-events +1 -0
@@ -12,6 +12,7 @@ colo_proxy_main(const char *chr) ": %s" # colo-compare.c colo_compare_main(const char *chr) ": %s" +colo_compare_drop_packet(const char *queue, const char *chr) ": %s: %s" colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s"
Signature · 1 line
2.17.1
RE: [PATCH v5 1/1] colo-compare: Fix memory leak in packet_enqueue()
Quoted 11 lines
-----Original Message-----
From: Derek Su <[email protected]>
Sent: Friday, April 10, 2020 10:01 AM
To: [email protected]
Cc: Zhang, Chen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Derek Su <[email protected]>
Subject: [PATCH v5 1/1] colo-compare: Fix memory leak inpacket_enqueue()
Quoted 6 lines
The patch is to fix the "pkt" memory leak in
packet_enqueue(). The allocated "pkt" needs to be freed if the colo compare primary or secondary queue is too big.Replace the
error_reportof full queue with a trace event.
Looks good for me. Thanks your contribution.
Thanks
Zhang Chen
Quoted 74 lines
Signed-off-by Derek Su <[email protected]>--- net/colo-compare.c | 23 +++++++++++++++-------- net/trace-events | 1 + 2 files changed, 16 insertions(+), 8 deletions(-)net/colo-compare.c index renamed from net/colo-compare.c +0
-0
10c0239f9d..035e11d4d3100644net/colo-compare.c +4
-0@@ -122,6 +122,10 @@ enum { SECONDARY_IN, }; +static const char *colo_mode[] = { + [PRIMARY_IN ] ="primary" , + [SECONDARY_IN ] ="secondary" , +};static int compare_chr_send (CompareState *s, const uint8_t *buf, @@ -217,6 +221,7 @@ static int
packet_enqueue(CompareState *s, int mode, Connection **con)ConnectionKey key; Packet *pkt = NULL; Connection *conn;+ int ret;
if (mode == PRIMARY_IN) { pkt = packet_new(s->pri_rs.buf, @@ -245,16 +250,18 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) } if (mode == PRIMARY_IN) {net/colo-compare.c +12
-8-if (!colo_insert_packet (&conn->primary_list, pkt, &conn->pack)) { -error_report ("colo compare primary queue size too big," -"drop packet" ); - } + ret =colo_insert_packet (&conn->primary_list, pkt, + &conn->pack); }else { -if (!colo_insert_packet (&conn->secondary_list, pkt, &conn->sack)) { -error_report ("colo compare secondary queue size too big," -"drop packet" ); - } + ret =colo_insert_packet (&conn->secondary_list, pkt, + &conn->sack); } + +if (!ret) { +trace_colo_compare_drop_packet (colo_mode[mode], +"queue size too big, drop packet" ); +packet_destroy (pkt,NULL ); + pkt =NULL ; + } + *con = conn;return 0 ;net/trace-events index renamed from net/trace-events +0
-0
02c13fd0ba..fa49c71533100644net/trace-events +1
-0@@ -12,6 +12,7 @@ colo_proxy_main(const char *chr) ": %s" # colo-compare.c colo_compare_main(const char *chr) ": %s" +colo_compare_drop_packet(const char *queue, const char *chr) ": %s: %s" colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize,const char *stc, const char *std) "ppkt size = %d,
ip_src= %s,ip_dst= %s, spkt size = %d,ip_src= %s,ip_dst= %s"
--
2.17.1
Re: [PATCH v5 1/1] colo-compare: Fix memory leak in packet_enqueue()
In reply to Derek SuQuoted 7 lines · On Fri, 10 Apr 2020 10:00:56 +0800 Derek Su <[email protected]> wrote:
The patch is to fix the "pkt" memory leak in
packet_enqueue(). The allocated "pkt" needs to be freed if the colo compare primary or secondary queue is too big.Replace the
error_reportof full queue with a trace event.Signed-off-by Derek Su <[email protected]>
Looks good now and works well in my tests.
Regards,
Lukas Straub
Quoted 67 lines
--- net/colo-compare.c | 23 +++++++++++++++-------- net/trace-events | 1 + 2 files changed, 16 insertions(+), 8 deletions(-)net/colo-compare.c +15
-8@@ -122,6 +122,10 @@ enum { SECONDARY_IN, }; +static const char *colo_mode[] = { + [PRIMARY_IN ] ="primary" , + [SECONDARY_IN ] ="secondary" , +}; static int compare_chr_send(CompareState *s, const uint8_t *buf,@@ -217,6 +221,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con)ConnectionKey key;Packet *pkt =NULL ;Connection *conn; +int ret;if (mode ==PRIMARY_IN ) { pkt = packet_new(s->pri_rs.buf,@@ -245,16 +250,18 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) }if (mode ==PRIMARY_IN ) { -if (!colo_insert_packet (&conn->primary_list, pkt, &conn->pack)) { -error_report ("colo compare primary queue size too big," -"drop packet" ); - } + ret =colo_insert_packet (&conn->primary_list, pkt, &conn->pack); }else { -if (!colo_insert_packet (&conn->secondary_list, pkt, &conn->sack)) { -error_report ("colo compare secondary queue size too big," -"drop packet" ); - } + ret =colo_insert_packet (&conn->secondary_list, pkt, &conn->sack); } + +if (!ret) { +trace_colo_compare_drop_packet (colo_mode[mode], +"queue size too big, drop packet" ); +packet_destroy (pkt,NULL ); + pkt =NULL ; + } + *con = conn;return 0 ;net/trace-events +1
-0@@ -12,6 +12,7 @@ colo_proxy_main(const char *chr) ": %s" # colo-compare.c colo_compare_main(const char *chr) ": %s" +colo_compare_drop_packet(const char *queue, const char *chr) ": %s: %s" colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize, const char *stc, const char *std) "ppkt size = %d, ip_src = %s, ip_dst = %s, spkt size = %d, ip_src = %s, ip_dst = %s"
RE: [PATCH v5 1/1] colo-compare: Fix memory leak in packet_enqueue()
Quoted 19 lines
-----Original Message-----
From: Lukas Straub <[email protected]>
Sent: Sunday, April 26, 2020 7:25 PM
To: Derek Su <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Zhang, Chen <[email protected]>; [email protected]
Subject: Re: [PATCH v5 1/1] colo-compare: Fix memory leak inpacket_enqueue()Quoted 4 lines · On Fri, 10 Apr 2020 10:00:56 +0800 Derek Su <[email protected]> wrote:
The patch is to fix the "pkt" memory leak in
packet_enqueue(). The allocated "pkt" needs to be freed if the colo compare primary or secondary queue is too big.
Quoted 8 lines
Quoted 3 lines
Replace the
error_reportof full queue with a trace event.Signed-off-by Derek Su <[email protected]>Looks good now and works well in my tests.
Reviewed-by Lukas Straub <[email protected]>Tested-by Lukas Straub <[email protected]>
I will queue this patch to COLO branch, then submit to Jason.
Thanks
Zhang Chen
Quoted 75 lines
Regards,
Lukas StraubQuoted 62 lines
--- net/colo-compare.c | 23 +++++++++++++++-------- net/trace-events | 1 + 2 files changed, 16 insertions(+), 8 deletions(-)net/colo-compare.c index renamed from net/colo-compare.c +0
-0
10c0239f9d..035e11d4d3100644net/colo-compare.c +4
-0@@ -122,6 +122,10 @@ enum { SECONDARY_IN, }; +static const char *colo_mode[] = { + [PRIMARY_IN ] ="primary" , + [SECONDARY_IN ] ="secondary" , +}; static int compare_chr_send(CompareState *s, const uint8_t *buf, @@ -217,6 +221,7 @@static int
packet_enqueue(CompareState *s, int mode, Connection **con)ConnectionKey key; Packet *pkt = NULL; Connection *conn;+ int ret;
if (mode == PRIMARY_IN) { pkt = packet_new(s->pri_rs.buf, @@ -245,16 +250,18 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) } if (mode == PRIMARY_IN) {net/colo-compare.c +12
-8-if (!colo_insert_packet (&conn->primary_list, pkt, &conn->pack)) { -error_report ("colo compare primary queue size too big," -"drop packet" ); - } + ret =colo_insert_packet (&conn->primary_list, pkt, + &conn->pack); }else { -if (!colo_insert_packet (&conn->secondary_list, pkt, &conn->sack)) { -error_report ("colo compare secondary queue size too big," -"drop packet" ); - } + ret =colo_insert_packet (&conn->secondary_list, pkt, + &conn->sack); } + +if (!ret) { +trace_colo_compare_drop_packet (colo_mode[mode], +"queue size too big, drop packet" ); +packet_destroy (pkt,NULL ); + pkt =NULL ; + } + *con = conn;return 0 ;net/trace-events index renamed from net/trace-events +0
-0
02c13fd0ba..fa49c71533100644net/trace-events colo_proxy_main(const char *chr) ": %s" · line 15
Quoted 4 lines
net/trace-events +1
-0@@ -12,6 +12,7 @@ colo_proxy_main(const char *chr) ": %s" # colo-compare.c colo_compare_main(const char *chr) ": %s" +colo_compare_drop_packet(const char *queue, const char *chr)": %s: %s"
net/trace-events colo_proxy_main(const char *chr) ": %s"
Quoted 3 lines
net/trace-events +0
-0colo_compare_udp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_icmp_miscompare(const char *sta, int size) ": %s = %d" colo_compare_ip_info(int psize, const char *sta, const char *stb, int ssize,const char *stc, const char *std) "ppkt size = %d,
ip_src= %s,ip_dst= %s, spkt size = %d,ip_src= %s,ip_dst= %s"