Why MySQL Performance Schema Triggers OOM with Huge max_connections and How to Fix It
This article examines how enabling MySQL 5.6 performance_schema with extremely high max_connections causes excessive virtual memory usage, swap pressure, and eventual out‑of‑memory errors, presents test data, references the related bug, and offers practical recommendations and discussion questions.
Background
When an application runs out of memory (OOM) it is painful; similarly MySQL can hit OOM or swap when performance_schema is enabled with a very high max_connections setting.
Test Environment
A RedHat 6 virtual machine with 1 GB physical memory and a 2 GB swap partition was created. MySQL 5.6.16 was installed, performance_schema was turned on, and max_connections was set to 22 000.
Observations
MySQL started and quickly ran out of memory, producing OOM.
Log analysis showed performance_schema allocated large amounts of memory, causing swap usage and eventual OOM.
Reducing max_connections to 19 000 mitigated the issue.
Performance Data
Key metrics for different max_connections values (with performance_schema on) are:
2 000 connections – VIRT 3.2 GB, RSS 799 MB
5 000 connections – VIRT 3.9 GB, RSS 807 MB
10 000 connections – VIRT 4.8 GB, RSS 802 MB
20 000 connections – OOM (performance_schema on) or VIRT 1.5 GB, RSS 110 MB (performance_schema off)
MySQL 5.7 with the same load shows lower memory usage (VIRT 2.8 GB, RSS 199 MB) due to improvements in performance_schema memory allocation.
Conclusion
The MySQL 5.6 performance_schema has a known memory‑allocation bug when max_connections is set extremely high. The bug is tracked as MySQL Bug #68514 (https://bugs.mysql.com/bug.php?id=68514) and was addressed in MySQL 5.7, which introduces scalable memory allocation for performance_schema. In production it is recommended to keep performance_schema disabled unless needed.
Discussion Questions
How does Linux allocate memory to a process (memory layout)?
What do the VIRT and RSS fields in the top command represent?
Why can VIRT be larger than RAM + SWAP?
Is a VIRT larger than RAM + SWAP a problem?
Under what conditions does Linux start swapping?
When does an application encounter OOM on Linux and what is the OOM process?
How can you analyze the cause of swap or OOM for an application?
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Weidian Tech Team
The Weidian Technology Platform is an open hub for consolidating technical knowledge. Guided by a spirit of sharing, we publish diverse tech insights and experiences to grow and look ahead together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
