mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: zhoufeng <zhoufeng.zf@bytedance.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	adobriyan@gmail.com, rppt@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	songmuchun@bytedance.com, zhouchengming@bytedance.com,
	chenying.kernel@bytedance.com, zhengqi.arch@bytedance.com
Subject: Re: [External] Re: [PATCH] fs/proc/kcore.c: add mmap interface
Date: Thu, 27 May 2021 14:37:32 +0800	[thread overview]
Message-ID: <5faab938-8eb9-268b-e45d-b33e6a9089d6@bytedance.com> (raw)
In-Reply-To: <20210526173953.49fb3dc48c0f2a8b3c31fe2b@linux-foundation.org>



在 2021/5/27 上午8:39, Andrew Morton 写道:
> On Wed, 26 May 2021 15:51:42 +0800 Feng zhou <zhoufeng.zf@bytedance.com> wrote:
> 
>> From: ZHOUFENG <zhoufeng.zf@bytedance.com>
>>
>> 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.
>>
> 
> hm, OK, I guess why not.  The performance improvements for DRGN (which
> appears to be useful) are nice and the code is simple.
> 
> I'm surprised that it makes this much difference.  Has DRGN been fully
> optimised to minimise the amount of pread()ing which it does?  Why does
> it do so much reading?

DRGN is a tool similar to Crash, but much lighter. It allows users to 
obtain kernel data structures from Python scripts. Based on this, we 
intend to use DRGN for kernel monitoring. So we used some pressure test 
scripts to test the loss of monitoring.
Monitoring is all about getting current real-time data, so every time 
DRGN tries to get kernel data, it needs to read /proc/kcore. In my 
script, I tried to loop 1000 times to obtain the information of all the 
processes in the machine, in order to construct a scene where kernel 
data is frequently read. So, the frequency in the default version of 
kcore, pread is very high. In view of this situation, our optimization 
idea is to reduce the number of context switches as much as possible 
under the scenario of frequent kernel data acquisition, to reduce the 
performance loss to a minimum, and then move the monitoring system to 
the production environment.  After running for a long time in a 
production environment, the number of kernel data reads was added as 
time went on, and the pread number also increased. If users use mmap, 
it's once for all.

Attached is the test script:
#!/usr/bin/env drgn
# Copyright (c) Facebook, Inc. and its affiliates.
# SPDX-License-Identifier: GPL-3.0-or-later

"""A simplified implementation of ps(1) using drgn"""

from drgn.helpers.linux.pid import for_each_task

count = 0
while (count < 1000):
     count = count + 1
     #print("PID        COMM")
     for task in for_each_task(prog):
         pid = task.pid.value_()
         comm = task.comm.string_().decode()
         #print(f"{pid:<10} {comm}")

> 
> Thanks, I shall await input from others before moving ahead with this.
> 

  reply	other threads:[~2021-05-27  6:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-26  7:51 Feng zhou
2021-05-27  0:39 ` Andrew Morton
2021-05-27  6:37   ` zhoufeng [this message]
     [not found]   ` <d71a4ffa-f21e-62f5-7fa6-83ca14b3f05b@bytedance.com>
2021-05-27 22:30     ` [External] " Andrew Morton
2021-05-28  2:10       ` zhoufeng
2021-06-01  1:23 ` Andrew Morton
2021-06-01  2:57   ` [External] " zhoufeng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5faab938-8eb9-268b-e45d-b33e6a9089d6@bytedance.com \
    --to=zhoufeng.zf@bytedance.com \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chenying.kernel@bytedance.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rppt@kernel.org \
    --cc=songmuchun@bytedance.com \
    --cc=zhengqi.arch@bytedance.com \
    --cc=zhouchengming@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®