Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 207279
b: refs/heads/master
c: d9f8984
h: refs/heads/master
i:
  207277: f687e69
  207275: fe83c7e
  207271: 5d8e89e
  207263: c27daef
v: v3
  • Loading branch information
Lai Jiangshan authored and Linus Torvalds committed Aug 10, 2010
1 parent 7cd7f77 commit 5339eaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: e31f3698cd3499e676f6b0ea12e3528f569c4fa3
refs/heads/master: d9f8984c2c23b91e202a764fe4b15041a29a201a
38 changes: 9 additions & 29 deletions trunk/mm/ksm.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/mmu_notifier.h>
#include <linux/swap.h>
#include <linux/ksm.h>
#include <linux/hash.h>

#include <asm/tlbflush.h>
#include "internal.h"
Expand Down Expand Up @@ -153,8 +154,9 @@ struct rmap_item {
static struct rb_root root_stable_tree = RB_ROOT;
static struct rb_root root_unstable_tree = RB_ROOT;

#define MM_SLOTS_HASH_HEADS 1024
static struct hlist_head *mm_slots_hash;
#define MM_SLOTS_HASH_SHIFT 10
#define MM_SLOTS_HASH_HEADS (1 << MM_SLOTS_HASH_SHIFT)
static struct hlist_head mm_slots_hash[MM_SLOTS_HASH_HEADS];

static struct mm_slot ksm_mm_head = {
.mm_list = LIST_HEAD_INIT(ksm_mm_head.mm_list),
Expand Down Expand Up @@ -269,28 +271,13 @@ static inline void free_mm_slot(struct mm_slot *mm_slot)
kmem_cache_free(mm_slot_cache, mm_slot);
}

static int __init mm_slots_hash_init(void)
{
mm_slots_hash = kzalloc(MM_SLOTS_HASH_HEADS * sizeof(struct hlist_head),
GFP_KERNEL);
if (!mm_slots_hash)
return -ENOMEM;
return 0;
}

static void __init mm_slots_hash_free(void)
{
kfree(mm_slots_hash);
}

static struct mm_slot *get_mm_slot(struct mm_struct *mm)
{
struct mm_slot *mm_slot;
struct hlist_head *bucket;
struct hlist_node *node;

bucket = &mm_slots_hash[((unsigned long)mm / sizeof(struct mm_struct))
% MM_SLOTS_HASH_HEADS];
bucket = &mm_slots_hash[hash_ptr(mm, MM_SLOTS_HASH_SHIFT)];
hlist_for_each_entry(mm_slot, node, bucket, link) {
if (mm == mm_slot->mm)
return mm_slot;
Expand All @@ -303,8 +290,7 @@ static void insert_to_mm_slots_hash(struct mm_struct *mm,
{
struct hlist_head *bucket;

bucket = &mm_slots_hash[((unsigned long)mm / sizeof(struct mm_struct))
% MM_SLOTS_HASH_HEADS];
bucket = &mm_slots_hash[hash_ptr(mm, MM_SLOTS_HASH_SHIFT)];
mm_slot->mm = mm;
hlist_add_head(&mm_slot->link, bucket);
}
Expand Down Expand Up @@ -1938,23 +1924,19 @@ static int __init ksm_init(void)
if (err)
goto out;

err = mm_slots_hash_init();
if (err)
goto out_free1;

ksm_thread = kthread_run(ksm_scan_thread, NULL, "ksmd");
if (IS_ERR(ksm_thread)) {
printk(KERN_ERR "ksm: creating kthread failed\n");
err = PTR_ERR(ksm_thread);
goto out_free2;
goto out_free;
}

#ifdef CONFIG_SYSFS
err = sysfs_create_group(mm_kobj, &ksm_attr_group);
if (err) {
printk(KERN_ERR "ksm: register sysfs failed\n");
kthread_stop(ksm_thread);
goto out_free2;
goto out_free;
}
#else
ksm_run = KSM_RUN_MERGE; /* no way for user to start it */
Expand All @@ -1970,9 +1952,7 @@ static int __init ksm_init(void)
#endif
return 0;

out_free2:
mm_slots_hash_free();
out_free1:
out_free:
ksm_slab_free();
out:
return err;
Expand Down

0 comments on commit 5339eaa

Please sign in to comment.