Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Linux上的内存使用情况与`free`不匹配大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我有一台 Linux机器在软件方面没有运行太多,但是在某种程度上使用了1.7GB的2GB已安装内存.当我自由奔跑时,我得到: @R_390_10586@l used free shared buffers cached Mem: 2072616 1979972 92644 0 164876 129740 -/
我有一台 Linux机器在软件方面没有运行太多,但是在某种程度上使用了1.7GB的2GB已安装内存.当我自由奔跑时,我得到:
@R_390_10586@l       used       free     shared    buffers     cached
Mem:       2072616    1979972      92644          0     164876     129740
-/+ buffers/cache:    1685356     387260
Swap:       498004       1632     496372

当我运行顶部时,我获得与第一行免费相同的数字(由于内存使用现已自行修复,因此无法重现).

但是,当我运行ps aux时,所有进程的内存使用量仅为295.9MB,这与使用免费报告的1.7GB内存相差甚远.

为什么会出现这种差异?

编辑:

这是请求的额外信息,但我认为它不会有多大帮助,因为我现在显示〜使用免费使用360MB,使用ps aux总计使用~300MB.不确定为什么问题会自行纠正.

自由

@R_390_10586@l       used       free     shared    buffers     cached
Mem:       2072616     668484    1404132          0     185868     139196
-/+ buffers/cache:     343420    1729196
Swap:       498004       1632     496372

cat / proc / meminfo

@H_749_16@mem@R_390_10586@l: 2072616 kB MemFree: 1404628 kB Buffers: 185792 kB Cached: 139196 kB SwapCached: 544 kB Active: 411448 kB Inactive: 210208 kB Active(anon): 218636 kB Inactive(anon): 78216 kB Active(filE): 192812 kB Inactive(filE): 131992 kB Unevictable: 0 kB Mlocked: 0 kB High@R_390_10586@l: 1187784 kB HighFree: 761112 kB Low@R_390_10586@l: 884832 kB LowFree: 643516 kB Swap@R_390_10586@l: 498004 kB SwapFree: 496372 kB Dirty: 60 kB WriteBACk: 0 kB AnonPages: 296168 kB Mapped: 14536 kB Shmem: 184 kB Slab: 39088 kB SReclaimable: 31720 kB SUnreclaim: 7368 kB KernelStack: 888 kB PageTables: 1184 kB NFS_Unstable: 0 kB Bounce: 0 kB WriteBACkTmp: 0 kB CommitLimit: 1534312 kB Committed_AS: 407808 kB Vmalloc@R_390_10586@l: 122880 kB VmallocUsed: 5132 kB VmallocChunk: 112808 kB DirectMap4k: 12280 kB DirectMap4M: 897024 kB

ps aux

