Loading src/common/mempool.c +48 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ #define FREE(x) tor_free(x) #define ASSERT(x) tor_assert(x) #undef ALLOC_CAN_RETURN_NULL #define TOR /* End Tor dependencies */ #else /* If you're not building this as part of Tor, you'll want to define the Loading Loading @@ -488,3 +489,50 @@ mp_pool_assert_ok(mp_pool_t *pool) ASSERT(pool->n_empty_chunks == n_empty); } #ifdef TOR /*FFFF uses Tor logging functions. */ /**DOCDOC*/ void mp_pool_log_status(mp_pool_t *pool, int severity) { uint64_t bytes_used = 0; uint64_t bytes_allocated = 0; uint64_t bu = 0, ba = 0; mp_chunk_t *chunk; int n_full = 0, n_used = 0; ASSERT(pool); for (chunk = pool->empty_chunks; chunk; chunk = chunk->next) { bytes_allocated += chunk->mem_size; } log_fn(severity, LD_MM, U64_FORMAT" bytes in %d empty chunks", U64_PRINTF_ARG(bytes_used), pool->n_empty_chunks); for (chunk = pool->used_chunks; chunk; chunk = chunk->next) { ++n_used; bu += chunk->n_allocated * pool->item_alloc_size; ba += chunk->mem_size; } log_fn(severity, LD_MM, U64_FORMAT"/"U64_FORMAT " bytes in %d partially full chunks", U64_PRINTF_ARG(bu), U64_PRINTF_ARG(ba), n_used); bytes_used += bu; bytes_allocated += bu; bu = ba = 0; for (chunk = pool->full_chunks; chunk; chunk = chunk->next) { ++n_full; bu += chunk->n_allocated * pool->item_alloc_size; ba += chunk->mem_size; } log_fn(severity, LD_MM, U64_FORMAT"/"U64_FORMAT " bytes in %d full chunks", U64_PRINTF_ARG(bu), U64_PRINTF_ARG(ba), n_full); bytes_used += bu; bytes_allocated += bu; log_fn(severity, LD_MM, "Total: "U64_FORMAT"/"U64_FORMAT" bytes allocated " "for cell pools are full.", U64_PRINTF_ARG(bytes_used), U64_PRINTF_ARG(bytes_allocated)); } #endif src/common/mempool.h +1 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ mp_pool_t *mp_pool_new(size_t item_size, size_t chunk_capacity); void mp_pool_clean(mp_pool_t *pool, int n); void mp_pool_destroy(mp_pool_t *pool); void mp_pool_assert_ok(mp_pool_t *pool); void mp_pool_log_status(mp_pool_t *pool, int severity); #ifdef MEMPOOL_PRIVATE /* These declarations are only used by mempool.c and test.c */ Loading src/or/main.c +1 −0 Original line number Diff line number Diff line Loading @@ -1443,6 +1443,7 @@ dumpmemusage(int severity) log(severity, LD_GENERAL, "In rephist: "U64_FORMAT" used by %d Tors.", U64_PRINTF_ARG(rephist_total_alloc), rephist_total_num); dump_routerlist_mem_usage(severity); dump_cell_pool_usage(severity); } /** Write all statistics to the log, with log level 'severity'. Called Loading src/or/or.h +1 −0 Original line number Diff line number Diff line Loading @@ -2698,6 +2698,7 @@ extern uint64_t stats_n_data_bytes_received; void init_cell_pool(void); void free_cell_pool(void); void clean_cell_pool(void); void dump_cell_pool_usage(int severity); void cell_queue_clear(cell_queue_t *queue); void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell); Loading src/or/relay.c +10 −0 Original line number Diff line number Diff line Loading @@ -1518,6 +1518,11 @@ packed_cell_alloc(void) { return mp_pool_get(cell_pool); } void dump_cell_pool_usage(int severity) { mp_pool_log_status(cell_pool, severity); } #else /* ENABLE_CELL_POOL isn't defined: here are some stubs to use tor_malloc() * and tor_free() instead. */ Loading Loading @@ -1547,6 +1552,11 @@ packed_cell_alloc(void) { return tor_malloc(sizeof(packed_cell_t)); } void dump_cell_pool_usage(int severity) { (void) severity; } #endif /** Allocate a new copy of packed <b>cell</b>. */ Loading Loading
src/common/mempool.c +48 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ #define FREE(x) tor_free(x) #define ASSERT(x) tor_assert(x) #undef ALLOC_CAN_RETURN_NULL #define TOR /* End Tor dependencies */ #else /* If you're not building this as part of Tor, you'll want to define the Loading Loading @@ -488,3 +489,50 @@ mp_pool_assert_ok(mp_pool_t *pool) ASSERT(pool->n_empty_chunks == n_empty); } #ifdef TOR /*FFFF uses Tor logging functions. */ /**DOCDOC*/ void mp_pool_log_status(mp_pool_t *pool, int severity) { uint64_t bytes_used = 0; uint64_t bytes_allocated = 0; uint64_t bu = 0, ba = 0; mp_chunk_t *chunk; int n_full = 0, n_used = 0; ASSERT(pool); for (chunk = pool->empty_chunks; chunk; chunk = chunk->next) { bytes_allocated += chunk->mem_size; } log_fn(severity, LD_MM, U64_FORMAT" bytes in %d empty chunks", U64_PRINTF_ARG(bytes_used), pool->n_empty_chunks); for (chunk = pool->used_chunks; chunk; chunk = chunk->next) { ++n_used; bu += chunk->n_allocated * pool->item_alloc_size; ba += chunk->mem_size; } log_fn(severity, LD_MM, U64_FORMAT"/"U64_FORMAT " bytes in %d partially full chunks", U64_PRINTF_ARG(bu), U64_PRINTF_ARG(ba), n_used); bytes_used += bu; bytes_allocated += bu; bu = ba = 0; for (chunk = pool->full_chunks; chunk; chunk = chunk->next) { ++n_full; bu += chunk->n_allocated * pool->item_alloc_size; ba += chunk->mem_size; } log_fn(severity, LD_MM, U64_FORMAT"/"U64_FORMAT " bytes in %d full chunks", U64_PRINTF_ARG(bu), U64_PRINTF_ARG(ba), n_full); bytes_used += bu; bytes_allocated += bu; log_fn(severity, LD_MM, "Total: "U64_FORMAT"/"U64_FORMAT" bytes allocated " "for cell pools are full.", U64_PRINTF_ARG(bytes_used), U64_PRINTF_ARG(bytes_allocated)); } #endif
src/common/mempool.h +1 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ mp_pool_t *mp_pool_new(size_t item_size, size_t chunk_capacity); void mp_pool_clean(mp_pool_t *pool, int n); void mp_pool_destroy(mp_pool_t *pool); void mp_pool_assert_ok(mp_pool_t *pool); void mp_pool_log_status(mp_pool_t *pool, int severity); #ifdef MEMPOOL_PRIVATE /* These declarations are only used by mempool.c and test.c */ Loading
src/or/main.c +1 −0 Original line number Diff line number Diff line Loading @@ -1443,6 +1443,7 @@ dumpmemusage(int severity) log(severity, LD_GENERAL, "In rephist: "U64_FORMAT" used by %d Tors.", U64_PRINTF_ARG(rephist_total_alloc), rephist_total_num); dump_routerlist_mem_usage(severity); dump_cell_pool_usage(severity); } /** Write all statistics to the log, with log level 'severity'. Called Loading
src/or/or.h +1 −0 Original line number Diff line number Diff line Loading @@ -2698,6 +2698,7 @@ extern uint64_t stats_n_data_bytes_received; void init_cell_pool(void); void free_cell_pool(void); void clean_cell_pool(void); void dump_cell_pool_usage(int severity); void cell_queue_clear(cell_queue_t *queue); void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell); Loading
src/or/relay.c +10 −0 Original line number Diff line number Diff line Loading @@ -1518,6 +1518,11 @@ packed_cell_alloc(void) { return mp_pool_get(cell_pool); } void dump_cell_pool_usage(int severity) { mp_pool_log_status(cell_pool, severity); } #else /* ENABLE_CELL_POOL isn't defined: here are some stubs to use tor_malloc() * and tor_free() instead. */ Loading Loading @@ -1547,6 +1552,11 @@ packed_cell_alloc(void) { return tor_malloc(sizeof(packed_cell_t)); } void dump_cell_pool_usage(int severity) { (void) severity; } #endif /** Allocate a new copy of packed <b>cell</b>. */ Loading