linux inactive,释放Linux Inactive Memory



I use

Nagios 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值