BUG/MEDIUM: pattern: don't load more than once a pattern list.

A memory optimization can use the same pattern expression for many
equal pattern list (same parse method, index method and index_smp
method).

The pattern expression is returned by "pattern_new_expr", but this
function dont indicate if the returned pattern is already in use.

So, the caller function reload the list of patterns in addition with
the existing patterns. This behavior is not a problem with tree indexed
pattern, but it grows the lists indexed patterns.

This fix add a "reuse" flag in return of the function "pattern_new_expr".
If the flag is set, I suppose that the patterns are already loaded.

This fix must be backported into 1.5.
This commit is contained in:
Thierry FOURNIER 2014-11-24 11:14:42 +01:00 committed by Willy Tarreau
parent cbf8cf68f5
commit 315ec4217f
3 changed files with 23 additions and 4 deletions

View File

@ -206,7 +206,8 @@ int pattern_read_from_file(struct pattern_head *head, unsigned int refflags, con
*/
void pattern_init_expr(struct pattern_expr *expr);
struct pattern_expr *pattern_lookup_expr(struct pattern_head *head, struct pat_ref *ref);
struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref *ref, char **err);
struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref *ref,
char **err, int *reuse);
struct sample_storage **pattern_find_smp(struct pattern_expr *expr, struct pat_ref_elt *elt);
int pattern_delete(struct pattern_expr *expr, struct pat_ref_elt *ref);

View File

@ -532,7 +532,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
}
/* Create new pattern expression associated to this reference. */
pattern_expr = pattern_new_expr(&expr->pat, ref, err);
pattern_expr = pattern_new_expr(&expr->pat, ref, err, NULL);
if (!pattern_expr)
goto out_free_expr;

View File

@ -1855,12 +1855,19 @@ struct pattern_expr *pattern_lookup_expr(struct pattern_head *head, struct pat_r
* <ref> can be NULL. If an error is occured, the function returns NULL and
* <err> is filled. Otherwise, the function returns new pattern_expr linked
* with <head> and <ref>.
*
* The returned value can be a alredy filled pattern list, in this case the
* flag <reuse> is set.
*/
struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref *ref, char **err)
struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref *ref,
char **err, int *reuse)
{
struct pattern_expr *expr;
struct pattern_expr_list *list;
if (reuse)
*reuse = 0;
/* Memory and initialization of the chain element. */
list = malloc(sizeof(*list));
if (!list) {
@ -1915,6 +1922,8 @@ struct pattern_expr *pattern_new_expr(struct pattern_head *head, struct pat_ref
* with ref and we must not free it.
*/
list->do_free = 0;
if (reuse)
*reuse = 1;
}
/* The new list element reference the pattern_expr. */
@ -2087,6 +2096,7 @@ int pattern_read_from_file(struct pattern_head *head, unsigned int refflags,
struct pat_ref *ref;
struct pattern_expr *expr;
struct pat_ref_elt *elt;
int reuse;
/* Lookup for the existing reference. */
ref = pat_ref_lookup(filename);
@ -2161,12 +2171,20 @@ int pattern_read_from_file(struct pattern_head *head, unsigned int refflags,
*/
expr = pattern_lookup_expr(head, ref);
if (!expr || (expr->mflags != patflags)) {
expr = pattern_new_expr(head, ref, err);
expr = pattern_new_expr(head, ref, err, &reuse);
if (!expr)
return 0;
expr->mflags = patflags;
}
/* The returned expression may be not empty, because the function
* "pattern_new_expr" lookup for similar pattern list and can
* reuse a already filled pattern list. In this case, we can not
* reload the patterns.
*/
if (reuse)
return 1;
/* Load reference content in the pattern expression. */
list_for_each_entry(elt, &ref->head, list) {
if (!pat_ref_push(elt, expr, patflags, err)) {