[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r17195: {tor} The chunk_size field in memarea_t was never actually set. Re (in tor/trunk: . src/common src/or)



Author: nickm
Date: 2008-11-05 15:34:22 -0500 (Wed, 05 Nov 2008)
New Revision: 17195

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/common/memarea.c
   tor/trunk/src/common/memarea.h
   tor/trunk/src/or/routerparse.c
   tor/trunk/src/or/test.c
Log:
The chunk_size field in memarea_t was never actually set.  Remove the whole thing.

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2008-11-05 19:29:17 UTC (rev 17194)
+++ tor/trunk/ChangeLog	2008-11-05 20:34:22 UTC (rev 17195)
@@ -56,6 +56,8 @@
       have already been marked for close.
     - Fix read-off-the-end-of-string error in unit tests when decoding
       introduction points.
+    - Fix uninitialized size field for memory area allocation: may improve
+      memory performance during directory parsing.
 
 
 Changes in version 0.2.1.6-alpha - 2008-09-30

Modified: tor/trunk/src/common/memarea.c
===================================================================
--- tor/trunk/src/common/memarea.c	2008-11-05 19:29:17 UTC (rev 17194)
+++ tor/trunk/src/common/memarea.c	2008-11-05 20:34:22 UTC (rev 17195)
@@ -53,13 +53,12 @@
 
 #define CHUNK_HEADER_SIZE STRUCT_OFFSET(memarea_chunk_t, u)
 
-#define CHUNK_SIZE 8192
+#define CHUNK_SIZE 4096
 
 /** A memarea_t is an allocation region for a set of small memory requests
  * that will all be freed at once. */
 struct memarea_t {
-  struct memarea_chunk_t *first; /**< Top of the chunk stack: never NULL. */
-  size_t chunk_size; /**<Size to use when allocating chunks.*/
+  memarea_chunk_t *first; /**< Top of the chunk stack: never NULL. */
 };
 
 #define MAX_FREELIST_LEN 4
@@ -101,11 +100,10 @@
 
 /** Allocate and return new memarea. */
 memarea_t *
-memarea_new(size_t chunk_size)/*XXXX021 remove this argument.*/
+memarea_new(void)
 {
   memarea_t *head = tor_malloc(sizeof(memarea_t));
-  head->first = alloc_chunk(chunk_size, 1);
-  (void)chunk_size;
+  head->first = alloc_chunk(CHUNK_SIZE, 1);
   return head;
 }
 
@@ -185,7 +183,7 @@
       chunk->next_chunk = new_chunk;
       chunk = new_chunk;
     } else {
-      memarea_chunk_t *new_chunk = alloc_chunk(area->chunk_size, 1);
+      memarea_chunk_t *new_chunk = alloc_chunk(CHUNK_SIZE, 1);
       new_chunk->next_chunk = chunk;
       area->first = chunk = new_chunk;
     }

Modified: tor/trunk/src/common/memarea.h
===================================================================
--- tor/trunk/src/common/memarea.h	2008-11-05 19:29:17 UTC (rev 17194)
+++ tor/trunk/src/common/memarea.h	2008-11-05 20:34:22 UTC (rev 17195)
@@ -8,7 +8,7 @@
 
 typedef struct memarea_t memarea_t;
 
-memarea_t *memarea_new(size_t chunk_size);
+memarea_t *memarea_new(void);
 void memarea_drop_all(memarea_t *area);
 void memarea_clear(memarea_t *area);
 int memarea_owns_ptr(const memarea_t *area, const void *ptr);

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2008-11-05 19:29:17 UTC (rev 17194)
+++ tor/trunk/src/or/routerparse.c	2008-11-05 20:34:22 UTC (rev 17195)
@@ -676,7 +676,7 @@
   const char *end, *cp;
   smartlist_t *tokens = NULL;
   crypto_pk_env_t *declared_key = NULL;
-  memarea_t *area = memarea_new(8192);
+  memarea_t *area = memarea_new();
 
   /* XXXX This could be simplified a lot, but it will all go away
    * once pre-0.1.1.8 is obsolete, and for now it's better not to
@@ -779,7 +779,7 @@
     log_warn(LD_DIR, "Unable to compute digest of running-routers");
     goto err;
   }
-  area = memarea_new(8192);
+  area = memarea_new();
   tokens = smartlist_create();
   if (tokenize_string(area,str,eos,tokens,dir_token_table,0)) {
     log_warn(LD_DIR, "Error tokenizing running-routers"); goto err;
@@ -846,7 +846,7 @@
     return NULL;
   ++cp; /* Now cp points to the start of the token. */
 
