diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-07-27 23:19:02 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-07-27 23:19:02 +0000 |
commit | 0d274e1db18473589658e098efdf682e304f01e7 (patch) | |
tree | 62edc5caca9d3a1700333b4530783ce5c4361f9f /src | |
parent | 43f64d09ead908957d9a12b181443e67d388774e (diff) | |
download | tor-0d274e1db18473589658e098efdf682e304f01e7.tar.gz tor-0d274e1db18473589658e098efdf682e304f01e7.zip |
r13952@catbus: nickm | 2007-07-27 19:18:46 -0400
Weasel noticed that many buffers spend their time with empty 4k, 8k, and 16k memory chunks. Thus, be more aggressive about putting empty chunks on the freelist, regardless of their high water marks. (Also, run buffer_shrink_freelist on the 8k-chunk freelist.)
svn:r10953
Diffstat (limited to 'src')
-rw-r--r-- | src/or/buffers.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 05132fa196..c5d8b1c7d0 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -281,9 +281,9 @@ buf_get_initial_mem(buf_t *buf, size_t sz) void buf_shrink_freelists(int free_all) { - int j; - for (j = 0; j < 2; ++j) { - free_mem_list_t *list = j ? &free_mem_list_16k : &free_mem_list_4k; + int list_elt_size; + for (list_elt_size = 4096; list_elt_size <= 16384; list_elt_size *= 2) { + free_mem_list_t *list = get_free_mem_list(list_elt_size); if (list->lowwater > list->slack || free_all) { int i, n_to_skip, n_to_free; char **ptr; @@ -452,8 +452,16 @@ buf_shrink(buf_t *buf) size_t new_len; new_len = buf->len; - if (buf->datalen == 0 && buf->highwater == 0 && + /* Actually, we ignore highwater here if we're going to throw it on the + * freelist, since it's way cheaper to use the freelist than to use (some) + * platform mallocs. + * + * DOCDOC If it turns out to be a good idea, add it to the doxygen for this + * function. + */ + if (buf->datalen == 0 && // buf->highwater == 0 && IS_FREELIST_SIZE(buf->len)) { + buf->highwater = 0; if (add_buf_mem_to_freelist(buf)) return; } |