Skip to content

Cgroup - #159

Closed
vlstill wants to merge 7 commits into
NixOS:masterfrom
vlstill:cgroup
Closed

Cgroup#159
vlstill wants to merge 7 commits into
NixOS:masterfrom
vlstill:cgroup

Conversation

@vlstill

@vlstill vlstill commented Aug 19, 2013

Copy link
Copy Markdown

Add support for (optionally) running nix-daemon actions in cgroups of calling process. Supported only if daemon can access given cgroups.

@edolstra

Copy link
Copy Markdown
Member

Some comments:

  • I'm wondering if it wouldn't be better to only run builders in the calling cgroup (rather than the entire worker). Otherwise there is a risk of priority inversion, i.e. a client with a low priority will also cause the daemon worker to run with low priority. Since it will typically acquire some SQLite locks, it can cause other (high-priority) clients to block for a long time. I just turned off the use of nice/ionice in the Nix daemon NixOS module for that reason.
  • Could you move the cgroup handling into a separate file instead of util.cc? E.g. cgroups.cc / cgroups.hh.
  • Please add a description of daemon-use-cgroups to doc/manual/conf-file.xml.

@vlstill

vlstill commented Sep 7, 2013

Copy link
Copy Markdown
Author

I implemented your comments.

As far as the whole-worker or just-build problem goes, my original intention was to prevent users with low priority from using system resources though Nix, but I guess I didn't really take locks into account. So now Nix uses cgroups only for building. The only downside is that now it needs to have write access also to it's original cgroups, as it needs to return to them in case other action is required.

@edolstra

edolstra commented Sep 9, 2013

Copy link
Copy Markdown
Member

It won't need to restore the cgroup if you only change the cgroup in the builder's child process, i.e., in initChild() in build.cc.

@stale

stale Bot commented Feb 13, 2021

Copy link
Copy Markdown

I marked this as stale due to inactivity. → More info

@stale stale Bot added the stale label Feb 13, 2021
@stale stale Bot removed the stale label Feb 28, 2022
@Ericson2314

Copy link
Copy Markdown
Member

I think it would be better to return to this after #3600 is merged.

@edolstra

edolstra commented Dec 9, 2022

Copy link
Copy Markdown
Member

We can close this now that #3600 has been merged.

@edolstra edolstra closed this Dec 9, 2022
zolodev pushed a commit to zolodev/nix that referenced this pull request Jan 1, 2024
…opybutton-0.3.3

chore(deps): bump sphinx-copybutton from 0.3.1 to 0.3.3
ConnorBaker pushed a commit to ConnorBaker/nix that referenced this pull request Jul 25, 2025
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
Goal::ChildEvents previously carried three type-segregated slots:
std::queue<ChildOutput> childOutputs, std::optional<ChildEOF> childEOF,
and std::unique_ptr<TimedOut> childTimeout. The shape was structurally
over-modelled — the segregation only existed to encode pop ordering
("outputs before EOF before timeout") and a defensive "EOF can only
fire once" assertion that was wrong: a multi-fd goal (notably
buildWithHook, which watches both hook->fromHook and hook->builderOut)
can have more than one fd reach EOF for the same goal.

Replace with a single std::deque<ChildEvent> plus a bool timedOut
flag. pushChildEvent(TimedOut) clears the deque and sets the flag;
subsequent ChildOutput/ChildEOF pushes early-return so the timeout
always wins. popChildEvent preserves the pre-tip ordering invariant
("ChildOutput first, then any marker") explicitly: it scans the deque
and returns any pending output before falling back to the front-of-
deque marker. This matters because the muxable-pipe poll loop walks
each goal's fds in one iterate() call: if hook->fromHook reaches EOF
in the same poll cycle as buffered output on hook->builderOut, the
buildWithHook consumer must still observe the output before breaking
on EOF, otherwise the final batch of builder-log lines is lost.

Catalog candidate NixOS#159.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
…ards

Adds **Branch:** lines to the 30 catalog entries that landed as commits
on the four cleanup shard branches (libexpr, libstore, libutil,
nix-cli) over the previous batch.

Per-shard tally (commits on each branch beyond the previously-pushed
tip):

