diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-02 20:39:26 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-11-02 20:39:26 +0100 |
| commit | 8f520e52d7d4081a0835374c7a448116baac64ab (patch) | |
| tree | fdb3c2e8d49aa8c94d6fff357ef2d18f3e0e553c /ot_clean.c | |
| parent | 7419a9524754dfc4222de2c4e4c22808b571477d (diff) | |
Turn the bucket count into a knob, but keep cleaner wake-ups at a constant rate
Diffstat (limited to 'ot_clean.c')
| -rw-r--r-- | ot_clean.c | 38 |
1 files changed, 23 insertions, 15 deletions
| @@ -125,26 +125,34 @@ static void clean_sleep(void) { | |||
| 125 | pthread_mutex_unlock(&g_clean_mutex); | 125 | pthread_mutex_unlock(&g_clean_mutex); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | /* Clean up all peers in current bucket, remove timedout pools and | 128 | /* Clean up all peers in one bucket, remove timedout pools and torrents */ |
| 129 | torrents */ | 129 | static void clean_bucket(size_t bucket) { |
| 130 | ot_vector *torrents_list = mutex_bucket_lock((int)bucket); | ||
| 131 | size_t toffs; | ||
| 132 | int delta_torrentcount = 0; | ||
| 133 | |||
| 134 | for (toffs = 0; toffs < torrents_list->size; ++toffs) { | ||
| 135 | ot_torrent *torrent = ((ot_torrent *)(torrents_list->data)) + toffs; | ||
| 136 | if (clean_single_torrent(torrent)) { | ||
| 137 | vector_remove_torrent(torrents_list, torrent); | ||
| 138 | --delta_torrentcount; | ||
| 139 | --toffs; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | mutex_bucket_unlock((int)bucket, delta_torrentcount); | ||
| 143 | } | ||
| 144 | |||
| 130 | static void *clean_worker(void *args) { | 145 | static void *clean_worker(void *args) { |
| 131 | (void)args; | 146 | (void)args; |
| 132 | while (1) { | 147 | while (1) { |
| 133 | size_t bucket = OT_BUCKET_COUNT; | 148 | size_t bucket = OT_BUCKET_COUNT; |
| 134 | while (bucket--) { | 149 | while (bucket) { |
| 135 | ot_vector *torrents_list = mutex_bucket_lock(bucket); | 150 | size_t todo = bucket < OT_CLEAN_BUCKETS_PER_WAKE ? bucket : OT_CLEAN_BUCKETS_PER_WAKE; |
| 136 | size_t toffs; | 151 | |
| 137 | int delta_torrentcount = 0; | 152 | /* One bucket is locked at a time, however many a wake gets through */ |
| 153 | while (todo--) | ||
| 154 | clean_bucket(--bucket); | ||
| 138 | 155 | ||
| 139 | for (toffs = 0; toffs < torrents_list->size; ++toffs) { | ||
| 140 | ot_torrent *torrent = ((ot_torrent *)(torrents_list->data)) + toffs; | ||
| 141 | if (clean_single_torrent(torrent)) { | ||
| 142 | vector_remove_torrent(torrents_list, torrent); | ||
| 143 | --delta_torrentcount; | ||
| 144 | --toffs; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | mutex_bucket_unlock(bucket, delta_torrentcount); | ||
| 148 | if (!g_opentracker_running) | 156 | if (!g_opentracker_running) |
| 149 | return NULL; | 157 | return NULL; |
| 150 | clean_sleep(); | 158 | clean_sleep(); |
