Browse Source

Removed the global buffer allocation counter

This global caused an assertion to fail due to a race condition
where it could become incorrect if different buffers are modified
in different threads at the same time.
Steven Engler 4 years ago
parent
commit
d354aebc10
4 changed files with 15 additions and 15 deletions
  1. 1 1
      src/core/or/circuitlist.c
  2. 1 1
      src/core/or/relay.c
  3. 12 12
      src/lib/buf/buffers.c
  4. 1 1
      src/lib/buf/buffers.h

+ 1 - 1
src/core/or/circuitlist.c

@@ -2680,7 +2680,7 @@ circuits_handle_oom(size_t current_allocation)
              " circuits withover-long queues. (This behavior is controlled by"
              " MaxMemInQueues.)",
              cell_queues_get_total_allocation(),
-             buf_get_total_allocation(),
+             //buf_get_total_allocation(),
              tor_compress_get_total_allocation(),
              tor_zlib_get_total_allocation(),
              tor_zstd_get_total_allocation(),

+ 1 - 1
src/core/or/relay.c

@@ -2699,7 +2699,7 @@ cell_queues_check_size(void)
   time_t now = time(NULL);
   size_t alloc = cell_queues_get_total_allocation();
   alloc += half_streams_get_total_allocation();
-  alloc += buf_get_total_allocation();
+  //alloc += buf_get_total_allocation();
   alloc += tor_compress_get_total_allocation();
   const size_t rend_cache_total = rend_cache_get_total_allocation();
   alloc += rend_cache_total;

+ 12 - 12
src/lib/buf/buffers.c

@@ -122,7 +122,7 @@ chunk_repack(chunk_t *chunk)
 }
 
 /** Keep track of total size of allocated chunks for consistency asserts */
-static size_t total_bytes_allocated_in_chunks = 0;
+//static size_t total_bytes_allocated_in_chunks = 0;
 static void
 buf_chunk_free_unchecked(chunk_t *chunk)
 {
@@ -131,9 +131,9 @@ buf_chunk_free_unchecked(chunk_t *chunk)
 #ifdef DEBUG_CHUNK_ALLOC
   tor_assert(CHUNK_ALLOC_SIZE(chunk->memlen) == chunk->DBG_alloc);
 #endif
-  tor_assert(total_bytes_allocated_in_chunks >=
-             CHUNK_ALLOC_SIZE(chunk->memlen));
-  total_bytes_allocated_in_chunks -= CHUNK_ALLOC_SIZE(chunk->memlen);
+  //tor_assert(total_bytes_allocated_in_chunks >=
+  //           CHUNK_ALLOC_SIZE(chunk->memlen));
+  //total_bytes_allocated_in_chunks -= CHUNK_ALLOC_SIZE(chunk->memlen);
   tor_free(chunk);
 }
 static inline chunk_t *
@@ -147,7 +147,7 @@ chunk_new_with_alloc_size(size_t alloc)
   ch->DBG_alloc = alloc;
 #endif
   ch->memlen = CHUNK_SIZE_WITH_ALLOC(alloc);
-  total_bytes_allocated_in_chunks += alloc;
+  //total_bytes_allocated_in_chunks += alloc;
   ch->data = &ch->mem[0];
   CHUNK_SET_SENTINEL(ch, alloc);
   return ch;
@@ -171,7 +171,7 @@ chunk_grow(chunk_t *chunk, size_t sz)
   tor_assert(chunk->DBG_alloc == orig_alloc);
   chunk->DBG_alloc = new_alloc;
 #endif
-  total_bytes_allocated_in_chunks += new_alloc - orig_alloc;
+  //total_bytes_allocated_in_chunks += new_alloc - orig_alloc;
   CHUNK_SET_SENTINEL(chunk, new_alloc);
   return chunk;
 }
@@ -434,7 +434,7 @@ static chunk_t *
 chunk_copy(const chunk_t *in_chunk)
 {
   chunk_t *newch = tor_memdup(in_chunk, CHUNK_ALLOC_SIZE(in_chunk->memlen));
-  total_bytes_allocated_in_chunks += CHUNK_ALLOC_SIZE(in_chunk->memlen);
+  //total_bytes_allocated_in_chunks += CHUNK_ALLOC_SIZE(in_chunk->memlen);
 #ifdef DEBUG_CHUNK_ALLOC
   newch->DBG_alloc = CHUNK_ALLOC_SIZE(in_chunk->memlen);
 #endif
@@ -510,11 +510,11 @@ buf_get_oldest_chunk_timestamp(const buf_t *buf, uint32_t now)
   }
 }
 
-size_t
-buf_get_total_allocation(void)
-{
-  return total_bytes_allocated_in_chunks;
-}
+//size_t
+//buf_get_total_allocation(void)
+//{
+//  return total_bytes_allocated_in_chunks;
+//}
 
 /** Append <b>string_len</b> bytes from <b>string</b> to the end of
  * <b>buf</b>.

+ 1 - 1
src/lib/buf/buffers.h

@@ -34,7 +34,7 @@ size_t buf_allocation(const buf_t *buf);
 size_t buf_slack(const buf_t *buf);
 
 uint32_t buf_get_oldest_chunk_timestamp(const buf_t *buf, uint32_t now);
-size_t buf_get_total_allocation(void);
+//size_t buf_get_total_allocation(void);
 
 int buf_add(buf_t *buf, const char *string, size_t string_len);
 void buf_add_string(buf_t *buf, const char *string);