[augeas-devel] [PATCH] Get rid of compiled regexps earlier

David Lutterkort dlutter at redhat.com
Fri May 16 16:33:22 UTC 2008


5 files changed, 35 insertions(+)
src/lens.c      |   18 ++++++++++++++++++
src/lens.h      |    3 +++
src/regexp.c    |    8 ++++++++
src/syntax.h    |    4 ++++
src/transform.c |    2 ++


# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1210955398 25200
# Node ID 57c5bd2083f6443baa60ba17056d5bfbf27704c7
# Parent  d55304a4ad71418a061cf429a6c2e20c309a371b
Get rid of compiled regexps earlier

After we're done with a transform, release the memory used by compiled
regexps; storage for compiled regexps accounts for the lion's share of
Augeas' memory needs.

Before this patch, augtool run against the files in tests/root/ used more
than 10MB of memory; with this patch, that is done to 250 kB after the
initial load, with a spike of about 6MB during loading.

diff -r d55304a4ad71 -r 57c5bd2083f6 src/lens.c
--- a/src/lens.c	Thu May 15 13:01:32 2008 -0700
+++ b/src/lens.c	Fri May 16 09:29:58 2008 -0700
@@ -580,6 +580,24 @@ void free_lens(struct lens *lens) {
     free(lens);
 }
 
+void lens_release(struct lens *lens) {
+    regexp_release(lens->ctype);
+    regexp_release(lens->atype);
+    if (lens->tag == L_KEY || lens->tag == L_STORE)
+        regexp_release(lens->regexp);
+
+    if (lens->tag == L_SUBTREE || lens->tag == L_STAR
+        || lens->tag == L_MAYBE) {
+        lens_release(lens->child);
+    }
+
+    if (lens->tag == L_UNION || lens->tag == L_CONCAT) {
+        for (int i=0; i < lens->nchildren; i++) {
+            lens_release(lens->children[i]);
+        }
+    }
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff -r d55304a4ad71 -r 57c5bd2083f6 src/lens.h
--- a/src/lens.h	Thu May 15 13:01:32 2008 -0700
+++ b/src/lens.h	Fri May 16 09:29:58 2008 -0700
@@ -144,6 +144,9 @@ void lns_put(FILE *out, struct lens *len
 void lns_put(FILE *out, struct lens *lens, struct tree *tree,
              const char *text, struct lns_error **err);
 
+/* Free up temporary data structures, most importantly compiled
+   regular expressions */
+void lens_release(struct lens *lens);
 void free_lens(struct lens *lens);
 #endif
 
diff -r d55304a4ad71 -r 57c5bd2083f6 src/regexp.c
--- a/src/regexp.c	Thu May 15 13:01:32 2008 -0700
+++ b/src/regexp.c	Fri May 16 09:29:58 2008 -0700
@@ -21,6 +21,7 @@
  */
 
 #include "syntax.h"
+#include "memory.h"
 
 static const struct string empty_pattern_string = {
     .ref = REF_MAX, .str = "()"
@@ -240,6 +241,13 @@ fa_t regexp_to_fa(struct regexp *regexp)
     return fa;
 }
 
+void regexp_release(struct regexp *regexp) {
+    if (regexp->re != NULL) {
+        regfree(regexp->re);
+        FREE(regexp->re);
+    }
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff -r d55304a4ad71 -r 57c5bd2083f6 src/syntax.h
--- a/src/syntax.h	Thu May 15 13:01:32 2008 -0700
+++ b/src/syntax.h	Fri May 16 09:29:58 2008 -0700
@@ -192,6 +192,10 @@ regexp_maybe(struct info *info, struct r
 regexp_maybe(struct info *info, struct regexp *r);
 
 struct regexp *regexp_make_empty(struct info *);
+
+/* Free up temporary data structures, most importantly compiled
+   regular expressions */
+void regexp_release(struct regexp *regexp);
 
 /* Construct a finite automaton from REGEXP. The pattern for REGEXP
  * must be known to be syntactically correct.
diff -r d55304a4ad71 -r 57c5bd2083f6 src/transform.c
--- a/src/transform.c	Thu May 15 13:01:32 2008 -0700
+++ b/src/transform.c	Fri May 16 09:29:58 2008 -0700
@@ -365,6 +365,7 @@ int transform_load(struct augeas *aug, s
         load_file(aug, xform->lens, matches[i]);
         free(matches[i]);
     }
+    lens_release(xform->lens);
     free(matches);
     return 0;
 }
@@ -443,6 +444,7 @@ int transform_save(struct augeas *aug, s
     result = 0;
 
  done:
+    lens_release(xform->lens);
     free(text);
     free(augnew);
     free(augorig);




More information about the augeas-devel mailing list