想知道Linux机器上是否有足够的内存来部署新的应用程序 [英] Want to know whether enough memory is free on a linux machine to deploy a new application

查看:118
本文介绍了想知道Linux机器上是否有足够的内存来部署新的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台linux机器,当我执行/ proc / meminfo时它的内存快照是:

I have got a linux machine whose memory snapshot when I do /proc/meminfo is :

MemTotal:     16413388 kB
**MemFree:         48296 kB**
Buffers:        193600 kB
Cached:        1986448 kB
SwapCached:     874512 kB
Active:       15034264 kB
Inactive:       713672 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:     16413388 kB
LowFree:         48296 kB
SwapTotal:     8385920 kB
SwapFree:      4682408 kB
Dirty:            3124 kB
Writeback:           0 kB
Mapped:       13005560 kB
Slab:           257784 kB
CommitLimit:  16592612 kB
Committed_AS: 59624324 kB
PageTables:     233748 kB
VmallocTotal: 536870911 kB
VmallocUsed:    267064 kB
VmallocChunk: 536603555 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     2048 kB

这是一台16 GB的机器,我有一个Java应用程序部署在这将有3个jvm实例,并且它们的组合典型内存要求将接近1 GB。

This is a 16 GB machine and I have a Java application to deploy on this which will have 3 jvm instances and combined typical memory requirement for them will be close to 1 GB.

我想知道部署该应用程序是否安全而不影响当前在该机器上运行的其他应用程序通过查看上面的内存快照我们可以找到吗?

I wanted to know will it be safe to deploy that application without affecting other applications currently running on that machine. By looking at the above memory snapshot can we find out?

还有哪些其他统计数据可以帮助我决定收集这些统计信息以及如何收集这些统计信息?

What other statistics will help me to decide that and how to collect those statistics?

推荐答案

(对于OP来说可能有点晚了,但这是经常被问到的,所以我会试一试)

(It's probably a bit late for the OP, but this is asked quite often, so I'll give it a shot)

免费通常会显示如下内容:

free normally shows something like this:

             total       used       free     shared    buffers     cached
Mem:       8195284    8137708      57576          0    1232328    2651156
-/+ buffers/cache:    4254224    3941060
Swap:     18892216     759852   18132364

人们倾向于查看内存:当试图找出他们有多少可用内存时。不幸的是,该行很容易产生误导,因为Linux内核试图(至少)以这些方式最佳地利用可用内存:

People tend to look at the Mem: line when trying to find out how much free memory they have. Unfortunately that line is quite misleading, because the Linux kernel tries to make optimal use of the available memory in (at least) these ways:


  • 它将缓存来自I / O子系统(例如磁盘)的数据,以便在需要时随时可用。

  • It will cache data from the I/O subsystem (e.g. the disk), so that it will be readily available if needed.

它会主动驱逐一段时间不活动到交换空间的进程,支持缓存活动进程的数据。这往往有利于吞吐量而非响应性,所以有些人调整他们的内核来改变这种行为。

It will actively evict processes that have been inactive for some time to the swap space, in favour of caching data for active processes. This tends to favour throughput over responsiveness, so some people tune their kernel to change this behaviour.

第一点是关于 free 的混淆源,因为 Mem:行包括用于在已用内存量中缓存的内存。但是,内核会因性能原因尽可能地进行缓存。实际上,在任何已经运行一段时间的Linux系统上,空闲内存往往接近于零 - 未使用的内存是浪费的内存。

The first point is the source of confusion regarding free, because the Mem: line includes the memory used for caching in the used memory amount. The kernel, though, will cache as much as possible for performance reasons. In fact, on any Linux system that has been up for some time, the free memory tends to be close to zero - unused memory is wasted memory.

缓存,但是,如果另一个进程需要,可以由内核释放。虽然它会在一定程度上影响I / O性能,但其他进程可以拥有更多内存而无需使用交换空间。因此,对于大多数意图和目的,内存是免费的

The cache memory, though, can be freed by the kernel if needed by another process. While it will impact I/O performance to a degree, other processes can have more memory without using the swap space. Therefore, for most intents and purposes, that memory is free.

这就是为什么免费包括第二行,其中缓存内存被认为是免费的:

That's why free includes a second line, where the cache memory is considered free:

-/+ buffers/cache:    4254224    3941060

第二行是人们在想知道他们是否有足够的可用内存时应该注意的目的。

This second line is what people should be looking at when they want to know if they have enough free memory for a certain purpose.

在上面的例子中,根据 Mem:行,有大约57 MB的可用内存。但是,如果读取第二行,实际上可以使用大约3.9 GB 而不强制活动进程交换。作为旁注,还有大约760 MB的很少使用的数据已被换出,以便在主内存中为进程和缓存腾出更多空间。

In the example above, according to the Mem: line there are ~57 MB of free memory. If one reads the second line, though, there are in fact about 3.9 GB that can be used without forcing active processes to swap. As a sidenote, there are also about 760 MB of rarely-used data that have been swapped out, to make more space in the main memory for processes and caching.

At大致相同的时间, / proc / meminfo 的内容:

