/etc/init.d/mysql does not respect resource limits when Linux starts up

Bug #1378657 reported by Jaime Sicam
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Percona Server moved to https://jira.percona.com/projects/PS
Status tracked in 5.7
5.1
Won't Fix
Wishlist
Unassigned
5.5
Triaged
Wishlist
Unassigned
5.6
Triaged
Wishlist
Unassigned
5.7
Triaged
Wishlist
Unassigned

Bug Description

I'm filing this as a feature request

Current resource limits when Linux(CentOS 6) starts up:

/etc/security/limits.conf
root soft nproc 3000
root hard nproc unlimited

Limits of init process:
cat /proc/1/limits |grep processes
Max processes 3778 3778 processes

Limits of mysqld:
cat /proc/`pidof mysqld`/limits |grep processes
Max processes 3778 3778 processes

Resource limits of mysqld after restarting MySQL as root:
[root@localhost ~]# cat /proc/`pidof mysqld`/limits |grep processes
Max processes 3000 unlimited processes

Workaround is to use runuser to start mysqld_safe on /etc/init.d/mysql:
Look for:
      # Give extra arguments to mysqld with the my.cnf file. This script
      # may be overwritten at next upgrade.
      $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?

Change to:
      # Give extra arguments to mysqld with the my.cnf file. This script
      # may be overwritten at next upgrade.
      runuser -l mysql -c "$bindir/mysqld_safe --datadir='$datadir' --pid-file='$mysqld_pid_file_path' $other_args >/dev/null 2>&1 &"
      wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?

Under /etc/security/limits.conf, add resource limits to mysql:

/etc/security/limits.conf
mysql soft nproc 3000
mysql hard nproc unlimited

Tags: pkg i46267
Revision history for this message
Nilnandan Joshi (nilnandan-joshi) wrote :

Able to reproduce the same.

[root@centos65 ~]# ps -ef | grep mysql
root 2621 1 0 15:02 pts/1 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/centos65.pid
mysql 2785 2621 4 15:02 pts/1 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/centos65.pid --socket=/var/lib/mysql/mysql.sock
root 2811 2562 0 15:02 pts/1 00:00:00 grep mysql
[root@centos65 ~]#
[root@centos65 ~]# cat /proc/2785/limits |grep processes
Max processes 7809 unlimited processes
[root@centos65 ~]#

[root@centos65 ~]# cat /etc/security/limits.d/90-nproc.conf | grep nproc
* soft nproc 1024
root soft nproc 3000
root hard nproc unlimited
[root@centos65 ~]#

From another session:

[root@centos65 ~]# service mysql restart
Shutting down MySQL (Percona Server)... SUCCESS!
Starting MySQL (Percona Server). SUCCESS!
[root@centos65 ~]#
[root@centos65 ~]# ps -ef | grep mysql
root 3147 1 0 15:07 pts/2 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/centos65.pid
mysql 3311 3147 3 15:07 pts/2 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/centos65.pid --socket=/var/lib/mysql/mysql.sock
root 3337 3089 0 15:07 pts/2 00:00:00 grep mysql
[root@centos65 ~]#
[root@centos65 ~]#
[root@centos65 ~]# cat /proc/3311/limits |grep processes
Max processes 7809 unlimited processes
[root@centos65 ~]#
[root@centos65 ~]# cat /proc/3147/limits |grep processes
Max processes 3000 unlimited processes
[root@centos65 ~]#

After reboot the server,
[root@centos65 ~]# ps -ef | grep mysql
root 1417 1 0 15:09 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/centos65.pid
mysql 1581 1417 0 15:09 ? 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/lib/mysql/centos65.pid --socket=/var/lib/mysql/mysql.sock
root 1903 1885 0 15:11 pts/0 00:00:00 grep mysql
[root@centos65 ~]#
[root@centos65 ~]# cat /proc/1581/limits |grep processes
Max processes 7809 7809 processes
[root@centos65 ~]#
[root@centos65 ~]# cat /proc/1417/limits |grep processes
Max processes 7809 7809 processes
[root@centos65 ~]#

tags: added: pkg
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-2452

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.