mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Make preferred_chunk_size nonstatic, and add a prefix to it
This commit is contained in:
parent
4bac93ba5d
commit
c0b9f594b6
@ -173,8 +173,8 @@ chunk_grow(chunk_t *chunk, size_t sz)
|
||||
|
||||
/** Return the allocation size we'd like to use to hold <b>target</b>
|
||||
* bytes. */
|
||||
STATIC size_t
|
||||
preferred_chunk_size(size_t target)
|
||||
size_t
|
||||
buf_preferred_chunk_size(size_t target)
|
||||
{
|
||||
tor_assert(target <= SIZE_T_CEILING - CHUNK_OVERHEAD);
|
||||
if (CHUNK_ALLOC_SIZE(target) >= MAX_CHUNK_ALLOC)
|
||||
@ -228,7 +228,7 @@ buf_pullup(buf_t *buf, size_t bytes, const char **head_out, size_t *len_out)
|
||||
size_t newsize;
|
||||
/* We need to grow the chunk. */
|
||||
chunk_repack(buf->head);
|
||||
newsize = CHUNK_SIZE_WITH_ALLOC(preferred_chunk_size(capacity));
|
||||
newsize = CHUNK_SIZE_WITH_ALLOC(buf_preferred_chunk_size(capacity));
|
||||
newhead = chunk_grow(buf->head, newsize);
|
||||
tor_assert(newhead->memlen >= capacity);
|
||||
if (newhead != buf->head) {
|
||||
@ -344,7 +344,7 @@ buf_t *
|
||||
buf_new_with_capacity(size_t size)
|
||||
{
|
||||
buf_t *b = buf_new();
|
||||
b->default_chunk_size = preferred_chunk_size(size);
|
||||
b->default_chunk_size = buf_preferred_chunk_size(size);
|
||||
return b;
|
||||
}
|
||||
|
||||
@ -469,7 +469,7 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
|
||||
} else if (capped && CHUNK_ALLOC_SIZE(capacity) > MAX_CHUNK_ALLOC) {
|
||||
chunk = chunk_new_with_alloc_size(MAX_CHUNK_ALLOC);
|
||||
} else {
|
||||
chunk = chunk_new_with_alloc_size(preferred_chunk_size(capacity));
|
||||
chunk = chunk_new_with_alloc_size(buf_preferred_chunk_size(capacity));
|
||||
}
|
||||
|
||||
chunk->inserted_time = (uint32_t)monotime_coarse_absolute_msec();
|
||||
|
@ -67,7 +67,7 @@ void buf_pullup(buf_t *buf, size_t bytes,
|
||||
#ifdef TOR_UNIT_TESTS
|
||||
buf_t *buf_new_with_data(const char *cp, size_t sz);
|
||||
#endif
|
||||
ATTR_UNUSED STATIC size_t preferred_chunk_size(size_t target);
|
||||
size_t buf_preferred_chunk_size(size_t target);
|
||||
|
||||
#define DEBUG_CHUNK_ALLOC
|
||||
/** A single chunk on a buffer. */
|
||||
|
@ -783,17 +783,17 @@ test_buffers_chunk_size(void *arg)
|
||||
(void)arg;
|
||||
const int min = 256;
|
||||
const int max = 65536;
|
||||
tt_uint_op(preferred_chunk_size(3), OP_EQ, min);
|
||||
tt_uint_op(preferred_chunk_size(25), OP_EQ, min);
|
||||
tt_uint_op(preferred_chunk_size(0), OP_EQ, min);
|
||||
tt_uint_op(preferred_chunk_size(256), OP_EQ, 512);
|
||||
tt_uint_op(preferred_chunk_size(65400), OP_EQ, max);
|
||||
tt_uint_op(buf_preferred_chunk_size(3), OP_EQ, min);
|
||||
tt_uint_op(buf_preferred_chunk_size(25), OP_EQ, min);
|
||||
tt_uint_op(buf_preferred_chunk_size(0), OP_EQ, min);
|
||||
tt_uint_op(buf_preferred_chunk_size(256), OP_EQ, 512);
|
||||
tt_uint_op(buf_preferred_chunk_size(65400), OP_EQ, max);
|
||||
/* Here, we're implicitly saying that the chunk header overhead is
|
||||
* between 1 and 100 bytes. 24..48 would probably be more accurate. */
|
||||
tt_uint_op(preferred_chunk_size(65536), OP_GT, 65536);
|
||||
tt_uint_op(preferred_chunk_size(65536), OP_LT, 65536+100);
|
||||
tt_uint_op(preferred_chunk_size(165536), OP_GT, 165536);
|
||||
tt_uint_op(preferred_chunk_size(165536), OP_LT, 165536+100);
|
||||
tt_uint_op(buf_preferred_chunk_size(65536), OP_GT, 65536);
|
||||
tt_uint_op(buf_preferred_chunk_size(65536), OP_LT, 65536+100);
|
||||
tt_uint_op(buf_preferred_chunk_size(165536), OP_GT, 165536);
|
||||
tt_uint_op(buf_preferred_chunk_size(165536), OP_LT, 165536+100);
|
||||
done:
|
||||
;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user