When to be concerned about memory levels on Linux

Memory management on Linux systems is complicated. Seeing high usage doesn’t necessarily mean there’s a problem. There are other things you should also consider.

Running out of memory on a Linux system is generallynota sign that there's a serious problem. Why? Because a healthy Linux system will cache disk activity in memory, basically gobbling memory that isn't being used, which is a very good thing.

In other words, it doesn't allow memory to go to waste. It uses the spare memory to increase disk access speed, and it does thiswithouttaking memory away from running applications. This memory caching, as you might well imagine, is hundreds of times faster than working directly with the hard-disk drives (HDD) and significantly faster than solid-state drives. Full or near full memory normally means that a system is running as efficiently as it can — not that it's running into problems.

How caching works

磁盘缓存仅仅意味着系统正在使用的资源优势(可用内存),以加快磁盘读取和写入。应用程序不会失去任何东西,每当他们最需要的时候能够获得更多的内存。此外,磁盘缓存不会导致应用程序诉诸使用掉。相反,用于磁盘缓存内存总是立即需要的时候回来和磁盘的内容更新。

Major and minor page faults

Linux系统通过破坏物理存储器分成块被称为“页”,然后映射这些页入过程虚拟存储器分配内存以处理。这似乎不再使用的页面可以从内存中删除 - 即使相关的进程仍在运行。当一个进程需要的是不再映射或者在存储器中不再是一个页面,则产生一个故障。所以,“故障”并不意味着“错误”,而是指“不可用”,并发挥故障的内存管理具有重要作用。

小故障意味着页面是在存储器中,但是没有分配给请求进程或没有标记为存在于所述存储器管理单元。主要故障是指在内存不再页面。

If you'd like to get a feel for how often minor and major page faults occur, try apscommand like this one. Note that we're asking for the fields related to page faults and the commands to be listed. Numerous lines were omitted from the output. The MINFL displays the number of minor faults, while MAJFL represents the number of major faults.

$ ps -eo min_flt,maj_flt,cmd MINFL MAJFL CMD 230760 150 /usr/lib/systemd/systemd --switched-root --system --deserialize 18 0 0 [kthreadd] 0 0 [rcu_gp] 0 0 [rcu_par_gp] 0 0 [kworker/0:0H-kblockd] ... 166 20 gpg-agent --homedir /var/lib/fwupd/gnupg --use-standard-socket --daemon 525 1 /usr/libexec/gvfsd-trash --spawner :1.16 /org/gtk/gvfs/exec_spaw/0 4966 4 /usr/libexec/gnome-terminal-server 3617 0 bash 0 0 [kworker/1:0H-kblockd] 927 0 gdm-session-worker [pam/gdm-password]

To report on a single process, you might try a command like this:

$ ps -o min_flt,maj_flt 1 MINFL MAJFL 230064 150

您还可以添加其他领域,如进程所有者的UID和GID。

$ ps -o min_flt,maj_flt,cmd,args,uid,gid 1 MINFL MAJFL CMD COMMAND UID GID 230064 150 /usr/lib/systemd/systemd -- /usr/lib/systemd/systemd -- 0 0

How full is full?

以获取有关如何存储更好地处理正在使用的一种方法是用free -mcommand. The-moption reports the numbers in mebibytes (MiBs) instead of bytes.

$ free -m total used free shared buff/cache available Mem: 3244 3069 35 49 140 667 Swap: 3535 0 3535

Note that "free" (unused) memory can be running low while "available" (available for starting new applications) might report a larger number. The distinction between these two fields is well worth paying attention to. Available means that it can be recovered and used when needed, while free means that it's available now.

When to worry

如果在Linux系统的性能似乎是不错的 - 应用程序响应,在命令行中没有显示出有问题的迹象 - 没准系统处于良好状态。请记住,一些应用程序可能会放慢一些原因,不影响整个系统。

An excessive number of hard faults may indeed indicate a problem, but balance this with observed performance.

一个好的经验法则是担心当可用内存是接近零或当“交换使用”现场的增长或显着波动。不要担心,如果“可用”的数字是总内存的可用合理的比例,因为它是从上方这里重复的例子:

$ free -m total used free shared buff/cache available Mem: 3244 3069 35 49 140 667 Swap: 3535 0 3535

Linux performance is complicated

所有这一切不谈,在Linux系统上的内存能够填满,性能可以减缓。只是不承担内存使用一个报告的指示系统的麻烦。

Memory management on Linux systems is complicated because of the measures taken to ensure the best use of system resources. Don't let the initial appearance of full memory trick you into believing that your system is in trouble when it isn't.

Join the Network World communities onFacebookLinkedInto comment on topics that are top of mind.

版权©2019足球竞彩网下载

IT Salary Survey:结果是在