Skip to content

Centralize allocator size-class lists - #14329

Merged
tclinkenbeard-oai merged 2 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/centralize-allocator-size-lists
Oct 22, 2026
Merged

tclinkenbeard-oai merged 2 commits into
apple:mainfrom
tclinkenbeard-oai:dev/tclinkenbeard/centralize-allocator-size-lists

Conversation

@tclinkenbeard-oai

@tclinkenbeard-oai tclinkenbeard-oai commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

FastAllocator's explicit instantiations, unused-memory sum, total-memory sum, and MemoryMetrics fields repeat the same twelve size classes. Define them once in a constexpr array and use an index-sequence template visitor for the accounting and trace fields.

Explicit class instantiations reference the same array by index, with a size assertion guarding their coverage. Retaining explicit instantiation preserves the early thread-local initializer. The visitor preserves getter order and accumulator types; MemoryMetrics keeps its field names and emits before aggregate accounting. Allocation dispatch and the separate MemSample instrumentation path are unchanged. No new macros are introduced.

Validation:

  • Source checks confirm the original twelve sizes, their order, instantiation coverage, and metric field names.
  • Changed-line clang-format 19 and git diff --check pass; independent source review found no issues.
  • Compilation and flow_test remain unrun because the remote validation environment is unavailable.

@tclinkenbeard-oai
tclinkenbeard-oai marked this pull request as ready for review October 20, 2026 17:24

@tclinkenbeard-oai tclinkenbeard-oai left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated by Codex.

What problem is this PR trying to solve? (ELI10)

FoundationDB keeps memory in twelve sizes of “bins.” Four places repeat the list of bin sizes: allocator instantiation, unused-memory accounting, total-memory accounting, and monitoring.

This creates maintenance risk. Illustratively, adding a size to the allocator but forgetting it in the accounting list could make memory reports incomplete. The existing monitoring code shows that duplication; this PR does not establish an existing accounting bug.

How does this PR solve the problem? (ELI10 and review walkthrough)

It gives those four places one shared list. A future update to that list feeds both accounting and monitoring, while a compile-time check reminds developers to update allocator instantiations.

  1. Define the sizes and visit them in order. The shared array and visitor preserve all twelve sizes. The comma fold calls the supplied operation once per size, synchronously and in order.

  2. Keep allocator initialization intact. The explicit class instantiations still request the same specializations. This preserves initialization of allocator state belonging to each thread.

  3. Produce the same monitoring fields. When system monitoring runs outside simulation, the new reporting block generates the existing field names for every size. Its scope ends before aggregate accounting, preserving when the event is emitted.

  4. Sum the same quantities. Total-memory accounting and unused-memory accounting retain their accumulator types and getter order.

What is it trying to do?

Centralize repeated allocator size lists without changing allocation dispatch, accounting semantics, or the memory metrics schema.

Is it correct?

Yes, based on inspection of head b42f6c53b97c68bd50cedc3e4164d42a2211ae28 against base f314e81f8ee1d2eeff4a35d4d658c47287f08e89.

The visitor preserves sequencing and reference lifetimes. Explicit instantiations preserve the existing thread-local initialization mechanism. Generated field names match the previous literals, and TraceEvent takes ownership of string keys, so temporary formatted names remain safe.

Accounting units, locks, assertions, and simulation hooks are unchanged. The project’s C++20 requirement supports the template syntax.

I ran no builds, tests, or simulation. At review time, clang-format passed; clang-tidy, the Windows Boost check, and FoundationDB build/cluster checks remained pending. No failing checks were visible.

Are there bugs?

I did not find any correctness bugs after checking compatibility, runtime cost, lifetimes, initialization, preserved invariants, and coverage.

Are there omissions?

None that I think block this. A test that merely repeats the twelve constants would add little independent protection. Compiler/linker acceptance across supported platforms remains unverified by this review.

Are there better ways of doing things?

Precomputed field names could avoid the 36 runtime format() calls introduced per monitoring sample. That is an optional optimization; the work is bounded and does not change the allocation path.

Should this CL be LGTMd?

Yes, LGTM on code inspection. The size coverage, accounting behavior, initialization, and trace compatibility are preserved. The highest remaining uncertainty is cross-platform compilation and linking while CI is pending.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-ide on Linux RHEL 9

  • Commit ID: b42f6c5
  • Duration 0:39:53
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos-m1 on macOS 14.x

  • Commit ID: b42f6c5
  • Duration 0:49:52
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr on Linux RHEL 9

  • Commit ID: b42f6c5
  • Duration 1:04:52
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang on Linux RHEL 9

  • Commit ID: b42f6c5
  • Duration 1:05:07
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-clang-arm on Linux RHEL 9

  • Commit ID: b42f6c5
  • Duration 1:05:20
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-cluster-tests on Linux RHEL 9

  • Commit ID: b42f6c5
  • Duration 1:49:13
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

This comment has been minimized.

@foundationdb-ci

Copy link
Copy Markdown
Contributor

Result of foundationdb-pr-macos on macOS 14.x

  • Commit ID: b42f6c5
  • Duration 2:52:59
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@tclinkenbeard-oai
tclinkenbeard-oai merged commit d9bda3b into apple:main Oct 22, 2026
10 checks passed
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.

3 participants