Commit 5c45a333 authored by Nick Mathewson's avatar Nick Mathewson 🥔
Browse files

Merge remote-tracking branch 'public/bug10169_023' into bug10169_024

Conflicts:
	doc/tor.1.txt
	src/or/config.c
	src/or/or.h

The conflicts were all pretty trivial.
parents 35115496 64724872
Loading
Loading
Loading
Loading

changes/bug10169

0 → 100644
+4 −0
Original line number Diff line number Diff line
  o Major features:
    - Also consider stream buffer sizes when calculating OOM
      conditions. Rename MaxMemInCellQueues to MaxMemInQueues. Fixes
      bug 10169.

changes/bug9686

0 → 100644
+3 −0
Original line number Diff line number Diff line
  o Minor changes:
    - Decrease the lower limit of MaxMemInQueues to 256 MBytes, to
      appease raspberry pi users. Fixes bug 9686.
 No newline at end of file
+5 −5
Original line number Diff line number Diff line
@@ -1679,13 +1679,13 @@ is non-zero):
    localhost, RFC1918 addresses, and so on. This can create security issues;
    you should probably leave it off. (Default: 0)

[[MaxMemInCellQueues]] **MaxMemInCellQueues**  __N__ **bytes**|**KB**|**MB**|**GB**::
[[MaxMemInQueues]] **MaxMemInQueues**  __N__ **bytes**|**KB**|**MB**|**GB**::
    This option configures a threshold above which Tor will assume that it
    needs to stop queueing cells because it's about to run out of memory.
    If it hits this threshold, it will begin killing circuits until it
    has recovered at least 10% of this memory.  Do not set this option too
    needs to stop queueing or buffering data because it's about to run out of
    memory.  If it hits this threshold, it will begin killing circuits until
    it has recovered at least 10% of this memory.  Do not set this option too
    low, or your relay may be unreliable under load.  This option only
    affects circuit queues, so the actual process size will be larger than
    affects some queues, so the actual process size will be larger than
    this. (Default: 8GB)

DIRECTORY SERVER OPTIONS
+42 −1
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@ typedef struct chunk_t {
  size_t datalen; /**< The number of bytes stored in this chunk */
  size_t memlen; /**< The number of usable bytes of storage in <b>mem</b>. */
  char *data; /**< A pointer to the first byte of data stored in <b>mem</b>. */
  uint32_t inserted_time; /**< Timestamp in truncated ms since epoch
                           * when this chunk was inserted. */
  char mem[FLEXIBLE_ARRAY_MEMBER]; /**< The actual memory used for storage in
                * this chunk. */
} chunk_t;
@@ -140,6 +142,9 @@ static chunk_freelist_t freelists[] = {
 * could help with? */
static uint64_t n_freelist_miss = 0;

/** DOCDOC */
static size_t total_bytes_allocated_in_chunks = 0;

static void assert_freelist_ok(chunk_freelist_t *fl);

/** Return the freelist to hold chunks of size <b>alloc</b>, or NULL if
@@ -173,6 +178,8 @@ chunk_free_unchecked(chunk_t *chunk)
  } else {
    if (freelist)
      ++freelist->n_free;
    tor_assert(total_bytes_allocated_in_chunks >= alloc);
    total_bytes_allocated_in_chunks -= alloc;
    tor_free(chunk);
  }
}
@@ -199,6 +206,7 @@ chunk_new_with_alloc_size(size_t alloc)
    else
      ++n_freelist_miss;
    ch = tor_malloc(alloc);
    total_bytes_allocated_in_chunks += alloc;
  }
  ch->next = NULL;
  ch->datalen = 0;
@@ -210,6 +218,10 @@ chunk_new_with_alloc_size(size_t alloc)
static void
chunk_free_unchecked(chunk_t *chunk)
{
  if (!chunk)
    return;
  tor_assert(total_bytes_allocated_in_chunks >= CHUNK_ALLOC_SIZE(chunk->memlen));
  total_bytes_allocated_in_chunks -= CHUNK_ALLOC_SIZE(chunk->memlen);
  tor_free(chunk);
}
static INLINE chunk_t *
@@ -220,6 +232,7 @@ chunk_new_with_alloc_size(size_t alloc)
  ch->next = NULL;
  ch->datalen = 0;
  ch->memlen = CHUNK_SIZE_WITH_ALLOC(alloc);
  total_bytes_allocated_in_chunks += alloc;
  ch->data = &ch->mem[0];
  return ch;
}
@@ -236,6 +249,7 @@ chunk_grow(chunk_t *chunk, size_t sz)
  chunk = tor_realloc(chunk, CHUNK_ALLOC_SIZE(sz));
  chunk->memlen = sz;
  chunk->data = chunk->mem + offset;
  total_bytes_allocated_in_chunks += (sz - chunk->memlen);
  return chunk;
}

@@ -297,6 +311,8 @@ buf_shrink_freelists(int free_all)
      *chp = NULL;
      while (chunk) {
        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);
        tor_free(chunk);
        chunk = next;
        --n_to_free;
@@ -530,7 +546,7 @@ buf_allocation(const buf_t *buf)
  size_t total = 0;
  const chunk_t *chunk;
  for (chunk = buf->head; chunk; chunk = chunk->next) {
    total += chunk->memlen;
    total += CHUNK_ALLOC_SIZE(chunk->memlen);
  }
  return total;
}
@@ -598,6 +614,7 @@ static chunk_t *
buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
{
  chunk_t *chunk;
  struct timeval now;
  if (CHUNK_ALLOC_SIZE(capacity) < buf->default_chunk_size) {
    chunk = chunk_new_with_alloc_size(buf->default_chunk_size);
  } else if (capped && CHUNK_ALLOC_SIZE(capacity) > MAX_CHUNK_ALLOC) {
@@ -605,6 +622,10 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
  } else {
    chunk = chunk_new_with_alloc_size(preferred_chunk_size(capacity));
  }

  tor_gettimeofday_cached(&now);
  chunk->inserted_time = (uint32_t)tv_to_msec(&now);

  if (buf->tail) {
    tor_assert(buf->head);
    buf->tail->next = chunk;
@@ -617,6 +638,26 @@ buf_add_chunk_with_capacity(buf_t *buf, size_t capacity, int capped)
  return chunk;
}

/** Return the age of the oldest chunk in the buffer <b>buf</b>, in
 * milliseconds.  Requires the current time, in truncated milliseconds since
 * the epoch, as its input <b>now</b>.
 */
uint32_t
buf_get_oldest_chunk_timestamp(const buf_t *buf, uint32_t now)
{
  if (buf->head) {
    return now - buf->head->inserted_time;
  } else {
    return 0;
  }
}

size_t
buf_get_total_allocation(void)
{
  return total_bytes_allocated_in_chunks;
}

/** Read up to <b>at_most</b> bytes from the socket <b>fd</b> into
 * <b>chunk</b> (which must be on <b>buf</b>). If we get an EOF, set
 * *<b>reached_eof</b> to 1.  Return -1 on error, 0 on eof or blocking,
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ size_t buf_datalen(const buf_t *buf);
size_t buf_allocation(const buf_t *buf);
size_t buf_slack(const buf_t *buf);

uint32_t buf_get_oldest_chunk_timestamp(const buf_t *buf, uint32_t now);
size_t buf_get_total_allocation(void);

int read_to_buf(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof,
                int *socket_error);
int read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf);
Loading