Press enter to see results or esc to cancel.

Limit The Size of Your Core Files on Linux

So we all know that when troubleshooting MySQL crashes or any other processes in that regard, we simply enable core files to be dumped when the appropriate signal it triggered. To get the best results, we’d set the core file size limit everywhere to unlimited and be done with it, but what if you want to limit that to a certain size? I stumble to a small confusion lately when doing this for MySQL, so let me share quickly.

First, for MySQL, mysqld_safe would use ulimit to set the core-file-size value you pass to it. Now remember according to the manual, this value should be in blocks (some documentation says its in chunks of 1024 bytes). However, according to my experience on CentOS 6, this is the physical block size of the device where your core_pattern is pointed to.

[root@centos6 ~]# ulimit -a
...
core file size          (blocks, -c) 0

[root@centos6 ~]# cat /proc/sys/kernel/core_pattern
/var/tmp/core

[root@centos6 ~]# blockdev --getbsz /dev/sda2
4096
[root@centos6 ~]# blockdev --getpbsz /dev/sda2
512

Based on the above, my core_pattern point to /var, which sits on sda2. This partition according to blockdev has a filesystem blocksize of 4K and a physical block size of 512B. Putting this to the test, say I configure MySQL to a core file size ulimit of 10240, then I would get:

[root@centos6 ~]# cat /proc/`pidof mysqld`/limits
Limit                     Soft Limit           Hard Limit           Units     
...   
Max core file size        5242880              5242880              bytes

So, 5242880 / 10240 here is 512, similarly with ulimit -c of 512000, 262144000 / 512000 is 512.

[root@centos6 ~]# cat /proc/`pidof mysqld`/limits           
Limit                     Soft Limit           Hard Limit           Units    
Max core file size        262144000            262144000            bytes

With that out of the way, another problem you would encounter is that when trying to start the MySQL service via the standard init script or mysqld_safe that comes with your package, the limit you set will not be enforced when starting MySQL as the OS root user for some reason. I’d always get the core file size set to unlimited so I would have to sudo as the mysql user to enforce that limit explicitly. Anyone know why this is?