--- /dev/null
+ o Removed code:
+ - We no longer maintain an internal freelist in memarea.c. Allocators
+ should be good enough to make this code unnecessary, and it's doubtful
+ that it ever had any performance benefit.
memarea_chunk_t *first; /**< Top of the chunk stack: never NULL. */
};
-/** How many chunks will we put into the freelist before freeing them? */
-#define MAX_FREELIST_LEN 4
-/** The number of memarea chunks currently in our freelist. */
-static int freelist_len=0;
-/** A linked list of unused memory area chunks. Used to prevent us from
- * spinning in malloc/free loops. */
-static memarea_chunk_t *freelist = NULL;
-
/** Helper: allocate a new memarea chunk of around <b>chunk_size</b> bytes. */
static memarea_chunk_t *
-alloc_chunk(size_t sz, int freelist_ok)
+alloc_chunk(size_t sz)
{
tor_assert(sz < SIZE_T_CEILING);
- if (freelist && freelist_ok) {
- memarea_chunk_t *res = freelist;
- freelist = res->next_chunk;
- res->next_chunk = NULL;
- --freelist_len;
- CHECK_SENTINEL(res);
- return res;
- } else {
- size_t chunk_size = freelist_ok ? CHUNK_SIZE : sz;
- memarea_chunk_t *res;
- chunk_size += SENTINEL_LEN;
- res = tor_malloc(chunk_size);
- res->next_chunk = NULL;
- res->mem_size = chunk_size - CHUNK_HEADER_SIZE - SENTINEL_LEN;
- res->next_mem = res->U_MEM;
- tor_assert(res->next_mem+res->mem_size+SENTINEL_LEN ==
- ((char*)res)+chunk_size);
- tor_assert(realign_pointer(res->next_mem) == res->next_mem);
- SET_SENTINEL(res);
- return res;
- }
+
+ size_t chunk_size = sz < CHUNK_SIZE ? CHUNK_SIZE : sz;
+ memarea_chunk_t *res;
+ chunk_size += SENTINEL_LEN;
+ res = tor_malloc(chunk_size);
+ res->next_chunk = NULL;
+ res->mem_size = chunk_size - CHUNK_HEADER_SIZE - SENTINEL_LEN;
+ res->next_mem = res->U_MEM;
+ tor_assert(res->next_mem+res->mem_size+SENTINEL_LEN ==
+ ((char*)res)+chunk_size);
+ tor_assert(realign_pointer(res->next_mem) == res->next_mem);
+ SET_SENTINEL(res);
+ return res;
}
-/** Release <b>chunk</b> from a memarea, either by adding it to the freelist
- * or by freeing it if the freelist is already too big. */
+/** Release <b>chunk</b> from a memarea. */
static void
chunk_free_unchecked(memarea_chunk_t *chunk)
{
CHECK_SENTINEL(chunk);
- if (freelist_len < MAX_FREELIST_LEN) {
- ++freelist_len;
- chunk->next_chunk = freelist;
- freelist = chunk;
- chunk->next_mem = chunk->U_MEM;
- } else {
- tor_free(chunk);
- }
+ tor_free(chunk);
}
/** Allocate and return new memarea. */
memarea_new(void)
{
memarea_t *head = tor_malloc(sizeof(memarea_t));
- head->first = alloc_chunk(CHUNK_SIZE, 1);
+ head->first = alloc_chunk(CHUNK_SIZE);
return head;
}
area->first->next_mem = area->first->U_MEM;
}
-/** Remove all unused memarea chunks from the internal freelist. */
-void
-memarea_clear_freelist(void)
-{
- memarea_chunk_t *chunk, *next;
- freelist_len = 0;
- for (chunk = freelist; chunk; chunk = next) {
- next = chunk->next_chunk;
- tor_free(chunk);
- }
- freelist = NULL;
-}
-
/** Return true iff <b>p</b> is in a range that has been returned by an
* allocation from <b>area</b>. */
int
if (sz+CHUNK_HEADER_SIZE >= CHUNK_SIZE) {
/* This allocation is too big. Stick it in a special chunk, and put
* that chunk second in the list. */
- memarea_chunk_t *new_chunk = alloc_chunk(sz+CHUNK_HEADER_SIZE, 0);
+ memarea_chunk_t *new_chunk = alloc_chunk(sz+CHUNK_HEADER_SIZE);
new_chunk->next_chunk = chunk->next_chunk;
chunk->next_chunk = new_chunk;
chunk = new_chunk;
} else {
- memarea_chunk_t *new_chunk = alloc_chunk(CHUNK_SIZE, 1);
+ memarea_chunk_t *new_chunk = alloc_chunk(CHUNK_SIZE);
new_chunk->next_chunk = chunk;
area->first = chunk = new_chunk;
}
char *memarea_strndup(memarea_t *area, const char *s, size_t n);
void memarea_get_stats(memarea_t *area,
size_t *allocated_out, size_t *used_out);
-void memarea_clear_freelist(void);
void memarea_assert_ok(memarea_t *area);
#endif
connection_free_all();
connection_edge_free_all();
scheduler_free_all();
- memarea_clear_freelist();
nodelist_free_all();
microdesc_free_all();
ext_orport_free_all();
#undef CHECK_FAIL
#undef CHECK_OK
done:
- memarea_clear_freelist();
routerinfo_free(ri);
}
done:
escaped(NULL);
- memarea_clear_freelist();
extrainfo_free(ei);
routerinfo_free(ri);
digestmap_free((digestmap_t*)map, routerinfo_free_wrapper_);
}
done:
- memarea_clear_freelist();
escaped(NULL);
policies_free_all();
config_free_lines(cl);
done:
NS_UNMOCK(geoip_get_country);
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
done:
teardown_capture_of_logs(previous_log);
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
done:
escaped(NULL); // This will free the leaking memory from the previous escaped
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
done:
teardown_capture_of_logs(previous_log);
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
done:
teardown_capture_of_logs(previous_log);
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
done:
free_options_test_data(tdata);
- memarea_clear_freelist();
policies_free_all();
tor_free(msg);
}
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
done:
teardown_capture_of_logs(previous_log);
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
done:
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
- memarea_clear_freelist();
policies_free_all();
// sandbox_free_getaddrinfo_cache();
tor_free(msg);
done:
teardown_capture_of_logs(previous_log);
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
done:
teardown_capture_of_logs(previous_log);
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
done:
escaped(NULL); // This will free the leaking memory from the previous escaped
- memarea_clear_freelist();
policies_free_all();
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
done:
escaped(NULL); // This will free the leaking memory from the previous escaped
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
teardown_capture_of_logs(previous_log);
free_options_test_data(tdata);
tor_free(msg);
done:
- memarea_clear_freelist();
policies_free_all();
free_options_test_data(tdata);
tor_free(msg);