码迷,mamicode.com
首页 > 系统相关 > 详细

Linux运维之内存分析2

时间:2020-07-12 01:07:14      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:ack   should   alt   code   添加   png   硬件   head   exp   

 

技术图片

What‘s going on?(这是怎么回事?)

Linux is borrowing unused memory for disk caching. This makes it looks like you are low on memory, but you are not! Everything is fine!

Linux正在借用未使用的内存进行磁盘缓存。 这使您看起来内存不足,但事实并非如此! 一切都很好!

Why is it doing this?(为什么这样做呢?)

Disk caching makes the system much faster and more responsive! There are no downsides, except for confusing newbies. It does not take memory away from applications in any way, ever!

磁盘缓存使系统更快,响应速度更快! 除了使新手感到困惑之外,没有其他缺点。 它永远不会以任何方式占用应用程序的内存!

What if I want to run more applications?(如果我想运行更多的应用程序怎么办?)

If your applications want more memory, they just take back a chunk that the disk cache borrowed. Disk cache can always be given back to applications immediately! You are not low on ram!

如果您的应用程序需要更多的内存,它们只会取回磁盘缓存借用的那一部分。 磁盘缓存始终可以立即归还给应用程序! 不要小看内存!

Do I need more swap?(我需要更多的swap吗?)

No, disk caching only borrows the ram that applications don‘t currently want. It will not use swap. If applications want more memory, they just take it back from the disk cache. They will not start swapping.

不需要,磁盘缓存仅借用应用程序当前不需要的内存。 它不会使用到swap。 如果应用程序需要更多的内存,则只需将其从磁盘缓存中取回即可。 他们将不会一开始就使用swap。

How do I stop Linux from doing this?(如何阻止Linux执行此操作?)

You can‘t disable disk caching. The only reason anyone ever wants to disable disk caching is because they think it takes memory away from their applications, which it doesn‘t! Disk cache makes applications load faster and run smoother, but it NEVER EVER takes memory away from them! Therefore, there‘s absolutely no reason to disable it!

您不能禁用磁盘缓存。 任何人都想禁用磁盘缓存的唯一原因是,他们认为它会占用应用程序的内存,而事实并非如此! 磁盘缓存使应用程序加载速度更快,运行更流畅,但它永远不会占用它们的内存! 因此,绝对没有理由禁用它!

Why does top and free say all my ram is used if it isn‘t?(为什么使用top和free说我的所有ram都被使用了?)

This is just a difference in terminology. Both you and Linux agree that memory taken by applications is "used", while memory that isn‘t used for anything is "free".

这仅是语言理解的不同。我们都认为应用程序占用的内存是“used”的未使用的内存是“free”的。

But how do you count memory that is currently used for something, but can still be made available to applications?

但是,如何计算当前已使用的但仍可用于应用程序的内存呢?

You might count that memory as "free" and/or "available". Linux instead counts it as "used", but also "available":

您可能会认为该内存为“free”或“available”才能使用。 但Linux将其视为“已使用的”,也可视为“可用”:

Memory that isYou‘d call itLinux calls it
used by applications Used Used
used, but can be made available Free (or Available) Used (and Available)
not used for anything Free Free

This "something" is (roughly) what top and free calls "buffers" and "cached". Since your and Linux‘s terminology differs, you might think you are low on ram when you‘re not.

这个就是是top和free所说的“缓冲区”和“缓存”。 由于您和Linux的用语不同,因此您可能会认为ram已经不够了。

How do I see how much free ram I really have?(如何查看实际上有多少免费的RAM?)

To see how much ram your applications could use without swapping, run free -m and look at the "available" column:

要查看您的应用程序在没有使用swap的情况下,可以使用多少内存,请运行free -m并查看“available”列:

  $ free -m
                total        used        free      shared  buff/cache   available
  Mem:           1504        1491          13           0         855      792
  Swap:          2047           6        2041

(On installations from before 2016, look at "free" column in the "-/+ buffers/cache" row instead.)

在2016年之前的安装的,请查看“-/+ buffers/cache”行中的“free”列。

This is your answer in MiB. If you just naively look at "used" and "free", you‘ll think your ram is 99% full when it‘s really just 47%!

这是以MiB单位显示的结果。 如果只看"used" 和"free",您会认为您的ram已满99%,而实际上只有47%!

For a more detailed and technical description of what Linux counts as "available", see the commit that added the field.

有关Linux算作“available”的更详细的技术说明,请参阅添加该字段的提交。

When should I start to worry?(什么时候开始担心内存告警呢?)

A healthy Linux system with more than enough memory will, after running for a while, show the following expected and harmless behavior:

运行一段时间后,具有足够内存的健康Linux系统将显示以下预期的健康状态:

  • free memory is close to 0(free值接近0)
  • used memory is close to total(used值接近total值)
  • available memory (or "free + buffers/cache") has enough room (let‘s say, 20%+ of total)(available值(或free + buffers/cache)有足够的空间(例如,占总内存的20%以上))
  • swap used does not change(swap不变)

Warning signs of a genuine low memory situation that you may want to look into:

真正内存不足的警告信号:

  • available memory (or "free + buffers/cache") is close to zero((available值(或free + buffers/cache)接近0)
  • swap used increases or fluctuates(swap使用量增加或一直变动)
  • dmesg | grep oom-killer shows the OutOfMemory-killer at work(dmesg | grep oom-killer命令可以显示OutOfMemory-killer在工作)

How can I verify these things?(如何验证以上内容?)

See this page for more details and how you can experiment with disk cache to show the effects described here. Few things make you appreciate disk caching more than measuring an order-of-magnitude speedup on your own hardware!

有关更多详细信息以及如何尝试使用磁盘缓存以验证此处描述的效果,请参见此页面(https://www.cnblogs.com/huhyoung/p/13286320.html)。 几乎没有什么比在您自己的硬件上测量数量级加速更让您欣赏磁盘缓存了!

原文链接:https://www.linuxatemyram.com/

Linux运维之内存分析2

标签:ack   should   alt   code   添加   png   硬件   head   exp   

原文地址:https://www.cnblogs.com/huhyoung/p/13286179.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!