USER       PID %cpu %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   1620   548 ?        Ss   May18   0:04 init [3]
root         2  0.0  0.0      0     0 ?        S    May18   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    May18   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    May18   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    May18   0:00 [watchdog/0]
root         6  0.0  0.0      0     0 ?        S    May18   0:00 [migration/1]
root         7  0.0  0.0      0     0 ?        S    May18   0:00 [ksoftirqd/1]
root         8  0.0  0.0      0     0 ?        S    May18   0:00 [watchdog/1]
root         9  0.0  0.0      0     0 ?        S    May18   0:00 [events/0]
root        10  0.0  0.0      0     0 ?        S    May18   0:00 [events/1]
root        11  0.0  0.0      0     0 ?        S    May18   0:00 [kHelper]
root        17  0.0  0.0      0     0 ?        S    May18   0:00 [async/mgr]
root       166  0.0  0.0      0     0 ?        S    May18   0:00 [sync_supers]
root       168  0.0  0.0      0     0 ?        S    May18   0:00 [bdi-default]
root       170  0.0  0.0      0     0 ?        S    May18   0:03 [kblockd/0]
root       171  0.0  0.0      0     0 ?        S    May18   0:03 [kblockd/1]
root       174  0.0  0.0      0     0 ?        S    May18   0:00 [kacpid]
root       175  0.0  0.0      0     0 ?        S    May18   0:00 [kacpi_notify]
root       176  0.0  0.0      0     0 ?        S    May18   0:00 [kacpi_hotplug]
root       332  0.0  0.0      0     0 ?        S    May18   0:00 [ata/0]
root       333  0.0  0.0      0     0 ?        S    May18   0:00 [ata/1]
root       334  0.0  0.0      0     0 ?        S    May18   0:00 [ata_aux]
root       336  0.0  0.0      0     0 ?        S    May18   0:00 [kseriod]
root       371  0.0  0.0      0     0 ?        S    May18   0:00 [rpciod/0]
root       372  0.0  0.0      0     0 ?        S    May18   0:00 [rpciod/1]
root       406  0.0  0.0      0     0 ?        S    May18   0:00 [khungtaskd]
root       407  0.0  0.0      0     0 ?        S    May18   0:20 [kswapd0]
root       408  0.0  0.0      0     0 ?        S    May18   0:00 [aio/0]
root       409  0.0  0.0      0     0 ?        S    May18   0:00 [aio/1]
root       410  0.0  0.0      0     0 ?        S    May18   0:00 [nfsiod]
root       411  0.0  0.0      0     0 ?        S<   May18   0:00 [kslowd000]
root       412  0.0  0.0      0     0 ?        S<   May18   0:00 [kslowd001]
root       414  0.0  0.0      0     0 ?        S    May18   0:00 [crypto/0]
root       415  0.0  0.0      0     0 ?        S    May18   0:00 [crypto/1]
root      1172  0.0  0.0      0     0 ?        S    May18   0:00 [scsi_tgtd/0]
root      1173  0.0  0.0      0     0 ?        S    May18   0:00 [scsi_tgtd/1]
root      1177  0.0  0.0      0     0 ?        S    May18   0:00 [scsi_eh_0]
root      1215  0.0  0.0      0     0 ?        S    May18   0:00 [kpsmoused]
root      1228  0.0  0.0      0     0 ?        S    May18   0:05 [jbd2/sda3-8]
root      1229  0.0  0.0      0     0 ?        S    May18   0:00 [ext4-dio-unwr]
root      1230  0.0  0.0      0     0 ?        S    May18   0:00 [ext4-dio-unwr]
root      1322  0.0  0.0   2044   632 ?        S<s  May18   0:00 /sbin/udevd --d
root      1650  0.0  0.0      0     0 ?        S    May18   0:25 [vmmemctl]
root      1678  0.0  0.0      0     0 ?        S    May18   0:00 [kjournald]
root      1680  0.0  0.0      0     0 ?        S    May18   0:00 [ksuspend_usbd]
root      1681  0.0  0.0      0     0 ?        S    May18   0:00 [khubd]
root      1709  0.0  0.0      0     0 ?        S    May18   0:02 [flush-8:0]
root      3157  0.0  0.0   5976  1576 ?        Ss   May18   0:10 /usr/bin/vmtool
root      3222  0.0  0.0   5984   276 ?        S    May18   0:00 supervising sys
root      3223  0.0  0.0   6220  1452 ?        Ss   May18   0:00 /usr/sbin/syslo
root      3224  0.0  0.0   4428  1240 ?        S    May18   0:00 /bin/sh /etc/sy
clamav    3808  0.1 11.4 256396 237488 ?       SNsl May18   2:44 /usr/sbin/clamd
clamav    3818  0.0  0.0  12368  1684 ?        SNs  May18   0:03 /usr/bin/freshc
root      3984  0.0  0.0   4048  1164 ?        Ss   May18   0:00 /usr/sbin/ntpd
root      4106  0.0  0.0  14228  1868 ?        Ss   May18   0:00 /usr/sbin/smbd
root      4115  0.0  0.0   8360  1128 ?        Ss   May18   0:00 /usr/sbin/nmbd
root      4119  0.0  0.0  14228   852 ?        S    May18   0:00 /usr/sbin/smbd
root      4176  0.0  0.0   8488  1832 ?        Ss   May18   0:00 sendmail: accep
smmsp     4179  0.0  0.0   8212  1372 ?        Ss   May18   0:00 sendmail: Queue
root      4235  0.0  0.1   9824  2700 ?        S    May18   0:06 /usr/sbin/snmpd
root      4295  0.0  0.0   5684  1060 ?        Ss   May18   0:00 /usr/sbin/sshd
root      4415  0.0  0.0   2044   512 ?        S<   May18   0:00 /sbin/udevd --d
uptimed   4456  0.0  0.0   1620   440 ?        Ss   May18   0:00 /usr/sbin/uptim
root      4515  0.0  0.0   3456   716 ?        Ss   May18   0:00 /usr/sbin/cron
root      4609  0.0  0.0   1672   668 tty1     Ss+  May18   0:00 /sbin/agetty 38
root      4610  0.0  0.0   1672   668 tty2     Ss+  May18   0:00 /sbin/agetty 38
root      4611  0.0  0.0   1676   672 tty3     Ss+  May18   0:00 /sbin/agetty 38
root      4612  0.0  0.0   1672   668 tty4     Ss+  May18   0:00 /sbin/agetty 38
root      4613  0.0  0.0   1668   664 tty5     Ss+  May18   0:00 /sbin/agetty 38
root      4614  0.0  0.0   1668   664 tty6     Ss+  May18   0:00 /sbin/agetty 38
root      8761  0.0  0.1   8740  3000 ?        Ss   02:02   0:02 sshd: root@nott
root      8763  0.0  0.0   5356  1632 ?        Ss   02:02   0:02 /usr/lib/misc/s
root      8774  0.0  0.1   8744  2988 ?        Ss   02:02   0:00 sshd: root@nott
root      8776  0.0  0.0   5368  1632 ?        Ss   02:02   0:00 /usr/lib/misc/s
root      8787  0.0  0.1   8736  2944 ?        Ss   02:02   0:00 sshd: root@nott
root      8789  0.0  0.0   5232  1520 ?        Ss   02:02   0:00 /usr/lib/misc/s
root      8812  0.0  0.1   8740  3000 ?        Ss   02:04   0:12 sshd: root@nott
root      8814  0.0  0.0   5416  1676 ?        Ss   02:04   0:13 /usr/lib/misc/s
root      8825  0.0  0.1   8744  2992 ?        Ss   02:04   0:00 sshd: root@nott
root      8827  0.0  0.0   5352  1628 ?        Ss   02:04   0:00 /usr/lib/misc/s
root      8838  0.0  0.1   8880  3080 ?        Ss   02:04   0:00 sshd: root@nott
root      8840  0.0  0.0   5436  1768 ?        Ss   02:04   0:00 /usr/lib/misc/s
root     15237  0.0  0.1   8744  2856 ?        Ss   16:00   0:00 sshd: hudson-sl
1000     15239  0.0  0.0   8884  1844 ?        S    16:00   0:00 sshd: hudson-sl
1000     15240  0.0  0.0   2908  1084 ?        Ss   16:00   0:00 bash -c wget --
1000     15242  0.2  2.1 671620 44412 ?        Sl   16:00   0:08 /etc/java-confi
root     15575  0.0  0.1   8768  3008 ?        Ss   16:25   0:00 sshd: root@pts/
root     15577  0.0  0.0   4304  1012 pts/0    Ss+  16:25   0:00 /usr/bin/screen
root     15620  0.0  0.1   5428  2100 ?        Ss   16:25   0:00 /usr/bin/SCREEN
root     15621  0.0  0.1   5304  2576 pts/1    Ss+  16:25   0:00 -/bin/bash
smmsp    15875  0.0  0.1   8492  3476 ?        S    16:54   0:00 sendmail: o4JLs
root     15888  0.0  0.1   8768  3004 ?        Ss   16:58   0:00 sshd: root@pts/
root     15890  0.0  0.0   4316  1028 pts/2    Ss+  16:59   0:00 /usr/bin/screen
root     15933  0.0  0.1   5432  2096 ?        Ss   16:59   0:00 /usr/bin/SCREEN
root     15934  0.1  0.1   5304  2604 pts/3    Ss   16:59   0:00 -/bin/bash
root     16021  0.0  0.0   3856  1060 pts/3    R+   17:00   0:00 ps aux