- libexpr (HEAD 437eea9 -> +10): NixOS#64, NixOS#66, NixOS#68, NixOS#106, NixOS#107, NixOS#109,
  NixOS#110, NixOS#112, NixOS#196, NixOS#199. Two of the original twelve were skipped on
  rule grounds: NixOS#194 (LookupPath::Elem flatten) — the candidate
  framing claimed the types were internal, but search-path.hh ships
  via install_headers, so collapsing is a public-ABI break, not a
  trivial flatten; NixOS#197 (one-arg findFile drop) — EvalState::lookupPath
  is a private member, so the candidate's "have callers pass it
  explicitly" prescription cannot apply.

- libstore (HEAD 5f5b815 -> +12): NixOS#4, NixOS#5, NixOS#6, NixOS#14, NixOS#47, NixOS#82, NixOS#114,
  NixOS#115, NixOS#119, NixOS#157, NixOS#159, NixOS#165. Several departures from the literal
  prescription, recorded in each commit body and in the per-candidate
  Branch line: NixOS#14 lifted only getRemoteFSAccessor with a
  getLocalNarCacheDir hook (left the trivial getFSAccessor overrides
  per-class); NixOS#115 extracted only the prelude (lockProfile +
  findGenerations) since two callers use stateful reverse iteration;
  NixOS#119 confirmed init's setDefault is a different shape and stayed
  out; NixOS#159 dropped the assert(!childEOF) defensive check after walking
  Goal::handleEOF producers; NixOS#165 used option (b) of the prescription
  (a new derivation-output-fwd.hh) because option (a) would have
  introduced an include cycle.

- libutil (HEAD 784a4f4 -> +3): NixOS#29, NixOS#99, NixOS#117. NixOS#29's commit body
  caveat (XDG_*_HOME / XDG_CONFIG_DIRS reads moved from per-call to
  cached) is recorded on the candidate Branch line.

- nix-cli (HEAD 48524e0 -> +5): NixOS#24, NixOS#77, NixOS#89, NixOS#91, NixOS#187. NixOS#91 shipped
  the GcRootNamer + nameForCurrent consolidation but deferred the
  candidate's addPermRootWithCounter free helper because three
  behavioural differences across call sites (rootNr increment
  position, absPath timing, printGCWarning conditions on store2 null)
  would have either changed user-visible path naming or grown the API.

STATUS.md's cleanup-branches table is updated with each shard's
expanded Addresses list, and the Status column now distinguishes the
already-pushed tips (libfetchers/libflake/libmain remain Pushed since
they got no new commits) from the four shards whose new commits are
local-only.

Push policy is explicit-only — none of the four shard branches has
been pushed past its prior tip.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 23, 2026
Three deep-dive adversarial reviews of the post-cleanup state surfaced
work that wasn't reflected in the catalog:

- **Wire-format review** found a public-API break in NixOS#6 (the
  GET_PROTOCOL_MAJOR/MINOR macros lived in install_headers-shipped
  headers; their deletion is observed by external consumers like
  Hydra/Lix/plugins). The candidate's Branch line now documents this
  as a deliberate API break and gives a migration recipe via
  WorkerProto::Version::Number::fromWire, including the subtle
  semantic shift (the old macro returned the high byte unshifted).
  The deletion-commit body in cleanup/libstore is amended to match.

- **Traceability audit** found that the macro→template follow-up
  commit on cleanup/libstore had no candidate reference in its body
  and neither NixOS#4 nor NixOS#5 mentioned the follow-up in their Branch line.
  Both now describe the two-stage evolution (initial macro
  consolidation, then full replacement with the
  LengthPrefixedProtoHelper template constrained on
  LengthPrefixContainer). Pattern matches the NixOS#6 hoist-then-delete
  and NixOS#110 extended-to-forceValueDeep annotations.

- **Bare libstore Branch lines** in NixOS#47 (DerivationGoal/
  DerivationBuildingGoal done* dedupe), NixOS#82 (tryAcquireSlotLock with
  the FdLock-bypass rationale), NixOS#114 (file-static getAttr<T>
  template) gain descriptive parentheticals matching the
  libexpr/libutil/nix-cli style.

