Bug #113367 | Memory of prepared statements is not released | ||
---|---|---|---|
Submitted: | 8 Dec 2023 2:42 | Modified: | 11 Dec 2023 7:14 |
Reporter: | Samuel Liang | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Prepared statements | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | CentOS |
Assigned to: | CPU Architecture: | Any |
[8 Dec 2023 2:42]
Samuel Liang
[8 Dec 2023 11:39]
MySQL Verification Team
Hi Mr. Liang, Thank you for your bug report. We have run your longish test case and repeated the memory allocation and observed that MySQL server had freed all the memory that sysbench generated with that test. We noticed that the amount of memory occupied by mysqld process was slightly smaller then during the test, but much larger then before the test began. We knew that it is how malloc library works, so we wrote a short C program and forced the OS to free memory by allocating and using all the gigabytes that were not released by malloc library. It works, as it usually does and we have done it so many times. Hence, it is not a bug. That is how malloc libraries work. They try to retain the memory with the process that is using it more, for the purpose that future allocations are much faster, so that kernel calls do not have to be made. Hence, this is not a bug at all, this is just how malloc libraries work ..... Not a bug.
[11 Dec 2023 7:14]
Samuel Liang
Hi MySQL I used the below code check the memory but it was released. Does My SQL use a different way? First the application's memory was 12.0g (Please see RES). PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 10875 root 20 0 12.0g 12.0g 2532 S 0.0 19.5 0:06.44 test02 Then it reduced to 2732 bytes. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 10875 root 20 0 18768 2732 2532 S 0.0 0.0 0:07.07 test02 #include <cstdlib> #include <string.h> #include <stdio.h> #include <iostream> using namespace std; int main() { cout << "!!!malloc 12G!!!" << endl; char* mem_1g[10]; for (int i = 0; i < 12; i++) { mem_1g[i] = (char*)malloc(1024*1024*1024); memset(mem_1g[i],'$', 1024*1024*1024); } getchar(); cout << "!!!free 12G!!!" << endl; for (int i = 0; i < 12; i++) { free(mem_1g[i]); } getchar(); return 0; }
[11 Dec 2023 11:16]
MySQL Verification Team
Hi Mr. Liang, Thank you ...... However, we must repeat that this has nothing to do with MySQL's memory allocation. This is all done by system's malloc library which is dynamically linked, by OS, to mysqld process. Not a bug/