Skip to content

Commit 2ffd867

Browse files
Hugh Dickinstorvalds
authored andcommitted
ksm: sysfs and defaults
At present KSM is just a waste of space if you don't have CONFIG_SYSFS=y to provide the /sys/kernel/mm/ksm files to tune and activate it. Make KSM depend on SYSFS? Could do, but it might be better to provide some defaults so that KSM works out-of-the-box, ready for testers to madvise MADV_MERGEABLE, even without SYSFS. Though anyone serious is likely to want to retune the numbers to their taste once they have experience; and whether these settings ever reach 2.6.32 can be discussed along the way. Save 1kB from tiny kernels by #ifdef'ing the SYSFS side of it. Signed-off-by: Hugh Dickins <hugh.dickins@tiscali.co.uk> Acked-by: Izik Eidus <ieidus@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1c2fb7a commit 2ffd867

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

‎mm/ksm.c‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,18 @@ static unsigned long ksm_pages_unshared;
163163
static unsigned long ksm_rmap_items;
164164

165165
/* Limit on the number of unswappable pages used */
166-
static unsigned long ksm_max_kernel_pages;
166+
static unsigned long ksm_max_kernel_pages = 2000;
167167

168168
/* Number of pages ksmd should scan in one batch */
169-
static unsigned int ksm_thread_pages_to_scan;
169+
static unsigned int ksm_thread_pages_to_scan = 200;
170170

171171
/* Milliseconds ksmd should sleep between batches */
172-
static unsigned int ksm_thread_sleep_millisecs;
172+
static unsigned int ksm_thread_sleep_millisecs = 20;
173173

174174
#define KSM_RUN_STOP 0
175175
#define KSM_RUN_MERGE 1
176176
#define KSM_RUN_UNMERGE 2
177-
static unsigned int ksm_run;
177+
static unsigned int ksm_run = KSM_RUN_MERGE;
178178

179179
static DECLARE_WAIT_QUEUE_HEAD(ksm_thread_wait);
180180
static DEFINE_MUTEX(ksm_thread_mutex);
@@ -506,6 +506,10 @@ static int unmerge_ksm_pages(struct vm_area_struct *vma,
506506
return err;
507507
}
508508

509+
#ifdef CONFIG_SYSFS
510+
/*
511+
* Only called through the sysfs control interface:
512+
*/
509513
static int unmerge_and_remove_all_rmap_items(void)
510514
{
511515
struct mm_slot *mm_slot;
@@ -563,6 +567,7 @@ static int unmerge_and_remove_all_rmap_items(void)
563567
spin_unlock(&ksm_mmlist_lock);
564568
return err;
565569
}
570+
#endif /* CONFIG_SYSFS */
566571

567572
static u32 calc_checksum(struct page *page)
568573
{
@@ -1454,6 +1459,11 @@ void __ksm_exit(struct mm_struct *mm)
14541459
}
14551460
}
14561461

1462+
#ifdef CONFIG_SYSFS
1463+
/*
1464+
* This all compiles without CONFIG_SYSFS, but is a waste of space.
1465+
*/
1466+
14571467
#define KSM_ATTR_RO(_name) \
14581468
static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
14591469
#define KSM_ATTR(_name) \
@@ -1636,6 +1646,7 @@ static struct attribute_group ksm_attr_group = {
16361646
.attrs = ksm_attrs,
16371647
.name = "ksm",
16381648
};
1649+
#endif /* CONFIG_SYSFS */
16391650

16401651
static int __init ksm_init(void)
16411652
{
@@ -1657,16 +1668,17 @@ static int __init ksm_init(void)
16571668
goto out_free2;
16581669
}
16591670

1671+
#ifdef CONFIG_SYSFS
16601672
err = sysfs_create_group(mm_kobj, &ksm_attr_group);
16611673
if (err) {
16621674
printk(KERN_ERR "ksm: register sysfs failed\n");
1663-
goto out_free3;
1675+
kthread_stop(ksm_thread);
1676+
goto out_free2;
16641677
}
1678+
#endif /* CONFIG_SYSFS */
16651679

16661680
return 0;
16671681

1668-
out_free3:
1669-
kthread_stop(ksm_thread);
16701682
out_free2:
16711683
mm_slots_hash_free();
16721684
out_free1:

0 commit comments

Comments
 (0)