Skip to content

farmemtopologymanager: extract findNUMACombo() out of Admit() - #4

Open
VijayP30 wants to merge 2 commits into
stingletfrom
pranav/refactor-findnumacombo
Open

farmemtopologymanager: extract findNUMACombo() out of Admit()#4
VijayP30 wants to merge 2 commits into
stingletfrom
pranav/refactor-findnumacombo

Conversation

@VijayP30

@VijayP30 VijayP30 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two small, independently-verified refactors to farmemtopologymanager, no behavior change:

  1. Extract findNUMACombo() out of Admit(). The first-fit nNUMA/zNUMA combo search was an ~80-line inline closure; it's now its own named method with identical logic (confirmed by diffing the moved block against the original — the only textual difference is two var declarations becoming named return values, semantically identical in Go).
  2. Extract uniqueNeighborZNUMAs() helper. The "dedupe a group of nNUMAs' neighbor zNUMAs via a map" pattern was duplicated three times: once in findNUMACombo() (filtered to nNUMAs with free CPUs) and twice in candidateBetterThanCurrent() (unfiltered, once each for the candidate and current group). Pulled into one shared helper taking a filter flag, with each call site keeping its existing filtering behavior exactly as before.

Together these make the combo search independently readable/testable and remove real duplication, without touching any decision logic.

Test plan

  • go build ./cmd/kubelet/... succeeds
  • Confirmed the findNUMACombo() extraction is textually identical to the original inline code (aside from two var declarations becoming named returns)
  • Confirmed each uniqueNeighborZNUMAs() call site preserves its original filtering behavior (the free-CPU filter only applies where it always did)

molivi3 added 2 commits July 21, 2026 18:01
Pure extraction, no behavior change -- the first-fit nNUMA/zNUMA combo
search was previously an inline block in Admit() with two var declarations;
it is now its own named method with the same declarations as named return
values. Makes the combo search independently readable/testable and gives
future callers (e.g. a retry-after-capacity-change path) something to call
without duplicating ~80 lines inline.
The "dedupe a group of nNUMAs neighbor zNUMAs via a map" pattern was
duplicated three times: once in findNUMACombo() (filtered to nNUMAs with
free CPUs) and twice in candidateBetterThanCurrent() (unfiltered, once for
the candidate group and once for the current one). Pulled into one shared
helper, uniqueNeighborZNUMAs(nNUMAsGrp, onlyFreeCPUNNUMAs), with each call
site keeping its existing filtering behavior via the second argument --
no behavior change, just removes the duplication.
VijayP30 pushed a commit that referenced this pull request Jul 21, 2026
The "dedupe a group of nNUMAs neighbor zNUMAs via a map" pattern was
duplicated three times: once in findNUMACombo() (filtered to nNUMAs with
free CPUs) and twice in candidateBetterThanCurrent() (unfiltered, once for
the candidate group and once for the current one). Pulled into one shared
helper, uniqueNeighborZNUMAs(nNUMAsGrp, onlyFreeCPUNNUMAs), with each call
site keeping its existing filtering behavior via the second argument --
no behavior change, just removes the duplication.

Mirrors the same extraction proposed to #4 (against
the stinglet branch), applied here too so this branch stays in sync with
that upstream refactor.
@VijayP30
VijayP30 requested a review from matte21 July 21, 2026 23:47
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.

1 participant