<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Memory Management on Digi Hunch</title><link>https://static.digihunch.com/tag/memory-management/</link><description>Recent content in Memory Management on Digi Hunch</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><lastBuildDate>Tue, 08 Apr 2025 14:46:49 -0400</lastBuildDate><atom:link href="https://static.digihunch.com/tag/memory-management/index.xml" rel="self" type="application/rss+xml"/><item><title>Java Garbage Collection</title><link>https://static.digihunch.com/2020/08/java-garbage-collection/</link><pubDate>Fri, 07 Aug 2020 23:19:17 -0400</pubDate><guid>https://static.digihunch.com/2020/08/java-garbage-collection/</guid><description>&lt;p class="wp-block-paragraph"&gt;Tuning the garbage collector is the most important thing that can be done to improve the performance of a Java application. GC is typically caused when the JVM decides GC is necessary, specifically when:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;a minor GC will be triggered when the new generation is full;&lt;/li&gt;&#10;&lt;li&gt;a full GC will be triggered when the old generation is full;&lt;/li&gt;&#10;&lt;li&gt;a concurrent GC (if applicable) will be triggered when the heap starts to fill up&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;OpenJDK has three collectors suitable for production, with different performance characteristics. In order to study the GC behaviours in application, it is important to turn on GC logging. The detailed step is different in JDK 8 and JDK 11 (read about java version &lt;a href="https://static.digihunch.com/2018/11/the-java-confusions/"&gt;here&lt;/a&gt;).&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Java developers don&amp;#8217;t need to manage life cycle of objects explicitly as the JVM automatically fress the object. In order to track objects that are still in use, it is insufficient to count references to objects. Instead, the JVM must periodically search the heap for unused objects. Once it finds unused objects, the JVM frees the memory occupied by those objects. It also needs to compact the memory to prevent memory fragmentation. The performance of GC is dominated by these basic operations (finding unused objects; freeing up their memory; compacting the heap), no matter which collector is used. Some algorithms delay compaction until absolutely necessary, some compact entire sections of the heap at a time, and some compact the heap by relocating small amounts of memory at a time. These different approaches are why different algorithms have different performance characteristics.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Java programs are typically heavily multithreaded, and the garbage collector itself often runs multiple threads too. We refer to the application logic threads as mutator threads, since they are mutating objects as part of the application logic. When GC threads track object references or move objects around in memory, they must make sure application threads are not using those objects on the move. This introduces a pause when all application threads are stopped (known as stop-the-world pauses), which generally has the greatest impact on the performance of an application. Minimizing those pauses is one important consideration when tuning GC.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-garbage-collectors-are-generational"&gt;Garbage collectors are generational&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Most garbage collectors work by splitting the heap into generations. These are called the old (or tenured) generation, and the young generation, which is further divided into sections known as eden and survivor spaces, with eden taking up the vast majority of the young generation. The rationale for having separate generations is that many objects are used for a very short period of time in the real life of application programming. Garbage collector is designed to take advantage of this. Objects are first allocated in the young generation, which is a subset of the entire heap. When the young generation fills up, the garbage collector will stop all the application threads and empty out the young generation. Objects that are no longer in use are discarded, and objects that are still in use are moved elsewhere. This operation is called a minor GC or a young GC. Common GC algorithms have stop-the-world pauses during collection of the young generation.&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large"&gt;&lt;img loading="lazy" decoding="async" width="553" height="276" src="https://static.digihunch.com/wp-content/uploads/2020/08/image-9.png" alt="" class="wp-image-1270"/&gt;&lt;figcaption class="wp-element-caption"&gt;Heap Generation&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;This design has two performance advantages. First, Cleaning up young generation as a only a portion of the entire heap causes shorter pause than cleaning up the entire heap. Second, by moving used objects to survivor spaces or old generation, and discarding unused objects, compatction is achieved.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;With used objects moved to the old generation, eventually it woo will fill up, and the JVM will needt o find any objects within the old generation that are no longer in use to discard. This is where GC algorithms have their biggest differences. The simpler alghorithms stop all application threads, find the unused objects, free their memory, and then compact the heap. This process is called a full GC, and it generally causes a relatively long pause for the application threads.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;On the other hand, sophisticated alghrithms are able to find unused objects while application threads are running. These algorithms are called concurrent collectors, or low-pause collectors. A concurrent collector typically allows an application to experience fewer and shorter pauses. The biggest trade-off here is the overall CPU required by the sophisticated algorithms.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-the-three-main-algorithms"&gt;The three main algorithms&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Serial GC is the simplest and the default for single core host (e.g. client-class machine, single-processor VM or Docker container). The serial collector uses a single thread to process the heap. It will stop all application threads as the heap is processed (for either a minor or full GC). During a full GC, it will fully compact the old generation. The serial collector is enabled by using the -XX:+UseSerialGC flag.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The throughput collector (aka parallel collector) is the default collector for any 64-bit machine with two or more CPUs. The throughput collector uses multiple threads to collect the young generation, which makes minor GCs much faster than when the serial collector is used. This uses multiple threads to process the old generation as well. The throughput collector stops all application threads during both minor and full GCs, and it fully compacts the old generation during a full GC. Since it is the default in most situations where it would be used, it needen&amp;#8217;t be expliticly enabled. To enable it where necessary, use the flag -XX:+UseParallelGC&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The G1 GC (or garbage first garbage collector) uses a concurrent collection strategy to collect the heap with minimal pauses. It is the default collector in JDK 11 and later for 64-bit JVMs on machines with two or more CPUs. G1 GC divides the heap into regions, but it still considers the heap to have two generations. Some of those regions make up the young generation, and the young generation is still collected by stopping all application threads and moving all objects that are alive into the old generation or the survisor spaces, using multiple threads. In G1 GC, the old generation is processed by background threads that don&amp;#8217;t need to stop the application threads to perform most of their work.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In G1 GC, the old generation is processed by background threads that don&amp;#8217;t need to stop the application threads to perform most of their work. Because the old generation is divided into regions, G1 GC can clean up objects from the old generation by copying from one region into another, which means that it compacts the heap during normal processing. This helps keep G1 GC heaps from becoming fragmented.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The trade-off for avoiding the full GC cycles is CPU time; the multiple background threads G1 GC uses to process the old generation requires CPU cycles available at the same time the application threads are running. G1 GC is enabled by specifying the flag -XX:+UseG1GC. It is the default in JDK 11, and functional in JDK 8 as well, with some performance feature missing.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In all cases, GC is caused when the JVM decices GC is necessary; a minor GC will be triggered when the new generation is full; a full GC will be triggered when the old generation is full, or a concurrent GC (if applicable) will be triggered when the heap starts to fill up. Java also provides a mechanism for applications to force a GC to occur: the System.gc() method, although it is always a bad idea to call that method explicitly because it triggers a full GC which hangs the application threads. This method can be disabled by including -XX:+DisableExplicitGC in the JVM arguments.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;As to choosing GC algorithm, the rule of thumb is that G1 GC is the better choice. However, in JDK 8, the ability of G1 GC to avoid a full GC is also a key consideration. In this case we may need to choose betwen serial collectors and throughput collectors, based on the number of CPUs on the machine.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The serial collector makes sense when running CPU-bound applications on a machine with a single CPU, even if that single CPU is hyper-threaded. The throughput collector makes sens on multi-CPU machines running jobs that are CPU bound. Even for jobs that are not CPU bound, the throughput collector can be the better choice if it does relatively few full GCs or if the old generation is generally full.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-basic-gc-tuning"&gt;Basic GC tuning&lt;/h3&gt;&#10;&lt;h4 class="wp-block-heading" id="h-sizing-the-heap"&gt;Sizing the heap&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;If the heap is too small, the program will spend too much time performing GC and not enough time performing application logic. On the contrary, a very large heap will increase the time spent in GC pauses, even thought the pauses occur less frequently. It is also potentially dangerous due to interaction with memory swap. If a Java program with a 12 GB heap is running on a system where &lt;a href="https://static.digihunch.com/2018/04/centos-remove-swap-safely/"&gt;swap&lt;/a&gt; is enabled, the OS may handle it by keeping 8GB of the heap in RAM and 4GB on disk. The JVM does not know about this because swapping is handled by the OS. The JVM will happily fill up all 12GB of heap it has been told to use. This can cause a sever performance penalty when OS swaps data from disk to RAM. Worse, the one time this swapping is guaranteed to occur is during a full GC, when the JVM must access the entire heap. Swapping during full GC makes the pause an order of magnitude longer.&lt;br&gt;So heap size (total for all JVMs) should never exceed the amount of physical memory on the machine. Size of heap is controled by two values (Xms as initial value and Xmx as maximum value). Having an initial and maximum size for the heap allows the JVM to tune its behaviour depending on the workload. If the JVM sees that it is doing too much GC, with the initial heap size, it will continually increase the heap until the JVM is doing the &amp;#8220;correct&amp;#8221; amount of GC, or until the heap hits its maximum size.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;A good rule of thumb is to size the heap so that it is 30% occupied after a full GC. To calculate this, start your application and push it to high load. Then connect to the application with jconsole, force a full GC, and observe how much memory is used when the full GC completes.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading" id="h-sizing-the-generations"&gt;Sizing the generations&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The JVM must also decide how much of the heap to allocate respectively to they young generation and old generation. THe JVM usually does this automatically and usually does a good job in determining the optimal ratio. In some cases you might hand-tune these values.&lt;br&gt;In general, if there is a relatively larger young generation, young GC pause times will increase, but the young generation will be collected less often, and fewer objects will be promoted into the old genration. But on the other hand, older generation will be relatively smaller and fill up more frequently and do more full GCs. The command-line flag to tune the generation sizes are:&lt;br&gt;-XX:NewRatio=N&lt;br&gt;-XX:NewSize=N&lt;br&gt;-XX:MaxNewSize=N&lt;br&gt;-Xmn N&lt;br&gt;The size of initial young generation is determined by initial heap size and new ratio:&lt;br&gt;Initial Young Gen Size = Initial Heap Size / (1 + NewRatio)&lt;br&gt;The young generation will grow in tandem with the overall heap size, but it can also fluctuate as a percentage of the total heap (based on the initial and maximum size of the young generation). Adaptive sizing controls how the JVM alters the ratio of young genration to old gneeration within the heap. It should be kept enabled in general. For finely tuned heaps, adaptive sizing can be disabled for a small performance boost.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading" id="h-sizing-the-metaspace"&gt;Sizing the metaspace&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;When the JVM loads classes, it must keep track of certain metadata about those classes. This occupies a separate heap space called the metaspace. In older JVMs this was handled by a different implementation called permgen. To end users, the metaspace is opaque. It does not hold the actual instance of the class. The objects are held in the regular heap. Information in the metaspace is used only by the compiler and JVM runtime, and the data it holds is referred to as class metadata.&lt;br&gt;Tuning the metaspace is fairly rare these days because the default values for the size of metaspace are very generous. It is sized dynamically based on an initial size (-XX:MetaspaceSize=N) and will increase as needed to a maximum size (-XX:MaxMetaspaceSize=N).&lt;br&gt;Resizing the metaspace requires a full GC, so it is an expensive operation. If there are a lot of full GCs during the startup of a program (as it it loading classes), it is often because permgen or metaspace is being resized, so increasing the initial size is a good idea to improve startup in that case.&lt;/p&gt;&#10;&lt;h4 class="wp-block-heading" id="h-controlling-parallelism"&gt;Controlling Parallelism&lt;/h4&gt;&#10;&lt;p class="wp-block-paragraph"&gt;All GC alghorithms except the serial collector use multiple threads. The number of these threads is controlled by the -XX:ParallelGCThreads=N flag. Bacuase these GC operations stop all application threads from executing, the JVM attempts to use as many CPU resources as it can in order to minimize the pause time. By default, that means the JVM will run one thread for each CPU on a machine, up to eight. Once that threashold has reached, the JVM adds new thread for only every 1.6 CPus. Sometimes this number is too large relative to the heap size and hand tuning is needed.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;Reference&lt;/strong&gt;: Java Performance by Scott Oaks&lt;/p&gt;&#10;&lt;figure class="wp-block-image size-large is-resized"&gt;&lt;img loading="lazy" decoding="async" src="https://static.digihunch.com/wp-content/uploads/2023/01/java-performance-780x1024.jpeg" alt="" class="wp-image-7911" width="240" height="315" srcset="https://static.digihunch.com/wp-content/uploads/2023/01/java-performance-780x1024.jpeg 780w, https://static.digihunch.com/wp-content/uploads/2023/01/java-performance-229x300.jpeg 229w, https://static.digihunch.com/wp-content/uploads/2023/01/java-performance-768x1008.jpeg 768w, https://static.digihunch.com/wp-content/uploads/2023/01/java-performance.jpeg 1036w" sizes="auto, (max-width: 240px) 100vw, 240px" /&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://www.amazon.com/gp/product/1492056111/ref=as_li_ss_il?ie=UTF8&amp;amp;linkCode=li2&amp;amp;tag=glowinghunch-20&amp;amp;linkId=a780d6a00fe93c93bf399c6c9393c806&amp;amp;language=en_US" target="_blank" rel="noopener noreferrer"&gt;&lt;/a&gt;This &lt;a href="https://engineering.linkedin.com/garbage-collection/garbage-collection-optimization-high-throughput-and-low-latency-java-applications"&gt;post&lt;/a&gt; also contains some helpful information, where the original Oracle &lt;a href="https://engineering.linkedin.com/garbage-collection/garbage-collection-optimization-high-throughput-and-low-latency-java-applications"&gt;white paper&lt;/a&gt; about GC was cited. Further than GC, this &lt;a href="https://www.oracle.com/java/technologies/javase/javase-core-technologies-apis.html"&gt;website&lt;/a&gt; from Oracle describes more about JVM.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://static.digihunch.com/2020/08/virtualization-of-graphics-computing-resource/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Virtualization 2 of 4 – Graphics Computing&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://static.digihunch.com/2020/08/cloud-storage-overview/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Cloud storage overview&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item><item><title>Virtualization 1 of 4 – Hypervisor</title><link>https://static.digihunch.com/2020/07/overview-of-virtualization/</link><pubDate>Mon, 27 Jul 2020 22:52:00 -0400</pubDate><guid>https://static.digihunch.com/2020/07/overview-of-virtualization/</guid><description>&lt;p class="wp-block-paragraph"&gt;In broad terms, virtualization of computing resource is about isolation of resources, at different levels. There are five levels of virtualization:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;Application level, such as JVM, .NET CLR&lt;/li&gt;&#10;&lt;li&gt;Library (user-level API) level&lt;/li&gt;&#10;&lt;li&gt;Operating system level, such as LXC, Docker, OpenVZ&lt;/li&gt;&#10;&lt;li&gt;Hardware abstraction layer (HAL) level, such as VMware, Xen, etc&lt;/li&gt;&#10;&lt;li&gt;Instruction set architecture (ISA) level&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;In my context I deal mostly with OS level and HAL (hardware abstraction layer) level of virtualization. In loose terms, the word &lt;em&gt;containerization&lt;/em&gt; refers to &lt;span style="text-decoration: underline;"&gt;OS level virtualization&lt;/span&gt;, while the word &lt;em&gt;virtualization&lt;/em&gt; is exclusively reserved for &lt;span style="text-decoration: underline;"&gt;HAL level virtualization&lt;/span&gt;, also referred to as &lt;span style="text-decoration: underline;"&gt;hypervisor-based virtualization&lt;/span&gt;. This post will just focus on this family of technology and loosely refers to it as virtualization.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Virtualization technology evolved from on-premise data centre environment and now is the backbone of cloud computing. The challenges of IT operation in the era of virtualization involves managing VM sprawling, investigating performance issues, planning capacity and addressing storage I/O block. The idea of virtualization is sharing (thus isolating) resources for better utilization, leading to better return on investment. This posting is to cover only the very basics of virtualization.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-hypervisor"&gt;Hypervisor&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Hypervisor is the software layer which provides the capability to run multiple virtual machines on the same physical host. It is broken down into two categories:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;Type I hypervisor (aka bare metal hypervisor)&lt;/strong&gt;: directly run on physical hardware. They control the hardware as well as manage the virtual machines. For example, Linux KVM, VMware ESXi, Xen and Microsoft Hyper-V&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Type II hypervisor&lt;/strong&gt;: runs as an application or service on top of the host operating system, which is installed on the bare metal. Guest operating system calls need to traverse via the host operating system stack to reach hardware resource. For example, Oracle Virtual Box, VMware Fusion and Linux Containers (LXC)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter"&gt;&lt;img decoding="async" src="https://img.vembu.com/wp-content/uploads/2019/12/Hypervisor-Types.png" alt="Type-1 vs Type-2 Hypervisor"/&gt;&lt;figcaption class="wp-element-caption"&gt;Hypervisor Types&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;h3 class="wp-block-heading" id="h-virtualization-techniques"&gt;Virtualization Techniques&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The most primitive form of technology that can be arguably categorized under virtualization is hardware emulation, where a piece of (more accessible) hardware imitates another (less accessible). The architecture limits itself in functional testing only, and is not built for performance or production at all.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The original virtualization technology deals with CPU and memory virtualization. In this well-written &lt;a href="https://github.com/skonstantinov89/books/blob/master/Understanding%20Full%20Virtualization%2C%20Paravirtualization%2C%20and%20Hardware%20Assist.pdf"&gt;whitepaper &lt;/a&gt;fromVMware, there are three CPU virtualization techniques introduced for x86 architecture.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The x86 architecture offers four levels of privilege known as Ring 0,1,2 and 3 to operating system and applications to manage access to the computer hardware. User-level applications typically run in Ring 3, the OS must execute its privileged instructions in Ring 0 since it needs to have direct access to memory and hardware. The two main challenges with virtualizing x86 architecture are:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;A virtualization layer between hardware operating system who expects Ring 0 privilege;&lt;/li&gt;&#10;&lt;li&gt;Some instructions with different semantics when not executed in Ring 0 cannot be virtualized effectively. They need to be translated at runtime.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p class="wp-block-paragraph"&gt;These challenges makes true virtualization of x86 architecture impossible and thus VMware developed three alternative technologies.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://en.wikipedia.org/wiki/Full_virtualization"&gt;&lt;strong&gt;Full virtualization&lt;/strong&gt;&lt;/a&gt; (using binary translation): virtual machine presents a complete simulation of the actual hardware environment so that an unmodified guest OS can run in isolation. The Guest OS is not aware that the underlying environment it is running on is virtualized, and issues hardware calls to communicate with (what it thinks as) hardware. The virtual processors have to understand guest CPU instruction, and reproduce the equivalent CPU instructions of the host machine. VMware&amp;#8217;s technology to address this is called &lt;strong&gt;Binary Translation&lt;/strong&gt;. This overhead makes true full virtualization difficult to achieve. In real life, a virtual environment that provides &amp;#8220;enough representation of the underlying hardware&amp;#8221; can be considered to provide full virtualization as long as it allows guest OS to run without modification. Full virtualization comes with a performance penalty. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://en.wikipedia.org/wiki/Paravirtualization"&gt;&lt;strong&gt;Paravirtualization &lt;/strong&gt;&lt;/a&gt;(aka OS assisted virtualization): refers to communication between the guest OS and the hypervisor to improve performance and efficiency. In this technology, guest OS is modified with an interface to host hardware to be able to communicate and operate seamlessly. Since the guest OS is modified, the VM does not need to be a complete simulation of the hardware. The modified guest OS knows it is running on a virtualized environment, and (vm driver) makes API calls (known as &amp;#8216;hyper calls&amp;#8217;) to the hypervisor. This allows para-virtualization technology to achieve performance closer to non-virtualized environment. However, since paravirtualization cannot support unmodified operating systems, its compatibility and portability is poor. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://en.wikipedia.org/wiki/Hardware-assisted_virtualization"&gt;&lt;strong&gt;Hardware-Assisted Virtualization&lt;/strong&gt;&lt;/a&gt;: hardware vendors such as Intel and AMD both have developed extensions (new features) to simplify virtualization techniques, for example, the introduction of privileged instructions with new CPU execution mode feature to allow hypervisor to run in a new root mode below ring 0. This removed the need for full virtualization and paravirtualization. With VMware originally as a promoter of full virtualization and Xen for paravirtualization, most virtualization technologies today utilizes hardware-assisted virtualization feature, for example, Linux KVM, VMware workstation, VMware fusion, Xen, VirtualBox, etc. Intel&amp;#8217;s virtualization extension is VT-x. AMD&amp;#8217;s counterpart is AMD-V technology.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;To virtualize memory, another level of memory virtualization is required (similar to the virtual memory support in Linux). Hypervisor is responsible for mapping guest physical memory to the actual machine memory, and it uses shadow page tables to accelerate the mappings, usually at a performance cost.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-popular-hypervisors"&gt;Popular hypervisors&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;On the market there are a few popular hypervisor technologies. They are all type 1 hypervisors:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;a href="https://en.wikipedia.org/wiki/Xen"&gt;Xen &lt;/a&gt;is an open-source &lt;a href="https://xenproject.org/"&gt;hypervisor project&lt;/a&gt; originally developed in Cambridge University, licensed under GPLv2. . Based on that, Citrix developed its commercial product XenServer, a bare-metal virtualization platform with enterprise-grade features for x86 and AMD environments. Oracle VM is another commercial implementation of Xen. The Xen project also supports many cloud platforms such as Openstack, Cloudstac, etc. Xen project supports paravirtualization (Xen-PV) as well as hardware-assisted virtualization (Xen-HVM) for virtualization of X86, IA64, ARM and other CPU architectures. The earlier versions does not support memory overcommit (aka &amp;#8220;dynamic memory optimization&amp;#8221;, &amp;#8220;memory &lt;a href="https://static.digihunch.com/2020/05/understanding-where-the-memory-goes-on-linux-vm/"&gt;ballooning&lt;/a&gt;&amp;#8220;, or as Citrix calls it &amp;#8220;dynamic memory control, DMC&amp;#8221;). This delivers better performance but also has higher budgetary requirement on hardware since there isn&amp;#8217;t room for over-subscription. &lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Hyper-V is a Microsoft product. It executes in high CPU privilege (Microsoft calls it ring -1 which is equivalent to root mode as Intel calls it). On the guest VM, OS kernel and drivers run in ring 0, application rin in ring 3. This eliminates the need for binary translation. Hyper-V does not support memory overcommit either. Hyper-V is well integrated with Windows platform. It supports Linux as well although with some performance penalty.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Linux KVM (Kernel-based Virtual Machine) is a full open-source virtualization solution for GNU/Linux. What makes KVM a special hypervisor is that it uses a loadable kernel module kvm.ko that turns itself into a hypervisor and provides VMs with direct access to the hardware. So it is a type 1 hypervisor despite of the presence of Linux OS. KVM also contains a processor specific module, kvm-intel.ko or kvm-amd.ko. KVM leverages qemu to access devices. Because KVM runs as a process inside of Linux OS, KVM can use many existing feature in Linux kernel. Redhat has an enterprise solution based on KVM.&lt;/p&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter size-full"&gt;&lt;img loading="lazy" decoding="async" width="850" height="414" src="https://static.digihunch.com/wp-content/uploads/2023/01/Comparison-of-Xen-KVM-and-QEMU.png" alt="" class="wp-image-7813" srcset="https://static.digihunch.com/wp-content/uploads/2023/01/Comparison-of-Xen-KVM-and-QEMU.png 850w, https://static.digihunch.com/wp-content/uploads/2023/01/Comparison-of-Xen-KVM-and-QEMU-300x146.png 300w, https://static.digihunch.com/wp-content/uploads/2023/01/Comparison-of-Xen-KVM-and-QEMU-768x374.png 768w" sizes="auto, (max-width: 850px) 100vw, 850px" /&gt;&lt;figcaption class="wp-element-caption"&gt;Xen vs KVM&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;VMware &lt;a href="https://en.wikipedia.org/wiki/VMware_ESXi"&gt;ESXi &lt;/a&gt;is VMware&amp;#8217;s premium hypervisor product (not open-source) and is available for &lt;s&gt;free download&lt;/s&gt;, although the advanced features are not free. (Update no free download link &lt;a href="https://www.reddit.com/r/vmware/comments/1amtzvc/esxi_hypervisor_free_gone/"&gt;anymore&lt;/a&gt;.) VMware &lt;a href="https://static.digihunch.com/2018/07/overview-of-vsphere/"&gt;vSphere&lt;/a&gt; is virtualization platform built on top of ESXi, including a whole family of virtualization products.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-market-segments-and-players"&gt;Market segments and players&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Virtualization involves many market segments such as virtual desktop infrastructure (VDI, for desktop virtualization), server virtualization is the predominant domain in the virtualization of data centre environment. This effort led to Hyper-Converged Infrastructure (HCI) where almost all the traditional hardware resources are software-defined through the virtualization layer. The management of infrastructure is abstracted away from the physical hardware management. The three most fundamental areas in HCI are:&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Server (compute) virtualization: the previous section covers the virtualization of memory and x86 CPU, which are the main focus on computing resource virtualization. Additionally, graphics computing resources can be virtualized today. Example products include: VMware vShpere (compute virtualization based on ESXi hypervisor).&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Storage_virtualization"&gt;Storage Virtualization&lt;/a&gt;&lt;/strong&gt;: the technology to abstract physical data storage resource to make them appear as if they were a centralized resource. Storage virtualization takes place at three levels depending on the use case: block-level, file-level and object level. Example products include: VMWare vSAN (vSphere-native storage), HPE 3PAR (Tier-1 storage), EMC VxRail, PureStorage Flash Array (Tier 1), etc. Storage Virtualization enables &lt;a href="https://en.wikipedia.org/wiki/Software-defined_storage"&gt;&lt;strong&gt;Software-Defined Storage&lt;/strong&gt; &lt;/a&gt;&lt;strong&gt;(SDS)&lt;/strong&gt;, the provisioning and management of data storage independent of the underlying hardware.&amp;nbsp;&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;&lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Network_virtualization"&gt;Network Virtualization&lt;/a&gt;&lt;/strong&gt;: the technology to abstract network resources that were traditionally delivered in hardware to software. Network virtualization decouples network services from the underlying hardware management and allows virtual provisioning of an entire network. VLAN is a classic example of network virtualization. There are also various overlay technologies such as VXLAN, which provides an industry framework for overlaying virtualized layer 2 network over layer 3 network (used in Docker network) using an encapsulation mechanism and a control plane. Example products include: VMware NSX Data Center (L2-L7 network and security virtualization platform), Cisco ACI, Palo Alto Panorama. Network Virtualization enables &lt;strong&gt;&lt;a href="https://en.wikipedia.org/wiki/Software-defined_networking"&gt;Software-Defined Network&lt;/a&gt; (SDN)&lt;/strong&gt;, an approach to network management that enables dynamic, programmatically efficient network configuration in order to improve network performance and monitoring, making it more like cloud computing than traditional network management.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-delivery-model"&gt;Delivery model&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Virtualization allows managed service providers (MSPs) to deliver IT service in the following three models:&lt;/p&gt;&#10;&lt;ul class="wp-block-list"&gt;&#10;&lt;li&gt;&lt;strong&gt;Iaas (Infrastructure as a Service)&lt;/strong&gt;: MSP delivers VM to customers.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;PaaS (Platform as a Service)&lt;/strong&gt;: MSP delivers environments to customers (e.g. Database as a Service, managed RabbitMQ service, etc).&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;SaaS (Software as a Service)&lt;/strong&gt;: MSP delivers entire application for the customer.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="wp-block-image"&gt;&#10;&lt;figure class="aligncenter is-resized"&gt;&lt;img decoding="async" src="https://www.redhat.com/cms/managed-files/iaas_focus-paas-saas-diagram-1200x1046.png" alt="What is IaaS?" style="width:608px;height:388px"/&gt;&lt;figcaption class="wp-element-caption"&gt;IT service delivery models enabled by virtualization technology&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;/div&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Since virtualization is the backbone of cloud computing. This model is also referred to as cloud computing delivery model.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-virtualization-and-containerization"&gt;Virtualization and Containerization&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;These two concepts are similar and could be confusing to beginners. Both provide a mechanism to isolate computing resource for different applications, for the purpose of higher utilization of resource. The difference lies in how and where the isolation is made. Virtualization requires a guest operating system per VM (OS level isolation), whereas the container technology isolates application processes along with its runtime into a container (dependency level isolation), using some new Linux kernel features such as &lt;em&gt;namespaces &lt;/em&gt;and &lt;em&gt;cgroups&lt;/em&gt;. All containers make their system calls to the container engine on the host operating system. So they share a kernel on the same host. In this sense, container engine running on OS could be considered as type 2 hypervisor.&lt;/p&gt;&#10;&lt;figure class="wp-block-image"&gt;&lt;img decoding="async" src="https://dzone.com/storage/temp/10561741-vm-container-figure1.jpg" alt="Image title"/&gt;&lt;figcaption class="wp-element-caption"&gt;From VMs to containers&lt;/figcaption&gt;&lt;/figure&gt;&#10;&lt;p class="wp-block-paragraph"&gt;VMware is a major player in enterprise data centre virtualization, which is facing fierce competition from public and private cloud vendors. VMware also has its own private cloud services. Docker is the most popular container technology that conforms to the specifications of Open Container Initiative (OCI), a governance structure for industry standards around container formats and runtimes.&lt;/p&gt;&#10;&lt;h3 class="wp-block-heading" id="h-virtualization-and-cloud"&gt;Virtualization and Cloud&lt;/h3&gt;&#10;&lt;p class="wp-block-paragraph"&gt;Among public cloud vendors, AWS &lt;a href="https://cloudacademy.com/blog/aws-ami-hvm-vs-pv-paravirtual-amazon/"&gt;EC2 &lt;/a&gt;used Xen PV and Xen HVM in its earlier implementations. It has transitioned to AWS bare metal. The history is well summarized &lt;a href="http://www.brendangregg.com/blog/2017-11-29/aws-ec2-virtualization-2017.html"&gt;here&lt;/a&gt;. Microsoft Azure runs Azure Hypervisor as the native hypervisor in Azure Cloud Services platform. It is a customized version of Microsoft Hyper-V specifically for Azure platform. With GCP, Google &lt;a href="https://cloud.google.com/compute/docs/faq"&gt;Compute Engine&lt;/a&gt; (GCE) instance runs VMs on KVM as hypervisor. It can also enable nested virtualization.&lt;/p&gt;&#10;&lt;p class="wp-block-paragraph"&gt;The scope of cloud computing is evolving overtime. It originally only refers to a business model of offering IT services (in one of the three delivery models outlined above) based on virtualization technology. Therefore I cannot make comparison between a technology and a business model. Today, with public cloud vendor extending their offerings (with various managed services and platforms) and people&amp;#8217;s misuse of the terms, the buzz-word &amp;#8220;cloud&amp;#8221; seems to suggest anything that is offered in public cloud service. The essence still remain the same where managed services and managed platforms are built on top of virtualized compute unit under the hood, which are driven by virtualization technologies.&lt;/p&gt;&#10;&lt;nav class="wp-post-navigation" aria-label="Post navigation"&gt;&#10;&lt;a rel="prev" href="https://static.digihunch.com/2020/07/zookeeper-and-kafka-overview/"&gt;&lt;span class="wp-post-navigation-label"&gt;Previous Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Kafka high-level Overview&lt;/strong&gt;&lt;/a&gt;&#10;&lt;a rel="next" href="https://static.digihunch.com/2020/08/virtualization-of-graphics-computing-resource/"&gt;&lt;span class="wp-post-navigation-label"&gt;Next Post&lt;/span&gt;&lt;strong class="wp-post-navigation-title"&gt;Virtualization 2 of 4 – Graphics Computing&lt;/strong&gt;&lt;/a&gt;&#10;&lt;/nav&gt;&#10;</description></item></channel></rss>