At roughly the same time, the contents of /proc/meminfo:

MemTotal:        8195284 kB
MemFree:           57660 kB
Buffers:         1232352 kB
Cached:          2651156 kB
SwapCached:       119936 kB
.
.
.

MemTotal :检测到的可用物理内存内核。

MemTotal: the available physical memory detected by the kernel.

MemFree :未使用的物理内存 - 中显示的可用内存内存:免费

MemFree: the unused physical memory - the free memory shown in the Mem: line of free.

缓冲区:原始磁盘块的相对临时存储。

Buffers: relatively temporary storage of raw disk blocks.

缓存:文件的内存缓存从磁盘读取。它不包括SwapCached内存。

Cached: in-memory cache for files read from the disk. It does not include SwapCached memory.

SwapCached :曾被换出的内存,然后换回来但是还在交换空间。如果需要,它的内容可以被丢弃(非常快!),而不必将它们交换出来(更慢)。

SwapCached: memory that was once swapped out, then swapped back in but is still in the swap space. If needed, its contents can be just discarded (very fast!), without having to swap them out (slower).

所以,要对其进行半精确估计实际可用的内存

So, to have a semi-accurate estimate of the memory that is actually available

MemFree + Buffers + Cached + SwapCached

是一个很好的起点 - 而免费显示在第二行。

is a good starting point - and the one free shows in that second line.

当然,内存管理以及相关的统计和测量比这更复杂。 免费显示的数字仅仅是估计数,因为如果你想要更深入,还有很多其他变量需要考虑。对于经常进行内存使用优化的人来说,这几乎是一种艺术形式。

Naturally, memory management and the related statistics and measurements are more complicated than this. The numbers shown by free are mere estimates at best, since there are a lot of other variables to take into account if you want to go deeper. For people who regularly perform memory usage optimization, this is almost a form of art.

编辑:

A关于这个问题的一些幽默链接:

A somewhat humorous link about this "issue":

http:// www.linuxatemyram.com/

编辑2:

确认有关内存使用的评论分析几乎是一种艺术形式:

To confirm the comment about memory use analysis almost being a form of art:

甚至免费错过了现代Linux系统上的一大块缓存数据。从我的系统上的 / proc / meminfo

Even free misses a major chunk of cached data on modern Linux systems. From /proc/meminfo on my system:

SReclaimable:    2253576 kB

这是系统使用的大约2GB的内存 slab 分配器用于缓存目录条目等,并且可以回收(即必要时可以由进程清除和使用)。然而 free 并不认为它是高速缓冲存储器,也不会在任何计算中输入它,因此它会显示为已使用的存储器。

That's about 2GB of memory that is used by the system slab allocator for caching directory entries and such and it is reclaimable (i.e. it can be cleared and used by processes if necessary). Yet free does not consider it cache memory and does not enter it in any of its calculations and therefore it shows up as used memory.

slabtop 实用程序(如果有)允许系统管理员查找 slab 缓存用于。

The slabtop utility, if available, allows the system administrator to find out what the slab cache is used for.

一种方式(仅限root用户)拥有免费显示系统的实际内存使用情况如下:

A way (for the root user only) to have free show the actual memory use of the system is the following:

# swapoff -a
# sync
# echo 3 > /proc/sys/vm/drop_caches 
# free
             total       used       free     shared    buffers     cached
Mem:       8195284    3181468    5013816          0       8656     228832
-/+ buffers/cache:    2943980    5251304
Swap:            0          0          0
# swapon -a

第一个命令禁用交换空间。如果可用内存可能不足以保存已换出的数据,则不应发出 - 在这种情况下,必须考虑交换:行在内存使用量计算中自由。

The first command disables the swap space. It should not be issued if the available memory may not be enough to hold the data that have been swapped out - in that case one has to take into account the Swap: line of free in their memory usage calculations.

第二个命令将所有缓冲的数据推送到磁盘。它允许在下一步中释放更多的高速缓存。

The second command pushes all buffered data to the disk. It allows more cache memory to be freed in the next step.

第三个命令是最重要的一组 - 它强制内核丢弃尽可能多的高速缓存数据可能(页面缓存,目录条目,inode等)。

The third command is the most important of the set - it forces the kernel to discard as much cached data as possible (page cache, directory entries, inodes etc).

然后 free 最后显示正在运行的进程实际使用的内容在其 - / + buffers / cache:行中。值得注意的是,即使在删除所有缓存数据后,内核也会再次快速启动缓存 - 在这种情况下,它在几秒钟内就已经达到了近250MB的缓存数据。

Then free finally shows what the running processes actually use in its -/+ buffers/cache: line. It is quite noticeable that even after dropping all cached data the kernel quickly starts caching again - in this case it has already reached almost 250MB of cached data within a few seconds.

最后一个命令再次启用交换空间 - 只有在使用第一个命令时才需要它。

The final command enables the swap space again - it is only necessary if the first command was used too.

应该注意这些命令应该由root用户执行为了拥有必要的特权。

It should be noted that these commands should be executed by the root user in order to have the necessary privileges.

这篇关于想知道Linux机器上是否有足够的内存来部署新的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