From 95060eacaeae4a32f0c478ca27f81e48d5daee8b Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 7 Sep 2018 19:31:53 -0400 Subject: [PATCH 1/2] Use networkstatus_read_cached_consensus() for GETINFO We already had fallback code for "dir/status-vote/current/consensus" to read from disk if we didn't have a cached_dir_t available. But there's a function in networkstatus_t that does it for us, so let's do that. --- src/feature/control/control.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/feature/control/control.c b/src/feature/control/control.c index 9e7d21308e..507afb9505 100644 --- a/src/feature/control/control.c +++ b/src/feature/control/control.c @@ -2341,9 +2341,7 @@ getinfo_helper_dir(control_connection_t *control_conn, *answer = tor_strdup(consensus->dir); } if (!*answer) { /* try loading it from disk */ - char *filename = get_cachedir_fname("cached-consensus"); - *answer = read_file_to_str(filename, RFTS_IGNORE_MISSING, NULL); - tor_free(filename); + *answer = networkstatus_read_cached_consensus("ns"); if (!*answer) { /* generate an error */ *errmsg = "Could not open cached consensus. " "Make sure FetchUselessDescriptors is set to 1."; From 33a0c619a8f44cacb400eccc4ab6192d330465c6 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 7 Sep 2018 19:45:01 -0400 Subject: [PATCH 2/2] Do not store cached_dir_t for consensus in RAM if not a dircache. There are three reasons we use a cached_dir_t to hold a consensus: 1. to serve that consensus to a client 2. to apply a consensus diff to an existing consensus 3. to send the consensus to a controller. But case 1 is dircache-only. Case 2 and case 3 both fall back to networkstatus_read_cached_consensus(). So there's no reason for us to store this as a client. Avoiding this saves about 23% of our RAM usage, according to our experiments last month. This is, semantically, a partial revert of e5c608e535ef9a4c4fe951a2. Fixes bug 27247; bugfix on 0.3.0.1-alpha. --- changes/ticket27247 | 5 +++++ src/feature/nodelist/networkstatus.c | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 changes/ticket27247 diff --git a/changes/ticket27247 b/changes/ticket27247 new file mode 100644 index 0000000000..e980913d32 --- /dev/null +++ b/changes/ticket27247 @@ -0,0 +1,5 @@ + o Minor bugfixes (client, memory usage): + - When not running as a directory cache, there is no need to store the + text of the current consensus networkstatus in RAM. Previously, + however, clients would store this anyway, at a cost of over 5 MB. + Now, they do not. Fixes bug 27247; bugfix on 0.3.0.1-alpha. diff --git a/src/feature/nodelist/networkstatus.c b/src/feature/nodelist/networkstatus.c index 6492b828b1..4af2021663 100644 --- a/src/feature/nodelist/networkstatus.c +++ b/src/feature/nodelist/networkstatus.c @@ -2098,12 +2098,13 @@ networkstatus_set_current_consensus(const char *consensus, } if (we_want_to_fetch_flavor(options, flav)) { - dirserv_set_cached_consensus_networkstatus(consensus, - flavor, - &c->digests, - c->digest_sha3_as_signed, - c->valid_after); if (dir_server_mode(get_options())) { + dirserv_set_cached_consensus_networkstatus(consensus, + flavor, + &c->digests, + c->digest_sha3_as_signed, + c->valid_after); + consdiffmgr_add_consensus(consensus, c); } }