MySQL Memory Monitoring Improvements in InnoDB 8.0.28
The article details the refactoring of memory monitoring in MySQL 8.0.28, introducing a new PFS metadata structure for precise tracking of memory allocations and deallocations across various components like Buffer Pool and user variables.
In MySQL 8.0.28, InnoDB introduced a new memory monitoring system called PFS (Performance Schema) metadata to replace the older method of wrapping malloc() and free(). The new system uses a unified metadata structure to track memory allocations and deallocations, improving accuracy and supporting modern C++ features.
The key components include:
memory_summary_by_account_by_event_name : Tracks memory from user and host perspectives.
memory_summary_by_host_by_event_name : Host-level memory tracking.
memory_summary_by_thread_by_event_name : Thread-level memory tracking.
memory_summary_by_user_by_event_name : User-level memory tracking.
memory_summary_global_by_event_name : Global memory tracking per event.
Each table provides columns like COUNT_ALLOC, SUM_NUMBER_OF_BYTES_ALLOC, CURRENT_COUNT_USED, and LOW_NUMBER_OF_BYTES_USED to analyze memory usage.
The new allocator uses a metadata structure embedded in allocated memory blocks, allowing precise tracking without modifying existing code. This supports modern C++ features and reduces coupling with Performance Schema.
An example shows how the allocator works, including the use of ut_new_pfx_t to store metadata and the allocate_trace and deallocate_trace functions for memory tracking.
The refactoring addresses limitations of the old method, such as lack of support for STL containers and modern C++ syntax, and improves extensibility by using a base allocator trait.
A case study demonstrates how this system helped diagnose a user's OOM issue caused by a memory leak in a stored procedure's variable history tracking.
Tencent Database Technology
Tencent's Database R&D team supports internal services such as WeChat Pay, WeChat Red Packets, Tencent Advertising, and Tencent Music, and provides external support on Tencent Cloud for TencentDB products like CynosDB, CDB, and TDSQL. This public account aims to promote and share professional database knowledge, growing together with database enthusiasts.
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.