Hyper-V 上具有动态内存的 CentOS 7

Hyper-V 上具有动态内存的 CentOS 7

我有一台在 Hyper-v 上运行的 CentOS 7 VM(全新安装)。我为其分配了 256 到 2048 MB 的动态内存(启动 RAM 设置为 512 MB)。启动后,内存占用量相当低,但会稳步增长至 2 GB 的限制。当我查看 VM 中的内存时,发现大部分内存都是空闲的。

为什么?如何让 CentOS 使用动态 RAM?

Hyper-V-Manager 显示虚拟机需要 1594 MB,而分配给虚拟机的内存为 1898 MB。我理解它分配的内存超过所需内存的原因(因为内存设置为 20%),但为什么它认为虚拟机需要 1594 MB,而实际上虚拟机仅使用了约 600 MB?虚拟机是 CentOS 7 最小/仅控制台安装。

以下是有关虚拟机的一些信息:

$ uname -a
Linux test.local 3.10.0-514.21.1.el7.x86_64 #1 SMP Thu May 25 17:04:51 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

实际有 1200 MB 可用内存:

$ free
              total        used        free      shared  buff/cache   available
Mem:        1990816      558872     1237140        4440      194804     1356912
Swap:       2097148           0     2097148

$ cat /proc/meminfo
MemTotal:        1990816 kB
MemFree:         1237404 kB
MemAvailable:    1357208 kB
Buffers:              76 kB
Cached:           137120 kB
SwapCached:            0 kB
Active:           270656 kB
Inactive:         152568 kB
Active(anon):     214744 kB
Inactive(anon):    75724 kB
Active(file):      55912 kB
Inactive(file):    76844 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        286048 kB
Mapped:            41484 kB
Shmem:              4440 kB
Slab:              57640 kB
SReclaimable:      23408 kB
SUnreclaim:        34232 kB
KernelStack:        4208 kB
PageTables:        14508 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     3092556 kB
Committed_AS:    1265440 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       80920 kB
VmallocChunk:   34359647220 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       59328 kB
DirectMap2M:     2037760 kB
DirectMap1G:           0 kB

$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
11  0      0 1237264     76 194760    0    0     3     1   23   65  0  0 100  0  0

据我所知,hv_内核模块是 Hyper-V 所需的 LIS 工具。也是hv_balloon动态内存所需的工具。

$ lsmod
Module                  Size  Used by
xt_multiport           12798  1
ip6t_rpfilter          12595  1
ipt_REJECT             12541  2
nf_reject_ipv4         13373  1 ipt_REJECT
ip6t_REJECT            12625  2
nf_reject_ipv6         13717  1 ip6t_REJECT
xt_conntrack           12760  11
ip_set                 36439  0
nfnetlink              14696  1 ip_set
ebtable_nat            12807  1
ebtable_broute         12731  1
bridge                107151  1 ebtable_broute
stp                    12976  1 bridge
llc                    14552  2 stp,bridge
ip6table_nat           12864  1
nf_conntrack_ipv6      18894  7
nf_defrag_ipv6         35104  1 nf_conntrack_ipv6
nf_nat_ipv6            14131  1 ip6table_nat
ip6table_mangle        12700  1
ip6table_security      12710  1
ip6table_raw           12683  1
iptable_nat            12875  1
nf_conntrack_ipv4      19108  6
nf_defrag_ipv4         12729  1 nf_conntrack_ipv4
nf_nat_ipv4            14115  1 iptable_nat
nf_nat                 26147  2 nf_nat_ipv4,nf_nat_ipv6
nf_conntrack          111302  6 nf_nat,nf_nat_ipv4,nf_nat_ipv6,xt_conntrack,nf_conntrack_ipv4,nf_conntrack_ipv6
iptable_mangle         12695  1
iptable_security       12705  1
iptable_raw            12678  1
ebtable_filter         12827  1
ebtables               35009  3 ebtable_broute,ebtable_nat,ebtable_filter
ip6table_filter        12815  1
ip6_tables             26901  5 ip6table_filter,ip6table_mangle,ip6table_security,ip6table_nat,ip6table_raw
iptable_filter         12810  1
intel_powerclamp       14419  0
iosf_mbi               13523  0
crc32_pclmul           13113  0
ghash_clmulni_intel    13259  0
aesni_intel            69884  0
lrw                    13286  1 aesni_intel
gf128mul               14951  1 lrw
glue_helper            13990  1 aesni_intel
ablk_helper            13597  1 aesni_intel
cryptd                 20359  3 ghash_clmulni_intel,aesni_intel,ablk_helper
sg                     40721  0
pcspkr                 12718  0
hv_utils               24418  0
hv_balloon             21753  0
i2c_piix4              22106  0
i2c_core               40756  1 i2c_piix4
ip_tables              27115  5 iptable_security,iptable_filter,iptable_mangle,iptable_nat,iptable_raw
xfs                   985347  2
libcrc32c              12644  1 xfs
sd_mod                 46322  3
crc_t10dif             12714  1 sd_mod
crct10dif_generic      12647  0
sr_mod                 22416  0
cdrom                  42556  1 sr_mod
ata_generic            12910  0
pata_acpi              13038  0
hv_netvsc              40261  0
hyperv_keyboard        12777  0
hid_hyperv             13108  0
hv_storvsc             18032  2
crct10dif_pclmul       14289  1
crct10dif_common       12595  3 crct10dif_pclmul,crct10dif_generic,crc_t10dif
crc32c_intel           22079  1
ata_piix               35038  0
hyperv_fb              17769  1
serio_raw              13462  0
libata                247095  3 pata_acpi,ata_generic,ata_piix
floppy                 69417  0
hv_vmbus              397185  7 hv_balloon,hyperv_keyboard,hv_netvsc,hid_hyperv,hv_utils,hyperv_fb,hv_storvsc
fjes                   32197  0
dm_mirror              22135  0
dm_region_hash         20862  1 dm_mirror
dm_log                 18411  2 dm_region_hash,dm_mirror
dm_mod                114430  8 dm_log,dm_mirror

答案1

答案在这里:https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1584597/comments/35

Hyper-V 气球驱动程序使用 Committed_AS 值,您可以在 /proc/meminfo 中读取该值。因此,问题在于您的某些软件预先分配了大量内存,然后 Windows 会将这些内存锁定在 RAM 中供 VM 使用。

相关内容