[{"content":"Dynamic Memory Management 动态内存管理 Introduction Optimized and effective memory management is a key factor in virtualization environments. KSM and Auto-Ballooning enables sophisticated and economic configurations for physical RAM utilization.\n优化和有效的内存管理是虚拟环境的关键因素，KSM和Auto-Ballooning为物理内存管理提供了复杂且实用的配置。\nKSM KSM (Kernel Samepage Merging) is running in the Linux kernel and scans the memory of all the virtual machines running on a single host, looking for duplication and consolidating. With KSM we\u0026rsquo;re able to improve virtual machine density by as much as 300% without impacting performance. One of the great benefits of using Linux as the hypervisor means KSM is not limited to KVM and virtual machines, but can also reduce memory pressure with normal Linux applications.\nKSM (Kernel Samepage Merging)运行在Linux内核中，它扫描所有在单主机上运行的虚拟机的内存，寻找重复的部分并进行整合。通过KSM，我们可以在不影响性能的情况下将虚拟机的密度提高300%。使用Linux作为管理程序的一大好处是KSM不局限于KVM和虚拟机，还能减轻普通Linux应用程序的内存压力。\nIt was integrated in PVE since version 1.5, and is implemented with the package \u0026ldquo;ksm-control-daemon\u0026rdquo; (check your version with the cli command \u0026ldquo;pveversion -v\u0026rdquo;).\n它自1.5版本开始被集成进PVE，且通过包\u0026quot;ksm-control-daemon\u0026quot;实现（通过cli命令\u0026quot;pveversion -v\u0026quot;检查你的版本）。\nKSM in action Just install several KVM virtual machines with the same OS (using at least 80% of your physical memory on the host) and wait a few minutes. You will notice higher CPU activities on the host (ksm daemon) and the used memory on the host will be lowered significantly (see start page showing the overall memory usage).\n仅需安装若干同一系统（使用主机至少80%物理内存）的KVM虚拟机并等待几分钟。你可以注意到主机上更高的CPU活动（KSM进程）和主机的内存使用量显著地下降（看开始页面展示的内存使用总览）。\nHowto verify that KSM is working (how many pages are being shared between your KVM guests):\n如何验证KSM是否有效（在你的KVM客户机之间有多少页被共享）：\nwatch cat /sys/kernel/mm/ksm/pages_sharing Note: a page is 4096 bytes\n注意：一页是4096字节\nThe file /etc/ksmtuned.conf allows for some customization of its behaviour.\n文件/etc/ksmtuned.conf允许对它的行为进行定制。\nSee also\nhttp://www.linux-kvm.org/page/KSM http://www.linux-kvm.com/content/using-ksm-kernel-samepage-merging-kvm http://en.wikipedia.org/wiki/Kernel_SamePage_Merging_%28KSM%29 Disable KSM If you don\u0026rsquo;t care about memory optimization but care about save CPU overhead produced by KSM, in Proxmox \u0026gt;= 4.x you can disable it with:\n如果你不关心内存优化但在意节省KSM产生的CPU开销，在\u0026gt;=4.x的Proxmox版本中，你可以用以下命令禁用它：\nsystemctl disable ksmtuned and reboot\nBallooning Memory ballooning (KVM only) allows you to have your guest dynamically change it’s memory usage by evicting unused memory during run time. It reduces the impact your guest can have on memory usage of your host by giving up unused memory back to the host.\n内存膨胀（仅KVM）允许你通过驱逐未使用的内存来动态地改变你的客户机的内存使用量。它通过将未使用的内存返还给主机，以减少你的客户机对主机内存使用的影响。\nThe Proxmox VE host can loan ballooned memory to a busy VM. The VM decides which processes or cache pages to swap out to free up memory for the balloon. The VM (Windows or Linux) knows best which memory regions it can give up without impacting performance of the VM.\nPVE主机可以将膨胀的内存给一台繁忙的虚拟机。由虚拟机来决定为了膨胀释放内存而替换掉哪些进程或者页缓存。虚拟机（Windows或Linux）知道放弃哪些内存区域对虚拟机的性能影响是最小的。\nRequirements for Windows VM Installation You need to install the VirtIO Balloon Driver and the management service (blnsvr.exe -i). Notice: there is a small blnsvr.exe bug on 32bit systems with RAM more than 2GB: https://github.com/YanVugenfirer/kvm-guest-drivers-windows/issues/11 See Windows VirtIO Drivers to get info about downloading VirtIO drivers changelog and guest OS compatibility other kind of guest devices supported Download Download the latest drivers (ISO) as suggested by the page Windows_VirtIO_Drivers to your desktop. Then upload the ISO to your Proxmox VE server:\nlogon to the Proxmox VE web interface select a ISO-enabled storage (see Storage_Model#Storage_type_Content) switch to \u0026ldquo;content\u0026rdquo; tab just use the \u0026ldquo;upload\u0026rdquo; button on the menu bar. Choose the right driver Follow the link: Windows_VirtIO_Drivers#Choose_the_right_driver Enable Auto-Ballooning on Windows Server 2012 / Windows 8.1 or newer Starting with virtio-win-0.1.173-2 the driver ISO provides an installer located at \u0026ldquo;\u0026lt;cddrive\u0026gt;:\\virtio-win-gt-x64.msi\u0026rdquo; that can, besides other things, install the ballooning service. If it does not work you can follow the manual way which is described below for Windows 2008r2.\nEnable Auto-Ballooning on Windows 2008r2 Set the VM memory to \u0026ldquo;Automatically allocate memory within this range\u0026rdquo; - I choose 4096/2048 as example (see screenshot) Start the VM and install all virtio drivers, including the balloon driver (see screenshot) Copy and rename as Administrator the WIN7\\AMD64 directory from the virtio.iso to \u0026ldquo;c:/Program files/Balloon\u0026rdquo; Open a CMD as Administrator and cd into \u0026ldquo;c:/Program Files/Balloon\u0026rdquo; Install the BLNSVR with \u0026ldquo;BLNSVR.exe -i\u0026rdquo; As soon as the service is started, also the memory information displayed on the Proxmox VE GUI is identical to the value shown in the windows task manager (see screenshot). If you need details about ballooning stats for this VM, go to the KVM monitor and enter \u0026lsquo;info balloon\u0026rsquo; VirtIO drivers: KVM project wiki downloads\nEnable Auto-Ballooning on Windows 2003 / Windows Xp You need to install the balloon service with BLNSVR, like for win2008. You also need to install the driver manually Download the \u0026ldquo;devcon\u0026rdquo; software on microsoft website http://support.microsoft.com/kb/311272 Then install the balloon driver with\ndevcon install BALLOON.inf \u0026#34;PCI\\VEN_1AF4\u0026amp;DEV_1002\u0026amp;SUBSYS_00051AF4\u0026amp;REV_00\u0026#34; See also Windows_VirtIO_Drivers Paravirtualized Block Drivers for Windows Paravirtualized Network Drivers for Windows Requirements for Linux VM Modern Linux Kernels does include the Balloon drivers by default. It works out of the box, and you only need to set the VM to \u0026ldquo;Automatically allocate memory within this range\u0026rdquo;\n现代Linux内核默认包含了Balloon驱动程序。它可以开箱即用，你只需要将虚拟机设置为\u0026quot;在此范围内自动分配内存\u0026quot;即可\nExternal Links tbd.\n","permalink":"https://logs.eu.org/posts/pve/dynamic-memory-management---proxmox-ve/","summary":"\u003ch1 id=\"dynamic-memory-management-动态内存管理\"\u003eDynamic Memory Management 动态内存管理\u003c/h1\u003e\n\u003ch2 id=\"introduction\"\u003eIntroduction\u003c/h2\u003e\n\u003cp\u003eOptimized and effective memory management is a key factor in virtualization environments. KSM and Auto-Ballooning enables sophisticated and economic configurations for physical RAM utilization.\u003c/p\u003e\n\u003cp\u003e\u003ccode\u003e优化和有效的内存管理是虚拟环境的关键因素，KSM和Auto-Ballooning为物理内存管理提供了复杂且实用的配置。\u003c/code\u003e\u003c/p\u003e\n\u003ch2 id=\"ksm\"\u003eKSM\u003c/h2\u003e\n\u003cp\u003eKSM (Kernel Samepage Merging) is running in the Linux kernel and scans the memory of all the virtual machines running on a single host, looking for duplication and consolidating. With KSM we\u0026rsquo;re able to improve virtual machine density by as much as 300% without impacting performance. One of the great benefits of using Linux as the hypervisor means KSM is not limited to KVM and virtual machines, but can also reduce memory pressure with normal Linux applications.\u003c/p\u003e","title":"Dynamic Memory Management - Proxmox VE"},{"content":"A swap file lets the kernel move idle pages out of RAM onto disk. It\u0026rsquo;s handy on small-memory hosts (VPS, VMs) that have no dedicated swap partition, and unlike a partition it can be resized or removed without repartitioning.\nCreate the swap file 1 2 3 4 5 6 7 # Allocate a 1 GiB file. dd is preferred over fallocate here because # swapon rejects files with holes on some filesystems (e.g. ext4, XFS). dd if=/dev/zero of=/swapfile bs=1M count=1024 status=progress chmod 0600 /swapfile # only root may read/write the swap file mkswap /swapfile # format it as swap space swapon /swapfile # enable it immediately Make it persistent Add an entry to /etc/fstab so the swap file is mounted on every boot. The grep guard keeps this idempotent — running it twice won\u0026rsquo;t add a duplicate line.\n1 grep -q \u0026#39;^/swapfile \u0026#39; /etc/fstab || echo \u0026#39;/swapfile none swap defaults 0 0\u0026#39; \u0026gt;\u0026gt; /etc/fstab Tune swappiness vm.swappiness (0–100, default 60) controls how aggressively the kernel swaps; a lower value keeps more data in RAM. 10 is a common choice for servers.\nWrite it to a drop-in file under /etc/sysctl.d/ rather than editing /etc/sysctl.conf directly with \u0026gt;, which would overwrite the whole file and wipe any existing settings.\n1 2 echo \u0026#39;vm.swappiness=10\u0026#39; \u0026gt; /etc/sysctl.d/99-swappiness.conf sysctl --system # reload all sysctl.d drop-ins Verify 1 2 swapon --show free -h ","permalink":"https://logs.eu.org/posts/make-swapfile/","summary":"\u003cp\u003eA swap file lets the kernel move idle pages out of RAM onto disk. It\u0026rsquo;s handy on\nsmall-memory hosts (VPS, VMs) that have no dedicated swap partition, and unlike a\npartition it can be resized or removed without repartitioning.\u003c/p\u003e\n\u003ch3 id=\"create-the-swap-file\"\u003eCreate the swap file\u003c/h3\u003e\n\u003cdiv class=\"highlight\"\u003e\u003cdiv class=\"chroma\"\u003e\n\u003ctable class=\"lntable\"\u003e\u003ctr\u003e\u003ctd class=\"lntd\"\u003e\n\u003cpre tabindex=\"0\" class=\"chroma\"\u003e\u003ccode\u003e\u003cspan class=\"lnt\"\u003e1\n\u003c/span\u003e\u003cspan class=\"lnt\"\u003e2\n\u003c/span\u003e\u003cspan class=\"lnt\"\u003e3\n\u003c/span\u003e\u003cspan class=\"lnt\"\u003e4\n\u003c/span\u003e\u003cspan class=\"lnt\"\u003e5\n\u003c/span\u003e\u003cspan class=\"lnt\"\u003e6\n\u003c/span\u003e\u003cspan class=\"lnt\"\u003e7\n\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/td\u003e\n\u003ctd class=\"lntd\"\u003e\n\u003cpre tabindex=\"0\" class=\"chroma\"\u003e\u003ccode class=\"language-shell\" data-lang=\"shell\"\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e# Allocate a 1 GiB file. dd is preferred over fallocate here because\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\u003cspan class=\"c1\"\u003e# swapon rejects files with holes on some filesystems (e.g. ext4, XFS).\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003edd \u003cspan class=\"k\"\u003eif\u003c/span\u003e\u003cspan class=\"o\"\u003e=\u003c/span\u003e/dev/zero \u003cspan class=\"nv\"\u003eof\u003c/span\u003e\u003cspan class=\"o\"\u003e=\u003c/span\u003e/swapfile \u003cspan class=\"nv\"\u003ebs\u003c/span\u003e\u003cspan class=\"o\"\u003e=\u003c/span\u003e1M \u003cspan class=\"nv\"\u003ecount\u003c/span\u003e\u003cspan class=\"o\"\u003e=\u003c/span\u003e\u003cspan class=\"m\"\u003e1024\u003c/span\u003e \u003cspan class=\"nv\"\u003estatus\u003c/span\u003e\u003cspan class=\"o\"\u003e=\u003c/span\u003eprogress\n\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003echmod \u003cspan class=\"m\"\u003e0600\u003c/span\u003e /swapfile   \u003cspan class=\"c1\"\u003e# only root may read/write the swap file\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003emkswap /swapfile       \u003cspan class=\"c1\"\u003e# format it as swap space\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"line\"\u003e\u003cspan class=\"cl\"\u003eswapon /swapfile       \u003cspan class=\"c1\"\u003e# enable it immediately\u003c/span\u003e\n\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\u003c/div\u003e\n\u003c/div\u003e\u003ch3 id=\"make-it-persistent\"\u003eMake it persistent\u003c/h3\u003e\n\u003cp\u003eAdd an entry to \u003ccode\u003e/etc/fstab\u003c/code\u003e so the swap file is mounted on every boot. The\n\u003ccode\u003egrep\u003c/code\u003e guard keeps this idempotent — running it twice won\u0026rsquo;t add a duplicate line.\u003c/p\u003e","title":"Create a Swap File on Linux"},{"content":"Hello world\u0026hellip;\n","permalink":"https://logs.eu.org/posts/my-first-post/","summary":"\u003cp\u003eHello world\u0026hellip;\u003c/p\u003e","title":"My First Post"},{"content":"This is my first static blog.\nJust try it.\n","permalink":"https://logs.eu.org/about/","summary":"\u003cp\u003eThis is my first static blog.\u003c/p\u003e\n\u003cp\u003eJust try it.\u003c/p\u003e","title":"About Me"}]