perf tools: Limit ordered events queue size
tip-bot for Jiri Olsa
merge botCommit-ID: 8d99a6ceebe862ac4afd832cdab332ee7b3b5599 Gitweb: http://git.kernel.org/tip/8d99a6ceebe862ac4afd832cdab332ee7b3b5599 Author: Jiri Olsa <[email protected]> AuthorDate: Wed, 11 Jun 2014 15:09:35 +0200 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 12 Aug 2014 12:02:57 -0300
perf tools: Limit ordered events queue size
Add limit to the ordered events queue allocation. This way we will be able to control the size of the queue buffers.
There's no limit at the moment (it's set to (u64) -1). The config code will come in following patches.
Signed-off-by Jiri Olsa <[email protected]>
Acked-by David Ahern <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jean Pihet <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/session.c | 12 +++++++++--- tools/perf/util/session.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-)
tools/perf/util/session.c +9 -3
@@ -78,6 +78,8 @@ struct perf_session *perf_session__new(struct perf_data_file *file,INIT_LIST_HEAD (&session->ordered_events.events);INIT_LIST_HEAD (&session->ordered_events.cache);INIT_LIST_HEAD (&session->ordered_events.to_free); + session->ordered_events.max_alloc_size = (u64) -1 ; + session->ordered_events.cur_alloc_size =0 ;machines__init (&session->machines);if (file) {
@@ -518,7 +520,7 @@ static void queue_event(struct ordered_events *oe, struct ordered_event *new)static struct ordered_event *alloc_event (struct ordered_events *oe) {struct list_head *cache = &oe->cache; -struct ordered_event *new; +struct ordered_event *new =NULL ;if (!list_empty (cache)) { new = list_entry(cache->next, struct ordered_event, list);
@@ -527,10 +529,14 @@ static struct ordered_event *alloc_event(struct ordered_events *oe) new = oe->buffer + oe->buffer_idx;if (++oe->buffer_idx ==MAX_SAMPLE_BUFFER ) oe->buffer =NULL ; - }else { - oe->buffer =malloc (MAX_SAMPLE_BUFFER *sizeof (*new)); + }else if (oe->cur_alloc_size < oe->max_alloc_size) { +size_t size =MAX_SAMPLE_BUFFER *sizeof (*new); + + oe->buffer =malloc (size);if (!oe->buffer)return NULL ; + + oe->cur_alloc_size += size;list_add (&oe->buffer->list, &oe->to_free);/* First entry is abused to maintain the to_free list. */
tools/perf/util/session.h +2 -0
@@ -20,6 +20,8 @@ struct ordered_events {u64 last_flush;u64 next_flush;u64 max_timestamp; +u64 max_alloc_size; +u64 cur_alloc_size;struct list_head events;struct list_head cache;struct list_head to_free;