LP #1710939: Run multiple INSERT values (data),(data)...(data) allocates too much memory

Description

**Reported in Launchpad by Marcelo Henrique Gonçalves last update 05-12-2017 18:55:52

Hi,

I would like you to test one problem I was able to reproduce and it is completely compatible with the scenario described here.
I reproduced the memory growth with and without libjemalloc lib in use.

How I reproduced a memory issue that can be related to this one.

1) Startup a new Percona Server Instance (5.6 or 5.7, I think both are affected) I used 5.6.36.
2) Setup only 1 variable in my.cnf: max_allowed_packet=96M

3) Create a dummy table like this one:

create database db;
use db;
create table db.dummy (acol bigint, anything varchar(256)) engine=innodb;

4) Create a SQL file (load_test.sql) like this one:
INSERT INTO db.dummy VALUES
(1,'This is a dummy value'),
(1,'This is a dummy value'),
...
(1,'This is a dummy value');

5) Repeat the values until you reach a file size bigger than 64MB. It needs to be bigger than 64MB and smaller then max_allowed_packet.

6) Take note of memory allocation and how it is.

7) Run the following:
mysql db < load_test.sql ; vmstat -S m 2 100

This might cause mysqld memory to explode! Run with bigger file size, bigger max_allowed_packet if needed.

Environment

None

Smart Checklist

Activity

Show:

lpjirasync January 22, 2018 at 2:51 PM

**Comment from Launchpad by: Marcelo Henrique Gonçalves on: 05-12-2017 18:55:52

Hi,

We do see a server in 5.6 crashing constantly because of lack of memory on the server. Memory explodes easily when loading files with LOAD or multiple INSERT. Are you sure this is an invalid bug for 5.6?
Version: 5.6.36-82.0-log Percona Server (GPL), Release 82.0, Revision 58e846a

Linux crashed again because of lack of memory:
Linux 4.9.62-21.56.amzn1.x86_64 #1 SMP Thu Nov 16 05:37:08 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

#######Output of sar -r:
01:40:01 PM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit
01:50:01 PM 2718156 12683972 82.35 152180 2574512 5082832 29.05
02:00:01 PM 2715168 12686960 82.37 152568 2574724 5091108 29.09
02:10:01 PM 2715704 12686424 82.37 152952 2575016 5086576 29.07
02:20:01 PM 2714540 12687588 82.38 153420 2575236 5090164 29.09
02:30:01 PM 2643552 12758576 82.84 156644 2577432 5091668 29.10
02:40:01 PM 2642828 12759300 82.84 157048 2577640 5086068 29.06
02:50:01 PM 2641996 12760132 82.85 157416 2577860 5086768 29.07
03:00:01 PM 2640388 12761740 82.86 157808 2578076 5080992 29.04
03:10:01 PM 2640800 12761328 82.85 158192 2578364 5084248 29.05
03:20:01 PM 2639740 12762388 82.86 158472 2578584 5094484 29.11
03:30:01 PM 2639484 12762644 82.86 158876 2578804 5090928 29.09
03:40:01 PM 2638936 12763192 82.87 159176 2579024 5085192 29.06
03:50:01 PM 2637984 12764144 82.87 159488 2579244 5076964 29.01
04:00:01 PM 2636660 12765468 82.88 159844 2579468 5075912 29.01
04:10:01 PM 2636104 12766024 82.88 160184 2579752 5092508 29.10
04:20:01 PM 2636724 12765404 82.88 160548 2579972 5089448 29.08
04:30:01 PM 2630276 12771852 82.92 161900 2580592 5090984 29.09
04:40:01 PM 2629792 12772336 82.93 162308 2580800 5083364 29.05
04:50:01 PM 2627088 12775040 82.94 162712 2581048 5093204 29.11
05:00:01 PM 2623780 12778348 82.96 163468 2581388 5089148 29.08
05:10:01 PM 2617808 12784320 83.00 165128 2582144 5086660 29.07
05:20:01 PM 2610820 12791308 83.05 166616 2582760 5090880 29.09
05:30:01 PM 2610120 12792008 83.05 167084 2582980 5089528 29.08
05:40:01 PM 2602844 12799284 83.10 168732 2583560 5088280 29.08
05:50:01 PM 2602228 12799900 83.10 168980 2583776 5082756 29.05
06:00:01 PM 2600048 12802080 83.12 169316 2583996 5087040 29.07
06:10:01 PM 2600272 12801856 83.12 169632 2584288 5091264 29.09
06:20:01 PM 996248 14405880 93.53 8156 366260 5092992 29.10
Average: 2732253 12669875 82.26 136568 2531603 5088746 29.08

