mm: add new mmgrab() helper
Subsystems (34)
PATCH 1/4 mm: add new mmgrab() helper
Apart from adding the helper function itself, the rest of the kernel is converted mechanically using:
git grep -l 'atomic_inc.*mm_count' | xargs sed -i 's/atomic_inc(&\(.*\)->mm_count);/mmgrab\(\1\);/' git grep -l 'atomic_inc.*mm_count' | xargs sed -i 's/atomic_inc(&\(.*\)\.mm_count);/mmgrab\(\&\1\);/'
This is needed for a later patch that hooks into the helper, but might be a worthwhile cleanup on its own.
(Michal Hocko provided most of the kerneldoc comment.)
--- arch/alpha/kernel/smp.c | 2 +- arch/arc/kernel/smp.c | 2 +- arch/arm/kernel/smp.c | 2 +- arch/arm64/kernel/smp.c | 2 +- arch/blackfin/mach-common/smp.c | 2 +- arch/hexagon/kernel/smp.c | 2 +- arch/ia64/kernel/setup.c | 2 +- arch/m32r/kernel/setup.c | 2 +- arch/metag/kernel/smp.c | 2 +- arch/mips/kernel/traps.c | 2 +- arch/mn10300/kernel/smp.c | 2 +- arch/parisc/kernel/smp.c | 2 +- arch/powerpc/kernel/smp.c | 2 +- arch/s390/kernel/processor.c | 2 +- arch/score/kernel/traps.c | 2 +- arch/sh/kernel/smp.c | 2 +- arch/sparc/kernel/leon_smp.c | 2 +- arch/sparc/kernel/smp_64.c | 2 +- arch/sparc/kernel/sun4d_smp.c | 2 +- arch/sparc/kernel/sun4m_smp.c | 2 +- arch/sparc/kernel/traps_32.c | 2 +- arch/sparc/kernel/traps_64.c | 2 +- arch/tile/kernel/smpboot.c | 2 +- arch/x86/kernel/cpu/common.c | 4 ++-- arch/xtensa/kernel/smp.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +- drivers/gpu/drm/i915/i915_gem_userptr.c | 2 +- drivers/infiniband/hw/hfi1/file_ops.c | 2 +- fs/proc/base.c | 4 ++-- fs/userfaultfd.c | 2 +- include/linux/sched.h | 22 ++++++++++++++++++++++ kernel/exit.c | 2 +- kernel/futex.c | 2 +- kernel/sched/core.c | 4 ++-- mm/khugepaged.c | 2 +- mm/ksm.c | 2 +- mm/mmu_context.c | 2 +- mm/mmu_notifier.c | 2 +- mm/oom_kill.c | 4 ++-- virt/kvm/kvm_main.c | 2 +- 40 files changed, 65 insertions(+), 43 deletions(-)
arch/alpha/kernel/smp.c +1 -1
@@ -144,7 +144,7 @@ smp_callin(void) alpha_mv.smp_callin ();/* All kernel threads share the same mm context. */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;/* inform the notifiers about the new cpu */
arch/arc/kernel/smp.c +1 -1
@@ -125,7 +125,7 @@ void start_kernel_secondary(void)setup_processor ();atomic_inc (&mm->mm_users); -atomic_inc (&mm->mm_count); +mmgrab (mm); current->active_mm = mm;cpumask_set_cpu (cpu,mm_cpumask (mm));
arch/arm/kernel/smp.c +1 -1
@@ -371,7 +371,7 @@ asmlinkage void secondary_start_kernel(void)* reference and switch to it. */ cpu =smp_processor_id (); -atomic_inc (&mm->mm_count); +mmgrab (mm); current->active_mm = mm;cpumask_set_cpu (cpu,mm_cpumask (mm));
arch/arm64/kernel/smp.c +1 -1
@@ -222,7 +222,7 @@ asmlinkage void secondary_start_kernel(void)* All kernel threads share the same mm context; grab a * reference and switch to it. */ -atomic_inc (&mm->mm_count); +mmgrab (mm); current->active_mm = mm;/*
arch/blackfin/mach-common/smp.c +1 -1
@@ -308,7 +308,7 @@ void secondary_start_kernel(void)/* Attach the new idle task to the global mm. */ atomic_inc (&mm->mm_users); -atomic_inc (&mm->mm_count); +mmgrab (mm); current->active_mm = mm;preempt_disable ();
arch/hexagon/kernel/smp.c +1 -1
@@ -162,7 +162,7 @@ void start_secondary(void) );/* Set the memory struct */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm; cpu =smp_processor_id ();
arch/ia64/kernel/setup.c +1 -1
@@ -992,7 +992,7 @@ cpu_init (void)*/ ia64_setreg (_IA64_REG_CR_DCR, (IA64_DCR_DP |IA64_DCR_DK |IA64_DCR_DX |IA64_DCR_DR |IA64_DCR_DA |IA64_DCR_DD |IA64_DCR_LC )); -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;BUG_ON (current->mm);
arch/m32r/kernel/setup.c +1 -1
@@ -403,7 +403,7 @@ void __init cpu_init (void)printk (KERN_INFO "Initializing CPU#%d\n" , cpu_id);/* Set up and load the per-CPU TSS and LDT */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;if (current->mm)BUG ();
arch/metag/kernel/smp.c +1 -1
@@ -345,7 +345,7 @@ asmlinkage void secondary_start_kernel(void)* reference and switch to it. */ atomic_inc (&mm->mm_users); -atomic_inc (&mm->mm_count); +mmgrab (mm); current->active_mm = mm;cpumask_set_cpu (cpu,mm_cpumask (mm));enter_lazy_tlb (mm, current);
arch/mips/kernel/traps.c +1 -1
@@ -2177,7 +2177,7 @@ void per_cpu_trap_init(bool is_boot_cpu)if (!cpu_data[cpu].asid_cache) cpu_data[cpu].asid_cache =asid_first_version (cpu); -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;BUG_ON (current->mm);enter_lazy_tlb (&init_mm, current);
arch/mn10300/kernel/smp.c +1 -1
@@ -589,7 +589,7 @@ static void __init smp_cpu_init(void) }printk (KERN_INFO "Initializing CPU#%d\n" , cpu_id); -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;BUG_ON (current->mm);
arch/parisc/kernel/smp.c +1 -1
@@ -279,7 +279,7 @@ smp_cpu_init(int cpunum)set_cpu_online (cpunum, true);/* Initialise the idle task for this CPU */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;BUG_ON (current->mm);enter_lazy_tlb (&init_mm, current);
arch/powerpc/kernel/smp.c +1 -1
@@ -707,7 +707,7 @@ void start_secondary(void *unused)unsigned int cpu =smp_processor_id ();int i, base; -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;smp_store_cpu_info (cpu);
arch/s390/kernel/processor.c +1 -1
@@ -73,7 +73,7 @@ void cpu_init(void)get_cpu_id (id);if (machine_has_cpu_mhz)update_cpu_mhz (NULL ); -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;BUG_ON (current->mm);enter_lazy_tlb (&init_mm, current);
arch/score/kernel/traps.c +1 -1
@@ -336,7 +336,7 @@ void __init trap_init(void)set_except_vector (18 , handle_dbe);flush_icache_range (DEBUG_VECTOR_BASE_ADDR ,IRQ_VECTOR_BASE_ADDR ); -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;cpu_cache_init (); }
arch/sh/kernel/smp.c +1 -1
@@ -178,7 +178,7 @@ asmlinkage void start_secondary(void)struct mm_struct *mm = &init_mm;enable_mmu (); -atomic_inc (&mm->mm_count); +mmgrab (mm);atomic_inc (&mm->mm_users); current->active_mm = mm;#ifdef CONFIG_MMU
arch/sparc/kernel/leon_smp.c +1 -1
@@ -93,7 +93,7 @@ void leon_cpu_pre_online(void *arg) : "memory" /* paranoid */);/* Attach to the address space of init_task. */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;while (!cpumask_test_cpu (cpuid, &smp_commenced_mask))
arch/sparc/kernel/smp_64.c +1 -1
@@ -122,7 +122,7 @@ void smp_callin(void)current_thread_info ()->new_child =0 ;/* Attach to the address space of init_task. */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;/* inform the notifiers about the new cpu */
arch/sparc/kernel/sun4d_smp.c +1 -1
@@ -93,7 +93,7 @@ void sun4d_cpu_pre_online(void *arg)show_leds (cpuid);/* Attach to the address space of init_task. */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm; local_ops->cache_all ();
arch/sparc/kernel/sun4m_smp.c +1 -1
@@ -59,7 +59,7 @@ void sun4m_cpu_pre_online(void *arg) : "memory" /* paranoid */);/* Attach to the address space of init_task. */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;while (!cpumask_test_cpu (cpuid, &smp_commenced_mask))
arch/sparc/kernel/traps_32.c +1 -1
@@ -448,7 +448,7 @@ void trap_init(void)thread_info_offsets_are_bolixed_pete ();/* Attach to the address space of init_task. */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;/* NOTE: Other cpus have this done as they are started
arch/sparc/kernel/traps_64.c +1 -1
@@ -2764,6 +2764,6 @@ void __init trap_init(void)/* Attach to the address space of init_task. On SMP we * do this in smp.c:smp_callin for other cpus. */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm; }
arch/tile/kernel/smpboot.c +1 -1
@@ -160,7 +160,7 @@ static void start_secondary(void)__this_cpu_write (current_asid, min_asid);/* Set up this thread as another owner of the init_mm */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); current->active_mm = &init_mm;if (current->mm)BUG ();
arch/x86/kernel/cpu/common.c +2 -2
@@ -1498,7 +1498,7 @@ void cpu_init(void)for (i =0 ; i <=IO_BITMAP_LONGS ; i++) t->io_bitmap[i] = ~0UL ; -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); me->active_mm = &init_mm;BUG_ON (me->mm);enter_lazy_tlb (&init_mm, me);
@@ -1549,7 +1549,7 @@ void cpu_init(void)/* * Set up and load the per-CPU TSS and LDT */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm); curr->active_mm = &init_mm;BUG_ON (curr->mm);enter_lazy_tlb (&init_mm, curr);
arch/xtensa/kernel/smp.c +1 -1
@@ -136,7 +136,7 @@ void secondary_start_kernel(void)/* All kernel threads share the same mm context. */ atomic_inc (&mm->mm_users); -atomic_inc (&mm->mm_count); +mmgrab (mm); current->active_mm = mm;cpumask_set_cpu (cpu,mm_cpumask (mm));enter_lazy_tlb (mm, current);
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -1
@@ -262,7 +262,7 @@ static void kfd_process_notifier_release(struct mmu_notifier *mn,* and because the mmu_notifier_unregister function also drop * mm_count we need to take an extra count here. */ -atomic_inc (&p->mm->mm_count); +mmgrab (p->mm);mmu_notifier_unregister_no_release (&p->mmu_notifier, p->mm);mmu_notifier_call_srcu (&p->rcu, &kfd_process_destroy_delayed); }
drivers/gpu/drm/i915/i915_gem_userptr.c +1 -1
@@ -334,7 +334,7 @@ i915_gem_userptr_init__mm_struct(struct drm_i915_gem_object *obj) mm->i915 =to_i915 (obj->base.dev); mm->mm = current->mm; -atomic_inc (¤t->mm->mm_count); +mmgrab (current->mm); mm->mn =NULL ;
drivers/infiniband/hw/hfi1/file_ops.c +1 -1
@@ -185,7 +185,7 @@ static int hfi1_file_open(struct inode *inode, struct file *fp)if (fd) { fd->rec_cpu_num =-1 ;/* no cpu affinity by default */ fd->mm = current->mm; -atomic_inc (&fd->mm->mm_count); +mmgrab (fd->mm); fp->private_data = fd; }else { fp->private_data =NULL ;
fs/proc/base.c +2 -2
@@ -798,7 +798,7 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)if (!IS_ERR_OR_NULL (mm)) {/* ensure this mm_struct can't be freed */ -atomic_inc (&mm->mm_count); +mmgrab (mm);/* but do not pin its memory */ mmput (mm); }
@@ -1096,7 +1096,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)if (p) {if (atomic_read (&p->mm->mm_users) >1 ) { mm = p->mm; -atomic_inc (&mm->mm_count); +mmgrab (mm); }task_unlock (p); }
fs/userfaultfd.c +1 -1
@@ -1306,7 +1306,7 @@ static struct file *userfaultfd_file_create(int flags) ctx->released = false; ctx->mm = current->mm;/* prevent the mm struct to be freed */ -atomic_inc (&ctx->mm->mm_count); +mmgrab (ctx->mm); file =anon_inode_getfile ("[userfaultfd]" , &userfaultfd_fops, ctx,O_RDWR | (flags &UFFD_SHARED_FCNTL_FLAGS ));
include/linux/sched.h +22 -0
@@ -2911,6 +2911,28 @@ static inline unsigned long sigsp(unsigned long sp, struct ksignal *ksig)*/ extern struct mm_struct *mm_alloc (void ); +/** +* mmgrab() - Pin a &struct mm_struct. +* @mm: The &struct mm_struct to pin. +* +* Make sure that @mm will not get freed even after the owning task +* exits. This doesn't guarantee that the associated address space +* will still exist later on and mmget_not_zero() has to be used before +* accessing it. +* +* This is a preferred way to to pin @mm for a longer/unbounded amount +* of time. +* +* Use mmdrop() to release the reference acquired by mmgrab(). +* +* See also <Documentation/vm/active_mm.txt> for an in-depth explanation +* of &mm_struct.mm_count vs &mm_struct.mm_users. +*/ +static inline void mmgrab (struct mm_struct *mm) +{ +atomic_inc (&mm->mm_count); +} +/* mmdrop drops the mm and the page tables */ extern void __mmdrop (struct mm_struct *);static inline void mmdrop (struct mm_struct *mm)
kernel/exit.c +1 -1
@@ -509,7 +509,7 @@ static void exit_mm(struct task_struct *tsk)__set_task_state (tsk,TASK_RUNNING );down_read (&mm->mmap_sem); } -atomic_inc (&mm->mm_count); +mmgrab (mm);BUG_ON (mm != tsk->active_mm);/* more a memory barrier than a real lock */ task_lock (tsk);
kernel/futex.c +1 -1
@@ -338,7 +338,7 @@ static inline bool should_fail_futex(bool fshared)static inline void futex_get_mm (union futex_key *key) { -atomic_inc (&key->private.mm->mm_count); +mmgrab (key->private.mm);/* * Ensure futex_get_mm() implies a full barrier such that * get_futex_key() implies a full barrier. This is relied upon
kernel/sched/core.c +2 -2
@@ -2878,7 +2878,7 @@ context_switch(struct rq *rq, struct task_struct *prev,if (!mm) { next->active_mm = oldmm; -atomic_inc (&oldmm->mm_count); +mmgrab (oldmm);enter_lazy_tlb (oldmm, next); }else switch_mm_irqs_off (oldmm, mm, next);
@@ -7686,7 +7686,7 @@ void __init sched_init(void)/* * The boot idle thread does lazy MMU switching as well: */ -atomic_inc (&init_mm.mm_count); +mmgrab (&init_mm);enter_lazy_tlb (&init_mm, current);/*
mm/khugepaged.c +1 -1
@@ -420,7 +420,7 @@ int __khugepaged_enter(struct mm_struct *mm)list_add_tail (&mm_slot->mm_node, &khugepaged_scan.mm_head);spin_unlock (&khugepaged_mm_lock); -atomic_inc (&mm->mm_count); +mmgrab (mm);if (wakeup)wake_up_interruptible (&khugepaged_wait);
mm/ksm.c +1 -1
@@ -1813,7 +1813,7 @@ int __ksm_enter(struct mm_struct *mm)spin_unlock (&ksm_mmlist_lock);set_bit (MMF_VM_MERGEABLE , &mm->flags); -atomic_inc (&mm->mm_count); +mmgrab (mm);if (needs_wakeup)wake_up_interruptible (&ksm_thread_wait);
mm/mmu_context.c +1 -1
@@ -25,7 +25,7 @@ void use_mm(struct mm_struct *mm)task_lock (tsk); active_mm = tsk->active_mm;if (active_mm != mm) { -atomic_inc (&mm->mm_count); +mmgrab (mm); tsk->active_mm = mm; } tsk->mm = mm;
mm/mmu_notifier.c +1 -1
@@ -275,7 +275,7 @@ static int do_mmu_notifier_register(struct mmu_notifier *mn, mm->mmu_notifier_mm = mmu_notifier_mm; mmu_notifier_mm =NULL ; } -atomic_inc (&mm->mm_count); +mmgrab (mm);/* * Serialize the update against mmu_notifier_unregister. A
mm/oom_kill.c +2 -2
@@ -660,7 +660,7 @@ static void mark_oom_victim(struct task_struct *tsk)/* oom_mm is bound to the signal struct life time. */ if (!cmpxchg (&tsk->signal->oom_mm,NULL , mm)) -atomic_inc (&tsk->signal->oom_mm->mm_count); +mmgrab (tsk->signal->oom_mm);/* * Make sure that the task is woken up from uninterruptible sleep
@@ -877,7 +877,7 @@ static void oom_kill_process(struct oom_control *oc, const char *message)/* Get a reference to safely compare mm after task_unlock(victim) */ mm = victim->mm; -atomic_inc (&mm->mm_count); +mmgrab (mm);/* * We should send SIGKILL before setting TIF_MEMDIE in order to prevent * the OOM victim from depleting the memory reserves from the user
virt/kvm/kvm_main.c +1 -1
@@ -616,7 +616,7 @@ static struct kvm *kvm_create_vm(unsigned long type)return ERR_PTR (-ENOMEM );spin_lock_init (&kvm->mmu_lock); -atomic_inc (¤t->mm->mm_count); +mmgrab (current->mm); kvm->mm = current->mm;kvm_eventfd_init (kvm);mutex_init (&kvm->lock);
Signature · 7 lines
2.11.0.1.gaa10c3f -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/4 mm: add new mmget() helper
Apart from adding the helper function itself, the rest of the kernel is converted mechanically using:
git grep -l 'atomic_inc.*mm_users' | xargs sed -i 's/atomic_inc(&\(.*\)->mm_users);/mmget\(\1\);/' git grep -l 'atomic_inc.*mm_users' | xargs sed -i 's/atomic_inc(&\(.*\)\.mm_users);/mmget\(\&\1\);/'
This is needed for a later patch that hooks into the helper, but might be a worthwhile cleanup on its own.
(Michal Hocko provided most of the kerneldoc comment.)
--- arch/arc/kernel/smp.c | 2 +- arch/blackfin/mach-common/smp.c | 2 +- arch/frv/mm/mmu-context.c | 2 +- arch/metag/kernel/smp.c | 2 +- arch/sh/kernel/smp.c | 2 +- arch/xtensa/kernel/smp.c | 2 +- include/linux/sched.h | 21 +++++++++++++++++++++ kernel/fork.c | 4 ++-- mm/swapfile.c | 10 +++++----- virt/kvm/async_pf.c | 2 +- 10 files changed, 35 insertions(+), 14 deletions(-)
arch/arc/kernel/smp.c +1 -1
@@ -124,7 +124,7 @@ void start_kernel_secondary(void)/* MMU, Caches, Vector Table, Interrupts etc */ setup_processor (); -atomic_inc (&mm->mm_users); +mmget (mm);mmgrab (mm); current->active_mm = mm;cpumask_set_cpu (cpu,mm_cpumask (mm));
arch/blackfin/mach-common/smp.c +1 -1
@@ -307,7 +307,7 @@ void secondary_start_kernel(void)local_irq_disable ();/* Attach the new idle task to the global mm. */ -atomic_inc (&mm->mm_users); +mmget (mm);mmgrab (mm); current->active_mm = mm;
arch/frv/mm/mmu-context.c +1 -1
@@ -188,7 +188,7 @@ int cxn_pin_by_pid(pid_t pid)task_lock (tsk);if (tsk->mm) { mm = tsk->mm; -atomic_inc (&mm->mm_users); +mmget (mm); ret =0 ; }task_unlock (tsk);
arch/metag/kernel/smp.c +1 -1
@@ -344,7 +344,7 @@ asmlinkage void secondary_start_kernel(void)* All kernel threads share the same mm context; grab a * reference and switch to it. */ -atomic_inc (&mm->mm_users); +mmget (mm);mmgrab (mm); current->active_mm = mm;cpumask_set_cpu (cpu,mm_cpumask (mm));
arch/sh/kernel/smp.c +1 -1
@@ -179,7 +179,7 @@ asmlinkage void start_secondary(void)enable_mmu ();mmgrab (mm); -atomic_inc (&mm->mm_users); +mmget (mm); current->active_mm = mm;#ifdef CONFIG_MMU enter_lazy_tlb (mm, current);
arch/xtensa/kernel/smp.c +1 -1
@@ -135,7 +135,7 @@ void secondary_start_kernel(void)/* All kernel threads share the same mm context. */ -atomic_inc (&mm->mm_users); +mmget (mm);mmgrab (mm); current->active_mm = mm;cpumask_set_cpu (cpu,mm_cpumask (mm));
include/linux/sched.h +21 -0
@@ -2955,6 +2955,27 @@ static inline void mmdrop_async(struct mm_struct *mm) } } +/** +* mmget() - Pin the address space associated with a &struct mm_struct. +* @mm: The address space to pin. +* +* Make sure that the address space of the given &struct mm_struct doesn't +* go away. This does not protect against parts of the address space being +* modified or freed, however. +* +* Never use this function to pin this address space for an +* unbounded/indefinite amount of time. +* +* Use mmput() to release the reference acquired by mmget(). +* +* See also <Documentation/vm/active_mm.txt> for an in-depth explanation +* of &mm_struct.mm_count vs &mm_struct.mm_users. +*/ +static inline void mmget (struct mm_struct *mm) +{ +atomic_inc (&mm->mm_users); +} +static inline bool mmget_not_zero (struct mm_struct *mm) {return atomic_inc_not_zero (&mm->mm_users);
kernel/fork.c +2 -2
@@ -994,7 +994,7 @@ struct mm_struct *get_task_mm(struct task_struct *task)if (task->flags &PF_KTHREAD ) mm =NULL ;else -atomic_inc (&mm->mm_users); +mmget (mm); }task_unlock (task);return mm;
@@ -1182,7 +1182,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)vmacache_flush (tsk);if (clone_flags &CLONE_VM ) { -atomic_inc (&oldmm->mm_users); +mmget (oldmm); mm = oldmm; goto good_mm; }
mm/swapfile.c +5 -5
@@ -1401,7 +1401,7 @@ int try_to_unuse(unsigned int type, bool frontswap,* that. */ start_mm = &init_mm; -atomic_inc (&init_mm.mm_users); +mmget (&init_mm);/* * Keep on scanning until all entries have gone. Usually,
@@ -1450,7 +1450,7 @@ int try_to_unuse(unsigned int type, bool frontswap,if (atomic_read (&start_mm->mm_users) ==1 ) {mmput (start_mm); start_mm = &init_mm; -atomic_inc (&init_mm.mm_users); +mmget (&init_mm); }/*
@@ -1487,8 +1487,8 @@ int try_to_unuse(unsigned int type, bool frontswap,struct mm_struct *prev_mm = start_mm;struct mm_struct *mm; -atomic_inc (&new_start_mm->mm_users); -atomic_inc (&prev_mm->mm_users); +mmget (new_start_mm); +mmget (prev_mm);spin_lock (&mmlist_lock);while (swap_count (*swap_map) && !retval && (p = p->next) != &start_mm->mmlist) {
@@ -1511,7 +1511,7 @@ int try_to_unuse(unsigned int type, bool frontswap,if (set_start_mm && *swap_map < swcount) {mmput (new_start_mm); -atomic_inc (&mm->mm_users); +mmget (mm); new_start_mm = mm; set_start_mm =0 ; }
virt/kvm/async_pf.c +1 -1
@@ -204,7 +204,7 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva, work->addr = hva; work->arch = *arch; work->mm = current->mm; -atomic_inc (&work->mm->mm_users); +mmget (work->mm);kvm_get_kvm (work->vcpu->kvm);/* this can't really happen otherwise gfn_to_pfn_async
Signature · 7 lines
2.11.0.1.gaa10c3f -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerRe: [PATCH 2/4] mm: add new mmget() helper
Quoted 11 lines · On Sun, 18 Dec 2016 13:32:27 +0100 Vegard Nossum <[email protected]>…
Apart from adding the helper function itself, the rest of the kernel is converted mechanically using:
git grep -l 'atomic_inc.*mm_users' | xargs sed -i 's/atomic_inc(&\(.*\)->mm_users);/mmget\(\1\);/' git grep -l 'atomic_inc.*mm_users' | xargs sed -i 's/atomic_inc(&\(.*\)\.mm_users);/mmget\(\&\1\);/'
This is needed for a later patch that hooks into the helper, but might be a worthwhile cleanup on its own.
...
mmgrap() and mmget() naming is really quite confusing.
arch/arc/kernel/smp.c void start_kernel_secondary(void) · line 127
Quoted 8 lines
arch/arc/kernel/smp.c +1
-1@@ -124,7 +124,7 @@ void start_kernel_secondary(void)/* MMU, Caches, Vector Table, Interrupts etc */ setup_processor (); -atomic_inc (&mm->mm_users); +mmget (mm);
I wonder if mmuse() would be a bit clearer than mmget(). Although that sounds like use_mm().
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/4 mm: use mmget_not_zero() helper
In reply to Vegard NossumWe already have the helper, we can convert the rest of the kernel mechanically using:
git grep -l 'atomic_inc_not_zero.*mm_users' | xargs sed -i 's/atomic_inc_not_zero(&\(.*\)->mm_users)/mmget_not_zero\(\1\)/'
This is needed for a later patch that hooks into the helper, but might be a worthwhile cleanup on its own.
--- drivers/gpu/drm/i915/i915_gem_userptr.c | 2 +- drivers/iommu/intel-svm.c | 2 +- fs/proc/base.c | 4 ++-- fs/proc/task_mmu.c | 4 ++-- fs/proc/task_nommu.c | 2 +- kernel/events/uprobes.c | 2 +- mm/swapfile.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_gem_userptr.c +1 -1
@@ -507,7 +507,7 @@ __i915_gem_userptr_get_pages_worker(struct work_struct *_work) flags |=FOLL_WRITE ; ret = -EFAULT ; -if (atomic_inc_not_zero (&mm->mm_users)) { +if (mmget_not_zero (mm)) {down_read (&mm->mmap_sem);while (pinned < npages) { ret = get_user_pages_remote
drivers/iommu/intel-svm.c +1 -1
@@ -579,7 +579,7 @@ static irqreturn_t prq_event_thread(int irq, void *d)if (!svm->mm) goto bad_req;/* If the mm is already defunct, don't handle faults. */ -if (!atomic_inc_not_zero (&svm->mm->mm_users)) +if (!mmget_not_zero (svm->mm)) goto bad_req;down_read (&svm->mm->mmap_sem); vma =find_extend_vma (svm->mm, address);
fs/proc/base.c +2 -2
@@ -845,7 +845,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,return -ENOMEM ; copied =0 ; -if (!atomic_inc_not_zero (&mm->mm_users)) +if (!mmget_not_zero (mm)) goto free;/* Maybe we should limit FOLL_FORCE to actual ptrace users? */
@@ -953,7 +953,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,return -ENOMEM ; ret =0 ; -if (!atomic_inc_not_zero (&mm->mm_users)) +if (!mmget_not_zero (mm)) goto free;down_read (&mm->mmap_sem);
fs/proc/task_mmu.c +2 -2
@@ -167,7 +167,7 @@ static void *m_start(struct seq_file *m, loff_t *ppos)return ERR_PTR (-ESRCH ); mm = priv->mm; -if (!mm || !atomic_inc_not_zero (&mm->mm_users)) +if (!mm || !mmget_not_zero (mm))return NULL ;down_read (&mm->mmap_sem);
@@ -1352,7 +1352,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,unsigned long end_vaddr;int ret =0 , copied =0 ; -if (!mm || !atomic_inc_not_zero (&mm->mm_users)) +if (!mm || !mmget_not_zero (mm)) goto out; ret = -EINVAL ;
fs/proc/task_nommu.c +1 -1
@@ -219,7 +219,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)return ERR_PTR (-ESRCH ); mm = priv->mm; -if (!mm || !atomic_inc_not_zero (&mm->mm_users)) +if (!mm || !mmget_not_zero (mm))return NULL ;down_read (&mm->mmap_sem);
kernel/events/uprobes.c +1 -1
@@ -741,7 +741,7 @@ build_map_info(struct address_space *mapping, loff_t offset, bool is_register)continue ; } -if (!atomic_inc_not_zero (&vma->vm_mm->mm_users)) +if (!mmget_not_zero (vma->vm_mm))continue ; info = prev;
mm/swapfile.c +1 -1
@@ -1493,7 +1493,7 @@ int try_to_unuse(unsigned int type, bool frontswap,while (swap_count (*swap_map) && !retval && (p = p->next) != &start_mm->mmlist) { mm = list_entry(p, struct mm_struct, mmlist); -if (!atomic_inc_not_zero (&mm->mm_users)) +if (!mmget_not_zero (mm))continue ;spin_unlock (&mmlist_lock);mmput (prev_mm);
Signature · 7 lines
2.11.0.1.gaa10c3f -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/4 mm: clarify mm_struct.mm_{users,count} documentation
In reply to Vegard NossumClarify documentation relating to mm_users and mm_count, and switch to kernel-doc syntax.
--- include/linux/mm_types.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
include/linux/mm_types.h +21 -2
@@ -407,8 +407,27 @@ struct mm_struct {unsigned long task_size;/* size of task vm space */ unsigned long highest_vm_end;/* highest vma end address */ pgd_t * pgd; -atomic_t mm_users;/* How many users with user space? */ -atomic_t mm_count;/* How many references to "struct mm_struct" (users count as 1) */ + +/** +* @mm_users: The number of users including userspace. +* +* Use mmget()/mmget_not_zero()/mmput() to modify. When this drops +* to 0 (i.e. when the task exits and there are no other temporary +* reference holders), we also release a reference on @mm_count +* (which may then free the &struct mm_struct if @mm_count also +* drops to 0). +*/ +atomic_t mm_users; + +/** +* @mm_count: The number of references to &struct mm_struct +* (@mm_users count as 1). +* +* Use mmgrab()/mmdrop() to modify. When this drops to 0, the +* &struct mm_struct is freed. +*/ +atomic_t mm_count; +atomic_long_t nr_ptes;/* PTE page table pages */ #if CONFIG_PGTABLE_LEVELS >2 atomic_long_t nr_pmds;/* PMD page table pages */
Signature · 7 lines
2.11.0.1.gaa10c3f -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 4/4] mm: clarify mm_struct.mm_{users,count} documentation
Quoted 2 lines · Vegard Nossum
Clarify documentation relating to
mm_usersandmm_count, and switch to kernel-doc syntax.
Looks good to me.
Quoted 1 line
Signed-off-by Vegard Nossum <[email protected]>
Quoted 41 lines
--- include/linux/mm_types.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)include/linux/mm_types.h +21
-2@@ -407,8 +407,27 @@ struct mm_struct {unsigned long task_size;/* size of task vm space */ unsigned long highest_vm_end;/* highest vma end address */ pgd_t * pgd; -atomic_t mm_users;/* How many users with user space? */ -atomic_t mm_count;/* How many references to "struct mm_struct" (users count as 1) */ + +/** +* @mm_users: The number of users including userspace. +* +* Use mmget()/mmget_not_zero()/mmput() to modify. When this drops +* to 0 (i.e. when the task exits and there are no other temporary +* reference holders), we also release a reference on @mm_count +* (which may then free the &struct mm_struct if @mm_count also +* drops to 0). +*/ +atomic_t mm_users; + +/** +* @mm_count: The number of references to &struct mm_struct +* (@mm_users count as 1). +* +* Use mmgrab()/mmdrop() to modify. When this drops to 0, the +* &struct mm_struct is freed. +*/ +atomic_t mm_count; +atomic_long_t nr_ptes;/* PTE page table pages */ #if CONFIG_PGTABLE_LEVELS >2 atomic_long_t nr_pmds;/* PMD page table pages */ Signature · 1 line
2.11.0.1.gaa10c3f
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
For all 4,
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Vegard Nossum
Apart from adding the helper function itself, the rest of the kernel is converted mechanically using:
git grep -l 'atomic_inc.*mm_count' | xargs sed -i 's/atomic_inc(&\(.*\)->mm_count);/mmgrab\(\1\);/' git grep -l 'atomic_inc.*mm_count' | xargs sed -i 's/atomic_inc(&\(.*\)\.mm_count);/mmgrab\(\&\1\);/'
Quoted 8 lines
This is needed for a later patch that hooks into the helper, but might be a worthwhile cleanup on its own.
(Michal Hocko provided most of the kerneldoc comment.)
Cc Andrew Morton <[email protected]>Acked-by Michal Hocko <[email protected]>Signed-off-by Vegard Nossum <[email protected]>
for the series
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>