I noticed a steady increase in system memory use %age (as reported by sar) which I've tracked to MariaDB. It's does not seem to be related to db load: this increase is notmatched by an increasing number of queries.
I have the following size configuration:
key_buffer_size = 400000000
innodb_buffer_pool_size = 1210612736
Total there is 1.5GB, yet it's now topped out at 2.3GB on RSS memory.
Why is it getting so greedy? Can I get it to stick to its limits better? Or perhaps it is sticking to the limits on InnoDB but is using memory for something else, if so, is there a way to understand that so that I can adjust the configuration to keep the total memory use within a certain level? Or perhaps it's like Linux kernel and just uses all free memory for caching while it's free, but happily relinquishes it as needed?
I'm on MariaDB 10.3.22 on Debian 10 (Buster). The workload is a webserver (so I need to keep some memory for other processes: nginx+php). Happy to post more config if required.
With credit for the forumla due to Gordon's answer and the link therein, the following command will tell you how much your MySQL/MariaDB database needs:
(I am the OP and this gives 2.9GB as my total configured usage - time to lower some figures!)
The memory settings you listed are shared. There are also various buffers that are allocated per thread. Here is a link to a MySQL memory calculator:
https://www.mysqlcalculator.com/
If you want to limit the overall memory usage of MariaDB, assuming you installed it with
apt
/apt-get
, you should be able to accomplish this with systemd.resource-control(5).Call with root:
Enter the following configuration in the editor that shows up, tweak if you want:
Save and quit. It takes effect immediately and is backed by cgroup memory controller.
Let's pick this apart:
There is no "perfect" formula. The mysqlcalculator site has many flaws. As does any other site claiming to have a formula.
If you are using MyISAM (or a mixture of MyISAM and InnoDB), then see http://mysql.rjweb.org/doc.php/memory