06:45:47 PM LINUX RESTART
user@hostname: ~ $ free -m
total used free shared buffers cached
Mem: 15041 2862 12179 0 16 720
-/+ buffers/cache: 2125 12915
Swap: 2047 0 2047

##########RELATED PARAMETERS
join_buffer_size=7340032
key_buffer_size=20971520
read_buffer_size=131072
read_rnd_buffer_size=262144
sort_buffer_size=524288
table_definition_cache=4096
table_open_cache=4096
table_open_cache_instances=8
thread_cache_size=32
innodb_buffer_pool_instances=4
innodb_buffer_pool_size=4G
innodb_sort_buffer_size=1048576
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1
innodb_log_buffer_size=8388608
query_cache_size=0
query_cache_type=0
max_connections=512

lpjirasync January 22, 2018 at 2:51 PM

**Comment from Launchpad by: Vlad Lesin on: 05-12-2017 18:23:35

The full massif output is attached.

lpjirasync January 22, 2018 at 2:50 PM

**Comment from Launchpad by: Vlad Lesin on: 05-12-2017 17:37:22

I am running the following test under valgring massif tool to understand the reason of the leak:

=============test begin==============
CREATE TABLE t (a BIGINT, b VARCHAR(256)) ENGINE=InnoDB;
--let INSERT_FILE_NAME = $MYSQLTEST_VARDIR/tmp/big-insert.sql
--let MAX_INSERT_SIZE=`SELECT @@max_allowed_packet`

--echo # GENERATE BIG "INSERT" STATEMENT
perl;
my $fname= $ENV{INSERT_FILE_NAME};
open(my $fh, '>', $fname) or die "Failed to open $fname: $!\n";
my $max_size = $ENV{MAX_INSERT_SIZE};
my $header = "INSERT INTO t VALUES\n";
my $values = "(1,'This is a dummy value'),\n";
my $footer = "(1,'This is a dummy value');";
my $cur_size = length($header) + length($footer);
my $max_size_without_footer = $max_size - length($footer);
print $fh $header;
while ($cur_size < $max_size_without_footer) {
print $fh $values;
$cur_size += length($values);
}
print $fh $footer;
close $fh;
EOF

SELECT * FROM sys.memory_global_total;
--echo # EXECUTE BIG "INSERT" STATEMENT
--disable_query_log
--source $INSERT_FILE_NAME
--enable_query_log
SELECT * FROM sys.memory_global_total;

--echo # SLEEP
SELECT SLEEP(600);
SELECT * FROM sys.memory_global_total;
--echo # EXECUTE BIG "INSERT" STATEMENT
--disable_query_log
--source $INSERT_FILE_NAME
--enable_query_log
SELECT * FROM sys.memory_global_total;

--echo # CLEANUP
--remove_file $INSERT_FILE_NAME
DROP TABLE t;
=============test end==============

To run this test the following fix is required:

=========mysqltest fix begin===========
— a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -6964,7 +6964,7 @@ bool is_delimiter(const char* p)
terminated by new line '\n' regardless how many "delimiter" it contain.
*/

-#define MAX_QUERY (256*1024*2) /* 256K – a test in sp-big is >128K */
+#define MAX_QUERY (500*1024*1024)
static char read_command_buf[MAX_QUERY];

