aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/vm/ksm.txt22
-rw-r--r--mm/Kconfig2
-rw-r--r--mm/ksm.c41
3 files changed, 10 insertions, 55 deletions
diff --git a/Documentation/vm/ksm.txt b/Documentation/vm/ksm.txt
index 262d8e6793a3..b392e496f816 100644
--- a/Documentation/vm/ksm.txt
+++ b/Documentation/vm/ksm.txt
@@ -16,9 +16,9 @@ by sharing the data common between them. But it can be useful to any
16application which generates many instances of the same data. 16application which generates many instances of the same data.
17 17
18KSM only merges anonymous (private) pages, never pagecache (file) pages. 18KSM only merges anonymous (private) pages, never pagecache (file) pages.
19KSM's merged pages are at present locked into kernel memory for as long 19KSM's merged pages were originally locked into kernel memory, but can now
20as they are shared: so cannot be swapped out like the user pages they 20be swapped out just like other user pages (but sharing is broken when they
21replace (but swapping KSM pages should follow soon in a later release). 21are swapped back in: ksmd must rediscover their identity and merge again).
22 22
23KSM only operates on those areas of address space which an application 23KSM only operates on those areas of address space which an application
24has advised to be likely candidates for merging, by using the madvise(2) 24has advised to be likely candidates for merging, by using the madvise(2)
@@ -44,20 +44,12 @@ includes unmapped gaps (though working on the intervening mapped areas),
44and might fail with EAGAIN if not enough memory for internal structures. 44and might fail with EAGAIN if not enough memory for internal structures.
45 45
46Applications should be considerate in their use of MADV_MERGEABLE, 46Applications should be considerate in their use of MADV_MERGEABLE,
47restricting its use to areas likely to benefit. KSM's scans may use 47restricting its use to areas likely to benefit. KSM's scans may use a lot
48a lot of processing power, and its kernel-resident pages are a limited 48of processing power: some installations will disable KSM for that reason.
49resource. Some installations will disable KSM for these reasons.
50 49
51The KSM daemon is controlled by sysfs files in /sys/kernel/mm/ksm/, 50The KSM daemon is controlled by sysfs files in /sys/kernel/mm/ksm/,
52readable by all but writable only by root: 51readable by all but writable only by root:
53 52
54max_kernel_pages - set to maximum number of kernel pages that KSM may use
55 e.g. "echo 100000 > /sys/kernel/mm/ksm/max_kernel_pages"
56 Value 0 imposes no limit on the kernel pages KSM may use;
57 but note that any process using MADV_MERGEABLE can cause
58 KSM to allocate these pages, unswappable until it exits.
59 Default: quarter of memory (chosen to not pin too much)
60
61pages_to_scan - how many present pages to scan before ksmd goes to sleep 53pages_to_scan - how many present pages to scan before ksmd goes to sleep
62 e.g. "echo 100 > /sys/kernel/mm/ksm/pages_to_scan" 54 e.g. "echo 100 > /sys/kernel/mm/ksm/pages_to_scan"
63 Default: 100 (chosen for demonstration purposes) 55 Default: 100 (chosen for demonstration purposes)
@@ -75,7 +67,7 @@ run - set 0 to stop ksmd from running but keep merged pages,
75 67
76The effectiveness of KSM and MADV_MERGEABLE is shown in /sys/kernel/mm/ksm/: 68The effectiveness of KSM and MADV_MERGEABLE is shown in /sys/kernel/mm/ksm/:
77 69
78pages_shared - how many shared unswappable kernel pages KSM is using 70pages_shared - how many shared pages are being used
79pages_sharing - how many more sites are sharing them i.e. how much saved 71pages_sharing - how many more sites are sharing them i.e. how much saved
80pages_unshared - how many pages unique but repeatedly checked for merging 72pages_unshared - how many pages unique but repeatedly checked for merging
81pages_volatile - how many pages changing too fast to be placed in a tree 73pages_volatile - how many pages changing too fast to be placed in a tree
@@ -87,4 +79,4 @@ pages_volatile embraces several different kinds of activity, but a high
87proportion there would also indicate poor use of madvise MADV_MERGEABLE. 79proportion there would also indicate poor use of madvise MADV_MERGEABLE.
88 80
89Izik Eidus, 81Izik Eidus,
90Hugh Dickins, 24 Sept 2009 82Hugh Dickins, 17 Nov 2009
diff --git a/mm/Kconfig b/mm/Kconfig
index d4b5fff6ea09..2310984591ed 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -212,7 +212,7 @@ config KSM
212 Enable Kernel Samepage Merging: KSM periodically scans those areas 212 Enable Kernel Samepage Merging: KSM periodically scans those areas
213 of an application's address space that an app has advised may be 213 of an application's address space that an app has advised may be
214 mergeable. When it finds pages of identical content, it replaces 214 mergeable. When it finds pages of identical content, it replaces
215 the many instances by a single resident page with that content, so 215 the many instances by a single page with that content, so
216 saving memory until one or another app needs to modify the content. 216 saving memory until one or another app needs to modify the content.
217 Recommended for use with KVM, or with other duplicative applications. 217 Recommended for use with KVM, or with other duplicative applications.
218 See Documentation/vm/ksm.txt for more information: KSM is inactive 218 See Documentation/vm/ksm.txt for more information: KSM is inactive
diff --git a/mm/ksm.c b/mm/ksm.c
index d4c228a9d278..56a0da1f9979 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -179,9 +179,6 @@ static unsigned long ksm_pages_unshared;
179/* The number of rmap_items in use: to calculate pages_volatile */ 179/* The number of rmap_items in use: to calculate pages_volatile */
180static unsigned long ksm_rmap_items; 180static unsigned long ksm_rmap_items;
181 181
182/* Limit on the number of unswappable pages used */
183static unsigned long ksm_max_kernel_pages;
184
185/* Number of pages ksmd should scan in one batch */ 182/* Number of pages ksmd should scan in one batch */
186static unsigned int ksm_thread_pages_to_scan = 100; 183static unsigned int ksm_thread_pages_to_scan = 100;
187 184
@@ -943,14 +940,6 @@ static struct page *try_to_merge_two_pages(struct rmap_item *rmap_item,
943{ 940{
944 int err; 941 int err;
945 942
946 /*
947 * The number of nodes in the stable tree
948 * is the number of kernel pages that we hold.
949 */
950 if (ksm_max_kernel_pages &&
951 ksm_max_kernel_pages <= ksm_pages_shared)
952 return NULL;
953
954 err = try_to_merge_with_ksm_page(rmap_item, page, NULL); 943 err = try_to_merge_with_ksm_page(rmap_item, page, NULL);
955 if (!err) { 944 if (!err) {
956 err = try_to_merge_with_ksm_page(tree_rmap_item, 945 err = try_to_merge_with_ksm_page(tree_rmap_item,
@@ -1850,8 +1839,8 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr,
1850 /* 1839 /*
1851 * KSM_RUN_MERGE sets ksmd running, and 0 stops it running. 1840 * KSM_RUN_MERGE sets ksmd running, and 0 stops it running.
1852 * KSM_RUN_UNMERGE stops it running and unmerges all rmap_items, 1841 * KSM_RUN_UNMERGE stops it running and unmerges all rmap_items,
1853 * breaking COW to free the unswappable pages_shared (but leaves 1842 * breaking COW to free the pages_shared (but leaves mm_slots
1854 * mm_slots on the list for when ksmd may be set running again). 1843 * on the list for when ksmd may be set running again).
1855 */ 1844 */
1856 1845
1857 mutex_lock(&ksm_thread_mutex); 1846 mutex_lock(&ksm_thread_mutex);
@@ -1876,29 +1865,6 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr,
1876} 1865}
1877KSM_ATTR(run); 1866KSM_ATTR(run);
1878 1867
1879static ssize_t max_kernel_pages_store(struct kobject *kobj,
1880 struct kobj_attribute *attr,
1881 const char *buf, size_t count)
1882{
1883 int err;
1884 unsigned long nr_pages;
1885
1886 err = strict_strtoul(buf, 10, &nr_pages);
1887 if (err)
1888 return -EINVAL;
1889
1890 ksm_max_kernel_pages = nr_pages;
1891
1892 return count;
1893}
1894
1895static ssize_t max_kernel_pages_show(struct kobject *kobj,
1896 struct kobj_attribute *attr, char *buf)
1897{
1898 return sprintf(buf, "%lu\n", ksm_max_kernel_pages);
1899}
1900KSM_ATTR(max_kernel_pages);
1901
1902static ssize_t pages_shared_show(struct kobject *kobj, 1868static ssize_t pages_shared_show(struct kobject *kobj,
1903 struct kobj_attribute *attr, char *buf) 1869 struct kobj_attribute *attr, char *buf)
1904{ 1870{
@@ -1948,7 +1914,6 @@ static struct attribute *ksm_attrs[] = {
1948 &sleep_millisecs_attr.attr, 1914 &sleep_millisecs_attr.attr,
1949 &pages_to_scan_attr.attr, 1915 &pages_to_scan_attr.attr,
1950 &run_attr.attr, 1916 &run_attr.attr,
1951 &max_kernel_pages_attr.attr,
1952 &pages_shared_attr.attr, 1917 &pages_shared_attr.attr,
1953 &pages_sharing_attr.attr, 1918 &pages_sharing_attr.attr,
1954 &pages_unshared_attr.attr, 1919 &pages_unshared_attr.attr,
@@ -1968,8 +1933,6 @@ static int __init ksm_init(void)
1968 struct task_struct *ksm_thread; 1933 struct task_struct *ksm_thread;
1969 int err; 1934 int err;
1970 1935
1971 ksm_max_kernel_pages = totalram_pages / 4;
1972
1973 err = ksm_slab_init(); 1936 err = ksm_slab_init();
1974 if (err) 1937 if (err)
1975 goto out; 1938 goto out;