diff options
| author | Linus Torvalds <[email protected]> | 2020-10-14 09:57:24 -0700 | 
|---|---|---|
| committer | Linus Torvalds <[email protected]> | 2020-10-14 09:57:24 -0700 | 
| commit | d5660df4a555a98154da850fb61f118269d0a283 (patch) | |
| tree | b2c5f3a15c300499df930321c32fd7d288467d6b /kernel/fork.c | |
| parent | b5fc7a89e58bcc059a3d5e4db79c481fb437de59 (diff) | |
| parent | f1f4f3ab54e9a52c7610c998ff8255f019742e67 (diff) | |
Merge branch 'akpm' (patches from Andrew)
Merge misc updates from Andrew Morton:
 "181 patches.
  Subsystems affected by this patch series: kbuild, scripts, ntfs,
  ocfs2, vfs, mm (slab, slub, kmemleak, dax, debug, pagecache, fadvise,
  gup, swap, memremap, memcg, selftests, pagemap, mincore, hmm, dma,
  memory-failure, vmallo and migration)"
* emailed patches from Andrew Morton <[email protected]>: (181 commits)
  mm/migrate: remove obsolete comment about device public
  mm/migrate: remove cpages-- in migrate_vma_finalize()
  mm, oom_adj: don't loop through tasks in __set_oom_adj when not necessary
  memblock: use separate iterators for memory and reserved regions
  memblock: implement for_each_reserved_mem_region() using __next_mem_region()
  memblock: remove unused memblock_mem_size()
  x86/setup: simplify reserve_crashkernel()
  x86/setup: simplify initrd relocation and reservation
  arch, drivers: replace for_each_membock() with for_each_mem_range()
  arch, mm: replace for_each_memblock() with for_each_mem_pfn_range()
  memblock: reduce number of parameters in for_each_mem_range()
  memblock: make memblock_debug and related functionality private
  memblock: make for_each_memblock_type() iterator private
  mircoblaze: drop unneeded NUMA and sparsemem initializations
  riscv: drop unneeded node initialization
  h8300, nds32, openrisc: simplify detection of memory extents
  arm64: numa: simplify dummy_numa_init()
  arm, xtensa: simplify initialization of high memory pages
  dma-contiguous: simplify cma_early_percent_memory()
  KVM: PPC: Book3S HV: simplify kvm_cma_reserve()
  ...
Diffstat (limited to 'kernel/fork.c')
| -rw-r--r-- | kernel/fork.c | 25 | 
1 files changed, 23 insertions, 2 deletions
| diff --git a/kernel/fork.c b/kernel/fork.c index a3795aaaab5c..50c90d368117 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -559,7 +559,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,  				atomic_dec(&inode->i_writecount);  			i_mmap_lock_write(mapping);  			if (tmp->vm_flags & VM_SHARED) -				atomic_inc(&mapping->i_mmap_writable); +				mapping_allow_writable(mapping);  			flush_dcache_mmap_lock(mapping);  			/* insert tmp into the share list, just after mpnt */  			vma_interval_tree_insert_after(tmp, mpnt, @@ -590,7 +590,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,  		mm->map_count++;  		if (!(tmp->vm_flags & VM_WIPEONFORK)) -			retval = copy_page_range(mm, oldmm, mpnt, tmp); +			retval = copy_page_range(tmp, mpnt);  		if (tmp->vm_ops && tmp->vm_ops->open)  			tmp->vm_ops->open(tmp); @@ -1812,6 +1812,25 @@ static __always_inline void delayed_free_task(struct task_struct *tsk)  		free_task(tsk);  } +static void copy_oom_score_adj(u64 clone_flags, struct task_struct *tsk) +{ +	/* Skip if kernel thread */ +	if (!tsk->mm) +		return; + +	/* Skip if spawning a thread or using vfork */ +	if ((clone_flags & (CLONE_VM | CLONE_THREAD | CLONE_VFORK)) != CLONE_VM) +		return; + +	/* We need to synchronize with __set_oom_adj */ +	mutex_lock(&oom_adj_mutex); +	set_bit(MMF_MULTIPROCESS, &tsk->mm->flags); +	/* Update the values in case they were changed after copy_signal */ +	tsk->signal->oom_score_adj = current->signal->oom_score_adj; +	tsk->signal->oom_score_adj_min = current->signal->oom_score_adj_min; +	mutex_unlock(&oom_adj_mutex); +} +  /*   * This creates a new process as a copy of the old one,   * but does not actually start it yet. @@ -2288,6 +2307,8 @@ static __latent_entropy struct task_struct *copy_process(  	trace_task_newtask(p, clone_flags);  	uprobe_copy_process(p, clone_flags); +	copy_oom_score_adj(clone_flags, p); +  	return p;  bad_fork_cancel_cgroup: |