I have more than enough free memory but after few days when mysql starts to use more memory it crashes.
total used free shared buffers cached
Mem: 4053 3822 231 0 187 2783
-/+ buffers/cache: 851 3202
Swap: 2047 41 2006

This is from error log, before that I had uptime on mysql around 120 days and I never had problems but after mysql restart and without changing any configuration settings Mysql is having hard time allocating memory.

Number of processes running now: 0
101203 20:40:19 mysqld restarted
101203 20:40:19 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.0.91-community-log' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Edition (GPL)
101205 22:50:28 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101205 22:50:28 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101205 22:50:28 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101205 22:50:28 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101205 22:50:28 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101205 22:50:28 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101205 22:50:32 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101205 22:50:32 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101205 22:50:32 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101205 22:50:32 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101205 22:50:32 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101205 22:50:32 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:41 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:41 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:41 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:41 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:41 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:41 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:41 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:41 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:41 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:41 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:41 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:41 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:44 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:44 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:44 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:44 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:44 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:44 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:44 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:44 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:44 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:44 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:44 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:44 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:44 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:44 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:53 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:53 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:53 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:53 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:53 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:53 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:53 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:53 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:53 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:53 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:01:53 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:01:53 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:15:39 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:15:39 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:15:39 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:15:39 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 9:15:39 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101206 9:15:39 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 23:39:10 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 4054792 bytes)
101206 23:39:10 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101206 23:39:13 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 4054792 bytes)
101206 23:39:13 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101207 23:00:03 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 2096680 bytes)
101207 23:25:31 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1375668 bytes)
101207 23:25:31 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101207 23:25:31 - mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.
key_buffer_size=268435456
read_buffer_size=2097152
max_used_connections=49
max_connections=200
threads_connected=4
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 1081344 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x9e5a4f80
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
Cannot determine thread, fp=0x9efa68c8, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
0x81827e5
0x81df06e
0x81df02d
0x81df02d
0x81df02d
0x81df02d
0x81df02d
0x81df02d
0x81e842e
0x81f01a6
0x81f0b5d
0x819aa08
0x81a091d
0x81a0e84
0x81a2e1f
0xb34832
0xa73f6e
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/mysql/en/using-stack-trace.html and follow instructions on how to resolve the stack trace. Res$
stack trace is much more helpful in diagnosing the problem, so please do
resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x9c12f018 is invalid pointer
thd->thread_id=1313095
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.

Number of processes running now: 0
101207 23:25:31 mysqld restarted
101207 23:25:31 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.0.91-community-log' socket: '/var/lib/mysql/mysql.sock' port: 0 MySQL Community Edition (GPL)
101208 21:25:50 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1441176 bytes)
101208 21:25:50 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$
101208 21:25:50 [ERROR] /usr/sbin/mysqld: Out of memory (Needed 1441176 bytes)
101208 21:25:50 [ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use$

Comment

Comment

If max memory size is in KB, then max allocate size that process can allocate is 524288 or 524MB, and MySQL is using 6-8% which doesn't even come close to that. And if MySQL doesn't ran out of space why doesn't it just use swap and not just crash.

Comment

Just to elaborate a bit more on what gmouse says.
The ulimit settings that limits your MySQL to 512M RAM is the hard limit for the _process_ which has nothing to do with the swap.
Swap is an operating system feature that is used when the total RAM usage on the machine is about to reach the limit.

In your case you can choose to set the ulimit for memory to "unlimited" which means that you won't box in all processes in the max 512M limit and instead there is only one hard limit which when the system runs out of memory (which is what you want I'm guessing).
I don't run RHEL myself but according to some Googling you change this in the /etc/security/limits.conf file.
This page discusses changing the ulimit a lot:http://www.puschitz.com/TuningLinuxForOracle.shtml

At the same time I have to ask a bit about the read_buffer_size variable setting that you have, do you really need it to be 2M when you allow 200 connections on a machine with so little RAM? That setting alone can occupy up to 400M of RAM. Are you really performing so many table scans? And if so could you possibly add indexes to avoid them?

Comment

Just to elaborate a bit more on what gmouse says.
The ulimit settings that limits your MySQL to 512M RAM is the hard limit for the _process_ which has nothing to do with the swap.
Swap is an operating system feature that is used when the total RAM usage on the machine is about to reach the limit.

In your case you can choose to set the ulimit for memory to "unlimited" which means that you won't box in all processes in the max 512M limit and instead there is only one hard limit which when the system runs out of memory (which is what you want I'm guessing).
I don't run RHEL myself but according to some Googling you change this in the /etc/security/limits.conf file.
This page discusses changing the ulimit a lot:http://www.puschitz.com/TuningLinuxForOracle.shtml

At the same time I have to ask a bit about the read_buffer_size variable setting that you have, do you really need it to be 2M when you allow 200 connections on a machine with so little RAM? That setting alone can occupy up to 400M of RAM. Are you really performing so many table scans? And if so could you possibly add indexes to avoid them?

Sorry I didn't replied sooner but I deleted few big tables and Mysql is not restarting anymore.
I just wondered if I have free space, how come mysql doesn't want to allocate it.
I didn't wrote this app, i'm using Joomla 1.5 and IPB 3.0.5 which until db grew worked just fine. After this cleanup again it works fine, and since my dbs are relatively small I didn't installed 64bit system.

Comment

Sorry I didn't replied sooner but I deleted few big tables and Mysql is not restarting anymore.
I just wondered if I have free space, how come mysql doesn't want to allocate it.

Read my last post about "ulimit" again, or google it.

Bono wrote on Mon, 17 January 2011 00:58

Mysql is using 9% of memory and I guess my problem could be joins, table cache and temp files.

Joins performed without indexes: 168924

That is definitely not a good figure!
But that will more affect the cpu load of the machine than the amount of memory used.
Set the ulimit to "unlimited" and you won't have the memory problem any longer.

Comment

I have fixed ulimit, I just do not understand why default value for RH has so small limit. I used so many different distributions which never had any limit, that is why I didn't even remember to look at ulimit values.