From: Jens Axboe Date: Sun, 11 Mar 2012 20:35:47 +0000 (+0100) Subject: graph: drop more than 1 entry, if we are more than 1 above the limit X-Git-Tag: gfio-0.1~183 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=c148daed3da130062a7575d5667ca0e044927153;ds=sidebyside graph: drop more than 1 entry, if we are more than 1 above the limit If we dynamically reduce the data entry limit, it's not enough to drop one entry when we add one. In that case, drop two everytime we add one. Then we'll eventually get smoothly down to the specified limit. Signed-off-by: Jens Axboe --- diff --git a/graph.c b/graph.c index 111a7203..9eae7272 100644 --- a/graph.c +++ b/graph.c @@ -600,11 +600,24 @@ static void graph_label_add_value(struct graph_label *i, void *value) if (i->parent->per_label_limit != -1 && i->value_count > i->parent->per_label_limit) { - x = i->values; - i->values = i->values->next; - free(x->value); - free(x); - i->value_count--; + int to_drop = 1; + + /* + * If the limit was dynamically reduced, making us more + * than 1 entry ahead after adding this one, drop two + * entries. This will make us (eventually) reach the + * specified limit. + */ + if (i->value_count - i->parent->per_label_limit >= 2) + to_drop = 2; + + while (to_drop--) { + x = i->values; + i->values = i->values->next; + free(x->value); + free(x); + i->value_count--; + } } }