int read_command(struct st_command** command_ptr)
=========mysqltest fix end===========

What I see is that the big amount of memory is allocated to parse and process a big statement. For example, for the statement of 300M length about 6G memory is allocated. After this the most of the memory is deallocated, but about several hundreds of megabytes still stays allocated. And this might be the leak we are looking for. But what is bothering me is that 6G. If the customer's process is killed by OOM then the reason is most likely in the amount of memory allocated for statement parsing and processing, but not in the leak.

This is the result of the above test for 300M file:

======the result 300M=======
worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 13000..13009
CREATE TABLE t (a BIGINT, b VARCHAR(256)) ENGINE=InnoDB;

  1. GENERATE BIG "INSERT" STATEMENT
    SELECT * FROM sys.memory_global_total;
    total_allocated
    127.64 MiB

  2. EXECUTE BIG "INSERT" STATEMENT
    SELECT * FROM sys.memory_global_total;
    total_allocated
    427.65 MiB

  3. SLEEP
    SELECT SLEEP(60);
    SLEEP(60)
    0
    SELECT * FROM sys.memory_global_total;
    total_allocated
    427.65 MiB

  4. EXECUTE BIG "INSERT" STATEMENT
    worker[1] Trying to dump core for [mysqltest - pid: 32505, winpid: 32505]
    worker[1] Trying to dump core for [mysqld.1 - pid: 32467, winpid: 32467]
    ======the result 300M end=======

As we can see the difference between the size of allocated memory before the statement and after it is about 300M. And the test fails with crash with the following backtrace:

=====the backtrace=====
Program terminated with signal SIGABRT, Aborted.
#0 __pthread_kill (threadid=<optimized out>, signo=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:62
62 ../sysdeps/unix/sysv/linux/pthread_kill.c: No such file or directory.
[Current thread is 1 (Thread 0x7ff8b4384740 (LWP 32468))]
#0 __pthread_kill (threadid=<optimized out>, signo=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:62
#1 0x00000000019c4155 in my_write_core (sig=6) at ./mysys/stacktrace.c:249
#2 0x0000000000f42a90 in handle_fatal_signal (sig=6) at ./sql/signal_handler.cc:223
#3 <signal handler called>
#4 0x00007ff8b27a570d in poll () at ../sysdeps/unix/syscall-template.S:84
#5 0x00000000017a9e1f in Mysqld_socket_listener::listen_for_connection_event (this=0x53f1ce0) at ./sql/conn_handler/socket_connection.cc:876
#6 0x0000000000f3b4b3 in Connection_acceptor<Mysqld_socket_listener>::connection_event_loop (this=0x53c5930) at ./sql/conn_handler/connection_acceptor.h:66
#7 0x0000000000f32a2a in mysqld_main (argc=94, argv=0x4e13268) at ./sql/mysqld.cc:5373
#8 0x0000000000f28d86 in main (argc=9, argv=0x7ffd8abb4228) at ./sql/main.cc:25
=====the backtrace end=====

Let's now look at the result and massif output for 150M statement.

=====the result of 150M=====
CREATE TABLE t (a BIGINT, b VARCHAR(256)) ENGINE=InnoDB;

  1. GENERATE BIG "INSERT" STATEMENT
    SELECT * FROM sys.memory_global_total;
    total_allocated
    117.14 MiB

  2. EXECUTE BIG "INSERT" STATEMENT
    SELECT * FROM sys.memory_global_total;
    total_allocated
    276.00 MiB

  3. SLEEP
    SELECT SLEEP(600);
    SLEEP(600)
    0
    SELECT * FROM sys.memory_global_total;
    total_allocated
    275.99 MiB

  4. EXECUTE BIG "INSERT" STATEMENT
    SELECT * FROM sys.memory_global_total;
    total_allocated
    276.01 MiB

  5. CLEANUP
    DROP TABLE t;
    =====the result of 150M end=====

This is the complete memory usage graphic. So for 150M statement parsing and processing we can see that about 3G of memory is used.

