Repository navigation
Centralize allocator size-class lists - #14329
tclinkenbeard-oai merged 2 commits into
Conversation
tclinkenbeard-oai
left a comment
There was a problem hiding this comment.
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.
-
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.
-
Keep allocator initialization intact. The explicit class instantiations still request the same specializations. This preserves initialization of allocator state belonging to each thread.
-
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.
-
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Result of foundationdb-pr-clang-ide on Linux RHEL 9
|
Result of foundationdb-pr-macos-m1 on macOS 14.x
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Result of foundationdb-pr on Linux RHEL 9
|
Result of foundationdb-pr-clang on Linux RHEL 9
|
Result of foundationdb-pr-clang-arm on Linux RHEL 9
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Result of foundationdb-pr-cluster-tests on Linux RHEL 9
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Result of foundationdb-pr-macos on macOS 14.x
|
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:
git diff --checkpass; independent source review found no issues.flow_testremain unrun because the remote validation environment is unavailable.