linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Liao, Chang" <liaochang1@huawei.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<namhyung@kernel.org>, <mark.rutland@arm.com>,
	<alexander.shishkin@linux.intel.com>, <jolsa@kernel.org>,
	<irogers@google.com>, <adrian.hunter@intel.com>,
	<kan.liang@linux.intel.com>, <ast@kernel.org>,
	<daniel@iogearbox.net>, <andrii@kernel.org>,
	<martin.lau@linux.dev>, <eddyz87@gmail.com>, <song@kernel.org>,
	<yonghong.song@linux.dev>, <john.fastabend@gmail.com>,
	<kpsingh@kernel.org>, <sdf@fomichev.me>, <haoluo@google.com>,
	<mykolal@fb.com>, <shuah@kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-perf-users@vger.kernel.org>, <bpf@vger.kernel.org>,
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH 1/2] uprobes: Optimize the return_instance related routines
Date: Thu, 11 Jul 2024 10:05:19 +0800	[thread overview]
Message-ID: <993a2fa6-b40e-b85c-ea87-e7940db11d3d@huawei.com> (raw)
In-Reply-To: <CAEf4BzYDvh2Ynrttk4NLyCGB8AVM2d-2tKSzRZF_cXVA80qucw@mail.gmail.com>



在 2024/7/11 5:21, Andrii Nakryiko 写道:
> On Wed, Jul 10, 2024 at 1:19 AM Liao, Chang <liaochang1@huawei.com> wrote:
>>
>>
>>
>> 在 2024/7/10 7:55, Andrii Nakryiko 写道:
>>> On Mon, Jul 8, 2024 at 6:00 PM Liao Chang <liaochang1@huawei.com> wrote:
>>>>
>>>> Reduce the runtime overhead for struct return_instance data managed by
>>>> uretprobe. This patch replaces the dynamic allocation with statically
>>>> allocated array, leverage two facts that are limited nesting depth of
>>>> uretprobe (max 64) and the function call style of return_instance usage
>>>> (create at entry, free at exit).
>>>>
>>>> This patch has been tested on Kunpeng916 (Hi1616), 4 NUMA nodes, 64
>>>> cores @ 2.4GHz. Redis benchmarks show a throughput gain by 2% for Redis
>>>> GET and SET commands:
>>>>
>>>> ------------------------------------------------------------------
>>>> Test case       | No uretprobes | uretprobes     | uretprobes
>>>>                 |               | (current)      | (optimized)
>>>> ==================================================================
>>>> Redis SET (RPS) | 47025         | 40619 (-13.6%) | 41529 (-11.6%)
>>>> ------------------------------------------------------------------
>>>> Redis GET (RPS) | 46715         | 41426 (-11.3%) | 42306 (-9.4%)
>>>> ------------------------------------------------------------------
>>>>
>>>> Signed-off-by: Liao Chang <liaochang1@huawei.com>
>>>> ---
>>>>  include/linux/uprobes.h |  10 ++-
>>>>  kernel/events/uprobes.c | 162 ++++++++++++++++++++++++----------------
>>>>  2 files changed, 105 insertions(+), 67 deletions(-)
>>>>
>>>
>>> [...]
>>>
>>>> +static void cleanup_return_instances(struct uprobe_task *utask, bool chained,
>>>> +                                    struct pt_regs *regs)
>>>> +{
>>>> +       struct return_frame *frame = &utask->frame;
>>>> +       struct return_instance *ri = frame->return_instance;
>>>> +       enum rp_check ctx = chained ? RP_CHECK_CHAIN_CALL : RP_CHECK_CALL;
>>>> +
>>>> +       while (ri && !arch_uretprobe_is_alive(ri, ctx, regs)) {
>>>> +               ri = next_ret_instance(frame, ri);
>>>> +               utask->depth--;
>>>> +       }
>>>> +       frame->return_instance = ri;
>>>> +}
>>>> +
>>>> +static struct return_instance *alloc_return_instance(struct uprobe_task *task)
>>>> +{
>>>> +       struct return_frame *frame = &task->frame;
>>>> +
>>>> +       if (!frame->vaddr) {
>>>> +               frame->vaddr = kcalloc(MAX_URETPROBE_DEPTH,
>>>> +                               sizeof(struct return_instance), GFP_KERNEL);
>>>
>>> Are you just pre-allocating MAX_URETPROBE_DEPTH instances always?
>>> I.e., even if we need just one (because there is no recursion), you'd
>>> still waste memory for all 64 ones?
>>
>> This is the truth. On my testing machines, each struct return_instance data
>> is 28 bytes, resulting in a total pre-allocated 1792 bytes when the first
>> instrumented function is hit.
>>
>>>
>>> That seems rather wasteful.
>>>
>>> Have you considered using objpool for fast reuse across multiple CPUs?
>>> Check lib/objpool.c.
>>
>> After studying how kretprobe uses objpool, I'm convinced it is a right solution for
>> managing return_instance in uretporbe. While I need some time to fully understand
>> the objpool code itself and run some benchmark to verify its performance.
>>
>> Thanks for the suggestion.
> 
> Keep in mind that there are two patch sets under development/review,
> both of which touch this code. [0] will make return_instance
> variable-sized, so think how to accommodate that. And [1] in general
> touches a bunch of this code. So I'd let those two settle and land
> before optimizing return_instance allocations further.
> 
>   [0] https://lore.kernel.org/linux-trace-kernel/20240701164115.723677-1-jolsa@kernel.org/
>   [1] https://lore.kernel.org/linux-kernel/20240708091241.544262971@infradead.org/

Thanks for letting me know. I've made a note to track the progress of these patch sets.

> 
>>
>>>
>>>> +               if (!frame->vaddr)
>>>> +                       return NULL;
>>>> +       }
>>>> +
>>>> +       if (!frame->return_instance) {
>>>> +               frame->return_instance = frame->vaddr;
>>>> +               return frame->return_instance;
>>>> +       }
>>>> +
>>>> +       return ++frame->return_instance;
>>>> +}
>>>> +
>>>> +static inline bool return_frame_empty(struct uprobe_task *task)
>>>> +{
>>>> +       return !task->frame.return_instance;
>>>>  }
>>>>
>>>>  /*
>>>
>>> [...]
>>
>> --
>> BR
>> Liao, Chang

-- 
BR
Liao, Chang

  reply	other threads:[~2024-07-11  2:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-09  0:51 [PATCH 0/2] Optimize the return_instance management of uretprobe Liao Chang
2024-07-09  0:51 ` [PATCH 1/2] uprobes: Optimize the return_instance related routines Liao Chang
2024-07-09 23:55   ` Andrii Nakryiko
2024-07-10  8:19     ` Liao, Chang
2024-07-10 21:21       ` Andrii Nakryiko
2024-07-11  2:05         ` Liao, Chang [this message]
2024-07-09  0:51 ` [PATCH 2/2] selftests/bpf: Add uretprobe test for return_instance management Liao Chang

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=993a2fa6-b40e-b85c-ea87-e7940db11d3d@huawei.com \
    --to=liaochang1@huawei.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=irogers@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=martin.lau@linux.dev \
    --cc=mingo@redhat.com \
    --cc=mykolal@fb.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).