TencentOS-kernel/mm
Yang Shi 2f09e7ee6d mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct
mmap_sem is on the hot path of kernel, and it very contended, but it is
abused too.  It is used to protect arg_start|end and evn_start|end when
reading /proc/$PID/cmdline and /proc/$PID/environ, but it doesn't make
sense since those proc files just expect to read 4 values atomically and
not related to VM, they could be set to arbitrary values by C/R.

And, the mmap_sem contention may cause unexpected issue like below:

INFO: task ps:14018 blocked for more than 120 seconds.
       Tainted: G            E 4.9.79-009.ali3000.alios7.x86_64 #1
 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this
message.
 ps              D    0 14018      1 0x00000004
 Call Trace:
   schedule+0x36/0x80
   rwsem_down_read_failed+0xf0/0x150
   call_rwsem_down_read_failed+0x18/0x30
   down_read+0x20/0x40
   proc_pid_cmdline_read+0xd9/0x4e0
   __vfs_read+0x37/0x150
   vfs_read+0x96/0x130
   SyS_read+0x55/0xc0
   entry_SYSCALL_64_fastpath+0x1a/0xc5

Both Alexey Dobriyan and Michal Hocko suggested to use dedicated lock
for them to mitigate the abuse of mmap_sem.

So, introduce a new spinlock in mm_struct to protect the concurrent
access to arg_start|end, env_start|end and others, as well as replace
write map_sem to read to protect the race condition between prctl and
sys_brk which might break check_data_rlimit(), and makes prctl more
friendly to other VM operations.

This patch just eliminates the abuse of mmap_sem, but it can't resolve
the above hung task warning completely since the later
access_remote_vm() call needs acquire mmap_sem.  The mmap_sem
scalability issue will be solved in the future.

[yang.shi@linux.alibaba.com: add comment about mmap_sem and arg_lock]
  Link: http://lkml.kernel.org/r/1524077799-80690-1-git-send-email-yang.shi@linux.alibaba.com
Link: http://lkml.kernel.org/r/1523730291-109696-1-git-send-email-yang.shi@linux.alibaba.com
Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mateusz Guzik <mguzik@redhat.com>
Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-07-26 16:13:08 +08:00
..
kasan arm64: implement ftrace with regs by using patchable-function-entry 2020-01-02 12:14:57 +08:00
Kconfig Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
Kconfig.debug Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
Makefile Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
backing-dev.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
balloon_compaction.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
bootmem.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
cleancache.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
cma.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
cma.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
cma_debug.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
compaction.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
debug.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
debug_page_ref.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
dmapool.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
early_ioremap.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
fadvise.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
failslab.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
filemap.c pagecachelimit: limit the pagecache ratio of totalram 2020-01-02 12:01:22 +08:00
frame_vector.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
frontswap.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
gup.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
highmem.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
hmm.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
huge_memory.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
hugetlb.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
hugetlb_cgroup.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
hwpoison-inject.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
init-mm.c mm: introduce arg_lock to protect arg_start|end and env_start|end in mm_struct 2021-07-26 16:13:08 +08:00
internal.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
interval_tree.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
khugepaged.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kmemleak-test.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
kmemleak.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
ksm.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
list_lru.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
maccess.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
madvise.c vm: add max_map_count isolate switch 2020-05-29 10:38:28 +08:00
memblock.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
memcontrol.c cgroup/memory: disable kmem limit by default 2021-07-16 12:05:47 +08:00
memory-failure.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
memory.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
memory_hotplug.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mempolicy.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mempool.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
memtest.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
migrate.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mincore.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mlock.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mm_init.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mmap.c vm: add max_map_count isolate switch 2020-05-29 10:38:28 +08:00
mmu_context.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mmu_notifier.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mmzone.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mprotect.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
mremap.c vm: add max_map_count isolate switch 2020-05-29 10:38:28 +08:00
msync.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
nobootmem.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
nommu.c vm: add max_map_count isolate switch 2020-05-29 10:38:28 +08:00
oom_kill.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page-writeback.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page_alloc.c pagecachelimit: add the slab(dentry&inode) limit support 2020-05-29 10:40:24 +08:00
page_counter.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page_ext.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page_idle.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page_io.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page_isolation.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page_owner.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page_poison.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
page_vma_mapped.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
pagewalk.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
percpu-internal.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
percpu-km.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
percpu-stats.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
percpu-vm.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
percpu.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
pgtable-generic.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
process_vm_access.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
quicklist.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
readahead.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
rmap.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
rodata_test.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
shmem.c pagecachelimit: limit the pagecache ratio of totalram 2020-01-02 12:01:22 +08:00
slab.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
slab.h Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
slab_common.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
slob.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
slub.c slub: add fast_slub_nr_free to track free objects 2020-05-29 10:40:21 +08:00
sparse-vmemmap.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
sparse.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
swap.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
swap_cgroup.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
swap_slots.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
swap_state.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
swapfile.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
truncate.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
usercopy.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
userfaultfd.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
util.c mm: modify max_map_count_isolated default to zero 2020-05-29 10:39:34 +08:00
vmacache.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
vmalloc.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
vmpressure.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
vmscan.c mm/vmscan: fix infinite loop in drop_slab_node 2021-06-16 14:27:59 +08:00
vmstat.c cgroup: add switch for subsystem stats isolated 2020-07-16 14:52:41 +08:00
workingset.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
z3fold.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
zbud.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
zpool.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
zsmalloc.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00
zswap.c Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces 2020-01-02 10:51:04 +08:00