Chinaunix首页 | 论坛 | 博客
  • 博客访问: 840133
  • 博文数量: 182
  • 博客积分: 1992
  • 博客等级: 上尉
  • 技术积分: 1766
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-18 11:49
文章分类

全部博文(182)

文章存档

2019年(1)

2016年(5)

2015年(29)

2014年(38)

2013年(21)

2012年(36)

2011年(52)

我的朋友

分类: LINUX

2014-02-10 14:17:32

转自: to monitor my systems and occasionally got alerts that I had high memory utilization on some of my machines. But using these tools, all I found was confusion. Untill recentley, I thought the only way to free up the memory was to reboot the server.

When it comes to how OS's manage their memory, it can be kind of unclear for some people. The reason "top" and "free -m" often dont seem to line up is because of the different states of memory. There are two states of "used" memory, "inactive" and "active".

Active memory is memory that is being used by a particular process. Inactive memory is memory that was allocated to a process that is no longer running. "top" and "free -m" do not differentiate between these two types of memory. This is why "free -m" may show only 2% memory not being used. while "top" may only show a few processes using 1 or 2%.

To better understand the differences between inactive and active memory, think of it this way. If you were to write something on a white board starting from the top left, and then you no-longer needed the information, you probably wouldn't erase that sentence and start in the top left again. You would probably drop to the next line and write in the next available space and only erase the information when you run out of available surface area.

The same concept holds true for memory in a computer. Instead of cleaning the "dirty" memory the computer just lets it sit there because it's not causing any detrimental effects or costing the computer anything in terms of performance or useability. The computer simply waits untill the memory is needed again before it clears it up and writes the new data to that section. Over time this can cause the levels of inactive memory to climb and therefore the level of "used" memory, and eventually, trigger threshold alarms, especially if you run memory intensive applications or scripts.

To determine whether or not you have a lot of inactive memory on a Linux system, look at /proc/meminfo

cat /proc/meminfo

On about the 6th and 7th lines, you should see two fields sowing how much memory is active and how much is inactive.

If you have a large amount of inactive memory, there are two ways that you can clear it up to make the threshold alarm go away. Either reboot the system, or simply run the following command.

free && sync && echo 3 > /proc/sys/vm/drop_caches && echo "" && free

This commands shows you the current state of the memory according to "free" and then clears the memory buffers/cache and then shows the new details as reported by "free". Keep in mind though that if you still have high levels of usage after running this command, it is probably actually being used by a process and as such can not be cleared without killing the process or restarting the box.

也可以用vmstat查看
阅读(1660) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~