Commit 8d99a6ce authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

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: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarDavid Ahern <dsahern@gmail.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jean Pihet <jean.pihet@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/n/tip-lw1ny3mk4ctb6su5ght5rsng@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent d8836b5d
...@@ -78,6 +78,8 @@ struct perf_session *perf_session__new(struct perf_data_file *file, ...@@ -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.events);
INIT_LIST_HEAD(&session->ordered_events.cache); INIT_LIST_HEAD(&session->ordered_events.cache);
INIT_LIST_HEAD(&session->ordered_events.to_free); 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); machines__init(&session->machines);
if (file) { if (file) {
...@@ -518,7 +520,7 @@ static void queue_event(struct ordered_events *oe, struct ordered_event *new) ...@@ -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) static struct ordered_event *alloc_event(struct ordered_events *oe)
{ {
struct list_head *cache = &oe->cache; struct list_head *cache = &oe->cache;
struct ordered_event *new; struct ordered_event *new = NULL;
if (!list_empty(cache)) { if (!list_empty(cache)) {
new = list_entry(cache->next, struct ordered_event, list); new = list_entry(cache->next, struct ordered_event, list);
...@@ -527,10 +529,14 @@ static struct ordered_event *alloc_event(struct ordered_events *oe) ...@@ -527,10 +529,14 @@ static struct ordered_event *alloc_event(struct ordered_events *oe)
new = oe->buffer + oe->buffer_idx; new = oe->buffer + oe->buffer_idx;
if (++oe->buffer_idx == MAX_SAMPLE_BUFFER) if (++oe->buffer_idx == MAX_SAMPLE_BUFFER)
oe->buffer = NULL; oe->buffer = NULL;
} else { } else if (oe->cur_alloc_size < oe->max_alloc_size) {
oe->buffer = malloc(MAX_SAMPLE_BUFFER * sizeof(*new)); size_t size = MAX_SAMPLE_BUFFER * sizeof(*new);
oe->buffer = malloc(size);
if (!oe->buffer) if (!oe->buffer)
return NULL; return NULL;
oe->cur_alloc_size += size;
list_add(&oe->buffer->list, &oe->to_free); list_add(&oe->buffer->list, &oe->to_free);
/* First entry is abused to maintain the to_free list. */ /* First entry is abused to maintain the to_free list. */
......
...@@ -20,6 +20,8 @@ struct ordered_events { ...@@ -20,6 +20,8 @@ struct ordered_events {
u64 last_flush; u64 last_flush;
u64 next_flush; u64 next_flush;
u64 max_timestamp; u64 max_timestamp;
u64 max_alloc_size;
u64 cur_alloc_size;
struct list_head events; struct list_head events;
struct list_head cache; struct list_head cache;
struct list_head to_free; struct list_head to_free;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment