
有一种技术,可以让 kvm 虚拟机可以看到和使用宿主机全部的内存,但是看不到其它虚拟机具体使用的进程,这是一种什么技术呢?希望有大佬解答一下,采纳后红包答谢。
1 equator OP 市面上有明确的云厂商做到了,但是不知道具体咋做的 |
2 samhjn 22 小时 57 分钟前 via iPhone 搞个 virtio-ballon 再配配策略是不是就好了 |
3 busier 22 小时 54 分钟前 via iPhone 你确定是 kvm 虚拟机? 搞不好是 lxc 或 openvz 之类的容器虚拟机技术 |
4 equator OP 购买过他家的服务器,通过 lscpu 看到是 KVM 虚拟化的。应该不是内存气球技术,内存气球会导致虚拟机可见的内存变小,它是虚拟机能看到并使用宿主机的全部内存;登录 finalshell ,资源监控那里能看到其他人占用了内存,但是看不到具体是被谁使用的。 |
6 busier 22 小时 32 分钟前 via iPhone lscpu 只是列出 cpu 支持的虚拟化指令集 怎么就确定当前运行的是 kvm 虚拟机了? |
8 busier 22 小时 30 分钟前 via iPhone 要不你把 lscpu 信息完整贴上来 让大家看看 |
9 equator OP 这个是 lscpu 的内容: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 46 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 80 On-line CPU(s) list: 0-79 Vendor ID: GenuineIntel Model name: Intel Xeon Processor CPU family: 6 Model: 85 Thread(s) per core: 2 Core(s) per socket: 20 Socket(s): 2 Stepping: 4 BogoMIPS: 5999.99 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mc a cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall n x pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopolog y cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pci d sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowp refetch cpuid_fault invpcid_single ibrs ibpb fsgsbase b mi1 hle avx2 smep bmi2 erms invpcid rtm avx512f avx512d q rdseed adx smap clwb avx512cd avx512bw avx512vl xsave opt xsavec xgetbv1 arat pku ospke Virtualization features: Hypervisor vendor: KVM Virtualization type: full Caches (sum of all): L1d: 2.5 MiB (80 instances) L1i: 2.5 MiB (80 instances) L2: 160 MiB (40 instances) L3: 32 MiB (2 instances) NUMA: NUMA node(s): 2 NUMA node0 CPU(s): 0-39 NUMA node1 CPU(s): 40-79 Vulnerabilities: Gather data sampling: Unknown: Dependent on hypervisor status Itlb multihit: KVM: Mitigation: VMX unsupported L1tf: Mitigation; PTE Inversion Mds: Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown Meltdown: Vulnerable Mmio stale data: Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown Retbleed: Mitigation; IBRS Spec rstack overflow: Not affected Spec store bypass: Vulnerable Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Spectre v2: Mitigation; IBRS, IBPB conditional, STIBP disabled, RSB filling, PBRSB-eIBRS Not affected Srbds: Not affected Tsx async abort: Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown |
10 cs8425 21 小时 3 分钟前 via Android 有没有一种可能 实体机先用 kvm 虚拟化一个 VM VM 内再用容器之类的技术租给使用者? 不是直接 kvm 的 vm 租出去 也不是实体机上面直接开容器组出去 |
11 Becod 20 小时 47 分钟前 |
12 yanqiyu 15 小时 32 分钟前 > 可以让 kvm 虚拟机可以看到和使用宿主机全部的内存 第一眼吓我一跳,我还以为你说的是虚拟机能字面意义的看到 host 的内存里面的每个 bit ,究极安全地狱。 > 通过 lscpu 命令能看到是 KVM 虚拟化 没什么意义,你在 kvm 的机器开个容器,运行 lscpu 看见的虚拟化也是 kvm ,因为容器看到的也是同一个 CPU 。要探测你看到的环境是什么 systemd-detect-virt 可能更恰当 > 应该不是内存气球技术,内存气球会导致虚拟机可见的内存变小 不,常见的内存气球实现一般是虚拟机里面一个气球驱动,在虚拟机占用掉一部分内存,然后把自己占用(但是实际上永不到)的内存还给主机。 要是你看到的内存占用和实际你的进程看到的内存占用+你能看见的内核占用完全不一致,说明你大概率在某种容器里面。 |
13 ysc3839 14 小时 23 分钟前 via Android VMware Workstation 是这样的机制,虚拟机内看到的内存大小是固定的,但不使用就不会占用宿主机内存。不过似乎使用后就不能释放掉。 Hyper-V 虚拟机里内存多大宿主机就要占用多大,即使没使用也要占用,然后虚拟机内存可以动态调大或调小,调小的话占用宿主机的内存就减少。但是实测如果有程序一次性使用大量内存,会来不及扩容而卡死,必须开启 swap 。 |
14 julyclyde 14 小时 11 分钟前 你这个可能是 kvm 内的容器,而不是 kvm 本身 |
15 equator OP 我被自己之前的经验误导了,因为之前在 LXD 容器里面看 lscpu ,是看到 Hypervisor vendor: LXD 的。 经过各位大佬点拨,我也感觉不是 kvm 虚拟机了。 我买了一个测试用,不过这个是没有 root 权限的,看起来有点像 docker 哦。 tyu-ukhx1xmi@share-idebu4dywzt:~$ df -h Filesystem Size Used Avail Use% Mounted on overlay 20G 36M 20G 1% / tmpfs 64M 0 64M 0% /dev shm 64M 0 64M 0% /dev/shm 192.168.101.71:/share/dir_idebu4dywzt 98G 30G 63G 33% /mnt/data /dev/sdb1 1000G 227G 773G 23% /etc/hosts tmpfs 126G 72K 126G 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 10G 0 10G 0% /run/user/1000 tyu-ukhx1xmi@share-idebu4dywzt:~$ virt-what -bash: virt-what: command not found tyu-ukhx1xmi@share-idebu4dywzt:~$ ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 00:40 ? 00:00:00 /sbin/init root 23 1 0 00:40 ? 00:00:00 /lib/systemd/systemd-journald systemd+ 39 1 0 00:40 ? 00:00:00 /lib/systemd/systemd-resolved message+ 41 1 0 00:40 ? 00:00:00 @dbus-daemon --system --address=systemd: --nofork root 43 1 0 00:40 ? 00:02:02 /mnt/data/tool/miniconda3/envs/jupyterhub/bin/pyth root 44 1 0 00:40 ? 00:00:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --ru root 47 1 0 00:40 ? 00:00:00 /lib/systemd/systemd-logind rstudio+ 50 1 0 00:40 ? 00:00:40 /usr/lib/rstudio-server/bin/rserver root 53 1 0 00:40 ? 00:00:00 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 sta root 54 1 0 00:40 pts/0 00:00:00 /sbin/agetty -o -p -- \u --noclear --keep-baud con root 87 1 0 00:40 ? 00:00:00 /sbin/agetty -o -p -- \u --noclear tty1 linux root 175 43 0 00:41 ? 00:00:01 node /mnt/data/tool/miniconda3/envs/jupyterhub/bin tyu-ukh+ 3655 43 0 00:47 ? 00:00:03 /mnt/data/tool/miniconda3/envs/jupyterhub/bin/pyth tyu-ukh+ 3951 3655 0 00:48 pts/3 00:00:00 /bin/bash -l root 12969 53 0 08:36 ? 00:00:00 sshd: tyu-ukhx1xmi [priv] tyu-ukh+ 12972 1 0 08:36 ? 00:00:00 /lib/systemd/systemd --user tyu-ukh+ 12973 12972 0 08:36 ? 00:00:00 (sd-pam) tyu-ukh+ 12987 12969 0 08:36 ? 00:00:00 sshd: tyu-ukhx1xmi@pts/1,pts/2 tyu-ukh+ 12988 12987 0 08:36 pts/1 00:00:00 -bash tyu-ukh+ 12992 12987 0 08:36 pts/2 00:00:00 -bash tyu-ukh+ 12993 12987 0 08:36 ? 00:00:00 /usr/lib/openssh/sftp-server tyu-ukh+ 13030 12992 0 08:36 pts/2 00:00:00 top tyu-ukh+ 13563 12987 0 08:37 ? 00:00:00 bash -c export LANG="en_US";export LANGUAGE="en_US tyu-ukh+ 13568 13563 0 08:37 ? 00:00:00 sleep 1 tyu-ukh+ 13569 12988 0 08:37 pts/1 00:00:00 ps -ef tyu-ukhx1xmi@share-idebu4dywzt:~$ df -T Filesystem Type 1K-blocks Used Available Use% Mounted on overlay overlay 20971520 33888 20937632 1% / tmpfs tmpfs 65536 0 65536 0% /dv shm tmpfs 65536 0 65536 0% /dev/shm 192.168.101.71:/share/dir_idebu4dywzt nfs4 102626304 31415296 65951744 33% /mnt/data /dev/sdb1 xfs 1048061956 237704416 810357540 23% /etc/hosts tmpfs tmpfs 132092204 72 132092132 1% /run tmpfs tmpfs 5120 0 5120 0% /run/lock tmpfs tmpfs 10485760 0 10485760 0% /run/user/1000 tyu-ukhx1xmi@share-idebu4dywzt:~$ |
17 vsomeone 13 小时 12 分钟前 首先气球驱动也可以实现你说的这件事情,不一定会让虚机“可见的内存变小”。其次听你描述,感觉更像是租了个 LXC 容器给你 |
19 equator OP 还有个问题想请教下大佬们,测试 kvm 的时候,发现 kvm 虚拟机,即使虚拟机里面的进程退出了,不占用内存了,在宿主机上看到那个虚拟机的进程还是占用着内存没释放。是否有方法可以做到内存的及时回收呢,像容器一样,一个虚拟机不用内存了,内存马上就释放了,其它虚拟机就能使用这部分内存了。 |
20 elehayym1618 11 小时 57 分钟前 @equator 这个叫内存回收,virtio_balloon 你可以查一下,需要宿主机主动调用触发 |
21 equator OP @elehayym1618 嗯嗯,现在想找一个不用宿主机主动调用触发的方法 |