<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Corradofiore</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Corradofiore"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Corradofiore"/>
	<updated>2026-06-10T03:00:05Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=22240</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=22240"/>
		<updated>2016-10-10T04:35:05Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: Corrected typo (KSM should be written in lowercase)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
KSM is a memory-saving de-duplication feature, developed by Red Hat. It first appeared in the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead == &amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node == &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
The KSM daemon is controlled by sysfs files in &amp;lt;code&amp;gt;/sys/kernel/mm/ksm/&amp;lt;/code&amp;gt;, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
You can copy the same command in &amp;lt;code&amp;gt;/etc/rc.local&amp;lt;/code&amp;gt; on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers == &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
Do not use the usual &amp;lt;code&amp;gt;# yum install ksm_preload&amp;lt;/code&amp;gt; command inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
[root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
&lt;br /&gt;
(If you get an error like &amp;quot;No package yum-downloadonly available&amp;quot;, just ignore it and proceed.  Most likely, your Yum installation includes that plugin already).&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
[root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications == &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 '''export LD_PRELOAD'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM == &amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/ksm/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;grep -H '' /sys/kernel/mm/ksm/*&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning == &amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for &amp;lt;code&amp;gt;/sys/kernel/mm/KSM/sleep_millisecs&amp;lt;/code&amp;gt; is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
[root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs&lt;br /&gt;
&lt;br /&gt;
== Caveats == &amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher &amp;lt;code&amp;gt;pages_to_scan&amp;lt;/code&amp;gt;, lower &amp;lt;code&amp;gt;sleep_millisecs&amp;lt;/code&amp;gt;) at the beginning, effectively trading CPU utilization for less chances of disk swapping, and then relax them after 10 mins or so.  Another possibility is to place your swap onto an SSD drive.&lt;br /&gt;
&lt;br /&gt;
== References == &amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External links == &amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
* [[wikipedia:Kernel same-page merging]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=22239</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=22239"/>
		<updated>2016-10-10T04:34:11Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: Added note in case yum-downloadonly plugin is not found&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
KSM is a memory-saving de-duplication feature, developed by Red Hat. It first appeared in the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead == &amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node == &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
The KSM daemon is controlled by sysfs files in &amp;lt;code&amp;gt;/sys/kernel/mm/ksm/&amp;lt;/code&amp;gt;, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
You can copy the same command in &amp;lt;code&amp;gt;/etc/rc.local&amp;lt;/code&amp;gt; on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers == &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
Do not use the usual &amp;lt;code&amp;gt;# yum install ksm_preload&amp;lt;/code&amp;gt; command inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
[root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
&lt;br /&gt;
(If you get an error like &amp;quot;No package yum-downloadonly available&amp;quot;, just ignore it and proceed.  Most likely, your Yum installation includes that plugin already).&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
[root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications == &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 '''export LD_PRELOAD'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM == &amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;grep -H '' /sys/kernel/mm/ksm/*&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning == &amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for &amp;lt;code&amp;gt;/sys/kernel/mm/KSM/sleep_millisecs&amp;lt;/code&amp;gt; is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
[root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs&lt;br /&gt;
&lt;br /&gt;
== Caveats == &amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher &amp;lt;code&amp;gt;pages_to_scan&amp;lt;/code&amp;gt;, lower &amp;lt;code&amp;gt;sleep_millisecs&amp;lt;/code&amp;gt;) at the beginning, effectively trading CPU utilization for less chances of disk swapping, and then relax them after 10 mins or so.  Another possibility is to place your swap onto an SSD drive.&lt;br /&gt;
&lt;br /&gt;
== References == &amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External links == &amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
* [[wikipedia:Kernel same-page merging]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Setup_OpenStack_with_Virtuozzo_7&amp;diff=18060</id>
		<title>Setup OpenStack with Virtuozzo 7</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Setup_OpenStack_with_Virtuozzo_7&amp;diff=18060"/>
		<updated>2015-12-14T04:50:47Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: Shortened the EPEL repo install command; no need to specify the full URL as it's a core package in CentOS&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Virtuozzo}}&lt;br /&gt;
&lt;br /&gt;
This howto describes steps by step installation of OpenStack devstack with [[Virtuozzo]] 7.&lt;br /&gt;
&lt;br /&gt;
Execute the following commands within you Virtuozzo 7 host as root:&lt;br /&gt;
&lt;br /&gt;
Install RDO repo:&lt;br /&gt;
&lt;br /&gt;
 $ yum install -y https://rdoproject.org/repos/rdo-release.rpm&lt;br /&gt;
&lt;br /&gt;
Install EPEL repo:&lt;br /&gt;
 &lt;br /&gt;
 $ yum install -y epel-release&lt;br /&gt;
&lt;br /&gt;
Install required packages:&lt;br /&gt;
 $ yum install -y git patch redhat-lsb-core euca2ools mysql-connector-python scsi-target-utils&lt;br /&gt;
&lt;br /&gt;
Reinstall http and mod_wsgi:&lt;br /&gt;
&lt;br /&gt;
 $ yum remove -y httpd httpd-tools mod_wsgi&lt;br /&gt;
 $ yum install -y httpd&lt;br /&gt;
&lt;br /&gt;
Enable IP connection tracking for CT0:&lt;br /&gt;
&lt;br /&gt;
 $ echo -ne &amp;quot;options nf_conntrack ip_conntrack_disable_ve0=0\n&amp;quot; &amp;gt; /etc/modprobe.d/vz.conf&lt;br /&gt;
 $ echo -ne &amp;quot;options nf_conntrack ip_conntrack_disable_ve0=0\n&amp;quot; &amp;gt; /etc/modprobe.d/parallels.conf&lt;br /&gt;
&lt;br /&gt;
Then reboot your system:&lt;br /&gt;
&lt;br /&gt;
 $ reboot&lt;br /&gt;
&lt;br /&gt;
Create user &amp;quot;stack&amp;quot; and add him to sudoers:&lt;br /&gt;
&lt;br /&gt;
 $ adduser stack -d /vz/stack&lt;br /&gt;
 $ chmod 755 /vz/stack&lt;br /&gt;
 $ echo &amp;quot;stack ALL=(ALL) NOPASSWD: ALL&amp;quot; &amp;gt;&amp;gt; /etc/sudoers&lt;br /&gt;
&lt;br /&gt;
Download and unpack container image:&lt;br /&gt;
&lt;br /&gt;
 $ su stack -c &amp;quot;cd ~ &amp;amp;&amp;amp; wget http://updates.virtuozzo.com/server/virtuozzo/en_us/odin/7/techpreview-ct/centos7-exe.hds.tar.gz&amp;quot;&lt;br /&gt;
 $ su stack -c &amp;quot;cd ~ &amp;amp;&amp;amp; tar -xzvf centos7-exe.hds.tar.gz&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Clone devstack:&lt;br /&gt;
 &lt;br /&gt;
 $ su stack -c &amp;quot;cd ~ &amp;amp;&amp;amp; git clone git://git.openstack.org/openstack-dev/devstack&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Create local.conf file:&lt;br /&gt;
&lt;br /&gt;
 $ cat &amp;gt; ~stack/devstack/local.conf &amp;lt;&amp;lt; _EOF&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[[local|localrc]]&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 FORCE=yes&lt;br /&gt;
 HOST_IP=1.1.1.1&lt;br /&gt;
 MYSQL_PASSWORD=password&lt;br /&gt;
 SERVICE_TOKEN=password&lt;br /&gt;
 SERVICE_PASSWORD=password&lt;br /&gt;
 ADMIN_PASSWORD=password&lt;br /&gt;
 LIBVIRT_TYPE=parallels&lt;br /&gt;
 RABBIT_PASSWORD=password&lt;br /&gt;
 #Basic services&lt;br /&gt;
 ENABLED_SERVICES=key,rabbit,mysql,horizon&lt;br /&gt;
 # Enable Nova services&lt;br /&gt;
 ENABLED_SERVICES+=,n-api,n-crt,n-cpu,n-cond,n-sch,n-novnc,n-cauth&lt;br /&gt;
 # Enable Glance services&lt;br /&gt;
 ENABLED_SERVICES+=,g-api,g-reg&lt;br /&gt;
 # Enable Cinder services&lt;br /&gt;
 #ENABLED_SERVICES+=,c-sch,c-api,c-vol&lt;br /&gt;
 # Enable Heat, to test orchestration&lt;br /&gt;
 #ENABLED_SERVICES+=,heat,h-api,h-api-cfn,h-api-cw,h-eng&lt;br /&gt;
 # Enable Neutron services&lt;br /&gt;
 ENABLED_SERVICES+=,q-svc,q-agt,q-dhcp,q-l3,q-meta,neutron&lt;br /&gt;
 # Destination path for installation&lt;br /&gt;
 DEST=/vz/stack&lt;br /&gt;
 # Destination for working data&lt;br /&gt;
 DATA_DIR=/vz/stack/data&lt;br /&gt;
 # Destination for status files&lt;br /&gt;
 SERVICE_DIR=/vz/stack/status&lt;br /&gt;
 LOG_COLOR=False&lt;br /&gt;
 LOGDAYS=3&lt;br /&gt;
 LOGFILE=/vz/stack/logs/stack.sh.log&lt;br /&gt;
 SCREEN_LOGDIR=/vz/stack/logs/screen&lt;br /&gt;
 ENABLE_METADATA_NETWORK=True&lt;br /&gt;
 ENABLE_ISOLATED_METADATA=True&lt;br /&gt;
 IMAGE_URLS=&amp;quot;file:///vz/stack/centos7-exe.hds&amp;quot;&lt;br /&gt;
 _EOF&lt;br /&gt;
&lt;br /&gt;
Change HOST_IP within created ~stack/devstack/local.conf to a valid IP address of your Virtuozzo 7 host.&lt;br /&gt;
Change password for OpenStack services to whatever you prefer in ~stack/devstack/local.conf.&lt;br /&gt;
Make libvirt daemon accessible via socket for stack user:&lt;br /&gt;
&lt;br /&gt;
 $ sed -i s/&amp;quot;#unix_sock_group = \&amp;quot;libvirt\&amp;quot;&amp;quot;/&amp;quot;unix_sock_group = \&amp;quot;stack\&amp;quot;&amp;quot;/ /etc/libvirt/libvirtd.conf&lt;br /&gt;
 $ sed -i s/&amp;quot;#unix_sock_ro_perms = \&amp;quot;0777\&amp;quot;&amp;quot;/&amp;quot;unix_sock_ro_perms = \&amp;quot;0777\&amp;quot;&amp;quot;/ /etc/libvirt/libvirtd.conf&lt;br /&gt;
 $ sed -i s/&amp;quot;#unix_sock_rw_perms = \&amp;quot;0770\&amp;quot;&amp;quot;/&amp;quot;unix_sock_rw_perms = \&amp;quot;0770\&amp;quot;&amp;quot;/ /etc/libvirt/libvirtd.conf&lt;br /&gt;
 $ sed -i s/&amp;quot;#unix_sock_dir = \&amp;quot;\/var\/run\/libvirt\&amp;quot;&amp;quot;/&amp;quot;unix_sock_dir = \&amp;quot;\/var\/run\/libvirt\&amp;quot;&amp;quot;/ /etc/libvirt/libvirtd.conf&lt;br /&gt;
 $ sed -i s/&amp;quot;#auth_unix_ro = \&amp;quot;none\&amp;quot;&amp;quot;/&amp;quot;auth_unix_ro = \&amp;quot;none\&amp;quot;&amp;quot;/ /etc/libvirt/libvirtd.conf&lt;br /&gt;
 $ sed -i s/&amp;quot;#auth_unix_rw = \&amp;quot;none\&amp;quot;&amp;quot;/&amp;quot;auth_unix_rw = \&amp;quot;none\&amp;quot;&amp;quot;/ /etc/libvirt/libvirtd.conf&lt;br /&gt;
&lt;br /&gt;
Clone nova repository:&lt;br /&gt;
&lt;br /&gt;
 $ su stack -c &amp;quot;cd ~ &amp;amp;&amp;amp; git clone git://git.openstack.org/openstack/nova&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Make libvirt 1.2.8 be minimum required version to run with Virtuozzo:&lt;br /&gt;
&lt;br /&gt;
 $ sed -i -e &amp;quot;s/MIN_LIBVIRT_PARALLELS_VERSION = (1, 2, 12)/MIN_LIBVIRT_PARALLELS_VERSION = (1, 2, 8)/&amp;quot;  ~stack/nova/nova/virt/libvirt/driver.py&lt;br /&gt;
&lt;br /&gt;
Start devstack:&lt;br /&gt;
&lt;br /&gt;
 $ su stack -c &amp;quot;~/devstack/stack.sh&amp;quot;&lt;br /&gt;
&lt;br /&gt;
After script finishes, setup your iptables rules to allow incoming http trafic if you want to use OpenStack dashboard. For instance:&lt;br /&gt;
&lt;br /&gt;
 $ iptables -D INPUT -j REJECT --reject-with icmp-host-prohibited&lt;br /&gt;
 $ iptables -A INPUT -p tcp --dport http -j ACCEPT&lt;br /&gt;
 $ iptables -A INPUT -j REJECT&lt;br /&gt;
&lt;br /&gt;
Here you are!&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Quick_installation&amp;diff=18059</id>
		<title>Quick installation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Quick_installation&amp;diff=18059"/>
		<updated>2015-12-14T04:39:53Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Setup on pre-installed Linux distribution */ Added EPEL requirement as per https://bugzilla.openvz.org/show_bug.cgi?id=3275&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Virtuozzo}}&lt;br /&gt;
&lt;br /&gt;
{{Note|See [[Quick installation]] if you are looking to install the current stable version of OpenVZ.}}&lt;br /&gt;
&lt;br /&gt;
This document briefly describes the steps needed to install Virtuozzo Linux distribution on your machine.&lt;br /&gt;
&lt;br /&gt;
There are a few ways to install Virtuozzo:&lt;br /&gt;
&lt;br /&gt;
=== Bare-metal installation ===&lt;br /&gt;
&lt;br /&gt;
OpenVZ project builds its own Linux distribution with both hypervisor and container virtualization.&lt;br /&gt;
It is based on our own Linux distribution, with the additions of [[Download/kernel/rhel7-testing|our custom kernel]], OpenVZ management utilities, [[QEMU]] and Virtuozzo installer. It is highly recommended to use OpenVZ containers and virtual machines with this Virtuozzo installation image. See [[Virtuozzo]].&lt;br /&gt;
[http://download.openvz.org/virtuozzo/releases/7.0-beta2/x86_64/iso/ Download] installation ISO image.&lt;br /&gt;
&lt;br /&gt;
=== Using Virtuozzo in the Vagrant box ===&lt;br /&gt;
&lt;br /&gt;
[https://www.vagrantup.com/ Vagrant] is a tool for creating reproducible and portable development environments.&lt;br /&gt;
It is easy to run environment with Virtuozzo using Vagrant:&lt;br /&gt;
&lt;br /&gt;
* Download and [https://docs.vagrantup.com/v2/installation/ install Vagrant]&lt;br /&gt;
* Download and install [https://www.virtualbox.org/wiki/Downloads Virtualbox], VMware Fusion or VMware Workstation&lt;br /&gt;
* Download [https://atlas.hashicorp.com/OpenVZ/boxes/Virtuozzo-7.0 Virtuozzo box]:&lt;br /&gt;
&lt;br /&gt;
   $ vagrant init OpenVZ/Virtuozzo-7.0&lt;br /&gt;
&lt;br /&gt;
* Run box:&lt;br /&gt;
&lt;br /&gt;
   $ vagrant up --provider virtualbox&lt;br /&gt;
&lt;br /&gt;
and in case of VMware hypervisor:&lt;br /&gt;
&lt;br /&gt;
   $ vagrant up --provider vmware_desktop&lt;br /&gt;
&lt;br /&gt;
and in case of Parallels hypervisor:&lt;br /&gt;
&lt;br /&gt;
   $ vagrant up --provider parallels&lt;br /&gt;
&lt;br /&gt;
* Attach to console:&lt;br /&gt;
&lt;br /&gt;
   $ vagrant ssh&lt;br /&gt;
&lt;br /&gt;
* Use ''vagrant/vagrant'' to login inside box&lt;br /&gt;
&lt;br /&gt;
=== Using Virtuozzo in the Amazon EC2 ===&lt;br /&gt;
&lt;br /&gt;
Follow steps in [[Using Virtuozzo in the Amazon EC2]].&lt;br /&gt;
&lt;br /&gt;
=== Setup on pre-installed Linux distribution ===&lt;br /&gt;
&lt;br /&gt;
{{Note|Pay attention, this installation method currently blocked by broken network after installation - {{OVZ|6454}}.}}&lt;br /&gt;
&lt;br /&gt;
Alternatively, one can install OpenVZ on a pre-installed RPM based Linux distribution.&lt;br /&gt;
Supported Linux distributions: Cloud Linux 7.*, CentOS 7.*, Scientific Linux 7.* etc&lt;br /&gt;
&lt;br /&gt;
Follow step-by-step instruction below:&lt;br /&gt;
&lt;br /&gt;
Package ''virtuozzo-release'' will bring meta information and YUM repositories:&lt;br /&gt;
&lt;br /&gt;
   # yum localinstall http://download.openvz.org/virtuozzo/releases/7.0/x86_64/os/Packages/v/virtuozzo-release-7.0.0-10.vz7.x86_64.rpm&lt;br /&gt;
&lt;br /&gt;
EPEL is a requisite:&lt;br /&gt;
&lt;br /&gt;
   # yum install -y epel-release&lt;br /&gt;
&lt;br /&gt;
Then install mandatory Virtuozzo RPM packages:&lt;br /&gt;
&lt;br /&gt;
   # yum install -y prlctl prl-disp-service vzkernel&lt;br /&gt;
&lt;br /&gt;
See OpenVZ [[Packages]] available in various Linux distributions.&lt;br /&gt;
&lt;br /&gt;
=== OpenVZ with upstream Linux kernel ===&lt;br /&gt;
&lt;br /&gt;
See article [[OpenVZ with upstream kernel]] if you want more details about support of upstream kernel.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using Virtuozzo ==&lt;br /&gt;
&lt;br /&gt;
Page with [[screencasts]] shows demo with a few Virtuozzo commands. Feel free to add more.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [https://docs.openvz.org/ Official Virtuozzo documentation]&lt;br /&gt;
&lt;br /&gt;
[[Category: Installation]]&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17084</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17084"/>
		<updated>2015-07-21T13:35:13Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Tuning */ Fixed a typo in the command:  there was a &amp;quot;:50&amp;quot; at the end.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, developed by Red Hat. It first appeared in the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in &amp;lt;code&amp;gt;/sys/kernel/mm/ksm/&amp;lt;/code&amp;gt;, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in &amp;lt;code&amp;gt;/etc/rc.local&amp;lt;/code&amp;gt; on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;lt;code&amp;gt;# yum install ksm_preload&amp;lt;/code&amp;gt; command inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;grep -H '' /sys/kernel/mm/ksm/*&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for &amp;lt;code&amp;gt;/sys/kernel/mm/KSM/sleep_millisecs&amp;lt;/code&amp;gt; is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher &amp;lt;code&amp;gt;pages_to_scan&amp;lt;/code&amp;gt;, lower &amp;lt;code&amp;gt;sleep_millisecs&amp;lt;/code&amp;gt;) at the beginning, effectively trading CPU utilization for less chances of disk swapping, and then relax them after 10 mins or so.  Another possibility is to place your swap onto an SSD drive.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
&lt;br /&gt;
* [[wikipedia:Kernel same-page merging]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17071</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17071"/>
		<updated>2015-07-18T11:29:22Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Caveats */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in &amp;lt;code&amp;gt;/sys/kernel/mm/ksm/&amp;lt;/code&amp;gt;, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in &amp;lt;code&amp;gt;/etc/rc.local&amp;lt;/code&amp;gt; on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;lt;code&amp;gt;# yum install ksm_preload&amp;lt;/code&amp;gt; command inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;grep -H '' /sys/kernel/mm/ksm/*&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for &amp;lt;code&amp;gt;/sys/kernel/mm/KSM/sleep_millisecs&amp;lt;/code&amp;gt; is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher &amp;lt;code&amp;gt;pages_to_scan&amp;lt;/code&amp;gt;, lower &amp;lt;code&amp;gt;sleep_millisecs&amp;lt;/code&amp;gt;) at the beginning, effectively trading CPU utilisation for less chances of disk swapping, and then relax them after 10 mins or so.  Another possibility is to place your swap onto an SSD drive.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17070</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17070"/>
		<updated>2015-07-18T11:27:09Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* How to check efficiency of KSM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in &amp;lt;code&amp;gt;/sys/kernel/mm/ksm/&amp;lt;/code&amp;gt;, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in &amp;lt;code&amp;gt;/etc/rc.local&amp;lt;/code&amp;gt; on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;lt;code&amp;gt;# yum install ksm_preload&amp;lt;/code&amp;gt; command inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;grep -H '' /sys/kernel/mm/ksm/*&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for &amp;lt;code&amp;gt;/sys/kernel/mm/KSM/sleep_millisecs&amp;lt;/code&amp;gt; is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher &amp;lt;code&amp;gt;pages_to_scan&amp;lt;/code&amp;gt;, lower &amp;lt;code&amp;gt;sleep_millisecs&amp;lt;/code&amp;gt;) at the beginning and then relax them after 10 mins or so.  Others suggest to place your swap onto an SSD drive.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17069</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17069"/>
		<updated>2015-07-18T11:26:17Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in &amp;lt;code&amp;gt;/sys/kernel/mm/ksm/&amp;lt;/code&amp;gt;, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in &amp;lt;code&amp;gt;/etc/rc.local&amp;lt;/code&amp;gt; on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;lt;code&amp;gt;# yum install ksm_preload&amp;lt;/code&amp;gt; command inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
  grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for &amp;lt;code&amp;gt;/sys/kernel/mm/KSM/sleep_millisecs&amp;lt;/code&amp;gt; is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher &amp;lt;code&amp;gt;pages_to_scan&amp;lt;/code&amp;gt;, lower &amp;lt;code&amp;gt;sleep_millisecs&amp;lt;/code&amp;gt;) at the beginning and then relax them after 10 mins or so.  Others suggest to place your swap onto an SSD drive.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17068</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17068"/>
		<updated>2015-07-18T11:25:09Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Enabling memory deduplication libraries in containers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in &amp;lt;code&amp;gt;/sys/kernel/mm/ksm/&amp;lt;/code&amp;gt;, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in &amp;lt;code&amp;gt;/etc/rc.local&amp;lt;/code&amp;gt; on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;lt;code&amp;gt;# yum install ksm_preload&amp;lt;/code&amp;gt; command inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
  grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for /sys/kernel/mm/KSM/sleep_millisecs is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher pages_to_scan, lower sleep_millisecs) at the beginning and then relax them after 10 mins or so.  Others suggest to place your swap onto an SSD drive.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17067</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17067"/>
		<updated>2015-07-18T11:24:09Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Enabling KSM on the hardware node */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in &amp;lt;code&amp;gt;/sys/kernel/mm/ksm/&amp;lt;/code&amp;gt;, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in &amp;lt;code&amp;gt;/etc/rc.local&amp;lt;/code&amp;gt; on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;quot;yum install ksm_preload&amp;quot; inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
  grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for /sys/kernel/mm/KSM/sleep_millisecs is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher pages_to_scan, lower sleep_millisecs) at the beginning and then relax them after 10 mins or so.  Others suggest to place your swap onto an SSD drive.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17066</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17066"/>
		<updated>2015-07-18T11:08:22Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Enabling KSM on the hardware node */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in /sys/kernel/mm/ksm/, readable by all but writable only by root.  On your hardware node, if KSM is not yet active, you'll see these default values:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in /etc/rc.local on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;quot;yum install ksm_preload&amp;quot; inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
  grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for /sys/kernel/mm/KSM/sleep_millisecs is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher pages_to_scan, lower sleep_millisecs) at the beginning and then relax them after 10 mins or so.  Others suggest to place your swap onto an SSD drive.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17065</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17065"/>
		<updated>2015-07-18T11:07:03Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* How to check efficiency of KSM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in /sys/kernel/mm/ksm/, readable by all but writable only by root:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in /etc/rc.local on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;quot;yum install ksm_preload&amp;quot; inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
To see all the KSM parameters, issue the following command on the HN:&lt;br /&gt;
  grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the same information in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for /sys/kernel/mm/KSM/sleep_millisecs is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher pages_to_scan, lower sleep_millisecs) at the beginning and then relax them after 10 mins or so.  Others suggest to place your swap onto an SSD drive.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17064</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17064"/>
		<updated>2015-07-18T11:05:46Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Tuning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in /sys/kernel/mm/ksm/, readable by all but writable only by root:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in /etc/rc.local on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;quot;yum install ksm_preload&amp;quot; inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the saved RAM amount in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for /sys/kernel/mm/KSM/sleep_millisecs is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;br /&gt;
&lt;br /&gt;
== Caveats ==&lt;br /&gt;
The ksmd daemon will take one or two minutes to start deduplicating memory and will require several minutes to reach stable state.  During the boot phase your HN could start swapping if you have heavily overcommitted your RAM.  You might want to use more aggressive settings (higher pages_to_scan, lower sleep_millisecs) at the beginning and then relax them after 10 mins or so.  Others suggest to place your swap onto an SSD drive.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17063</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17063"/>
		<updated>2015-07-18T10:38:50Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Enabling memory deduplication in applications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in /sys/kernel/mm/ksm/, readable by all but writable only by root:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in /etc/rc.local on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;quot;yum install ksm_preload&amp;quot; inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;br /&gt;
&lt;br /&gt;
== How to check efficiency of KSM ==&lt;br /&gt;
To check if KSM is actually reducing memory usage, issue this command on the HN:&lt;br /&gt;
 [root@HN /]# cat /sys/kernel/mm/KSM/pages_sharing&lt;br /&gt;
If the value is greater than 0, you're saving memory.  Refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt for more details.&lt;br /&gt;
&lt;br /&gt;
On [https://gist.github.com/wankdanker/1206923 this page] you'll find a simple script which displays the saved RAM amount in MB.&lt;br /&gt;
&lt;br /&gt;
== Tuning ==&lt;br /&gt;
On a production machine, you'll want to modify some of the default values.  A more sane value for /sys/kernel/mm/KSM/sleep_millisecs is usually between 50 and 250 (YMMV though):&lt;br /&gt;
&lt;br /&gt;
 [root@HN ~]# echo 50 &amp;gt; /sys/kernel/mm/ksm/sleep_millisecs:50&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17062</id>
		<title>KSM (kernel same-page merging)</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=KSM_(kernel_same-page_merging)&amp;diff=17062"/>
		<updated>2015-07-18T08:46:50Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: Initial version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KSM is a memory-saving de-duplication feature, added by RedHat to the Linux kernel version 2.6.32.&lt;br /&gt;
&lt;br /&gt;
KSM replaces RAM pages of identical content with a single write-protected page, which in turn gets automatically copied to a new one if a process later wants to update its content.  This makes the de-duplication mechanism transparent to applications.  This strategy is commonly known as COW (''Copy On Write'').&lt;br /&gt;
&lt;br /&gt;
Although KSM was originally developed for use with KVM, it can be used with OpenVZ containers as well.&lt;br /&gt;
&lt;br /&gt;
== Performance and overhead ==&lt;br /&gt;
KSM is more effective when the hardware node has plenty of RAM and is running many containers with the same applications (e.g. a HN running 50 containers with Apache, PHP and MySQL).&lt;br /&gt;
&lt;br /&gt;
The amount of RAM that can be saved is in the 30-50% range depending on the application, with applications that have a mixed I/O and CPU footprint (e.g. MySQL and Apache) getting the best results.&amp;lt;ref&amp;gt;[http://www.researchgate.net/publication/220946080_An_Empirical_Study_on_Memory_Sharing_of_Virtual_Machines_for_Server_Consolidation ''An Empirical Study on Memory Sharing of Virtual Machines for Server Consolidation'']&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that KSM and Virtuozzo use totally different strategies for RAM deduplication:  KSM provides a constantly running daemon (called ''ksmd'') which scans the HN's memory and merges identical RAM pages gradually over time, whereas Virtuozzo merges requests from different containers to the same physical binaries on disk.  In doing so, Virtuozzo incurs no overhead at all, while KSM has a 5-10% CPU overhead depending on its configuration (faster scanning of the HN RAM will require more CPU power).&lt;br /&gt;
&lt;br /&gt;
== Enabling KSM on the hardware node ==&lt;br /&gt;
First, you'll want to verify that KSM support is present and enabled in your OpenVZ kernel:&lt;br /&gt;
 [root@HN ~]# grep KSM /boot/config-`uname -r`&lt;br /&gt;
 CONFIG_KSM=y&lt;br /&gt;
&lt;br /&gt;
The KSM daemon is controlled by sysfs files in /sys/kernel/mm/ksm/, readable by all but writable only by root:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;[root@HN ~]# grep -H '' /sys/kernel/mm/ksm/*&lt;br /&gt;
/sys/kernel/mm/ksm/full_scans:0&lt;br /&gt;
/sys/kernel/mm/ksm/merge_across_nodes:1&lt;br /&gt;
/sys/kernel/mm/ksm/pages_shared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_sharing:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_to_scan:100&lt;br /&gt;
/sys/kernel/mm/ksm/pages_unshared:0&lt;br /&gt;
/sys/kernel/mm/ksm/pages_volatile:0&lt;br /&gt;
/sys/kernel/mm/ksm/run:0&lt;br /&gt;
/sys/kernel/mm/ksm/sleep_millisecs:20&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the meaning of each parameter, please refer to https://www.kernel.org/doc/Documentation/vm/ksm.txt&lt;br /&gt;
&lt;br /&gt;
To start ''ksmd'', issue&lt;br /&gt;
 [root@HN ~]# echo 1 &amp;gt; /sys/kernel/mm/ksm/run&lt;br /&gt;
&lt;br /&gt;
You can copy the same command in /etc/rc.local on the HN to make it persistent at boot.&lt;br /&gt;
&lt;br /&gt;
Verify that ''ksmd'' is running:&lt;br /&gt;
 [root@HN ~]# ps aux | grep ksmd&lt;br /&gt;
 root         264  0.3  0.0      0     0 ?        SN   Jun14 176:52 [ksmd]&lt;br /&gt;
 root      989187  0.0  0.0 103252   896 pts/0    S+   09:30   0:00 grep ksmd&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication libraries in containers ==&lt;br /&gt;
In order to have KSM consider a memory page as a candidate for deduplication, the application itself must mark it as mergeable:&lt;br /&gt;
&lt;br /&gt;
:''KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE).''&lt;br /&gt;
&lt;br /&gt;
Note that most applications do not use madvise() at all:  that's why KSM is generally used in conjunction with KVM, which takes care of marking pages as mergeable on behalf of the applications running within each virtual machine.&lt;br /&gt;
&lt;br /&gt;
Luckily, we can override the default behaviour of each application using the '''ksm_preload''' package (http://vleu.net/ksm_preload/) available in CentOS base repo.&lt;br /&gt;
&lt;br /&gt;
:''Linux ≥ 2.6.32 features a memory-saving mechanism that works by deduplicating areas of memory that are identical in different processes (even if they were generated at runtime and after the fork() of their common ancestors).''&lt;br /&gt;
&lt;br /&gt;
:''This mechanism requires the application to opt-in using the madvise() syscall. KSM Preload enables legacy applications (about any current application) to leverage this system by calling madvise(…, MADV_MERGEABLE) on every heap-allocated pages.''&lt;br /&gt;
&lt;br /&gt;
Do not use the usual &amp;quot;yum install ksm_preload&amp;quot; inside your containers, as it will install an unnecessary stream of dependencies.  Assuming your container is running on a recent CentOS 6.x template, issue the following commands instead:&lt;br /&gt;
&lt;br /&gt;
 [root@container /]# cd /usr/local/src&lt;br /&gt;
 [root@container /]# yum install -y yum-downloadonly&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 &lt;br /&gt;
 [root@container src]# yum -y --downloadonly --downloaddir=/usr/local/src install ksm_preload&lt;br /&gt;
     ''...bunch of output...''&lt;br /&gt;
 exiting because --downloadonly specified  ''// this is OK''&lt;br /&gt;
&lt;br /&gt;
We can now install just the ksm_preload RPM:&lt;br /&gt;
&lt;br /&gt;
 [root@container src]# rpm -i ksm_preload-0.10-3.el6.x86_64.rpm --nodeps&lt;br /&gt;
&lt;br /&gt;
== Enabling memory deduplication in applications ==&lt;br /&gt;
In order to make an application take advantage of ksm_preload and use KSM on the HN, add this line into its startup script (assuming your container is running CentOS 6.x x86_64):&lt;br /&gt;
 LD_PRELOAD=/usr/lib64/libksm_preload.so&lt;br /&gt;
&lt;br /&gt;
E.g., if you want to make Percona Server use KSM, modify its startup script like the following:&lt;br /&gt;
 [root@container /]# nano /etc/init.d/mysql&lt;br /&gt;
 &lt;br /&gt;
 ''...''&lt;br /&gt;
 ''PATH=&amp;quot;/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin&amp;quot;''&lt;br /&gt;
 ''export PATH''&lt;br /&gt;
 &lt;br /&gt;
 '''LD_PRELOAD=/usr/lib64/libksm_preload.so'''&lt;br /&gt;
 &lt;br /&gt;
 ''mode=$1    # start or stop''&lt;br /&gt;
 ''...''&lt;br /&gt;
&lt;br /&gt;
Then (re)start your Percona Server as usual.&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Ploop/Getting_started&amp;diff=15561</id>
		<title>Ploop/Getting started</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Ploop/Getting_started&amp;diff=15561"/>
		<updated>2014-09-20T14:31:46Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to use container-in-a-file technology aka [[ploop]]&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
The following is required for ploop to work:&lt;br /&gt;
&lt;br /&gt;
# [[Download/kernel/rhel6|RHEL6-based OpenVZ kernel]], i.e. 042stabXXX.&lt;br /&gt;
# &amp;lt;code&amp;gt;/vz&amp;lt;/code&amp;gt; partition formatted as &amp;lt;code&amp;gt;ext4&amp;lt;/code&amp;gt; and mounted in ordered mode, or residing on NFS. No other filesystem is supported.&lt;br /&gt;
# ploop library and tools installed (run &amp;lt;code&amp;gt;yum install ploop&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Making a CT on ploop ==&lt;br /&gt;
&lt;br /&gt;
=== Global configuration ===&lt;br /&gt;
&lt;br /&gt;
In global VZ configuration file [[Man/vz.conf.5|/etc/vz/vz.conf]], set&lt;br /&gt;
&lt;br /&gt;
 VE_LAYOUT=ploop &lt;br /&gt;
&lt;br /&gt;
This means that all new containers you will create will have ploop layout by default.&lt;br /&gt;
&lt;br /&gt;
You don't have to set this option if you don't want ploop to be default. Alternatively, you can:&lt;br /&gt;
&lt;br /&gt;
* use &amp;lt;code&amp;gt;--layout&amp;lt;/code&amp;gt; option of &amp;lt;code&amp;gt;vzctl create&amp;lt;/code&amp;gt; command;&lt;br /&gt;
* convert existing container to ploop.&lt;br /&gt;
&lt;br /&gt;
=== Creating a new CT ===&lt;br /&gt;
&lt;br /&gt;
To create a new container on ploop, use:&lt;br /&gt;
&lt;br /&gt;
 vzctl create ''CTID'' [--layout ploop] [--diskspace ''nnn''G]&lt;br /&gt;
&lt;br /&gt;
# You can omit &amp;lt;code&amp;gt;--layout&amp;lt;/code&amp;gt; option if you have set &amp;lt;code&amp;gt;VE_LAYOUT=ploop&amp;lt;/code&amp;gt; in {{Man|vz.conf|5}}&lt;br /&gt;
# You can specify initial file system size using &amp;lt;code&amp;gt;--diskspace&amp;lt;/code&amp;gt; option (example: 10G for 10 gigabytes)&lt;br /&gt;
# If &amp;lt;code&amp;gt;--diskspace&amp;lt;/code&amp;gt; is not specified, the size defaults to DISKSPACE limit value in sample CT config used&lt;br /&gt;
&lt;br /&gt;
=== Converting an existing CT ===&lt;br /&gt;
&lt;br /&gt;
1. Set some sane diskspace value (which will be used as a size of newly created ploop image). Here is the example to set diskspace to 10 gigabytes:&lt;br /&gt;
 vzctl set ''CTID'' --diskspace 10G --save&lt;br /&gt;
&lt;br /&gt;
2. Convert:&lt;br /&gt;
 vzctl convert ''CTID''&lt;br /&gt;
&lt;br /&gt;
== Resizing a ploop image ==&lt;br /&gt;
&lt;br /&gt;
Ploop image can be resized in both directions (i.e. either shrank or grown). Ploop also supports online/live resize so you don't have to stop a CT to do resize.&lt;br /&gt;
&lt;br /&gt;
To resize a ploop CT image, use&lt;br /&gt;
&lt;br /&gt;
 vzctl set ''CTID'' --diskspace ''nnn''G --save&lt;br /&gt;
&lt;br /&gt;
Note that&lt;br /&gt;
* resize can safely be performed online (i.e. when container is running)&lt;br /&gt;
* there is no need to specify two values for diskspace (unlike simfs, there is no soft and hard quota).&lt;br /&gt;
* there is no way to limit or change the number of inodes available for a container (i.e. option '''--diskinodes''' is ignored)&lt;br /&gt;
&lt;br /&gt;
== Showing disk space usage / limits ==&lt;br /&gt;
&lt;br /&gt;
You can use {{Man|vzlist|8}} to see CT disk space usage and limits in a uniform way for any containers (simfs or ploop, started or stopped).&lt;br /&gt;
&lt;br /&gt;
The field '''diskspace''' is showing the current disk space usage, and the fields '''diskspace.s''' and '''diskspace.h''' are showing the filesystem size (or disk space quotas, for simfs case).&lt;br /&gt;
&lt;br /&gt;
The field '''diskinodes''' is showing the current inodes usage, and the fields '''diskinodes.s''' and '''diskinodes.h''' are showing the filesystem size (or disk inodes quotas, for simfs case).&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
 vzlist -o smart_name,diskspace.h,diskspace&lt;br /&gt;
 vzlist -o smart_name,diskinodes.h,diskinodes&lt;br /&gt;
&lt;br /&gt;
On a lower level, same info can be obtained via '''ploop info''' command:&lt;br /&gt;
&lt;br /&gt;
 ploop info /vz/private/501/root.hdd/DiskDescriptor.xml&lt;br /&gt;
&lt;br /&gt;
== Using disk quotas inside container ==&lt;br /&gt;
&lt;br /&gt;
If you want to use standard Linux per-user and per-group disk quota inside a container, you have to enable it using&lt;br /&gt;
&lt;br /&gt;
 vzctl set ''CTID'' --quotaugidlimit 1000 --save&lt;br /&gt;
&lt;br /&gt;
Note that:&lt;br /&gt;
* unlike with simfs, ''--quotaugidlimit'' argument can be any non-zero value;&lt;br /&gt;
* enabling or disabling in-container disk quotas requires a container restart, so you can use vzctl's '''--setmode''' option.&lt;br /&gt;
&lt;br /&gt;
See {{Man|vzctl|8}} for more details.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Ploop]]&lt;br /&gt;
* [[Ploop/backup]]&lt;br /&gt;
* {{Man|ploop|8}}&lt;br /&gt;
* {{Man|vz.conf|5}}&lt;br /&gt;
* {{Man|vzctl|8}}&lt;br /&gt;
&lt;br /&gt;
[[Category: Storage]]&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Ploop/Getting_started&amp;diff=15560</id>
		<title>Ploop/Getting started</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Ploop/Getting_started&amp;diff=15560"/>
		<updated>2014-09-20T14:31:22Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to use container-in-a-file technology aka [[ploop]]&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
The following is required for ploop to work:&lt;br /&gt;
&lt;br /&gt;
# [[Download/kernel/rhel6|RHEL6-based OpenVZ kernel]], i.e. 042stabXXX.&lt;br /&gt;
# &amp;lt;code&amp;gt;/vz&amp;lt;/code&amp;gt; partition formatted as &amp;lt;code&amp;gt;ext4&amp;lt;/code&amp;gt; in ordered mode, or residing on NFS. No other filesystem is supported.&lt;br /&gt;
# ploop library and tools installed (run &amp;lt;code&amp;gt;yum install ploop&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== Making a CT on ploop ==&lt;br /&gt;
&lt;br /&gt;
=== Global configuration ===&lt;br /&gt;
&lt;br /&gt;
In global VZ configuration file [[Man/vz.conf.5|/etc/vz/vz.conf]], set&lt;br /&gt;
&lt;br /&gt;
 VE_LAYOUT=ploop &lt;br /&gt;
&lt;br /&gt;
This means that all new containers you will create will have ploop layout by default.&lt;br /&gt;
&lt;br /&gt;
You don't have to set this option if you don't want ploop to be default. Alternatively, you can:&lt;br /&gt;
&lt;br /&gt;
* use &amp;lt;code&amp;gt;--layout&amp;lt;/code&amp;gt; option of &amp;lt;code&amp;gt;vzctl create&amp;lt;/code&amp;gt; command;&lt;br /&gt;
* convert existing container to ploop.&lt;br /&gt;
&lt;br /&gt;
=== Creating a new CT ===&lt;br /&gt;
&lt;br /&gt;
To create a new container on ploop, use:&lt;br /&gt;
&lt;br /&gt;
 vzctl create ''CTID'' [--layout ploop] [--diskspace ''nnn''G]&lt;br /&gt;
&lt;br /&gt;
# You can omit &amp;lt;code&amp;gt;--layout&amp;lt;/code&amp;gt; option if you have set &amp;lt;code&amp;gt;VE_LAYOUT=ploop&amp;lt;/code&amp;gt; in {{Man|vz.conf|5}}&lt;br /&gt;
# You can specify initial file system size using &amp;lt;code&amp;gt;--diskspace&amp;lt;/code&amp;gt; option (example: 10G for 10 gigabytes)&lt;br /&gt;
# If &amp;lt;code&amp;gt;--diskspace&amp;lt;/code&amp;gt; is not specified, the size defaults to DISKSPACE limit value in sample CT config used&lt;br /&gt;
&lt;br /&gt;
=== Converting an existing CT ===&lt;br /&gt;
&lt;br /&gt;
1. Set some sane diskspace value (which will be used as a size of newly created ploop image). Here is the example to set diskspace to 10 gigabytes:&lt;br /&gt;
 vzctl set ''CTID'' --diskspace 10G --save&lt;br /&gt;
&lt;br /&gt;
2. Convert:&lt;br /&gt;
 vzctl convert ''CTID''&lt;br /&gt;
&lt;br /&gt;
== Resizing a ploop image ==&lt;br /&gt;
&lt;br /&gt;
Ploop image can be resized in both directions (i.e. either shrank or grown). Ploop also supports online/live resize so you don't have to stop a CT to do resize.&lt;br /&gt;
&lt;br /&gt;
To resize a ploop CT image, use&lt;br /&gt;
&lt;br /&gt;
 vzctl set ''CTID'' --diskspace ''nnn''G --save&lt;br /&gt;
&lt;br /&gt;
Note that&lt;br /&gt;
* resize can safely be performed online (i.e. when container is running)&lt;br /&gt;
* there is no need to specify two values for diskspace (unlike simfs, there is no soft and hard quota).&lt;br /&gt;
* there is no way to limit or change the number of inodes available for a container (i.e. option '''--diskinodes''' is ignored)&lt;br /&gt;
&lt;br /&gt;
== Showing disk space usage / limits ==&lt;br /&gt;
&lt;br /&gt;
You can use {{Man|vzlist|8}} to see CT disk space usage and limits in a uniform way for any containers (simfs or ploop, started or stopped).&lt;br /&gt;
&lt;br /&gt;
The field '''diskspace''' is showing the current disk space usage, and the fields '''diskspace.s''' and '''diskspace.h''' are showing the filesystem size (or disk space quotas, for simfs case).&lt;br /&gt;
&lt;br /&gt;
The field '''diskinodes''' is showing the current inodes usage, and the fields '''diskinodes.s''' and '''diskinodes.h''' are showing the filesystem size (or disk inodes quotas, for simfs case).&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
 vzlist -o smart_name,diskspace.h,diskspace&lt;br /&gt;
 vzlist -o smart_name,diskinodes.h,diskinodes&lt;br /&gt;
&lt;br /&gt;
On a lower level, same info can be obtained via '''ploop info''' command:&lt;br /&gt;
&lt;br /&gt;
 ploop info /vz/private/501/root.hdd/DiskDescriptor.xml&lt;br /&gt;
&lt;br /&gt;
== Using disk quotas inside container ==&lt;br /&gt;
&lt;br /&gt;
If you want to use standard Linux per-user and per-group disk quota inside a container, you have to enable it using&lt;br /&gt;
&lt;br /&gt;
 vzctl set ''CTID'' --quotaugidlimit 1000 --save&lt;br /&gt;
&lt;br /&gt;
Note that:&lt;br /&gt;
* unlike with simfs, ''--quotaugidlimit'' argument can be any non-zero value;&lt;br /&gt;
* enabling or disabling in-container disk quotas requires a container restart, so you can use vzctl's '''--setmode''' option.&lt;br /&gt;
&lt;br /&gt;
See {{Man|vzctl|8}} for more details.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Ploop]]&lt;br /&gt;
* [[Ploop/backup]]&lt;br /&gt;
* {{Man|ploop|8}}&lt;br /&gt;
* {{Man|vz.conf|5}}&lt;br /&gt;
* {{Man|vzctl|8}}&lt;br /&gt;
&lt;br /&gt;
[[Category: Storage]]&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Performance&amp;diff=12280</id>
		<title>Performance</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Performance&amp;diff=12280"/>
		<updated>2012-04-13T07:44:49Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Benchmark results ==&lt;br /&gt;
&lt;br /&gt;
This page is to collect a list of benchmark results available and demonstrate not only the words about containers technology being more superior from performance point of view compared to hypervisors but also to provide some data proving that.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Benchmarks&lt;br /&gt;
|-&lt;br /&gt;
|| '''Benchmark''' || '''Description'''&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Response Time/]]&lt;br /&gt;
|| Microbenchmark demonstrating latency issues of interactive applications in virtualized and loaded systems (netperf RR in various conditions).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Network Throughput/]]&lt;br /&gt;
|| 10Gbit simple network throughput comparison using netperf test.&lt;br /&gt;
|-&lt;br /&gt;
|| [[/LAMP/]]&lt;br /&gt;
|| Linux Apache+MySql+PHP (LAMP) stack benchmark in multiple simultaneously running virtualization instances.&lt;br /&gt;
|-&lt;br /&gt;
|| [[/vConsolidate-UP/]]&lt;br /&gt;
|| UP configuration of Intel vConsolidate server consolidation benchmark (Java+Apache+MySQL workloads).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/vConsolidate-SMP/]]&lt;br /&gt;
|| SMP configuration of Intel vConsolidate server consolidation benchmark (Java+Apache+MySQL workloads).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Microbenchmarks/]]&lt;br /&gt;
|| Various microbenchmarks like context switch, system call, etc. Plus Unixbench resuls.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [http://www.hpl.hp.com/techreports/2007/HPL-2007-59R1.pdf HP Labs: Performance Evaluation of Virtualization Technologies for Server Consolidation]&lt;br /&gt;
* [http://www.ieee-jp.org/section/kansai/chapter/ces/1569177239.pdf A Comparative Study of Open Source Softwares for Virtualization with Streaming Server Applications] - conference proceedings of the 13th IEEE International Symposium on Consumer Electronics (ISCE2009)&lt;br /&gt;
* [http://thesai.org/Downloads/Volume2No9/Paper%2020%20-%20The%20Performance%20between%20XEN-HVM,%20XEN-PV%20and%20Open-VZ%20during%20live-migration.pdf The Performance between XEN-HVM, XEN-PV and Open-VZ during live-migration]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Performance&amp;diff=12279</id>
		<title>Performance</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Performance&amp;diff=12279"/>
		<updated>2012-04-13T07:43:58Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* External sources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Benchmark results ==&lt;br /&gt;
&lt;br /&gt;
This page is to collect a list of benchmark results available and demonstrate not only the words about containers technology being more superior from performance point of view compared to hypervisors but also to provide some data proving that.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Benchmarks&lt;br /&gt;
|-&lt;br /&gt;
|| '''Benchmark''' || '''Description'''&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Response Time/]]&lt;br /&gt;
|| Microbenchmark demonstrating latency issues of interactive applications in virtualized and loaded systems (netperf RR in various conditions).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Network Throughput/]]&lt;br /&gt;
|| 10Gbit simple network throughput comparison using netperf test.&lt;br /&gt;
|-&lt;br /&gt;
|| [[/LAMP/]]&lt;br /&gt;
|| Linux Apache+MySql+PHP (LAMP) stack benchmark in multiple simultaneously running virtualization instances.&lt;br /&gt;
|-&lt;br /&gt;
|| [[/vConsolidate-UP/]]&lt;br /&gt;
|| UP configuration of Intel vConsolidate server consolidation benchmark (Java+Apache+MySQL workloads).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/vConsolidate-SMP/]]&lt;br /&gt;
|| SMP configuration of Intel vConsolidate server consolidation benchmark (Java+Apache+MySQL workloads).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Microbenchmarks/]]&lt;br /&gt;
|| Various microbenchmarks like context switch, system call, etc. Plus Unixbench resuls.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [http://www.hpl.hp.com/techreports/2007/HPL-2007-59R1.pdf HP Labs: Performance Evaluation of Virtualization Technologies for Server Consolidation]&lt;br /&gt;
* [http://www.ieee-jp.org/section/kansai/chapter/ces/1569177239.pdf A Comparative Study of Open Source Softwares for Virtualization with Streaming Server Applications] - conference proceedings of the 13th IEEE International Symposium on Consumer Electronics (ISCE2009)&lt;br /&gt;
* [http://thesai.org/Downloads/Volume2No9/Paper%2020%20-%20The%20Performance%20between%20XEN-HVM,%20XEN-PV%20and%20Open-VZ%20during%20live-migration.pdf The Performance between XEN-HVM, XEN-PV and &lt;br /&gt;
Open-VZ during live-migration]&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Performance&amp;diff=12122</id>
		<title>Performance</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Performance&amp;diff=12122"/>
		<updated>2012-03-18T23:15:18Z</updated>

		<summary type="html">&lt;p&gt;Corradofiore: /* External sources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Benchmark results ==&lt;br /&gt;
&lt;br /&gt;
This page is to collect a list of benchmark results available and demonstrate not only the words about containers technology being more superior from performance point of view compared to hypervisors but also to provide some data proving that.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Benchmarks&lt;br /&gt;
|-&lt;br /&gt;
|| '''Benchmark''' || '''Description'''&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Response Time/]]&lt;br /&gt;
|| Microbenchmark demonstrating latency issues of interactive applications in virtualized and loaded systems (netperf RR in various conditions).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Network Throughput/]]&lt;br /&gt;
|| 10Gbit simple network throughput comparison using netperf test.&lt;br /&gt;
|-&lt;br /&gt;
|| [[/LAMP/]]&lt;br /&gt;
|| Linux Apache+MySql+PHP (LAMP) stack benchmark in multiple simultaneously running virtualization instances.&lt;br /&gt;
|-&lt;br /&gt;
|| [[/vConsolidate-UP/]]&lt;br /&gt;
|| UP configuration of Intel vConsolidate server consolidation benchmark (Java+Apache+MySQL workloads).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/vConsolidate-SMP/]]&lt;br /&gt;
|| SMP configuration of Intel vConsolidate server consolidation benchmark (Java+Apache+MySQL workloads).&lt;br /&gt;
|-&lt;br /&gt;
|| [[/Microbenchmarks/]]&lt;br /&gt;
|| Various microbenchmarks like context switch, system call, etc. Plus Unixbench resuls.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [http://www.hpl.hp.com/techreports/2007/HPL-2007-59R1.pdf HP Labs: Performance Evaluation of Virtualization Technologies for Server Consolidation]&lt;br /&gt;
* [http://www.ieee-jp.org/section/kansai/chapter/ces/1569177239.pdf A Comparative Study of Open Source Softwares for Virtualization with Streaming Server Applications] - conference proceedings of the 13th IEEE International Symposium on Consumer Electronics (ISCE2009)&lt;/div&gt;</summary>
		<author><name>Corradofiore</name></author>
		
	</entry>
</feed>