STATUS.md `vibe-coding/cleanup/libstore` row's Addresses column gains
two annotations (`NixOS#4 (extended to template form)`, `NixOS#5 (extended to
template form)`) plus the existing `NixOS#6 (hoist-then-delete)` framing,
so future readers can map row entries to commit ranges without having
to walk git history.

The libstore commit body for `1812c99a3` (macro→template) is amended
in a parallel rebase on cleanup/libstore to add `Refs candidates NixOS#4
and NixOS#5`. The deletion commit `9f2478416` is amended to include the
public-API break documentation. The NixOS#159 ChildEvents collapse commit
(`ead54c3c7`) is amended to add a `childEventsHighWatermark = 16`
runtime assert in pushChildEvent, converting the structural fd-count
bound documented in popChildEvent's comment into a check that catches
future Goal subclasses with many fds.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 24, 2026
Six edits to candidate bodies / Branch lines:
- NixOS#159: deque/find_if + high-watermark assertion (not queue/FIFO)
- NixOS#226: scope expanded from 3 renderers to 5 (file-content-address pair)
- NixOS#148: name commit efd3e26 directly instead of "primary commit message"
- NixOS#128: "soft style issue" → accepted-bundling history note
- NixOS#225: helper for the latent-bug fix belongs in libutil
- NixOS#89: prefetch.cc was actually converted; NixOS#95 scope shrinks

No code change; doc-branch only.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 24, 2026
Goal::ChildEvents previously carried three type-segregated slots:
std::queue<ChildOutput> childOutputs, std::optional<ChildEOF> childEOF,
and std::unique_ptr<TimedOut> childTimeout. The shape was structurally
over-modelled — the segregation only existed to encode pop ordering
("outputs before EOF before timeout") and a defensive "EOF can only
fire once" assertion that was wrong: a multi-fd goal (notably
buildWithHook, which watches both hook->fromHook and hook->builderOut)
can have more than one fd reach EOF for the same goal.

Replace with a single std::deque<ChildEvent> plus a bool timedOut
flag. pushChildEvent(TimedOut) clears the deque and sets the flag;
subsequent ChildOutput/ChildEOF pushes early-return so the timeout
always wins. popChildEvent preserves the pre-tip ordering invariant
("ChildOutput first, then any marker") explicitly: it scans the deque
and returns any pending output before falling back to the front-of-
deque marker. This matters because the muxable-pipe poll loop walks
each goal's fds in one iterate() call: if hook->fromHook reaches EOF
in the same poll cycle as buffered output on hook->builderOut, the
buildWithHook consumer must still observe the output before breaking
on EOF, otherwise the final batch of builder-log lines is lost.

Catalog candidate NixOS#159.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ConnorBaker added a commit to ConnorBaker/nix that referenced this pull request May 25, 2026
Goal::ChildEvents previously carried three type-segregated slots:
std::queue<ChildOutput> childOutputs, std::optional<ChildEOF> childEOF,
and std::unique_ptr<TimedOut> childTimeout. The shape was structurally
over-modelled — the segregation only existed to encode pop ordering
("outputs before EOF before timeout") and a defensive "EOF can only
fire once" assertion that was wrong: a multi-fd goal (notably
buildWithHook, which watches both hook->fromHook and hook->builderOut)
can have more than one fd reach EOF for the same goal.

Replace with a single std::deque<ChildEvent> plus a bool timedOut
flag. pushChildEvent(TimedOut) clears the deque and sets the flag;
subsequent ChildOutput/ChildEOF pushes early-return so the timeout
always wins. popChildEvent preserves the pre-tip ordering invariant
("ChildOutput first, then any marker") explicitly: it scans the deque
and returns any pending output before falling back to the front-of-
deque marker. This matters because the muxable-pipe poll loop walks
each goal's fds in one iterate() call: if hook->fromHook reaches EOF
in the same poll cycle as buffered output on hook->builderOut, the
buildWithHook consumer must still observe the output before breaking
on EOF, otherwise the final batch of builder-log lines is lost.

Catalog candidate NixOS#159.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Feature request or proposal stale

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants