sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget&/translations/zh_CN/admin-guide/mm/ksmmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/zh_TW/admin-guide/mm/ksmmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/it_IT/admin-guide/mm/ksmmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/ja_JP/admin-guide/mm/ksmmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/ko_KR/admin-guide/mm/ksmmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget&/translations/sp_SP/admin-guide/mm/ksmmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hKernel Samepage Mergingh]hKernel Samepage Merging}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhh@/var/lib/git/docbuild/linux/Documentation/admin-guide/mm/ksm.rsthKubh)}(hhh](h)}(hOverviewh]hOverview}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(hKSM is a memory-saving de-duplication feature, enabled by CONFIG_KSM=y, added to the Linux kernel in 2.6.32. See ``mm/ksm.c`` for its implementation, and http://lwn.net/Articles/306704/ and https://lwn.net/Articles/330589/h](hrKSM is a memory-saving de-duplication feature, enabled by CONFIG_KSM=y, added to the Linux kernel in 2.6.32. See }(hhhhhNhNubhliteral)}(h ``mm/ksm.c``h]hmm/ksm.c}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh for its implementation, and }(hhhhhNhNubh reference)}(hhttp://lwn.net/Articles/306704/h]hhttp://lwn.net/Articles/306704/}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurihuh1hhhubh and }(hhhhhNhNubh)}(h https://lwn.net/Articles/330589/h]h https://lwn.net/Articles/330589/}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurihuh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXKSM was originally developed for use with KVM (where it was known as Kernel Shared Memory), to fit more virtual machines into physical memory, by sharing the data common between them. But it can be useful to any application which generates many instances of the same data.h]hXKSM was originally developed for use with KVM (where it was known as Kernel Shared Memory), to fit more virtual machines into physical memory, by sharing the data common between them. But it can be useful to any application which generates many instances of the same data.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hXThe KSM daemon ksmd periodically scans those areas of user memory which have been registered with it, looking for pages of identical content which can be replaced by a single write-protected page (which is automatically copied if a process later wants to update its content). The amount of pages that KSM daemon scans in a single pass and the time between the passes are configured using :ref:`sysfs interface `h](hXThe KSM daemon ksmd periodically scans those areas of user memory which have been registered with it, looking for pages of identical content which can be replaced by a single write-protected page (which is automatically copied if a process later wants to update its content). The amount of pages that KSM daemon scans in a single pass and the time between the passes are configured using }(hjhhhNhNubh)}(h":ref:`sysfs interface `h]hinline)}(hj(h]hsysfs interface}(hj,hhhNhNubah}(h]h ](xrefstdstd-refeh"]h$]h&]uh1j*hj&ubah}(h]h ]h"]h$]h&]refdocadmin-guide/mm/ksm refdomainj7reftyperef refexplicitrefwarn reftarget ksm_sysfsuh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hX(KSM only merges anonymous (private) pages, never pagecache (file) pages. KSM's merged pages were originally locked into kernel memory, but can now be swapped out just like other user pages (but sharing is broken when they are swapped back in: ksmd must rediscover their identity and merge again).h]hX*KSM only merges anonymous (private) pages, never pagecache (file) pages. KSM’s merged pages were originally locked into kernel memory, but can now be swapped out just like other user pages (but sharing is broken when they are swapped back in: ksmd must rediscover their identity and merge again).}(hjQhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h]overviewah ]h"]overviewah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hControlling KSM with madviseh]hControlling KSM with madvise}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjghhhhhKubh)}(hKSM 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::h]hKSM 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:}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK!hjghhubh literal_block)}(h)int madvise(addr, length, MADV_MERGEABLE)h]h)int madvise(addr, length, MADV_MERGEABLE)}hjsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1jhhhK%hjghhubh)}(hThe app may callh]hThe app may call}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK'hjghhubj)}(h+int madvise(addr, length, MADV_UNMERGEABLE)h]h+int madvise(addr, length, MADV_UNMERGEABLE)}hjsbah}(h]h ]h"]h$]h&]jjuh1jhhhK+hjghhubh)}(hX to cancel that advice and restore unshared pages: whereupon KSM unmerges whatever it merged in that range. Note: this unmerging call may suddenly require more memory than is available - possibly failing with EAGAIN, but more probably arousing the Out-Of-Memory killer.h]hX to cancel that advice and restore unshared pages: whereupon KSM unmerges whatever it merged in that range. Note: this unmerging call may suddenly require more memory than is available - possibly failing with EAGAIN, but more probably arousing the Out-Of-Memory killer.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjghhubh)}(hXIf KSM is not configured into the running kernel, madvise MADV_MERGEABLE and MADV_UNMERGEABLE simply fail with EINVAL. If the running kernel was built with CONFIG_KSM=y, those calls will normally succeed: even if the KSM daemon is not currently running, MADV_MERGEABLE still registers the range for whenever the KSM daemon is started; even if the range cannot contain any pages which KSM could actually merge; even if MADV_UNMERGEABLE is applied to a range which was never MADV_MERGEABLE.h]hXIf KSM is not configured into the running kernel, madvise MADV_MERGEABLE and MADV_UNMERGEABLE simply fail with EINVAL. If the running kernel was built with CONFIG_KSM=y, those calls will normally succeed: even if the KSM daemon is not currently running, MADV_MERGEABLE still registers the range for whenever the KSM daemon is started; even if the range cannot contain any pages which KSM could actually merge; even if MADV_UNMERGEABLE is applied to a range which was never MADV_MERGEABLE.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK2hjghhubh)}(hIf a region of memory must be split into at least one new MADV_MERGEABLE or MADV_UNMERGEABLE region, the madvise may return ENOMEM if the process will exceed ``vm.max_map_count`` (see Documentation/admin-guide/sysctl/vm.rst).h](hIf a region of memory must be split into at least one new MADV_MERGEABLE or MADV_UNMERGEABLE region, the madvise may return ENOMEM if the process will exceed }(hjhhhNhNubh)}(h``vm.max_map_count``h]hvm.max_map_count}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh/ (see Documentation/admin-guide/sysctl/vm.rst).}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK:hjghhubh)}(hXLike other madvise calls, they are intended for use on mapped areas of the user address space: they will report ENOMEM if the specified range includes unmapped gaps (though working on the intervening mapped areas), and might fail with EAGAIN if not enough memory for internal structures.h]hXLike other madvise calls, they are intended for use on mapped areas of the user address space: they will report ENOMEM if the specified range includes unmapped gaps (though working on the intervening mapped areas), and might fail with EAGAIN if not enough memory for internal structures.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK>hjghhubh)}(hApplications should be considerate in their use of MADV_MERGEABLE, restricting its use to areas likely to benefit. KSM's scans may use a lot of processing power: some installations will disable KSM for that reason.h]hApplications should be considerate in their use of MADV_MERGEABLE, restricting its use to areas likely to benefit. KSM’s scans may use a lot of processing power: some installations will disable KSM for that reason.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChjghhubhtarget)}(h.. _ksm_sysfs:h]h}(h]h ]h"]h$]h&]refid ksm-sysfsuh1j hKGhjghhhhubeh}(h]controlling-ksm-with-madviseah ]h"]controlling ksm with madviseah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hKSM daemon sysfs interfaceh]hKSM daemon sysfs interface}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj"hhhhhKJubh)}(hrThe KSM daemon is controlled by sysfs files in ``/sys/kernel/mm/ksm/``, readable by all but writable only by root:h](h/The KSM daemon is controlled by sysfs files in }(hj3hhhNhNubh)}(h``/sys/kernel/mm/ksm/``h]h/sys/kernel/mm/ksm/}(hj;hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj3ubh,, readable by all but writable only by root:}(hj3hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKLhj"hhubhdefinition_list)}(hhh](hdefinition_list_item)}(hXpages_to_scan how many pages to scan before ksmd goes to sleep e.g. ``echo 100 > /sys/kernel/mm/ksm/pages_to_scan``. The pages_to_scan value cannot be changed if ``advisor_mode`` has been set to scan-time. Default: 100 (chosen for demonstration purposes) h](hterm)}(h pages_to_scanh]h pages_to_scan}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKVhjZubh definition)}(hhh](h)}(hfhow many pages to scan before ksmd goes to sleep e.g. ``echo 100 > /sys/kernel/mm/ksm/pages_to_scan``.h](h6how many pages to scan before ksmd goes to sleep e.g. }(hjshhhNhNubh)}(h/``echo 100 > /sys/kernel/mm/ksm/pages_to_scan``h]h+echo 100 > /sys/kernel/mm/ksm/pages_to_scan}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjsubh.}(hjshhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKPhjpubh)}(hXThe pages_to_scan value cannot be changed if ``advisor_mode`` has been set to scan-time.h](h-The pages_to_scan value cannot be changed if }(hjhhhNhNubh)}(h``advisor_mode``h]h advisor_mode}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh has been set to scan-time.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKShjpubh)}(h0Default: 100 (chosen for demonstration purposes)h]h0Default: 100 (chosen for demonstration purposes)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKVhjpubeh}(h]h ]h"]h$]h&]uh1jnhjZubeh}(h]h ]h"]h$]h&]uh1jXhhhKVhjUubjY)}(hsleep_millisecs how many milliseconds ksmd should sleep before next scan e.g. ``echo 20 > /sys/kernel/mm/ksm/sleep_millisecs`` Default: 20 (chosen for demonstration purposes) h](j_)}(hsleep_millisecsh]hsleep_millisecs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhK\hjubjo)}(hhh](h)}(hnhow many milliseconds ksmd should sleep before next scan e.g. ``echo 20 > /sys/kernel/mm/ksm/sleep_millisecs``h](h>how many milliseconds ksmd should sleep before next scan e.g. }(hjhhhNhNubh)}(h0``echo 20 > /sys/kernel/mm/ksm/sleep_millisecs``h]h,echo 20 > /sys/kernel/mm/ksm/sleep_millisecs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhKYhjubh)}(h/Default: 20 (chosen for demonstration purposes)h]h/Default: 20 (chosen for demonstration purposes)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK\hjubeh}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhK\hjUhhubjY)}(hXXmerge_across_nodes specifies if pages from different NUMA nodes can be merged. When set to 0, ksm merges only pages which physically reside in the memory area of same NUMA node. That brings lower latency to access of shared pages. Systems with more nodes, at significant NUMA distances, are likely to benefit from the lower latency of setting 0. Smaller systems, which need to minimize memory usage, are likely to benefit from the greater sharing of setting 1 (default). You may wish to compare how your system performs under each setting, before deciding on which to use. ``merge_across_nodes`` setting can be changed only when there are no ksm shared pages in the system: set run 2 to unmerge pages first, then to 1 after changing ``merge_across_nodes``, to remerge according to the new setting. Default: 1 (merging across nodes as in earlier releases) h](j_)}(hmerge_across_nodesh]hmerge_across_nodes}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKmhjubjo)}(hhh](h)}(hX specifies if pages from different NUMA nodes can be merged. When set to 0, ksm merges only pages which physically reside in the memory area of same NUMA node. That brings lower latency to access of shared pages. Systems with more nodes, at significant NUMA distances, are likely to benefit from the lower latency of setting 0. Smaller systems, which need to minimize memory usage, are likely to benefit from the greater sharing of setting 1 (default). You may wish to compare how your system performs under each setting, before deciding on which to use. ``merge_across_nodes`` setting can be changed only when there are no ksm shared pages in the system: set run 2 to unmerge pages first, then to 1 after changing ``merge_across_nodes``, to remerge according to the new setting.h](hX*specifies if pages from different NUMA nodes can be merged. When set to 0, ksm merges only pages which physically reside in the memory area of same NUMA node. That brings lower latency to access of shared pages. Systems with more nodes, at significant NUMA distances, are likely to benefit from the lower latency of setting 0. Smaller systems, which need to minimize memory usage, are likely to benefit from the greater sharing of setting 1 (default). You may wish to compare how your system performs under each setting, before deciding on which to use. }(hj-hhhNhNubh)}(h``merge_across_nodes``h]hmerge_across_nodes}(hj5hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh setting can be changed only when there are no ksm shared pages in the system: set run 2 to unmerge pages first, then to 1 after changing }(hj-hhhNhNubh)}(h``merge_across_nodes``h]hmerge_across_nodes}(hjGhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj-ubh*, to remerge according to the new setting.}(hj-hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK_hj*ubh)}(h8Default: 1 (merging across nodes as in earlier releases)h]h8Default: 1 (merging across nodes as in earlier releases)}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKmhj*ubeh}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKmhjUhhubjY)}(hXMrun * set to 0 to stop ksmd from running but keep merged pages, * set to 1 to run ksmd e.g. ``echo 1 > /sys/kernel/mm/ksm/run``, * set to 2 to stop ksmd and unmerge all pages currently merged, but leave mergeable areas registered for next run. Default: 0 (must be changed to 1 to activate KSM, except if CONFIG_SYSFS is disabled) h](j_)}(hrunh]hrun}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKvhjyubjo)}(hhh](h bullet_list)}(hhh](h list_item)}(h9set to 0 to stop ksmd from running but keep merged pages,h]h)}(hjh]h9set to 0 to stop ksmd from running but keep merged pages,}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKphjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(h>set to 1 to run ksmd e.g. ``echo 1 > /sys/kernel/mm/ksm/run``,h]h)}(hjh](hset to 1 to run ksmd e.g. }(hjhhhNhNubh)}(h#``echo 1 > /sys/kernel/mm/ksm/run``h]hecho 1 > /sys/kernel/mm/ksm/run}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh,}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKqhjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hqset to 2 to stop ksmd and unmerge all pages currently merged, but leave mergeable areas registered for next run. h]h)}(hpset to 2 to stop ksmd and unmerge all pages currently merged, but leave mergeable areas registered for next run.h]hpset to 2 to stop ksmd and unmerge all pages currently merged, but leave mergeable areas registered for next run.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKrhjubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]bullet*uh1jhhhKphjubh)}(hUDefault: 0 (must be changed to 1 to activate KSM, except if CONFIG_SYSFS is disabled)h]hUDefault: 0 (must be changed to 1 to activate KSM, except if CONFIG_SYSFS is disabled)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKuhjubeh}(h]h ]h"]h$]h&]uh1jnhjyubeh}(h]h ]h"]h$]h&]uh1jXhhhKvhjUhhubjY)}(hXuse_zero_pages specifies whether empty pages (i.e. allocated pages that only contain zeroes) should be treated specially. When set to 1, empty pages are merged with the kernel zero page(s) instead of with each other as it would happen normally. This can improve the performance on architectures with coloured zero pages, depending on the workload. Care should be taken when enabling this setting, as it can potentially degrade the performance of KSM for some workloads, for example if the checksums of pages candidate for merging match the checksum of an empty page. This setting can be changed at any time, it is only effective for pages merged after the change. Default: 0 (normal KSM behaviour as in earlier releases) h](j_)}(huse_zero_pagesh]huse_zero_pages}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh](h)}(hXspecifies whether empty pages (i.e. allocated pages that only contain zeroes) should be treated specially. When set to 1, empty pages are merged with the kernel zero page(s) instead of with each other as it would happen normally. This can improve the performance on architectures with coloured zero pages, depending on the workload. Care should be taken when enabling this setting, as it can potentially degrade the performance of KSM for some workloads, for example if the checksums of pages candidate for merging match the checksum of an empty page. This setting can be changed at any time, it is only effective for pages merged after the change.h]hXspecifies whether empty pages (i.e. allocated pages that only contain zeroes) should be treated specially. When set to 1, empty pages are merged with the kernel zero page(s) instead of with each other as it would happen normally. This can improve the performance on architectures with coloured zero pages, depending on the workload. Care should be taken when enabling this setting, as it can potentially degrade the performance of KSM for some workloads, for example if the checksums of pages candidate for merging match the checksum of an empty page. This setting can be changed at any time, it is only effective for pages merged after the change.}(hj$hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKyhj!ubh)}(h8Default: 0 (normal KSM behaviour as in earlier releases)h]h8Default: 0 (normal KSM behaviour as in earlier releases)}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj!ubeh}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubjY)}(hXmax_page_sharing Maximum sharing allowed for each KSM page. This enforces a deduplication limit to avoid high latency for virtual memory operations that involve traversal of the virtual mappings that share the KSM page. The minimum value is 2 as a newly created KSM page will have at least two sharers. The higher this value the faster KSM will merge the memory and the higher the deduplication factor will be, but the slower the worst case virtual mappings traversal could be for any given KSM page. Slowing down this traversal means there will be higher latency for certain virtual memory operations happening during swapping, compaction, NUMA balancing and page migration, in turn decreasing responsiveness for the caller of those virtual memory operations. The scheduler latency of other tasks not involved with the VM operations doing the virtual mappings traversal is not affected by this parameter as these traversals are always schedule friendly themselves. h](j_)}(hmax_page_sharingh]hmax_page_sharing}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjLubjo)}(hhh]h)}(hXMaximum sharing allowed for each KSM page. This enforces a deduplication limit to avoid high latency for virtual memory operations that involve traversal of the virtual mappings that share the KSM page. The minimum value is 2 as a newly created KSM page will have at least two sharers. The higher this value the faster KSM will merge the memory and the higher the deduplication factor will be, but the slower the worst case virtual mappings traversal could be for any given KSM page. Slowing down this traversal means there will be higher latency for certain virtual memory operations happening during swapping, compaction, NUMA balancing and page migration, in turn decreasing responsiveness for the caller of those virtual memory operations. The scheduler latency of other tasks not involved with the VM operations doing the virtual mappings traversal is not affected by this parameter as these traversals are always schedule friendly themselves.h]hXMaximum sharing allowed for each KSM page. This enforces a deduplication limit to avoid high latency for virtual memory operations that involve traversal of the virtual mappings that share the KSM page. The minimum value is 2 as a newly created KSM page will have at least two sharers. The higher this value the faster KSM will merge the memory and the higher the deduplication factor will be, but the slower the worst case virtual mappings traversal could be for any given KSM page. Slowing down this traversal means there will be higher latency for certain virtual memory operations happening during swapping, compaction, NUMA balancing and page migration, in turn decreasing responsiveness for the caller of those virtual memory operations. The scheduler latency of other tasks not involved with the VM operations doing the virtual mappings traversal is not affected by this parameter as these traversals are always schedule friendly themselves.}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj^ubah}(h]h ]h"]h$]h&]uh1jnhjLubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubjY)}(hXbstable_node_chains_prune_millisecs specifies how frequently KSM checks the metadata of the pages that hit the deduplication limit for stale information. Smaller milllisecs values will free up the KSM metadata with lower latency, but they will make ksmd use more CPU during the scan. It's a noop if not a single KSM page hit the ``max_page_sharing`` yet. h](j_)}(h"stable_node_chains_prune_millisecsh]h"stable_node_chains_prune_millisecs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhj{ubjo)}(hhh]h)}(hX>specifies how frequently KSM checks the metadata of the pages that hit the deduplication limit for stale information. Smaller milllisecs values will free up the KSM metadata with lower latency, but they will make ksmd use more CPU during the scan. It's a noop if not a single KSM page hit the ``max_page_sharing`` yet.h](hX'specifies how frequently KSM checks the metadata of the pages that hit the deduplication limit for stale information. Smaller milllisecs values will free up the KSM metadata with lower latency, but they will make ksmd use more CPU during the scan. It’s a noop if not a single KSM page hit the }(hjhhhNhNubh)}(h``max_page_sharing``h]hmax_page_sharing}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh yet.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhj{ubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubjY)}(hXsmart_scan Historically KSM checked every candidate page for each scan. It did not take into account historic information. When smart scan is enabled, pages that have previously not been de-duplicated get skipped. How often these pages are skipped depends on how often de-duplication has already been tried and failed. By default this optimization is enabled. The ``pages_skipped`` metric shows how effective the setting is. h](j_)}(h smart_scanh]h smart_scan}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(hXHistorically KSM checked every candidate page for each scan. It did not take into account historic information. When smart scan is enabled, pages that have previously not been de-duplicated get skipped. How often these pages are skipped depends on how often de-duplication has already been tried and failed. By default this optimization is enabled. The ``pages_skipped`` metric shows how effective the setting is.h](hXcHistorically KSM checked every candidate page for each scan. It did not take into account historic information. When smart scan is enabled, pages that have previously not been de-duplicated get skipped. How often these pages are skipped depends on how often de-duplication has already been tried and failed. By default this optimization is enabled. The }(hjhhhNhNubh)}(h``pages_skipped``h]h pages_skipped}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh+ metric shows how effective the setting is.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubjY)}(hXadvisor_mode The ``advisor_mode`` selects the current advisor. Two modes are supported: none and scan-time. The default is none. By setting ``advisor_mode`` to scan-time, the scan time advisor is enabled. The section about ``advisor`` explains in detail how the scan time advisor works. h](j_)}(h advisor_modeh]h advisor_mode}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(hXThe ``advisor_mode`` selects the current advisor. Two modes are supported: none and scan-time. The default is none. By setting ``advisor_mode`` to scan-time, the scan time advisor is enabled. The section about ``advisor`` explains in detail how the scan time advisor works.h](hThe }(hjhhhNhNubh)}(h``advisor_mode``h]h advisor_mode}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhk selects the current advisor. Two modes are supported: none and scan-time. The default is none. By setting }(hjhhhNhNubh)}(h``advisor_mode``h]h advisor_mode}(hj,hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhC to scan-time, the scan time advisor is enabled. The section about }(hjhhhNhNubh)}(h ``advisor``h]hadvisor}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh4 explains in detail how the scan time advisor works.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubjY)}(huadivsor_max_cpu specifies the upper limit of the cpu percent usage of the ksmd background thread. The default is 70. h](j_)}(hadivsor_max_cpuh]hadivsor_max_cpu}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjbubjo)}(hhh]h)}(hdspecifies the upper limit of the cpu percent usage of the ksmd background thread. The default is 70.h]hdspecifies the upper limit of the cpu percent usage of the ksmd background thread. The default is 70.}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjtubah}(h]h ]h"]h$]h&]uh1jnhjbubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubjY)}(hadvisor_target_scan_time specifies the target scan time in seconds to scan all the candidate pages. The default value is 200 seconds. h](j_)}(hadvisor_target_scan_timeh]hadvisor_target_scan_time}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(hlspecifies the target scan time in seconds to scan all the candidate pages. The default value is 200 seconds.h]hlspecifies the target scan time in seconds to scan all the candidate pages. The default value is 200 seconds.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubjY)}(hadvisor_min_pages_to_scan specifies the lower limit of the ``pages_to_scan`` parameter of the scan time advisor. The default is 500. h](j_)}(hadvisor_min_pages_to_scanh]hadvisor_min_pages_to_scan}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(hjspecifies the lower limit of the ``pages_to_scan`` parameter of the scan time advisor. The default is 500.h](h!specifies the lower limit of the }(hjhhhNhNubh)}(h``pages_to_scan``h]h pages_to_scan}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh8 parameter of the scan time advisor. The default is 500.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubjY)}(hadivsor_max_pages_to_scan specifies the upper limit of the ``pages_to_scan`` parameter of the scan time advisor. The default is 30000. h](j_)}(hadivsor_max_pages_to_scanh]hadivsor_max_pages_to_scan}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(hlspecifies the upper limit of the ``pages_to_scan`` parameter of the scan time advisor. The default is 30000.h](h!specifies the upper limit of the }(hjhhhNhNubh)}(h``pages_to_scan``h]h pages_to_scan}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh: parameter of the scan time advisor. The default is 30000.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjUhhubeh}(h]h ]h"]h$]h&]uh1jShj"hhhhhNubh)}(hPThe effectiveness of KSM and MADV_MERGEABLE is shown in ``/sys/kernel/mm/ksm/``:h](h8The effectiveness of KSM and MADV_MERGEABLE is shown in }(hjHhhhNhNubh)}(h``/sys/kernel/mm/ksm/``h]h/sys/kernel/mm/ksm/}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjHubh:}(hjHhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj"hhubjT)}(hhh](jY)}(hHgeneral_profit how effective is KSM. The calculation is explained below.h](j_)}(hgeneral_profith]hgeneral_profit}(hjohhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjkubjo)}(hhh]h)}(h9how effective is KSM. The calculation is explained below.h]h9how effective is KSM. The calculation is explained below.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj}ubah}(h]h ]h"]h$]h&]uh1jnhjkubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhubjY)}(h6pages_scanned how many pages are being scanned for ksmh](j_)}(h pages_scannedh]h pages_scanned}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(h(how many pages are being scanned for ksmh]h(how many pages are being scanned for ksm}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(h1pages_shared how many shared pages are being usedh](j_)}(h pages_sharedh]h pages_shared}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(h$how many shared pages are being usedh]h$how many shared pages are being used}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(hFpages_sharing how many more sites are sharing them i.e. how much savedh](j_)}(h pages_sharingh]h pages_sharing}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(h8how many more sites are sharing them i.e. how much savedh]h8how many more sites are sharing them i.e. how much saved}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(hGpages_unshared how many pages unique but repeatedly checked for mergingh](j_)}(hpages_unsharedh]hpages_unshared}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhj'ubjo)}(hhh]h)}(h8how many pages unique but repeatedly checked for mergingh]h8how many pages unique but repeatedly checked for merging}(hj<hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj9ubah}(h]h ]h"]h$]h&]uh1jnhj'ubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(hFpages_volatile how many pages changing too fast to be placed in a treeh](j_)}(hpages_volatileh]hpages_volatile}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjVubjo)}(hhh]h)}(h7how many pages changing too fast to be placed in a treeh]h7how many pages changing too fast to be placed in a tree}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhubah}(h]h ]h"]h$]h&]uh1jnhjVubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(hIpages_skipped how many pages did the "smart" page scanning algorithm skiph](j_)}(h pages_skippedh]h pages_skipped}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(h;how many pages did the "smart" page scanning algorithm skiph]h?how many pages did the “smart” page scanning algorithm skip}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(h?full_scans how many times all mergeable areas have been scannedh](j_)}(h full_scansh]h full_scans}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(h4how many times all mergeable areas have been scannedh]h4how many times all mergeable areas have been scanned}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(hRstable_node_chains the number of KSM pages that hit the ``max_page_sharing`` limith](j_)}(hstable_node_chainsh]hstable_node_chains}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjubjo)}(hhh]h)}(h?the number of KSM pages that hit the ``max_page_sharing`` limith](h%the number of KSM pages that hit the }(hjhhhNhNubh)}(h``max_page_sharing``h]hmax_page_sharing}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh limit}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jnhjubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(h/stable_node_dups number of duplicated KSM pagesh](j_)}(hstable_node_dupsh]hstable_node_dups}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhj$ubjo)}(hhh]h)}(hnumber of duplicated KSM pagesh]hnumber of duplicated KSM pages}(hj9hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj6ubah}(h]h ]h"]h$]h&]uh1jnhj$ubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubjY)}(hoksm_zero_pages how many zero pages that are still mapped into processes were mapped by KSM when deduplicating. h](j_)}(hksm_zero_pagesh]hksm_zero_pages}(hjWhhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhKhjSubjo)}(hhh]h)}(h_how many zero pages that are still mapped into processes were mapped by KSM when deduplicating.h]h_how many zero pages that are still mapped into processes were mapped by KSM when deduplicating.}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjeubah}(h]h ]h"]h$]h&]uh1jnhjSubeh}(h]h ]h"]h$]h&]uh1jXhhhKhjhhhubeh}(h]h ]h"]h$]h&]uh1jShj"hhhhhNubh)}(hWhen ``use_zero_pages`` is/was enabled, the sum of ``pages_sharing`` + ``ksm_zero_pages`` represents the actual number of pages saved by KSM. if ``use_zero_pages`` has never been enabled, ``ksm_zero_pages`` is 0.h](hWhen }(hjhhhNhNubh)}(h``use_zero_pages``h]huse_zero_pages}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh is/was enabled, the sum of }(hjhhhNhNubh)}(h``pages_sharing``h]h pages_sharing}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh + }(hjhhhNhNubh)}(h``ksm_zero_pages``h]hksm_zero_pages}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh8 represents the actual number of pages saved by KSM. if }(hjhhhNhNubh)}(h``use_zero_pages``h]huse_zero_pages}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh has never been enabled, }(hjhhhNhNubh)}(h``ksm_zero_pages``h]hksm_zero_pages}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh is 0.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj"hhubh)}(hX8A high ratio of ``pages_sharing`` to ``pages_shared`` indicates good sharing, but a high ratio of ``pages_unshared`` to ``pages_sharing`` indicates wasted effort. ``pages_volatile`` embraces several different kinds of activity, but a high proportion there would also indicate poor use of madvise MADV_MERGEABLE.h](hA high ratio of }(hjhhhNhNubh)}(h``pages_sharing``h]h pages_sharing}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh to }(hjhhhNhNubh)}(h``pages_shared``h]h pages_shared}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh- indicates good sharing, but a high ratio of }(hjhhhNhNubh)}(h``pages_unshared``h]hpages_unshared}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh to }hjsbh)}(h``pages_sharing``h]h pages_sharing}(hj. hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh indicates wasted effort. }(hjhhhNhNubh)}(h``pages_volatile``h]hpages_volatile}(hj@ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh embraces several different kinds of activity, but a high proportion there would also indicate poor use of madvise MADV_MERGEABLE.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj"hhubh)}(hThe maximum possible ``pages_sharing/pages_shared`` ratio is limited by the ``max_page_sharing`` tunable. To increase the ratio ``max_page_sharing`` must be increased accordingly.h](hThe maximum possible }(hjX hhhNhNubh)}(h``pages_sharing/pages_shared``h]hpages_sharing/pages_shared}(hj` hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjX ubh ratio is limited by the }(hjX hhhNhNubh)}(h``max_page_sharing``h]hmax_page_sharing}(hjr hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjX ubh tunable. To increase the ratio }(hjX hhhNhNubh)}(h``max_page_sharing``h]hmax_page_sharing}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjX ubh must be increased accordingly.}(hjX hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj"hhubeh}(h](ksm-daemon-sysfs-interfacejeh ]h"](ksm daemon sysfs interface ksm_sysfseh$]h&]uh1hhhhhhhhKJexpect_referenced_by_name}j jsexpect_referenced_by_id}jjsubh)}(hhh](h)}(hMonitoring KSM profith]hMonitoring KSM profit}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhKubh)}(hXTKSM can save memory by merging identical pages, but also can consume additional memory, because it needs to generate a number of rmap_items to save each scanned page's brief rmap information. Some of these pages may be merged, but some may not be abled to be merged after being checked several times, which are unprofitable memory consumed.h]hXVKSM can save memory by merging identical pages, but also can consume additional memory, because it needs to generate a number of rmap_items to save each scanned page’s brief rmap information. Some of these pages may be merged, but some may not be abled to be merged after being checked several times, which are unprofitable memory consumed.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj hhubhenumerated_list)}(hhh](j)}(hXHow to determine whether KSM save memory or consume memory in system-wide range? Here is a simple approximate calculation for reference:: general_profit =~ ksm_saved_pages * sizeof(page) - (all_rmap_items) * sizeof(rmap_item); where ksm_saved_pages equals to the sum of ``pages_sharing`` + ``ksm_zero_pages`` of the system, and all_rmap_items can be easily obtained by summing ``pages_sharing``, ``pages_shared``, ``pages_unshared`` and ``pages_volatile``. h](h)}(hHow to determine whether KSM save memory or consume memory in system-wide range? Here is a simple approximate calculation for reference::h]hHow to determine whether KSM save memory or consume memory in system-wide range? Here is a simple approximate calculation for reference:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubj)}(hjgeneral_profit =~ ksm_saved_pages * sizeof(page) - (all_rmap_items) * sizeof(rmap_item);h]hjgeneral_profit =~ ksm_saved_pages * sizeof(page) - (all_rmap_items) * sizeof(rmap_item);}hj sbah}(h]h ]h"]h$]h&]jjuh1jhhhKhj ubh)}(hwhere ksm_saved_pages equals to the sum of ``pages_sharing`` + ``ksm_zero_pages`` of the system, and all_rmap_items can be easily obtained by summing ``pages_sharing``, ``pages_shared``, ``pages_unshared`` and ``pages_volatile``.h](h+where ksm_saved_pages equals to the sum of }(hj hhhNhNubh)}(h``pages_sharing``h]h pages_sharing}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh + }(hj hhhNhNubh)}(h``ksm_zero_pages``h]hksm_zero_pages}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhE of the system, and all_rmap_items can be easily obtained by summing }(hj hhhNhNubh)}(h``pages_sharing``h]h pages_sharing}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh, }(hj hhhNhNubh)}(h``pages_shared``h]h pages_shared}(hj+ hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh, }hj sbh)}(h``pages_unshared``h]hpages_unshared}(hj= hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh and }(hj hhhNhNubh)}(h``pages_volatile``h]hpages_volatile}(hjO hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj ubeh}(h]h ]h"]h$]h&]uh1jhj hhhhhNubj)}(hXThe KSM profit inner a single process can be similarly obtained by the following approximate calculation:: process_profit =~ ksm_saved_pages * sizeof(page) - ksm_rmap_items * sizeof(rmap_item). where ksm_saved_pages equals to the sum of ``ksm_merging_pages`` and ``ksm_zero_pages``, both of which are shown under the directory ``/proc//ksm_stat``, and ksm_rmap_items is also shown in ``/proc//ksm_stat``. The process profit is also shown in ``/proc//ksm_stat`` as ksm_process_profit. h](h)}(hjThe KSM profit inner a single process can be similarly obtained by the following approximate calculation::h]hiThe KSM profit inner a single process can be similarly obtained by the following approximate calculation:}(hjq hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjm ubj)}(hhprocess_profit =~ ksm_saved_pages * sizeof(page) - ksm_rmap_items * sizeof(rmap_item).h]hhprocess_profit =~ ksm_saved_pages * sizeof(page) - ksm_rmap_items * sizeof(rmap_item).}hj sbah}(h]h ]h"]h$]h&]jjuh1jhhhMhjm ubh)}(hX0where ksm_saved_pages equals to the sum of ``ksm_merging_pages`` and ``ksm_zero_pages``, both of which are shown under the directory ``/proc//ksm_stat``, and ksm_rmap_items is also shown in ``/proc//ksm_stat``. The process profit is also shown in ``/proc//ksm_stat`` as ksm_process_profit.h](h+where ksm_saved_pages equals to the sum of }(hj hhhNhNubh)}(h``ksm_merging_pages``h]hksm_merging_pages}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh and }(hj hhhNhNubh)}(h``ksm_zero_pages``h]hksm_zero_pages}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh., both of which are shown under the directory }(hj hhhNhNubh)}(h``/proc//ksm_stat``h]h/proc//ksm_stat}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh&, and ksm_rmap_items is also shown in }(hj hhhNhNubh)}(h``/proc//ksm_stat``h]h/proc//ksm_stat}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh&. The process profit is also shown in }(hj hhhNhNubh)}(h``/proc//ksm_stat``h]h/proc//ksm_stat}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh as ksm_process_profit.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhMhjm ubeh}(h]h ]h"]h$]h&]uh1jhj hhhhhNubeh}(h]h ]h"]h$]h&]enumtypearabicprefixhsuffix)uh1j hj hhhhhKubh)}(hXQFrom the perspective of application, a high ratio of ``ksm_rmap_items`` to ``ksm_merging_pages`` means a bad madvise-applied policy, so developers or administrators have to rethink how to change madvise policy. Giving an example for reference, a page's size is usually 4K, and the rmap_item's size is separately 32B on 32-bit CPU architecture and 64B on 64-bit CPU architecture. so if the ``ksm_rmap_items/ksm_merging_pages`` ratio exceeds 64 on 64-bit CPU or exceeds 128 on 32-bit CPU, then the app's madvise policy should be dropped, because the ksm profit is approximately zero or negative.h](h5From the perspective of application, a high ratio of }(hj hhhNhNubh)}(h``ksm_rmap_items``h]hksm_rmap_items}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh to }(hj hhhNhNubh)}(h``ksm_merging_pages``h]hksm_merging_pages}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhX) means a bad madvise-applied policy, so developers or administrators have to rethink how to change madvise policy. Giving an example for reference, a page’s size is usually 4K, and the rmap_item’s size is separately 32B on 32-bit CPU architecture and 64B on 64-bit CPU architecture. so if the }(hj hhhNhNubh)}(h$``ksm_rmap_items/ksm_merging_pages``h]h ksm_rmap_items/ksm_merging_pages}(hj2 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh ratio exceeds 64 on 64-bit CPU or exceeds 128 on 32-bit CPU, then the app’s madvise policy should be dropped, because the ksm profit is approximately zero or negative.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM hj hhubeh}(h]monitoring-ksm-profitah ]h"]monitoring ksm profitah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hMonitoring KSM eventsh]hMonitoring KSM events}(hjU hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjR hhhhhMubh)}(hX_There are some counters in /proc/vmstat that may be used to monitor KSM events. KSM might help save memory, it's a tradeoff by may suffering delay on KSM COW or on swapping in copy. Those events could help users evaluate whether or how to use KSM. For example, if cow_ksm increases too fast, user may decrease the range of madvise(, , MADV_MERGEABLE).h]hXaThere are some counters in /proc/vmstat that may be used to monitor KSM events. KSM might help save memory, it’s a tradeoff by may suffering delay on KSM COW or on swapping in copy. Those events could help users evaluate whether or how to use KSM. For example, if cow_ksm increases too fast, user may decrease the range of madvise(, , MADV_MERGEABLE).}(hjc hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjR hhubjT)}(hhh](jY)}(hcow_ksm is incremented every time a KSM page triggers copy on write (COW) when users try to write to a KSM page, we have to make a copy. h](j_)}(hcow_ksmh]hcow_ksm}(hjx hhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhMhjt ubjo)}(hhh]h)}(his incremented every time a KSM page triggers copy on write (COW) when users try to write to a KSM page, we have to make a copy.h]his incremented every time a KSM page triggers copy on write (COW) when users try to write to a KSM page, we have to make a copy.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj ubah}(h]h ]h"]h$]h&]uh1jnhjt ubeh}(h]h ]h"]h$]h&]uh1jXhhhMhjq ubjY)}(hksm_swpin_copy is incremented every time a KSM page is copied when swapping in note that KSM page might be copied when swapping in because do_swap_page() cannot do all the locking needed to reconstitute a cross-anon_vma KSM page. h](j_)}(hksm_swpin_copyh]hksm_swpin_copy}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1j^hhhM"hj ubjo)}(hhh]h)}(his incremented every time a KSM page is copied when swapping in note that KSM page might be copied when swapping in because do_swap_page() cannot do all the locking needed to reconstitute a cross-anon_vma KSM page.h]his incremented every time a KSM page is copied when swapping in note that KSM page might be copied when swapping in because do_swap_page() cannot do all the locking needed to reconstitute a cross-anon_vma KSM page.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM hj ubah}(h]h ]h"]h$]h&]uh1jnhj ubeh}(h]h ]h"]h$]h&]uh1jXhhhM"hjq hhubeh}(h]h ]h"]h$]h&]uh1jShjR hhhhhNubeh}(h]monitoring-ksm-eventsah ]h"]monitoring ksm eventsah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(hAdvisorh]hAdvisor}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhM%ubh)}(hXbThe number of candidate pages for KSM is dynamic. It can be often observed that during the startup of an application more candidate pages need to be processed. Without an advisor the ``pages_to_scan`` parameter needs to be sized for the maximum number of candidate pages. The scan time advisor can changes the ``pages_to_scan`` parameter based on demand.h](hThe number of candidate pages for KSM is dynamic. It can be often observed that during the startup of an application more candidate pages need to be processed. Without an advisor the }(hj hhhNhNubh)}(h``pages_to_scan``h]h pages_to_scan}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubhn parameter needs to be sized for the maximum number of candidate pages. The scan time advisor can changes the }(hj hhhNhNubh)}(h``pages_to_scan``h]h pages_to_scan}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubh parameter based on demand.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM'hj hhubh)}(hThe advisor can be enabled, so KSM can automatically adapt to changes in the number of candidate pages to scan. Two advisors are implemented: none and scan-time. With none, no advisor is enabled. The default is none.h]hThe advisor can be enabled, so KSM can automatically adapt to changes in the number of candidate pages to scan. Two advisors are implemented: none and scan-time. With none, no advisor is enabled. The default is none.}(hj# hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM-hj hhubh)}(hX^The scan time advisor changes the ``pages_to_scan`` parameter based on the observed scan times. The possible values for the ``pages_to_scan`` parameter is limited by the ``advisor_max_cpu`` parameter. In addition there is also the ``advisor_target_scan_time`` parameter. This parameter sets the target time to scan all the KSM candidate pages. The parameter ``advisor_target_scan_time`` decides how aggressive the scan time advisor scans candidate pages. Lower values make the scan time advisor to scan more aggressively. This is the most important parameter for the configuration of the scan time advisor.h](h"The scan time advisor changes the }(hj1 hhhNhNubh)}(h``pages_to_scan``h]h pages_to_scan}(hj9 hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1 ubhI parameter based on the observed scan times. The possible values for the }(hj1 hhhNhNubh)}(h``pages_to_scan``h]h pages_to_scan}(hjK hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1 ubh parameter is limited by the }(hj1 hhhNhNubh)}(h``advisor_max_cpu``h]hadvisor_max_cpu}(hj] hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1 ubh* parameter. In addition there is also the }(hj1 hhhNhNubh)}(h``advisor_target_scan_time``h]hadvisor_target_scan_time}(hjo hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1 ubhc parameter. This parameter sets the target time to scan all the KSM candidate pages. The parameter }(hj1 hhhNhNubh)}(h``advisor_target_scan_time``h]hadvisor_target_scan_time}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj1 ubh decides how aggressive the scan time advisor scans candidate pages. Lower values make the scan time advisor to scan more aggressively. This is the most important parameter for the configuration of the scan time advisor.}(hj1 hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM1hj hhubh)}(hThe initial value and the maximum value can be changed with ``advisor_min_pages_to_scan`` and ``advisor_max_pages_to_scan``. The default values are sufficient for most workloads and use cases.h](hhj hhubh)}(h(-- Izik Eidus, Hugh Dickins, 17 Nov 2009h]h(-- Izik Eidus, Hugh Dickins, 17 Nov 2009}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMAhj hhubeh}(h]advisorah ]h"]advisorah$]h&]uh1hhhhhhhhM%ubeh}(h]kernel-samepage-mergingah ]h"]kernel samepage mergingah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerj, error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}j]jasnameids}(j j jdjajjj jj j jO jL j j j j u nametypes}(j jdjj j jO j j uh}(j hjahjjgjj"j j"jL j j jR j j u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]hsystem_message)}(hhh]h)}(h`Possible incomplete section title. Treating the overline as ordinary text because it's so short.h]hbPossible incomplete section title. Treating the overline as ordinary text because it’s so short.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj ubah}(h]h ]h"]h$]h&]levelKtypeINFOlineMAsourcehuh1j hj hhhhhMCubatransform_messages]j )}(hhh]h)}(hhh]h/Hyperlink target "ksm-sysfs" is not referenced.}hj sbah}(h]h ]h"]h$]h&]uh1hhj ubah}(h]h ]h"]h$]h&]levelKtypej sourcehlineKGuh1j uba transformerN include_log] decorationNhhub.