summaryrefslogtreecommitdiffstats
path: root/src/arena.c
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2016-10-11 05:15:10 (GMT)
committerJason Evans <jasone@canonware.com>2016-10-11 05:15:10 (GMT)
commit5f11fb7d43795e9e2f5d72c8a43a042baaee9b63 (patch)
tree24e3b4aeb23578b483b46f9804d0a6545aac5a8b /src/arena.c
parentee0c74b77a24dc4fdaad2c950bcf621b6fa54095 (diff)
downloadjemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.zip
jemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.tar.gz
jemalloc-5f11fb7d43795e9e2f5d72c8a43a042baaee9b63.tar.bz2
Do not advance decay epoch when time goes backwards.
Instead, move the epoch backward in time. Additionally, add nstime_monotonic() and use it in debug builds to assert that time only goes backward if nstime_update() is using a non-monotonic time source.
Diffstat (limited to 'src/arena.c')
-rw-r--r--src/arena.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/arena.c b/src/arena.c
index 9750208..f53a464 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -693,10 +693,23 @@ arena_maybe_purge_decay(tsdn_t *tsdn, arena_t *arena)
return;
}
- nstime_copy(&time, &arena->decay.epoch);
- if (unlikely(nstime_update(&time))) {
- /* Time went backwards. Force an epoch advance. */
- nstime_copy(&time, &arena->decay.deadline);
+ nstime_init(&time, 0);
+ nstime_update(&time);
+ if (unlikely(!nstime_monotonic() && nstime_compare(&arena->decay.epoch,
+ &time) > 0)) {
+ /*
+ * Time went backwards. Move the epoch back in time, with the
+ * expectation that time typically flows forward for long enough
+ * periods of time that epochs complete. Unfortunately,
+ * this strategy is susceptible to clock jitter triggering
+ * premature epoch advances, but clock jitter estimation and
+ * compensation isn't feasible here because calls into this code
+ * are event-driven.
+ */
+ nstime_copy(&arena->decay.epoch, &time);
+ } else {
+ /* Verify that time does not go backwards. */
+ assert(nstime_compare(&arena->decay.epoch, &time) <= 0);
}
if (arena_decay_deadline_reached(arena, &time))