mysqld eats more than 16 GB of memory on startup
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MySQL Server |
Unknown
|
Unknown
|
|||
mysql-5.7 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
(this bug has been reproduced in an LXC container running on Arch Linux, that's why the strange kernel version)
On Ubuntu 18.04, systemd runs mysqld in two steps. First:
ExecStartPre=
In this script, one of the steps is: mysqld --verbose --help --innodb-read-only
Then:
ExecStart=
It's the first mysqld (with --help) which is a problem. The problem happens because, due to PermissionsStar
Aug 08 18:19:23 mysql57 bash[13131]: core file size (blocks, -c) unlimited
Aug 08 18:19:23 mysql57 bash[13131]: data seg size (kbytes, -d) unlimited
Aug 08 18:19:23 mysql57 bash[13131]: scheduling priority (-e) 0
Aug 08 18:19:23 mysql57 bash[13131]: file size (blocks, -f) unlimited
Aug 08 18:19:23 mysql57 bash[13131]: pending signals (-i) 63701
Aug 08 18:19:23 mysql57 bash[13131]: max locked memory (kbytes, -l) 16384
Aug 08 18:19:23 mysql57 bash[13131]: max memory size (kbytes, -m) unlimited
Aug 08 18:19:23 mysql57 bash[13131]: open files (-n) 1073741816 <--- see this?
Aug 08 18:19:23 mysql57 bash[13131]: pipe size (512 bytes, -p) 8
Aug 08 18:19:23 mysql57 bash[13131]: POSIX message queues (bytes, -q) 819200
Aug 08 18:19:23 mysql57 bash[13131]: real-time priority (-r) 0
Aug 08 18:19:23 mysql57 bash[13131]: stack size (kbytes, -s) 8192
Aug 08 18:19:23 mysql57 bash[13131]: cpu time (seconds, -t) unlimited
Aug 08 18:19:23 mysql57 bash[13131]: max user processes (-u) 63701
Aug 08 18:19:23 mysql57 bash[13131]: virtual memory (kbytes, -v) unlimited
Aug 08 18:19:23 mysql57 bash[13131]: file locks (-x) unlimited
When running with such a high "ulimit -n" (again, this is something which systemd does by default for ExecStartPre), "mysqld --help" consumes unimaginable amounts of memory and even causes swapping and page allocation failures on my PC with 16 GB of RAM.
Workaround in /etc/systemd/
[Service]
ExecStartPre=
ExecStartPre=
ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: mysql-server-5.7 5.7.27-
Uname: Linux 5.2.5-arch1-1-ARCH x86_64
ApportVersion: 2.20.9-0ubuntu7.7
Architecture: amd64
Date: Thu Aug 8 18:29:38 2019
Logs.var.
MySQLConf.
MySQLConf.
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
MySQLConf.
[mysqld_safe]
syslog
MySQLVarLibDirL
ProcEnviron:
LANG=en_US.UTF-8
TERM=xterm-
SHELL=/bin/bash
XDG_RUNTIME_
PATH=(custom, no user)
SourcePackage: mysql-5.7
UpgradeStatus: No upgrade log present (probably fresh install)
modified.
mtime.conffile.
tags: | removed: server-triage-discuss |
Since the LimitNOFILE=5000 isn't applied, the process gets whatever default the host has. In this case, Arch's kernel, since this is an LXC container.
Aug 08 18:19:23 mysql57 bash[13131]: open files (-n) 1073741816 <--- see this?
You probably have the same value on the host. I've seen another bug recently that involved arch linux and high limits: https:/ /github. com/kubernetes- sigs/kind/ pull/760
There it is claimed that Arch's default is 1073741816, which matches your number above. A bug was filed against mariadb, which has the same behavior you described with mysql here:
https:/ /jira.mariadb. org/browse/ MDEV-18360
The same code is in mysql 5.7
All that being said, this works fine when the host is Ubuntu, because the limits are set to lower values there by default. One could still argue that mysql is running on Ubuntu, just with an "odd" non-ubuntu kernel, and that it shouldn't allocate memory like that.