diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-07 19:39:01 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-07 19:39:01 +0100 |
| commit | 589cb500fa5a6df13fa9634d0071922ec11fce17 (patch) | |
| tree | fa5fc07d6d13d7b241d884441d3d22c1d0189d87 /src/ot_stats.c | |
| parent | 1e7248b330bde4c70528ccf91535391e19294dc3 (diff) | |
Unify the peerlists for v4 and v6
This commit finishes what started with unifying v4 and v6 trackers, from then on, torrents
carried a peer list per family, with obvious redundancies. With the race to save memory,
these became burdening enough that now these peerlist pointers have been moved into a
single struct, holding both v4 and v6 peers in their respective ot_vectors, so the per-
torrent cost shrunk by another pointer's size.
Each peerlist also lost its peer count cache, as in most cases, it's trivial to load it
directly from the ot_vector's entry count. The seed counts that were kept per family only
to be aggregated later for every consumer, are also merged now.
Total savings depend on the tracker's actual load. In some corner cases, where only one
address family dominates the torrents, we actually use a few bytes more in the ot_vector
for the absent family, but even that mostly becomes noise: before it actually adds to the
memory load, the peer payload will be the deciding factor.
Most wins are on what often is experienced on trackers: A long tail of abandoned torrents
now needs eight fewer bytes, slipping into a smaller allocation unit on glibc's allocator.
Diffstat (limited to 'src/ot_stats.c')
| -rw-r--r-- | src/ot_stats.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/ot_stats.c b/src/ot_stats.c index 9e2eabe..0e2fc67 100644 --- a/src/ot_stats.c +++ b/src/ot_stats.c | |||
| @@ -243,15 +243,15 @@ static void stats_slash24s_txt(char **reply, const char *reply_end, size_t amoun | |||
| 243 | for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { | 243 | for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { |
| 244 | ot_vector *torrents_list = mutex_bucket_lock(bucket); | 244 | ot_vector *torrents_list = mutex_bucket_lock(bucket); |
| 245 | for (i = 0; i < torrents_list->size; ++i) { | 245 | for (i = 0; i < torrents_list->size; ++i) { |
| 246 | ot_peerlist *peer_list = (((ot_torrent *)(torrents_list->data))[i]).peer_list4; | 246 | ot_peerlist *peer_list = (((ot_torrent *)(torrents_list->data))[i]).peer_list; |
| 247 | ot_vector *bucket_list; | 247 | ot_vector *bucket_list; |
| 248 | int num_buckets = 1; | 248 | int num_buckets = 1; |
| 249 | 249 | ||
| 250 | if (!peer_list) | 250 | if (!peer_list) |
| 251 | continue; | 251 | continue; |
| 252 | bucket_list = &peer_list->peers; | 252 | bucket_list = &peer_list->peers4; /* /24 networks are an IPv4 notion */ |
| 253 | 253 | ||
| 254 | if (OT_PEERLIST_HASBUCKETS(peer_list)) { | 254 | if (OT_VECTOR_HASBUCKETS(bucket_list)) { |
| 255 | num_buckets = bucket_list->size; | 255 | num_buckets = bucket_list->size; |
| 256 | bucket_list = (ot_vector *)bucket_list->data; | 256 | bucket_list = (ot_vector *)bucket_list->data; |
| 257 | } | 257 | } |
| @@ -303,8 +303,8 @@ typedef struct { | |||
| 303 | static int torrent_statter(ot_torrent *torrent, uintptr_t data) { | 303 | static int torrent_statter(ot_torrent *torrent, uintptr_t data) { |
| 304 | torrent_stats *stats = (torrent_stats *)data; | 304 | torrent_stats *stats = (torrent_stats *)data; |
| 305 | stats->torrent_count++; | 305 | stats->torrent_count++; |
| 306 | stats->peer_count += peerlist_peer_count(torrent->peer_list6) + peerlist_peer_count(torrent->peer_list4); | 306 | stats->peer_count += torrent_peer_count(torrent); |
| 307 | stats->seed_count += peerlist_seed_count(torrent->peer_list6) + peerlist_seed_count(torrent->peer_list4); | 307 | stats->seed_count += torrent_seed_count(torrent); |
| 308 | return 0; | 308 | return 0; |
| 309 | } | 309 | } |
| 310 | 310 | ||
| @@ -347,8 +347,8 @@ void stats_top_txt(char **reply, const char *reply_end, size_t amount) { | |||
| 347 | ot_vector *torrents_list = mutex_bucket_lock(bucket); | 347 | ot_vector *torrents_list = mutex_bucket_lock(bucket); |
| 348 | for (j = 0; j < torrents_list->size; ++j) { | 348 | for (j = 0; j < torrents_list->size; ++j) { |
| 349 | ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j; | 349 | ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j; |
| 350 | size_t peer_count = peerlist_peer_count(torrent->peer_list6) + peerlist_peer_count(torrent->peer_list4); | 350 | size_t peer_count = torrent_peer_count(torrent); |
| 351 | size_t seed_count = peerlist_seed_count(torrent->peer_list6) + peerlist_seed_count(torrent->peer_list4); | 351 | size_t seed_count = torrent_seed_count(torrent); |
| 352 | size_t leech_count = peer_count - seed_count; | 352 | size_t leech_count = peer_count - seed_count; |
| 353 | 353 | ||
| 354 | stats_insert_into_highscore(peer_count, top100c, amount, &torrent->hash); | 354 | stats_insert_into_highscore(peer_count, top100c, amount, &torrent->hash); |
