diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-12-26 00:12:08 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-12-26 00:12:08 +0000 |
commit | a7ef07b4bd3a4a3ba66336601e5a27649cb923d9 (patch) | |
tree | 7a38a26ea71a0ead464c54d0b8d58ec7330877f8 /src/or/connection.c | |
parent | 1401bc54f4b8aeeea21950ad20e8d79ffc87ba0b (diff) | |
download | tor-a7ef07b4bd3a4a3ba66336601e5a27649cb923d9.tar.gz tor-a7ef07b4bd3a4a3ba66336601e5a27649cb923d9.zip |
r15693@tombo: nickm | 2007-12-25 19:11:29 -0500
Here, have some terribly clever new buffer code. It uses a mbuf-like strategy rather than a ring buffer strategy, so it should require far far less extra memory to hold any given amount of data. Also, it avoids access patterns like x=malloc(1024);x=realloc(x,1048576);x=realloc(x,1024);append_to_freelist(x) that might have been contributing to memory fragmentation. I've tested it out a little on peacetime, and it seems to work so far. If you want to benchmark it for speed, make sure to remove the #define PARANOIA; #define NOINLINE macros at the head of the module.
svn:r12983
Diffstat (limited to 'src/or/connection.c')
-rw-r--r-- | src/or/connection.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/or/connection.c b/src/or/connection.c index ba0bd63e7a..69b3f75360 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -1873,7 +1873,7 @@ static int connection_read_to_buf(connection_t *conn, int *max_to_read) { int result, at_most = *max_to_read; - size_t bytes_in_buf, more_to_read; + size_t slack_in_buf, more_to_read; size_t n_read = 0, n_written = 0; if (at_most == -1) { /* we need to initialize it */ @@ -1882,11 +1882,11 @@ connection_read_to_buf(connection_t *conn, int *max_to_read) at_most = connection_bucket_read_limit(conn, time(NULL)); } - bytes_in_buf = buf_capacity(conn->inbuf) - buf_datalen(conn->inbuf); + slack_in_buf = buf_slack(conn->inbuf); again: - if ((size_t)at_most > bytes_in_buf && bytes_in_buf >= 1024) { - more_to_read = at_most - bytes_in_buf; - at_most = bytes_in_buf; + if ((size_t)at_most > slack_in_buf && slack_in_buf >= 1024) { + more_to_read = at_most - slack_in_buf; + at_most = slack_in_buf; } else { more_to_read = 0; } @@ -1997,8 +1997,7 @@ connection_read_to_buf(connection_t *conn, int *max_to_read) connection_buckets_decrement(conn, time(NULL), n_read, n_written); if (more_to_read && result == at_most) { - bytes_in_buf = buf_capacity(conn->inbuf) - buf_datalen(conn->inbuf); - tor_assert(bytes_in_buf < 1024); + slack_in_buf = buf_slack(conn->inbuf); at_most = more_to_read; goto again; } @@ -2785,11 +2784,11 @@ connection_dump_buffer_mem_stats(int severity) ++n_conns_by_type[tp]; if (c->inbuf) { used_by_type[tp] += buf_datalen(c->inbuf); - alloc_by_type[tp] += buf_capacity(c->inbuf); + alloc_by_type[tp] += buf_allocation(c->inbuf); } if (c->outbuf) { used_by_type[tp] += buf_datalen(c->outbuf); - alloc_by_type[tp] += buf_capacity(c->outbuf); + alloc_by_type[tp] += buf_allocation(c->outbuf); } }); for (i=0; i <= _CONN_TYPE_MAX; ++i) { |