-  area = memarea_new(1024);
+  area = memarea_new();
   tok = get_next_token(area, &cp, eos, dir_token_table);
   if (!tok) {
     log_warn(LD_DIR, "Unparseable dir-signing-key token");
@@ -1131,7 +1131,7 @@
   while (end > s+2 && *(end-1) == '\n' && *(end-2) == '\n')
     --end;
 
-  area = memarea_new(4096);
+  area = memarea_new();
   tokens = smartlist_create();
   if (prepend_annotations) {
     if (tokenize_string(area,prepend_annotations,NULL,tokens,
@@ -1456,7 +1456,7 @@
     return NULL;
   }
   tokens = smartlist_create();
-  area = memarea_new(8192);
+  area = memarea_new();
   if (tokenize_string(area,s,end,tokens,extrainfo_token_table,0)) {
     log_warn(LD_DIR, "Error tokenizing extra-info document.");
     goto err;
@@ -1574,7 +1574,7 @@
   len = eos - s;
 
   tokens = smartlist_create();
-  area = memarea_new(8192);
+  area = memarea_new();
   if (tokenize_string(area,s, eos, tokens, dir_key_certificate_table, 0) < 0) {
     log_warn(LD_DIR, "Error tokenizing key certificate");
     goto err;
@@ -1971,7 +1971,7 @@
     goto err;
   }
 
-  area = memarea_new(8192);
+  area = memarea_new();
   eos = find_start_of_next_routerstatus(s);
   if (tokenize_string(area, s, eos, tokens, netstatus_token_table,0)) {
     log_warn(LD_DIR, "Error tokenizing network-status header.");
@@ -2146,7 +2146,7 @@
     goto err;
   }
 
-  area = memarea_new(8192);
+  area = memarea_new();
   end_of_header = find_start_of_next_routerstatus(s);
   if (tokenize_string(area, s, end_of_header, tokens,
                       (ns_type == NS_TYPE_CONSENSUS) ?
@@ -2370,7 +2370,7 @@
 
   /* Parse routerstatus lines. */
   rs_tokens = smartlist_create();
-  rs_area = memarea_new(512);
+  rs_area = memarea_new();
   s = end_of_header;
   ns->routerstatus_list = smartlist_create();
 
@@ -2539,7 +2539,7 @@
   if (!eos)
     eos = s + strlen(s);
 
-  area = memarea_new(8192);
+  area = memarea_new();
   if (tokenize_string(area,s, eos, tokens,
                       networkstatus_detached_signature_token_table, 0)) {
     log_warn(LD_DIR, "Error tokenizing detached networkstatus signatures");
@@ -2666,7 +2666,7 @@
   }
 
   eos = cp + strlen(cp);
-  area = memarea_new(128);
+  area = memarea_new();
   tok = get_next_token(area, &cp, eos, routerdesc_token_table);
   if (tok->tp == _ERR) {
     log_warn(LD_DIR, "Error reading address policy: %s", tok->error);
@@ -3476,7 +3476,7 @@
     goto err;
   }
   /* Tokenize descriptor. */
-  area = memarea_new(4096);
+  area = memarea_new();
   if (tokenize_string(area, desc, eos, tokens, desc_token_table, 0)) {
     log_warn(LD_REND, "Error tokenizing descriptor.");
     goto err;
@@ -3748,7 +3748,7 @@
   end_of_intro_points = intro_points_encoded + intro_points_encoded_size;
   tokens = smartlist_create();
   parsed->intro_nodes = smartlist_create();
-  area = memarea_new(4096);
+  area = memarea_new();
 
   while (!memcmpstart(current_ipo, end_of_intro_points-current_ipo,
                       "introduction-point ")) {
@@ -3860,7 +3860,7 @@
   tokens = smartlist_create();
   /* Begin parsing with first entry, skipping comments or whitespace at the
    * beginning. */
-  area = memarea_new(4096);
+  area = memarea_new();
   current_entry = eat_whitespace(ckstr);
   while (!strcmpstart(current_entry, "client-name ")) {
     rend_authorized_client_t *parsed_entry;

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2008-11-05 19:29:17 UTC (rev 17194)
+++ tor/trunk/src/or/test.c	2008-11-05 20:34:22 UTC (rev 17195)
@@ -3908,7 +3908,7 @@
 static void
 test_util_memarea(void)
 {
-  memarea_t *area = memarea_new(1024);
+  memarea_t *area = memarea_new();
   char *p1, *p2, *p3, *p1_orig;
   int i;
   test_assert(area);