From: "Wangnan (F)" <wangnan0@huawei.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: <ast@plumgrid.com>, <brendan.d.gregg@gmail.com>,
<a.p.zijlstra@chello.nl>, <daniel@iogearbox.net>,
<dsahern@gmail.com>, <hekuang@huawei.com>, <jolsa@kernel.org>,
<lizefan@huawei.com>, Ingo Molnar <mingo@kernel.org>,
<masami.hiramatsu.pt@hitachi.com>, <namhyung@kernel.org>,
<paulus@samba.org>, <linux-kernel@vger.kernel.org>,
<pi3orama@163.com>, <xiakaixu@huawei.com>
Subject: Re: [RFC PATCH 5/7] perf tools: Support setting different slots in a BPF map separately
Date: Mon, 23 Nov 2015 13:45:15 +0800 [thread overview]
Message-ID: <5652A7EB.8090106@huawei.com> (raw)
In-Reply-To: <56527394.70602@huawei.com>
On 2015/11/23 10:01, Wangnan (F) wrote:
>
>
> On 2015/11/20 23:34, Arnaldo Carvalho de Melo wrote:
>> Em Fri, Nov 20, 2015 at 09:25:36PM +0800, Wangnan (F) escreveu:
>>>> + case BPF_MAP_PRIV_KEY_INDICS:
>>>> + for (i = 0; i < priv->key.indics.nr_indics; i++) {
>>>> + u64 _idx = priv->key.indics.indics[i];
>>>> + unsigned int idx = (unsigned int)(_idx);
>>>> +
>>>> + err = (*func)(name, map_fd, &def,
>>>> + priv, &idx, arg);
>>>> + if (err) {
>>>> + pr_debug("ERROR: failed to insert value to
>>>> %s[%u]\n",
>>>> + name, idx);
>>>> + return err;
>>>> + }
>>>> + }
>>> This for-loop has a potential problem that, if perf's user want to
>>> set a very big array using indices, for example:
>>>
>>> # perf record -e
>>> mybpf.c/maps:mymap:values[1,2,3,10-100000,200000-400000]=3/
>>> mybpf.c/maps:mymap:values[100000-200000]=3/ ...
>>>
>>> Perf would alloc nearly 300000 slots for indices array, consume too
>>> much
>>> memory.
>>>
>>> I will fix this problem by reinterprete indices array, makes negative
>>> value represent range start and use next slot to store range size. For
>>> example, the above perf cmdline can be converted to:
>>>
>>> {1,2,3,-10, 99991,-200000,200001} and {-100000,100001}.
>> Why is that changing the way you specify what entries should be set to
>> a value will make it not allocate too much memory?
>
> It is actually a problem in the next patch, in which it expand all range
> into a series of indices. If user wants 1-10000, it creates an array as
> [1,2,3,4,...10000], so user is possible to use a simple cmdline to
> consume
> all of available memory.
>
> However, the method I described above is not the best way to solve
> this probelm.
> I thought yesterday that we should not insist on indices array. We can
> make parser always return ranges. For example, [1,2,3-5] can be represent
> using [(1,1), (2,1), (3,3)], so we don't need the above ugly negative
> indicators.
>
>> I found the first form of representing ( start-end ) to be better than (
>> -start, size ), but I would use what the C language uses for expressing
>> ranges in switch case ranges, which is familiar and doesn't reuses the
>> minus arithmetic operator to express a range, i.e.:
>>
>> # perf record -e \
>> mybpf.c/maps:mymap:values[1,2,3,10..100000,200000..400000]=3/
>>
>> # perf record -e \
>> mybpf.c/maps:mymap:values[100000..200000]=3/ ...
>
> '..' is better.
>
One problem: the case range syntax is introduced by gcc extension, not a
part of standard, and should be '...'.
Please see: https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html
So I'll use '...' also.
Thank you.
> Thank you.
>
>> - Arnaldo
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2015-11-23 5:46 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-17 10:48 [RFC PATCH 0/7] perf tools: Config BPF maps through perf cmdline Wang Nan
2015-10-17 10:48 ` [RFC PATCH 1/7] perf tools: Add API to config maps in bpf object Wang Nan
2015-11-20 8:13 ` Wangnan (F)
2015-11-23 11:20 ` Wangnan (F)
2015-10-17 10:48 ` [RFC PATCH 2/7] perf tools: Add API to apply config to BPF map Wang Nan
2015-10-17 10:48 ` [RFC PATCH 3/7] perf record: Apply config to BPF objects before recording Wang Nan
2015-10-17 10:48 ` [RFC PATCH 4/7] perf tools: Enable BPF object configure syntax Wang Nan
2015-10-23 4:48 ` Wangnan (F)
2015-10-17 10:48 ` [RFC PATCH 5/7] perf tools: Support setting different slots in a BPF map separately Wang Nan
2015-11-20 13:25 ` Wangnan (F)
2015-11-20 15:34 ` Arnaldo Carvalho de Melo
2015-11-23 2:01 ` Wangnan (F)
2015-11-23 5:45 ` Wangnan (F) [this message]
2015-10-17 10:48 ` [RFC PATCH 6/7] perf tools: Enable indics setting syntax for BPF maps Wang Nan
2015-10-17 10:48 ` [RFC PATCH 7/7] perf tools: Enable passing event to BPF object Wang Nan
2015-10-17 20:35 ` [RFC PATCH 0/7] perf tools: Config BPF maps through perf cmdline Alexei Starovoitov
2015-10-17 23:58 ` Wangnan (F)
2015-10-18 0:07 ` Alexei Starovoitov
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=5652A7EB.8090106@huawei.com \
--to=wangnan0@huawei.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=ast@plumgrid.com \
--cc=brendan.d.gregg@gmail.com \
--cc=daniel@iogearbox.net \
--cc=dsahern@gmail.com \
--cc=hekuang@huawei.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=pi3orama@163.com \
--cc=xiakaixu@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.