performance – Why MySQL tends to use more and more swap while there is enough RAM?


I have a server with 64GB RAM and 64 GB swap.
It’s running MySQL 8.0.19 and few php scripts.

Here is my config:

innodb_buffer_pool_size=40G
innodb_buffer_pool_instances=4
innodb_buffer_pool_chunk_size=10G
sync_binlog=0
innodb_log_file_size=1G
innodb_ft_result_cache_limit=4000000000
max_heap_table_size=4G
tmp_table_size=4G
innodb_online_alter_log_max_size=512M
range_optimizer_max_mem_size=0
performance_schema="OFF"

This server is used for heavy calculations, maximum 5 scripts running at same time, no users.

The huge swap is necessary for rare cases when some script needs a lot of RAM for itself.

The more server works the more memory MySQL tries to consume. If I don’t restart it during few weeks it ends up with 90GB total memory consumed (~60RAM + ~30 in swap). And all of this degrades the performance drastically.

For now I don’t know any solution besides simple restart. It clears entire swap and makes MySQL restart with ~40GB RAM consumption.

Do you have any ideas how to make MySQL not use swap that much? Perhaps this happens when some PHP script allocates too much RAM and pushes MySQL’s memory into swap, but once that program finishes, MySQL doesn’t free swap as I supposed it should do.