fs/proc/kcore.c: add mmap interface
When we do the kernel monitor, use the DRGN
(https://github.com/osandov/drgn) access to kernel data structures, found
that the system calls a lot. DRGN is implemented by reading /proc/kcore.
After looking at the kcore code, it is found that kcore does not implement
mmap, resulting in frequent context switching triggered by read.
Therefore, we want to add mmap interface to optimize performance. Since
vmalloc and module areas will change with allocation and release,
consistency cannot be guaranteed, so mmap interface only maps KCORE_TEXT
and KCORE_RAM.
The test results:
1. the default version of kcore
real 11.00
user 8.53
sys 3.59
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
99.64 128.578319 12
11168701 pread64
...
------ ----------- ----------- --------- --------- ----------------
100.00 129.042853
11193748 966 total
2. added kcore for the mmap interface
real 6.44
user 7.32
sys 0.24
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
32.94 0.130120 24 5317 315 futex
11.66 0.046077 21 2231 1 lstat
9.23 0.036449 177 206 mmap
...
------ ----------- ----------- --------- --------- ----------------
100.00 0.395077 25435 971 total
The test results show that the number of system calls and time
consumption are significantly reduced.
Link: https://lkml.kernel.org/r/20210704062208.7898-1-zhoufeng.zf@bytedance.com
Co-developed-by: Ying Chen <chenying.kernel@bytedance.com>
Signed-off-by: Ying Chen <chenying.kernel@bytedance.com>
Signed-off-by: Feng Zhou <zhoufeng.zf@bytedance.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>