Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ksm: add some comments

Added slightly more detail to the Documentation of merge_across_nodes, a
few comments in areas indicated by review, and renamed get_ksm_page()'s
argument from "locked" to "lock_it". No functional change.

Signed-off-by: Hugh Dickins <hughd@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Petr Holasek <pholasek@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Izik Eidus <izik.eidus@ravellosystems.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Hugh Dickins and committed by
Linus Torvalds
8fdb3dbf 49cd0a5c

+27 -9
+12 -4
Documentation/vm/ksm.txt
··· 60 60 61 61 merge_across_nodes - specifies if pages from different numa nodes can be merged. 62 62 When set to 0, ksm merges only pages which physically 63 - reside in the memory area of same NUMA node. It brings 64 - lower latency to access to shared page. Value can be 65 - changed only when there is no ksm shared pages in system. 66 - Default: 1 63 + reside in the memory area of same NUMA node. That brings 64 + lower latency to access of shared pages. Systems with more 65 + nodes, at significant NUMA distances, are likely to benefit 66 + from the lower latency of setting 0. Smaller systems, which 67 + need to minimize memory usage, are likely to benefit from 68 + the greater sharing of setting 1 (default). You may wish to 69 + compare how your system performs under each setting, before 70 + deciding on which to use. merge_across_nodes setting can be 71 + changed only when there are no ksm shared pages in system: 72 + set run 2 to unmerge pages first, then to 1 after changing 73 + merge_across_nodes, to remerge according to the new setting. 74 + Default: 1 (merging across nodes as in earlier releases) 67 75 68 76 run - set 0 to stop ksmd from running but keep merged pages, 69 77 set 1 to run ksmd e.g. "echo 1 > /sys/kernel/mm/ksm/run",
+15 -5
mm/ksm.c
··· 87 87 * take 10 attempts to find a page in the unstable tree, once it is found, 88 88 * it is secured in the stable tree. (When we scan a new page, we first 89 89 * compare it against the stable tree, and then against the unstable tree.) 90 + * 91 + * If the merge_across_nodes tunable is unset, then KSM maintains multiple 92 + * stable trees and multiple unstable trees: one of each for each NUMA node. 90 93 */ 91 94 92 95 /** ··· 529 526 * a page to put something that might look like our key in page->mapping. 530 527 * is on its way to being freed; but it is an anomaly to bear in mind. 531 528 */ 532 - static struct page *get_ksm_page(struct stable_node *stable_node, bool locked) 529 + static struct page *get_ksm_page(struct stable_node *stable_node, bool lock_it) 533 530 { 534 531 struct page *page; 535 532 void *expected_mapping; ··· 578 575 goto stale; 579 576 } 580 577 581 - if (locked) { 578 + if (lock_it) { 582 579 lock_page(page); 583 580 if (ACCESS_ONCE(page->mapping) != expected_mapping) { 584 581 unlock_page(page); ··· 708 705 return 0; 709 706 } 710 707 711 - if (WARN_ON_ONCE(page_mapped(page))) 712 - err = -EBUSY; 713 - else { 708 + if (WARN_ON_ONCE(page_mapped(page))) { 714 709 /* 710 + * This should not happen: but if it does, just refuse to let 711 + * merge_across_nodes be switched - there is no need to panic. 712 + */ 713 + err = -EBUSY; 714 + } else { 715 + /* 716 + * The stable node did not yet appear stale to get_ksm_page(), 717 + * since that allows for an unmapped ksm page to be recognized 718 + * right up until it is freed; but the node is safe to remove. 715 719 * This page might be in a pagevec waiting to be freed, 716 720 * or it might be PageSwapCache (perhaps under writeback), 717 721 * or it might have been removed from swapcache a moment ago.