Bug #100704 Potential memory leak in MySQL 8.0.19 + 8.0.20 + 8.0.21
Submitted: 1 Sep 2020 9:51 Modified: 24 Sep 2020 12:36
Reporter: NC NC Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0.21 OS:CentOS (8.1.1911)
Assigned to: CPU Architecture:x86

[1 Sep 2020 9:51] NC NC
Description:
Hi all,

I have opened this bug request because I think there is a memory leak in MySQL 8.0.X.
We have the problem which follows since we have replaced my 5.6 servers by 8.0.X servers.

After few days, my MySQL server consumes most of the ram of the machine.
I have seen this problem on all machines that we have migrated.
The migration consists to:
  - create a new cluster (master/slave) with CentOS 8.1.1911 + MySQL 8.0.X (new machines ; not an upgrade) to replace my previous cluster (CentOS 7 + MySQL 5.6)
  - migrate databases using a dump
  - plug the application on the new database

The virtual machines are dedicated to MySQL: there is no other server installed.

In DEV, TEST, PREPROD environment, we have 8 GB of memory per machine.
These machines are very, very little used:
  - we have a script executed every 4H to synchronize datas: we read data in another database and we update the MySQL database
  - the rest of the time, except if we have an ongoing development, we have no activity on these servers

If we restart the MySQL daemon, the consumed memory goes down instantaneously: so far it's logical.
But after few days, with a MySQL instance at rest, memory consumption is high.

For example at this moment:
# ps aux --sort -rss | grep "/usr/sbin/mysqld"
mysql    114529  0.3 83.3 8935968 6651624 ?     Ssl  Aug20  55:16 /usr/sbin/mysqld --defaults-file=/mnt/mysql/conf/my.cnf

-> we consumme 83.3%

Please see file in attachment for the complete analysis.

Is someone has an idea about our problem?
Is it a memory leak?

How to repeat:
Restart MySQL daemon

Wait few days
[1 Sep 2020 9:52] NC NC
Our complete analysis

Attachment: mysql_full_analysis.txt (text/plain), 138.88 KiB.

[8 Sep 2020 3:20] Masaksazu Shiobara
I had a similar problem with CentOS 8.1.1911 and MySQL 8.0.21.

But I resolve my problem by using tcmalloc.

https://dev.mysql.com/doc/refman/8.0/en/mysqld-safe.html#option_mysqld_safe_malloc-lib

Please try it.
[9 Sep 2020 3:53] jingbo zhao
Have you use the event scheduler? We use the event scheduler have caused memory leak.
[24 Sep 2020 12:36] MySQL Verification Team
Hi Mr. NC,

Thank you for your bug report.

However, this is not a bug.

Simply, you have some buffers that are too large, while these buffers are allocated for each thread that needs that infrastructure. Hence, for example 10 threads needing 1 Gb, means that only for that one thread buffer you are using 10 Gb.

This is all explained in our Reference Manual, where you can also find which buffers are local and which are thread specific.

Next, you are using Linux and its default malloc library tends to keep memory attached to the process that consumes most of it. This can be tuned out, or even better improved by changing a malloc library and there are several available.

In short:

Not A Bug.