mirror of
https://github.com/torvalds/linux.git
synced 2026-11-26 16:33:17 +00:00
mm/mmu_notifier: init notifier if necessary
While registering MMU notifier, new instance of MMU notifier_mm will be allocated and later free'd if currrent mm_struct's MMU notifier_mm has been initialized. That causes some overhead. The patch tries to elominate that. Signed-off-by: Gavin Shan <[email protected]> Signed-off-by: Wanpeng Li <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Avi Kivity <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Marcelo Tosatti <[email protected]> Cc: Xiao Guangrong <[email protected]> Cc: Sagi Grimberg <[email protected]> Cc: Haggai Eran <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
committed by
Linus Torvalds
parent
21a92735f6
commit
e0f3c3f78d
+11
-11
@@ -207,22 +207,23 @@ static int do_mmu_notifier_register(struct mmu_notifier *mn,
|
||||
*/
|
||||
BUG_ON(!srcu.per_cpu_ref);
|
||||
|
||||
ret = -ENOMEM;
|
||||
mmu_notifier_mm = kmalloc(sizeof(struct mmu_notifier_mm), GFP_KERNEL);
|
||||
if (unlikely(!mmu_notifier_mm))
|
||||
goto out;
|
||||
|
||||
if (take_mmap_sem)
|
||||
down_write(&mm->mmap_sem);
|
||||
ret = mm_take_all_locks(mm);
|
||||
if (unlikely(ret))
|
||||
goto out_cleanup;
|
||||
goto out;
|
||||
|
||||
if (!mm_has_notifiers(mm)) {
|
||||
mmu_notifier_mm = kmalloc(sizeof(struct mmu_notifier_mm),
|
||||
GFP_KERNEL);
|
||||
if (unlikely(!mmu_notifier_mm)) {
|
||||
ret = -ENOMEM;
|
||||
goto out_of_mem;
|
||||
}
|
||||
INIT_HLIST_HEAD(&mmu_notifier_mm->list);
|
||||
spin_lock_init(&mmu_notifier_mm->lock);
|
||||
|
||||
mm->mmu_notifier_mm = mmu_notifier_mm;
|
||||
mmu_notifier_mm = NULL;
|
||||
}
|
||||
atomic_inc(&mm->mm_count);
|
||||
|
||||
@@ -238,13 +239,12 @@ static int do_mmu_notifier_register(struct mmu_notifier *mn,
|
||||
hlist_add_head(&mn->hlist, &mm->mmu_notifier_mm->list);
|
||||
spin_unlock(&mm->mmu_notifier_mm->lock);
|
||||
|
||||
out_of_mem:
|
||||
mm_drop_all_locks(mm);
|
||||
out_cleanup:
|
||||
out:
|
||||
if (take_mmap_sem)
|
||||
up_write(&mm->mmap_sem);
|
||||
/* kfree() does nothing if mmu_notifier_mm is NULL */
|
||||
kfree(mmu_notifier_mm);
|
||||
out:
|
||||
|
||||
BUG_ON(atomic_read(&mm->mm_users) <= 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user