[MDEV-30889] Memory leak issues with MariaDB 10.6.12 and OOM Crashes Created: 2023-03-20 Updated: 2024-02-05 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Stored routines |
| Affects Version/s: | 10.6.12 |
| Fix Version/s: | 10.6 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Pravin Malali | Assignee: | Oleksandr Byelkin |
| Resolution: | Unresolved | Votes: | 10 |
| Labels: | None | ||
| Environment: |
OS - Debian Bullseye |
||
| Attachments: |
|
||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||
| Description |
|
The MariaDB consumes all memory allocated on the server and eventually crashes due to OOM
|
| Comments |
| Comment by Pravin Malali [ 2023-03-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Please see attached pattern of memory usage. The timings marked with downward arrows are when the DB service was restarted or crashed due to OOM. Also note how mariadb does not release memory back to the OS even after crash or restarts. Please see below .cnf configs we have:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-03-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
pravin_malali, thank you for the report. I see that your innodb_buffer_pool_size is 72GiB despite 64GiB in the configuration, and the total maximum memory usage is 94GiB. What kind of workload are you running? Any prepared statements or stored procedures? I wonder if this could be related to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Pravin Malali [ 2023-03-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes we run a lot of prepared statements and stored procedures. The load is very read heavy. The anomaly with innodb buffer pool size was weird too. After a restart it is reflecting the current value. We are running MariaDB 10.6.12 and we still have these issues. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-04-17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
JFYI, in PS/SP was found 4 memory leak, 3 fixed (in review), one in process of fixing... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-04-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have fixed 3 memory leaks (will be in the next release). Feedback is needed if it will hep. Also work of finding memory leaks continue... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vincent Jancso [ 2023-05-09 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I built 10.6.12 with the 3 fixes:
Unfortunately, still the same memory leaks. Looking forward to test with the 4th fix that is coming soon. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Pravin Malali [ 2023-05-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The MariaDB 10.6.13 came out on 10th of May 2023. Does it address the OOM issues? Or are we still waiting on a fix for this issue in general? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-06-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As you can see (comment above) we have fixed some issues, but the bugreport does not point something concrete (no test case and so on) so we are just trying find memory leaks and fix them. If you have something we can repeat you are welcome to share. Just now we are making tools to catch possible memory leaks in SP/PS and fix all what we have found (so far 3 of them). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vincent Jancso [ 2023-06-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We can reproduce memory leaks with the attached query. It's a typo3 instance which is doing a lot of SELECT queries with many nested subqueries. No prepared statements nor stored procedures nor virtual columns are used. Let me know If you need more informations. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-06-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I will try to reconstruct some database to the query, will see it it will behave the same | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2023-06-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Vincent, can you attach 'show create table' for the tables involved in the query ? insert into other_table (key1,key2,key3) select seq,seq,seq from seq_1_to_1000; If we can repeat the issue, then we can fix it! Please also add an EXPLAIN of the query so we can see what the optimizer is doing. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vincent Jancso [ 2023-06-08 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As it's a customer's database, I have to clarify if we can share the table definitions and data. In case I get the permission, do you have a secure way to share that data? Otherwise I will have to anonymize part of the data. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Tobias Schneider [ 2023-06-13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Good Morning, we do also experiencing a memory leak and just starting to analyze it. Is there any data I can provide to help you? Version: 10.6.13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Tobias Schneider [ 2023-06-13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We upgraded to 10.6.14. I will provide more information about the memory consumption on Thursday. Edit: We have still a memory leak with 10.6.14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vincent Jancso [ 2023-06-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I just uploaded a full dump and a query through your FTP. Best way to reproduce it is to run the query simultaneously (~10x) in an endless loop. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Lena Startseva [ 2023-06-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Possible scripts for filling with testdata, but it is needed to clarify the description of the tables and valid range of values for some columns, allowable range and statistic of values for some data:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-06-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
vrj95 Thank you a lot for the query and the dump, but I can not repeat memaory leack. I will try more but if you could you tell: 1) how the query executed (binary/text protocol) it can speed up the process... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-06-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Actually outputs of:
could be useful to detect which thread/comands lead to memory leack (and if the memory registered at all) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2023-06-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Could you do try to do a graph on If it increases then also doing And check with process increses max_memory_used the most. If the above memory_used does not increase, it could be that the problem is memory fragmentation and changing to use jemalloc may help. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2023-09-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I was looking at the graphs attached to the issue.
Having the output from 'select * from information_schema.processlist' done every 1/2 hour over some period of time would be very helpful in figuring out what is wrong. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vincent Jancso [ 2023-09-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sorry for the long delay. In collaboration with our customer, we managed to setup a replica of their production server so we can test around. I have disabled page caching of the typo3 instance and running a script that constantly makes some requests to the site. Please have a look at the graph. I can now fully reproduce it. RES size was about 800MB, Virtual Memory 5GB when I started yesterday. I also made a graph from SHOW GLOBAL STATUS LIKE "memory_used" as requested. It does not increase over time. I also logged the process list and uploaded it through your FTP (MDEV-30889-processlist.log) Regarding the settings: sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-09-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
vrj95, as global "memory_used" value isn't growing, it means the memory that the server can account for isn't leaking. It could still be a memory leak inside InnoDB or not a memory leak at all, but, for example, an extreme case of memory fragmentation that causes memory allocator to use more and more system memory. The latter is more likely, we've seen these cases before. You're likely using ptmalloc2, default glibc memory allocator. Can you try jemalloc or tcmalloc? A different allocator will have a different memory allocation strategy and often it is enough to fix the fragmentation problem. If you start MariaDB via mysqld_safe, run it with --malloc-lib=jemalloc or add this to your my.cnf. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vincent Jancso [ 2023-10-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sorry, I just realized I never mentioned that I'm using FreeBSD. This may be important for you. I originally posted to Under FreeBSD, it seems that jemalloc is the default memory allocator. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-10-02 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
For what it is worth, years ago in InnoDB there was a memory fragmentation issue that was fixed by reducing the number of heap memory allocations when tables are being added to the InnoDB data dictionary cache. I remember that the function dict_add_col_name() was added to address that. That change was bundled with a bigger change MySQL Bug #20877. My understanding is that memory allocator libraries have it easier if there are fewer memory allocation requests and they are of the same size. Hopefully there are some debugging tools that would report internal memory fragmentation in the allocator, and allows to find the malloc() or realloc() that are most contributing to it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vincent Jancso [ 2023-10-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I was able to switch to the tcmalloc allocator which seems to fix the problem. Both virtual and resident memory remains stable. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2023-10-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
When the user moved to use jemalloc, the OOM issues disappeared. Some of the things we can try is to allocate most all memory blocks of the same size, making some special handling of big blobs etc. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michal Dobroczynski [ 2023-11-13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We are currently being hit by this issue big time.
The first graph shows mem usage as reported by the monitoring. With `innodb_buffer_pool_size = 16G` it should not soar so high. Now I slashed it down to 12G (on a 32GB instance) - and after less than 24hrs it's on 76%. The second graph - I took VSIZE and RSS from `ps` (every minute). Both basically only go up. Can we safely jump on the jemalloc train or what are our options? Will upgrading to 10.6.15 change anything? I am not sure if there is any correlation, but innodb does preload some stuff from disk to speed up "warming up" if I remember correctly? Disabling that feature - or discarding the current "image"? We take regular backups (mysqldump, single transaction) - obviously during that time it tanks mem, but only after a fresh restart - and that is also expected (tanks below the innodb buffer pool). When I ask mariadb about the configured size, to be 100% sure no monkey business is involved: If there's anything I can do to help - let me know. This is our prod machine, so doing risky stuff is not really on the table, but I can spin a copy where I can run experiments. Thanks in advance for any advice on the subject. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-11-13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
there are many other allocations besides InnoDB buffer pool. check also
and
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michal Dobroczynski [ 2023-11-13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for your insight. Yes, I am aware of that, but unless there are thousands of connections it should not cause me much of a trouble? I am puzzled because previously when you allocated innodb buffer pool to be 70% of total RAM (dedicated DB machine) - then it would hold. Now when allocating 37.5% it goes south within 2-3 days. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vincent Jancso [ 2023-11-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Same problem with 10.6.16 @Michael Widenius Let me know if there's anything else I can do to help you find the cause. I still believe it may be caused by queries that have a lot of nested subqueries as the one I provided on 06/06/2023. Queries like this one caused the virtual memory to jump up by 400-500MB everytime I execute it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michal Dobroczynski [ 2023-11-21 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@Vincent Jancso The issue got completely out of hand here and I decided to follow the initial advice, i.e. `tcmalloc` or `jemalloc`. In my case it was the latter one. It solved the issue - although I am surprised that the fragmentation is going so much out of hand. I have similar workloads that run on the same version and are super stable. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-11-22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I think that it could be a useful exercise to evaluate and classify all malloc() calls that are executed for some rather short SQL input. When it comes to the InnoDB storage engine, I think that the situation was improved in the past by | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Roman Trapickin [ 2024-01-30 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We had a similar issue in our deployment with a containerized MariaDB 10.11.6. Memory usage was going up with the execution of our daily mysqldump backup and never went down. After some time the DB process was OOM killed. Memory usage curve was very similar to that of Michal. We gave the container up to 20 GB (overkill accroding to mysqltuner) of memory to no avail. In our case it was tcmalloc which solved the issue. We tried jemalloc too, which changed the course of the curve but not the tendency. FYI: cat /proc/buddyinfo listed very low numbers on the right side of the table. Memory chunks larger than 512 KiB were almost absent and there were plenty of very small chunks. It looks like a memory fragmentation issue indeed. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Bruno Bear [ 2024-02-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We still have this problem and tried to solve it with: disabling Transparent Huge Pages and using jemalloc, didnt helpt. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Carl-Philip Hänsch [ 2024-02-05 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
We also experience severe memory leaks that require a server reboot every 15 minutes to not run into OOM issues. Here's the setup: RAM Limit for MariaDB: 16 GB. Usage: 26.8G (84% of systems memory) The issue occurs after writing queries like UPDATE or INSERT, especially when TRIGGERs are involved. Server version: 10.11.6-MariaDB-1:10.11.6+maria~deb11 In the moment, we are porting a lot of projects to PostgreSQL to reduce the number of MariaDB crashes per hour. |