From 589cb500fa5a6df13fa9634d0071922ec11fce17 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 7 Nov 2026 19:39:01 +0100 Subject: 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. --- src/ot_stats.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/ot_stats.c') 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 for (bucket = 0; bucket < OT_BUCKET_COUNT; ++bucket) { ot_vector *torrents_list = mutex_bucket_lock(bucket); for (i = 0; i < torrents_list->size; ++i) { - ot_peerlist *peer_list = (((ot_torrent *)(torrents_list->data))[i]).peer_list4; + ot_peerlist *peer_list = (((ot_torrent *)(torrents_list->data))[i]).peer_list; ot_vector *bucket_list; int num_buckets = 1; if (!peer_list) continue; - bucket_list = &peer_list->peers; + bucket_list = &peer_list->peers4; /* /24 networks are an IPv4 notion */ - if (OT_PEERLIST_HASBUCKETS(peer_list)) { + if (OT_VECTOR_HASBUCKETS(bucket_list)) { num_buckets = bucket_list->size; bucket_list = (ot_vector *)bucket_list->data; } @@ -303,8 +303,8 @@ typedef struct { static int torrent_statter(ot_torrent *torrent, uintptr_t data) { torrent_stats *stats = (torrent_stats *)data; stats->torrent_count++; - stats->peer_count += peerlist_peer_count(torrent->peer_list6) + peerlist_peer_count(torrent->peer_list4); - stats->seed_count += peerlist_seed_count(torrent->peer_list6) + peerlist_seed_count(torrent->peer_list4); + stats->peer_count += torrent_peer_count(torrent); + stats->seed_count += torrent_seed_count(torrent); return 0; } @@ -347,8 +347,8 @@ void stats_top_txt(char **reply, const char *reply_end, size_t amount) { ot_vector *torrents_list = mutex_bucket_lock(bucket); for (j = 0; j < torrents_list->size; ++j) { ot_torrent *torrent = (ot_torrent *)(torrents_list->data) + j; - size_t peer_count = peerlist_peer_count(torrent->peer_list6) + peerlist_peer_count(torrent->peer_list4); - size_t seed_count = peerlist_seed_count(torrent->peer_list6) + peerlist_seed_count(torrent->peer_list4); + size_t peer_count = torrent_peer_count(torrent); + size_t seed_count = torrent_seed_count(torrent); size_t leech_count = peer_count - seed_count; stats_insert_into_highscore(peer_count, top100c, amount, &torrent->hash); -- cgit v1.3