Announcement

Announcement Module
Collapse
No announcement yet.

MySQL 5 cannot allocate memory

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MySQL 5 cannot allocate memory

    Hi, i'm running 32bit RedHat version 5 and after long uptime I always ran in problems with RedHat, I never had such problems with Debian which I normally use.

    Long uptime:
    00:10:01 up 347 days, 21:33, 1 user, load average: 0.77, 0.88, 0.90

    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$


    EDIT: Sorry wrong section, please move it to LAMP.

  • #2
    What is your:
    ps aux |grep mysql

    And why the heck are you using 32bit version ? This way you cannot use more that about 3GB for a process.

    Comment


    • #3
      I got only 4GB of ram and my databases are small, so 3 years ago 32bit was OK.

      mysql 10192 44.5 6.2 465412 257768 ? S root 23331 0.0 0.0 5444 1120 ? S Nov23 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/v

      Comment


      • #4
        What does ulimit -a report?

        Comment


        • #5
          core file size (blocks, -c) 0
          data seg size (kbytes, -d) unlimited
          scheduling priority (-e) 0
          file size (blocks, -f) unlimited
          pending signals (-i) 73728
          max locked memory (kbytes, -l) 32
          max memory size (kbytes, -m) 524288
          open files (-n) 1024
          pipe size (512 bytes, -p) 8
          POSIX message queues (bytes, -q) 819200
          real-time priority (-r) 0
          stack size (kbytes, -s) 10240
          cpu time (seconds, -t) unlimited
          max user processes (-u) 73728
          virtual memory (kbytes, -v) 524288
          file locks (-x) unlimited

          Comment


          • #6
            can you interpret these results?

            Comment


            • #7
              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


              • #8
                key_buffer_size=268435456

                How can it not even come close to 512MB? It cannot swap because swap memory is also limited.

                Comment


                • #9
                  gmouse wrote on Thu, 16 December 2010
                  ...
                  It cannot swap because swap memory is also limited.
                  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


                  • #10
                    sterin wrote on Thu, 16 December 2010 07:44
                    gmouse wrote on Thu, 16 December 2010
                    ...
                    It cannot swap because swap memory is also limited.
                    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.

                    This is my memory stats:
                    total used free shared buffers cached
                    Mem: 4053 3968 85 0 214 2901
                    -/+ buffers/cache: 852 3201
                    Swap: 2047 0 2047

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

                    Joins performed without indexes: 168924
                    Temporary tables created on disk: 38% (4M on disk / 10M total)
                    Table cache hit rate: 1% (968 open / 73K opened)

                    I didn't stressed out about read_buffer_size because I got 3GB of free memory, but I guess I could decrease that value.

                    Thanks guys for you input.

                    Comment


                    • #11
                      Bono wrote on Mon, 17 January 2011 00:58
                      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


                      • #12
                        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.

                        Thank you.

                        Comment


                        • #13
                          Bono wrote on Tue, 18 January 2011 21:36
                          I have fixed ulimit, I just do not understand why default value for RH has so small limit.
                          You are not alone in this my friend!

                          Comment

                          Working...
                          X