Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760677AbbKTPgN (ORCPT ); Fri, 20 Nov 2015 10:36:13 -0500 Received: from mail.kernel.org ([198.145.29.136]:56656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1163050AbbKTPgH (ORCPT ); Fri, 20 Nov 2015 10:36:07 -0500 Date: Fri, 20 Nov 2015 12:34:34 -0300 From: Arnaldo Carvalho de Melo To: "Wangnan (F)" 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 , 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 Message-ID: <20151120153434.GR29361@kernel.org> References: <1445078910-73699-1-git-send-email-wangnan0@huawei.com> <1445078910-73699-6-git-send-email-wangnan0@huawei.com> <564F1F50.9000807@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <564F1F50.9000807@huawei.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1896 Lines: 51 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? 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/ ... - 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/