GB
3.249^ @

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
0 +----------------------------------------------------------------------->h
0 2.192

Let's see the snapshot for the "sleep" period:

-------------------------------------------------------------------------------- n time(ms) total(B) useful-heap(B) extra-heap(B) stacks(B)
-------------------------------------------------------------------------------- 255 3,674,655 263,376,328 263,293,265 83,063 0
99.97% (263,293,265B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->61.59% (162,217,441B) 0x19AC8E5: my_raw_malloc (my_malloc.c:191)

->61.59% (162,217,441B) 0x19AC4D1: my_malloc (my_malloc.c:54)

->59.75% (157,367,570B) 0x19AC617: my_realloc (my_malloc.c:88)

 

->59.72% (157,286,439B) 0x1540BF9: net_realloc (net_serv.cc:168)

 

 

->59.72% (157,286,439B) 0x1541CF4: net_read_packet(st_net*, unsigned long*) (net_serv.cc:855)

 

 

->59.72% (157,286,439B) 0x1541DFC: my_net_read (net_serv.cc:909)

 

 

 

->59.72% (157,286,439B) 0x1559D80: Protocol_classic::read_packet() (protocol_classic.cc:808)

 

 

 

->59.72% (157,286,439B) 0x155A281: Protocol_classic::get_command(COM_DATA*, enum_server_command*) (protocol_classic.cc:965)

 

 

 

->59.72% (157,286,439B) 0x16433C6: do_command(THD*) (sql_parse.cc:960)

 

 

 

->59.72% (157,286,439B) 0x1795AF0: handle_connection (connection_handler_per_thread.cc:312)

 

 

 

->59.72% (157,286,439B) 0x1E05ED7: pfs_spawn_thread (pfs.cc:2188)

 

 

 

->59.72% (157,286,439B) 0x58996B8: start_thread (pthread_create.c:333)

 

 

 

->59.72% (157,286,439B) 0x64573DB: clone (clone.S:109)

Here we can see that the memory was allocated for input buffer. It stays allocated while connection is active, and it is deallocated when connection is broken.

I would not consider this as memory leak.

Ok, let's look on what exactly such big amount of memory(~3G) is allocated:

->97.10% (3,386,602,393B) 0x19AC8E5: my_raw_malloc (my_malloc.c:191)

->97.10% (3,386,602,393B) 0x19AC4D1: my_malloc (my_malloc.c:54)

->92.51% (3,226,443,504B) 0x19A5120: alloc_root (my_alloc.c:279)

 

->45.05% (1,571,263,520B) 0xF28260: Item::operator new(unsigned long, st_mem_root*) (item.h:771)

 

 

->23.14% (806,974,656B) 0x17C7AC1: MYSQLparse(THD*) (sql_yacc.yy:12985)

 

 

 

->23.14% (806,974,656B) 0x1654193: parse_sql(THD*, Parser_state*, Object_creation_ctx*) (sql_parse.cc:7486)

 

 

 

->23.14% (806,974,656B) 0x1650603: mysql_parse(THD*, Parser_state*) (sql_parse.cc:5787)

 

 

 

->23.14% (806,974,656B) 0x16449AD: dispatch_command(THD*, COM_DATA const*, enum_server_command) (sql_parse.cc:1493)

 

 

 

->23.14% (806,974,656B) 0x164374E: do_command(THD*) (sql_parse.cc:1021)

 

 

 

->23.14% (806,974,656B) 0x1795AF0: handle_connection (connection_handler_per_thread.cc:312)

 

 

 

->23.14% (806,974,656B) 0x1E05ED7: pfs_spawn_thread (pfs.cc:2188)

 

 

 

->23.14% (806,974,656B) 0x58996B8: start_thread (pthread_create.c:333)

 

 

 

->23.14% (806,974,656B) 0x64573DB: clone (clone.S:109)

 

 

 

 

 

->21.91% (764,280,672B) 0x17C83C4: MYSQLparse(THD*) (sql_yacc.yy:13096)

 

 

 

->21.91% (764,280,672B) 0x1654193: parse_sql(THD*, Parser_state*, Object_creation_ctx*) (sql_parse.cc:7486)

 

 

 

->21.91% (764,280,672B) 0x1650603: mysql_parse(THD*, Parser_state*) (sql_parse.cc:5787)

 

 

 

->21.91% (764,280,672B) 0x16449AD: dispatch_command(THD*, COM_DATA const*, enum_server_command) (sql_parse.cc:1493)

 

 

 

->21.91% (764,280,672B) 0x164374E: do_command(THD*) (sql_parse.cc:1021)

 

 

 

->21.91% (764,280,672B) 0x1795AF0: handle_connection (connection_handler_per_thread.cc:312)

 

 

 

->21.91% (764,280,672B) 0x1E05ED7: pfs_spawn_thread (pfs.cc:2188)

 

 

 

->21.91% (764,280,672B) 0x58996B8: start_thread (pthread_create.c:333)

 

 

 

->21.91% (764,280,672B) 0x64573DB: clone (clone.S:109)

 

 

 

 

 

->00.00% (8,192B) in 1+ places, all below ms_print's threshold (01.00%)

 

 

 

->23.11% (805,984,096B) 0x175DAE6: sql_alloc(unsigned long) (thr_malloc.cc:39)

 

 

->13.14% (458,307,296B) 0xF52390: Sql_alloc::operator new(unsigned long) (sql_alloc.h:30)

 

 

 

->13.14% (458,307,296B) 0xF653EF: base_list::push_back(void*) (sql_list.h:195)

 

 

 

 

->10.33% (360,426,144B) 0xF67547: List<Item>::push_back(Item*) (sql_list.h:545)

 

 

 

 

 

->10.33% (360,426,144B) 0x17D6104: PT_item_list::push_back(Item*) (parse_tree_helpers.h:87)

 

 

 

 

 

 

->06.24% (217,721,216B) 0x17C36BE: MYSQLparse(THD*) (sql_yacc.yy:11731)

 

 

 

 

 

 

 

->06.24% (217,721,216B) 0x1654193: parse_sql(THD*, Parser_state*, Object_creation_ctx*) (sql_parse.cc:7486)

 

 

 

 

 

 

 

->06.24% (217,721,216B) 0x1650603: mysql_parse(THD*, Parser_state*) (sql_parse.cc:5787)

 

 

 

 

 

 

 

->06.24% (217,721,216B) 0x16449AD: dispatch_command(THD*, COM_DATA const*, enum_server_command) (sql_parse.cc:1493)

 

 

 

 

 

 

 

->06.24% (217,721,216B) 0x164374E: do_command(THD*) (sql_parse.cc:1021)

 

 

 

 

 

 

 

->06.24% (217,721,216B) 0x1795AF0: handle_connection (connection_handler_per_thread.cc:312)

 

 

 

 

 

 

 

->06.24% (217,721,216B) 0x1E05ED7: pfs_spawn_thread (pfs.cc:2188)

 

 

 

 

 

 

 

->06.24% (217,721,216B) 0x58996B8: start_thread (pthread_create.c:333)

 

 

 

 

 

 

 

->06.24% (217,721,216B) 0x64573DB: clone (clone.S:109)

 

 

 

 

 

 

 

 

 

 

 

 

 

->04.09% (142,704,928B) 0x17C374F: MYSQLparse(THD*) (sql_yacc.yy:11738)

 

 

 

 

 

 

->04.09% (142,704,928B) 0x1654193: parse_sql(THD*, Parser_state*, Object_creation_ctx*) (sql_parse.cc:7486)

 

 

 

 

 

 

->04.09% (142,704,928B) 0x1650603: mysql_parse(THD*, Parser_state*) (sql_parse.cc:5787)

 

 

 

 

 

 

->04.09% (142,704,928B) 0x16449AD: dispatch_command(THD*, COM_DATA const*, enum_server_command) (sql_parse.cc:1493)

 

 

 

 

 

 

->04.09% (142,704,928B) 0x164374E: do_command(THD*) (sql_parse.cc:1021)

 

 

 

 

 

 

->04.09% (142,704,928B) 0x1795AF0: handle_connection (connection_handler_per_thread.cc:312)

 

 

 

 

 

 

->04.09% (142,704,928B) 0x1E05ED7: pfs_spawn_thread (pfs.cc:2188)

 

 

 

 

 

 

->04.09% (142,704,928B) 0x58996B8: start_thread (pthread_create.c:333)

 

 

 

 

 

 

->04.09% (142,704,928B) 0x64573DB: clone (clone.S:109)

 

 

 

 

 

 

 

 

 

 

 

->00.00% (0B) in 1+ places, all below ms_print's threshold (01.00%)

 

 

 

 

 

 

 

 

 

->02.81% (97,881,152B) 0x17E2063: List<List<Item> >::push_back(List<Item>*) (sql_list.h:545)

 

 

 

 

->02.81% (97,881,152B) 0x17DDC29: PT_insert_values_list::push_back(List<Item>*) (parse_tree_nodes.h:2584)

 

 

 

 

->02.81% (97,881,152B) 0x17C357B: MYSQLparse(THD*) (sql_yacc.yy:11692)

 

 

 

 

->02.81% (97,881,152B) 0x1654193: parse_sql(THD*, Parser_state*, Object_creation_ctx*) (sql_parse.cc:7486)

 

 

 

 

->02.81% (97,881,152B) 0x1650603: mysql_parse(THD*, Parser_state*) (sql_parse.cc:5787)

 

 

 

 

->02.81% (97,881,152B) 0x16449AD: dispatch_command(THD*, COM_DATA const*, enum_server_command) (sql_parse.cc:1493)

 

 

 

 

->02.81% (97,881,152B) 0x164374E: do_command(THD*) (sql_parse.cc:1021)

 

 

 

 

->02.81% (97,881,152B) 0x1795AF0: handle_connection (connection_handler_per_thread.cc:312)

 

 

 

 

->02.81% (97,881,152B) 0x1E05ED7: pfs_spawn_thread (pfs.cc:2188)

 

 

 

 

->02.81% (97,881,152B) 0x58996B8: start_thread (pthread_create.c:333)

 

 

 

 

->02.81% (97,881,152B) 0x64573DB: clone (clone.S:109)

 

 

 

 

 

 

 

->00.00% (0B) in 1+ places, all below ms_print's threshold (01.00%)

 

 

 

 

 

->09.96% (347,309,248B) 0x175DC9D: sql_strmake_with_convert(char const*, unsigned long, charset_info_st const*, unsigned long, charset_info_st const*, unsigned long*) (thr_malloc.cc:93)

 

 

 

->09.96% (347,309,248B) 0xFE42BE: Name_string::copy(char const*, unsigned long, charset_info_st const*) (item.cc:1153)

 

 

 

->09.96% (347,309,248B) 0xF6694C: Item_string::init(char const*, unsigned long, charset_info_st const*, Derivation, unsigned int) (item.h:3642)

 

 

 

->09.96% (347,309,248B) 0x17E025B: PTI_text_literal_text_string::itemize(Parse_context*, Item**) (parse_tree_items.h:490)

 

 

 

->09.96% (347,309,248B) 0x185F38F: PT_insert_values_list::contextualize(Parse_context*) (parse_tree_nodes.cc:846)

 

 

 

->09.96% (347,309,248B) 0x185F6C1: PT_insert::contextualize(Parse_context*) (parse_tree_nodes.cc:913)

 

 

 

->09.96% (347,309,248B) 0x185F951: PT_insert::make_cmd(THD*) (parse_tree_nodes.cc:953)

 

 

 

->09.96% (347,309,248B) 0x17A5C73: MYSQLparse(THD*) (sql_yacc.yy:1691)

 

 

 

->09.96% (347,309,248B) 0x1654193: parse_sql(THD*, Parser_state*, Object_creation_ctx*) (sql_parse.cc:7486)

 

 

 

->09.96% (347,309,248B) 0x1650603: mysql_parse(THD*, Parser_state*) (sql_parse.cc:5787)

 

 

 

->09.96% (347,309,248B) 0x16449AD: dispatch_command(THD*, COM_DATA const*, enum_server_command) (sql_parse.cc:1493)

 

 

 

->09.96% (347,309,248B) 0x164374E: do_command(THD*) (sql_parse.cc:1021)

 

 

 

->09.96% (347,309,248B) 0x1795AF0: handle_connection (connection_handler_per_thread.cc:312)

 

 

 

->09.96% (347,309,248B) 0x1E05ED7: pfs_spawn_thread (pfs.cc:2188)

 

 

 

->09.96% (347,309,248B) 0x58996B8: start_thread (pthread_create.c:333)

 

 

 

->09.96% (347,309,248B) 0x64573DB: clone (clone.S:109)

 

 

 

 

 

->00.01% (367,552B) in 1+ places, all below ms_print's threshold (01.00%)

 

 

 

->12.48% (435,359,600B) 0xF66B17: Query_arena::alloc(unsigned long) (sql_class.h:825)

 

 

->04.51% (157,286,440B) 0x160D91D: Lex_input_stream::init(THD*, char const*, unsigned long) (sql_lex.cc:187)

 

 

 

->04.51% (157,286,440B) 0xF7918E: Parser_state::init(THD*, char const*, unsigned long) (sql_lex.h:3668)

 

 

 

->04.51% (157,286,440B) 0x164498C: dispatch_command(THD*, COM_DATA const*, enum_server_command) (sql_parse.cc:1490)

 

 

 

 

->04.51% (157,286,440B) 0x164374E: do_command(THD*) (sql_parse.cc:1021)

 

 

 

 

->04.51% (157,286,440B) 0x1795AF0: handle_connection (connection_handler_per_thread.cc:312)

 

 

 

 

->04.51% (157,286,440B) 0x1E05ED7: pfs_spawn_thread (pfs.cc:2188)

 

 

 

 

->04.51% (157,286,440B) 0x58996B8: start_thread (pthread_create.c:333)

 

 

 

 

->04.51% (157,286,440B) 0x64573DB: clone (clone.S:109)

 

 

 

 

 

 

 

->00.00% (0B) in 1+ places, all below ms_print's threshold (01.00%)

So the most memory is allocated for parsing. This is how parser currently works, and we can do nothing with it.

Conclusion:

1) There is no memory leak, what we can see is just network buffer expanding. The buffer itself is deallocated on connection finishing.

2) Current parser can consume up to 20x more memory the statement length, and we can do nothing with it.

lpjirasync January 22, 2018 at 2:50 PM

**Comment from Launchpad by: Marcelo Henrique Gonçalves on: 25-10-2017 21:36:36

Thank you very much Sveta,

I kindly ask your attention to one point.
I could not see the memory going free but the allocation of memory was much higher than expected in 5.6. The case is that it caused OOM and MySQL was killed.
So, one of the concern is that for a file of near 72MB of load, the memory went above 2GB even for very limited buffer_pool.
The main reason of this ticket is an issue in 5.6 loading file using a 256MB sql with multiple rows insert exploding memory in several Gigas and being killed by OOM.

Please, assess if this makes sense.

Thank you
Marcelo

lpjirasync January 22, 2018 at 2:50 PM

**Comment from Launchpad by: Sveta Smirnova on: 25-10-2017 18:29:46

I can repeat memory leak only with version 5.7. Version 5.5 and 5.6 free memory after job done.

Done

Details

Assignee

Reporter

Priority

Smart Checklist

Created January 22, 2018 at 2:48 PM
Updated December 19, 2023 at 7:44 AM
Resolved January 22, 2018 at 2:49 PM