From c72a0810c0ebe0635db426675d33adcce2f96b9c Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Wed, 12 Jun 2024 08:18:52 -0600 Subject: [PATCH] shrink string cache reset threshold a bit A slow ramp up to 4 MiB could _look_ like a memory leak. However, a slow ramp to 2 MiB is probably going to look like it's within normal operating ranges. --- profiling/src/profiling/stack_walking.rs | 6 ++++-- profiling/src/string_set.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/profiling/src/profiling/stack_walking.rs b/profiling/src/profiling/stack_walking.rs index fe914b00079..339dedb899a 100644 --- a/profiling/src/profiling/stack_walking.rs +++ b/profiling/src/profiling/stack_walking.rs @@ -172,8 +172,10 @@ mod detail { CACHED_STRINGS.with(|cell| { let set: &StringSet = &cell.borrow(); let arena_used_bytes = set.arena_used_bytes(); - // todo: pin down threshold - let threshold = 4 * 1024 * 1024; + // A slow ramp up to 2 MiB is probably _not_ going to look like + // a memory leak, whereas a higher threshold could make a user + // suspect a leak. + let threshold = 2 * 1024 * 1024; if arena_used_bytes > threshold { debug!("string cache arena is using {arena_used_bytes} bytes which exceeds the {threshold} byte threshold, resetting"); // Note that this cannot be done _during_ a request. The diff --git a/profiling/src/string_set.rs b/profiling/src/string_set.rs index d35352b18df..5a8a89fa01d 100644 --- a/profiling/src/string_set.rs +++ b/profiling/src/string_set.rs @@ -35,7 +35,7 @@ impl StringSet { // Keep this in the megabyte range. It's virtual, so we do not need // to worry much about unused amounts, but asking for wildly too much // up front, like in gigabyte+ range, is not good either. - const SIZE_HINT: usize = 4 * 1024 * 1024; + const SIZE_HINT: usize = 2 * 1024 * 1024; let arena = ChainAllocator::new_in(SIZE_HINT, VirtualAllocator {}); let mut strings = HashSet::with_hasher(Hasher::default());