解决方法

因为linux内存管理只是简单的古怪?

抛开笑话,认真对待 – Linux中的内存管理并不是一个简单的野兽. “查看”“免费”和“使用”的内容有不同的方法,以及even the most obvious number might not be so obvious once you look into it.我认为您可能想要量化“使用”的定义,然后将该定义应用于您正在查看的数字,特别是关于你使用的数字.

> Are you taking into account shared memory?根据您使用“计算”​​的方式,程序的内存可以很小或更大,更大.您是否单独计算共享内存,或者好像连接到它的每个进程都拥有它?
> Shared libraries也可以具有相同的行为:程序加载与另一个程序共享的库(libmylibrary.so).一种内存视图表明该库不计入使用的内存;另一个视图说它不仅会,但它会计算两次 – 一次用于刚刚使用它的程序,再次用于已经使用它的程序,因为每个程序都需要虚拟内存映射才能使库工作.第三种观点认为库实际上只占用了加载它所需的内存.哪一个是“正确”的记忆观?>磁盘缓存/缓冲区还可以创建“使用”与“免费”的复杂视图.系统将耗尽程序未使用的内存,但如果需要内存来加载程序,则会丢弃缓存并重新使用以加载该程序的实例.您可以轻松地在内存中加载3Mbyte代码,但消耗600Mbyte的磁盘缓存.再一次,哪一个是“正确的”观点?

大佬总结

以上是大佬教程为你收集整理的Linux上的内存使用情况与`free`不匹配全部内容,希望文章能够帮你解决Linux上的内存使用情况与`free`不匹配所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。