diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-02-12 12:39:15 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-02-12 12:39:15 -0500 |
commit | 05d8111eedee9e11e4bb1c42e93ae2fc168d52ec (patch) | |
tree | 6a77e7b0e087d594adce42693bc369478cd01d6f /src/or/buffers.c | |
parent | 5c45a333c3cdfc4c7a817425a1c3ae88085c389b (diff) | |
parent | fd28754dd3dce0e00304825d531348414c0a354b (diff) | |
download | tor-05d8111eedee9e11e4bb1c42e93ae2fc168d52ec.tar.gz tor-05d8111eedee9e11e4bb1c42e93ae2fc168d52ec.zip |
Merge remote-tracking branch 'public/bug10169_023' into bug10169_024
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r-- | src/or/buffers.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 34a2480ed5..c0a3534d8d 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -244,12 +244,13 @@ static INLINE chunk_t * chunk_grow(chunk_t *chunk, size_t sz) { off_t offset; + size_t memlen_orig = chunk->memlen; tor_assert(sz > chunk->memlen); offset = chunk->data - chunk->mem; chunk = tor_realloc(chunk, CHUNK_ALLOC_SIZE(sz)); chunk->memlen = sz; chunk->data = chunk->mem + offset; - total_bytes_allocated_in_chunks += (sz - chunk->memlen); + total_bytes_allocated_in_chunks += CHUNK_ALLOC_SIZE(sz) - CHUNK_ALLOC_SIZE(memlen_orig); return chunk; } @@ -274,12 +275,14 @@ preferred_chunk_size(size_t target) } /** Remove from the freelists most chunks that have not been used since the - * last call to buf_shrink_freelists(). */ -void + * last call to buf_shrink_freelists(). Return the amount of memory + * freed. */ +size_t buf_shrink_freelists(int free_all) { #ifdef ENABLE_BUF_FREELISTS int i; + size_t total_freed = 0; disable_control_logging(); for (i = 0; freelists[i].alloc_size; ++i) { int slack = freelists[i].slack; @@ -313,6 +316,7 @@ buf_shrink_freelists(int free_all) chunk_t *next = chunk->next; tor_assert(total_bytes_allocated_in_chunks >= CHUNK_ALLOC_SIZE(chunk->memlen)); total_bytes_allocated_in_chunks -= CHUNK_ALLOC_SIZE(chunk->memlen); + total_freed += CHUNK_ALLOC_SIZE(chunk->memlen); tor_free(chunk); chunk = next; --n_to_free; @@ -330,18 +334,21 @@ buf_shrink_freelists(int free_all) } // tor_assert(!n_to_free); freelists[i].cur_length = new_length; + tor_assert(orig_n_to_skip == new_length); log_info(LD_MM, "Cleaned freelist for %d-byte chunks: original " - "length %d, kept %d, dropped %d.", + "length %d, kept %d, dropped %d. New length is %d", (int)freelists[i].alloc_size, orig_length, - orig_n_to_skip, orig_n_to_free); + orig_n_to_skip, orig_n_to_free, new_length); } freelists[i].lowest_length = freelists[i].cur_length; assert_freelist_ok(&freelists[i]); } done: enable_control_logging(); + return total_freed; #else (void) free_all; + return 0; #endif } @@ -579,6 +586,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); newch->next = NULL; if (in_chunk->data) { off_t offset = in_chunk->data - in_chunk->mem; |