大网数据广告活动
服务器运维问答

mysqld.service for systemd - Failed to parse resource value, ignoring: 40000 - LimitMEMLOCK

· 52CE 我爱测

I got this error mysql systemd[1]: [/usr/lib/systemd/system/mysqld.service:39] Failed to parse resource value, ignoring: 40000 on Centos 7 with mysql 5.7 when I set the LimitMEMLOCK limit for MYSQL 5.7. LimitMEMLOCK=40000 Why it …

问题原文

原帖链接 · Berlin · CC BY-SA 3.0

I got this error mysql systemd[1]: [/usr/lib/systemd/system/mysqld.service:39] Failed to parse resource value, ignoring: 40000 on Centos 7 with mysql 5.7 when I set the LimitMEMLOCK limit for MYSQL 5.7.

LimitMEMLOCK=40000
  1. Why it is not possible to set a numeric limit for LimitMEMLOCK?
  2. What is the purpose of LimitMEMLOCK ?
  3. Is the only soultion LimitMEMLOCK=infinity?

*

#cat /etc/*-release
CentOS Linux release 7.3.1611 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.3.1611 (Core)
CentOS Linux release 7.3.1611 (Core)

*

service mysqld status
Redirecting to /bin/systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2016-12-19 23:21:24 UTC; 9s ago
 Main PID: 11170 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─11170 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

mysql systemd[1]: Starting MySQL Server...
mysql mysqld_pre_systemd[11143]: /usr/sbin/restorecon:  Warning no default label for /mnt/data/mysql
mysql systemd[1]: Started MySQL Server.
mysql systemd[1]: [/usr/lib/systemd/system/mysqld.service:39] Failed to parse resource value, ignoring: 40000

I do not see this error message on other Centos 7 version (CentOS Linux release 7.2.1511 (Core)) when mysqld.service set up with LimitMEMLOCK=40000.

cat /etc/*-release
CentOS Linux release 7.2.1511 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.2.1511 (Core)
CentOS Linux release 7.2.1511 (Core)

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 3.0

Let's start with the systemd documentation:

LimitCPU=, LimitFSIZE=, LimitDATA=, LimitSTACK=, LimitCORE=, LimitRSS=, LimitNOFILE=, LimitAS=, LimitNPROC=, LimitMEMLOCK=, LimitLOCKS=, LimitSIGPENDING=, LimitMSGQUEUE=, LimitNICE=, LimitRTPRIO=, LimitRTTIME=

Set soft and hard limits on various resources for executed processes. See setrlimit(2) for details on the resource limit concept.

For MEMLOCK, that man page explains:

   RLIMIT_MEMLOCK
          The maximum number of bytes of memory that may be locked into
          RAM.  In effect this limit is rounded down to the nearest
          multiple of the system page size.  This limit affects mlock(2)
          and mlockall(2) and the mmap(2) MAP_LOCKED operation.  Since
          Linux 2.6.9 it also affects the shmctl(2) SHM_LOCK operation,
          where it sets a maximum on the total bytes in shared memory
          segments (see shmget(2)) that may be locked by the real user
          ID of the calling process.  The shmctl(2) SHM_LOCK locks are
          accounted for separately from the per-process memory locks
          established by mlock(2), mlockall(2), and mmap(2) MAP_LOCKED;
          a process can lock bytes up to this limit in each of these two
          categories.

          In Linux kernels before 2.6.9, this limit controlled the
          amount of memory that could be locked by a privileged process.
          Since Linux 2.6.9, no limits are placed on the amount of
          memory that a privileged process may lock, and this limit
          instead governs the amount of memory that an unprivileged
          process may lock.

Locking memory into RAM prevents the kernel from swapping it out. This isn't often done, but for certain performance-critical stuff it is quite useful. Databases are one of those things that can make good use of this.

Setting this value to 40000 makes no sense. Even if you could do it, it would cripple the database and probably cause it to crash. MySQL locks memory when large page support is enabled and the documentation states that memlock must be unlimited (infinity in your systemd unit).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-12-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。