Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

is there a way to reduce the VIRT mem usage? I am not sure what the reason is for such high usage. It has reached upto 12g as well.

Using top command

Tasks: 348 total,   1 running, 344 sleeping,   0 stopped,   3 zombie
Cpu(s):  1.4%us,  0.2%sy,  0.0%ni, 98.3%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  39131036k total,  4522864k used, 34608172k free,   228124k buffers
Swap: 16764924k total,        0k used, 16764924k free,  1316196k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
26760 www-data  20   0  312m  39m 4292 S   11  0.1   0:01.84 /usr/sbin/apache2 -
27149 www-data  20   0  312m  38m 3760 S   11  0.1   0:00.34 /usr/sbin/apache2 -
27193 www-data  20   0  312m  39m 4984 S   11  0.1   0:00.90 /usr/sbin/apache2 -
 1103 mysql     20   0  9.8g 195m 8244 S    1  0.5   5:40.69 /usr/sbin/mysqld
27180 www-data  20   0     0    0    0 Z    1  0.0   0:00.47 [apache2] <defunct>
   66 root      20   0     0    0    0 S    0  0.0   0:00.23 [kworker/15:0]
 8037 ntp       20   0 31496 1588 1244 S    0  0.0   0:01.13 /usr/sbin/ntpd -p /
26676 www-data  20   0  332m  58m 3960 S    0  0.2   0:01.73 /usr/sbin/apache2 -
26737 www-data  20   0  290m  16m 3476 S    0  0.0   0:00.23 /usr/sbin/apache2 -
26738 www-data  20   0  312m  39m 4292 S    0  0.1   0:00.68 /usr/sbin/apache2 -
26772 www-data  20   0  289m  15m 3928 S    0  0.0   0:00.41 /usr/sbin/apache2 -
26883 www-data  20   0  312m  39m 4300 S    0  0.1   0:00.48 /usr/sbin/apache2 -
27150 www-data  20   0  284m 8372 1516 S    0  0.0   0:00.02 /usr/sbin/apache2 -
27154 www-data  20   0  312m  39m 3876 S    0  0.1   0:00.44 /usr/sbin/apache2 -
27191 www-data  20   0  329m  55m 3644 S    0  0.1   0:00.44 /usr/sbin/apache2 -
27222 webaau    20   0 17568 1636 1072 R    0  0.0   0:00.06 top
    1 root      20   0 24428 2388 1352 S    0  0.0   0:03.60 /sbin/init

my.cnf

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
#
# * Fine Tuning
#
key_buffer              = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
max_connections        = 300
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 64M

#added by SRTPL
# changed qauery_cache_size from 16M to 32
tmp_table_size          = 64M
max_heap_table_size     = 64M
table_cache             = 500
wait_timeout            = 900
interactive_timeout     = 900
#2880

#End of adding
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#log_bin                        = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]
quick
quote-names
max_allowed_packet      = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer              = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

Another issue i had faced was that actual memory usage was high though no process was using the mem. After few tweeking in my.cnf and a restart high usage of actual mem didn't occur again.

Using ubuntu 12.04
5.5.22-0ubuntu1
Apache2.2.22
PHP Version 5.3.10-1ubuntu3.1

share|improve this question
    
What's the actual problem? –  mgorven Jun 19 '12 at 6:21
    
usage is high. and response gets slow because of it. –  preetam Jun 19 '12 at 6:33
    
@preetam: Your top command output shows nearly 34 GB of completely free memory. How is that high usage? –  Janne Pikkarainen Jun 19 '12 at 6:34
    
ram was increased from 16g to 39131036k yesterday, so the issue has not effected the response for the day. highest ram usage till now was 15.6g. –  preetam Jun 19 '12 at 6:34
    
the server was restarted once and the usage reduced. 1103 mysql 20 0 9.8g 195m 8244 S 1 0.5 5:40.69 /usr/sbin/mysqld has gone upto 12g 315m yesterday and then it started using swap –  preetam Jun 19 '12 at 6:35
show 3 more comments

1 Answer

up vote 2 down vote accepted

MySQL has only mapped the memory pages, and is not actually using them. VIRT != memory use. Linux memory usage can be very confusing sometimes.

You can see from your top output by yourself that no swap has been used, and RAM is mostly unused too.

share|improve this answer
    
yes it is not showing swap usage now. yesterday it was using swap as well. I then had the server restarted as i couldn't access it with ssh too. after the restart it started working properly. –  preetam Jun 19 '12 at 6:41
    
btw, does MySQL always map that much of memory pages? is it a common occurrence? does all the servers have that much of VIRT memory? or is it because of some configuration i have done? –  preetam Jun 19 '12 at 8:13
    
btw, thought i should share this too. i tried echo 3 | sudo tee /proc/sys/vm/drop_caches to see what all was in cache... reduced memory usage to 1gb :) –  preetam Mar 13 at 7:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.