Skip to content

Synchronize background process actions disable in malloc_extension_test. - #1054

Draft
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_985542030
Draft

copybara-service[bot] wants to merge 1 commit into
masterfrom
test_985542030

Conversation

@copybara-service

Copy link
Copy Markdown

Synchronize background process actions disable in malloc_extension_test.

In malloc_extension_test (21.6s max duration in -c dbg, 8.34s in -c opt):

  • DynamicSlabMallocMetadata (5.03s) instantiates ScopedBackgroundProcessActionsEnabled background(false), which previously called absl::SleepFor(absl::Seconds(5)) to wait for any active background thread iteration to complete.
  • CpuCacheFlags (3.31s) toggles CPU cache parameters across background thread iterations.

Guard MallocExtension_Internal_SetBackgroundProcessActionsEnabled with the same mutex (background_mutex) held by MallocExtension_Internal_ProcessBackgroundActions, and replace absl::SleepFor(sleep_time) in the background loop with background_mutex.AwaitWithTimeout(..., sleep_time). This guarantees that SetBackgroundProcessActionsEnabled(false) waits for any in-flight background action to complete and immediately wakes up any sleeping background thread without needing an arbitrary 5-second sleep in ScopedBackgroundProcessActionsEnabled.

This reduces execution time across all unsharded malloc_extension_test variants from 21.6s to 1.63s in -c dbg (0.72s in -c fastbuild, 0.64s in -c opt) with 0 flakes across 300 runs (100/100 in -c dbg, -c fastbuild, and -c opt under blase --configs=none).

In `malloc_extension_test` (`21.6s` max duration in `-c dbg`, `8.34s` in `-c opt`):
- `DynamicSlabMallocMetadata` (`5.03s`) instantiates `ScopedBackgroundProcessActionsEnabled background(false)`, which previously called `absl::SleepFor(absl::Seconds(5))` to wait for any active background thread iteration to complete.
- `CpuCacheFlags` (`3.31s`) toggles CPU cache parameters across background thread iterations.

Guard `MallocExtension_Internal_SetBackgroundProcessActionsEnabled` with the same mutex (`background_mutex`) held by `MallocExtension_Internal_ProcessBackgroundActions`, and replace `absl::SleepFor(sleep_time)` in the background loop with `background_mutex.AwaitWithTimeout(..., sleep_time)`. This guarantees that `SetBackgroundProcessActionsEnabled(false)` waits for any in-flight background action to complete and immediately wakes up any sleeping background thread without needing an arbitrary 5-second sleep in `ScopedBackgroundProcessActionsEnabled`.

This reduces execution time across all unsharded `malloc_extension_test` variants from `21.6s` to `1.63s` in `-c dbg` (`0.72s` in `-c fastbuild`, `0.64s` in `-c opt`) with 0 flakes across 300 runs (`100/100` in `-c dbg`, `-c fastbuild`, and `-c opt` under `blase --configs=none`).

PiperOrigin-RevId: 985542030
@google-cla

google-cla Bot commented Sep 21, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants