Skip to content

Enable parallel marking in boehm-gc#13708

Merged
xokdvium merged 3 commits intomasterfrom
parallel-mark-2
Aug 7, 2025
Merged

Enable parallel marking in boehm-gc#13708
xokdvium merged 3 commits intomasterfrom
parallel-mark-2

Conversation

@edolstra
Copy link
Member

@edolstra edolstra commented Aug 7, 2025

Motivation

Previously marking was done by only one thread, which takes a long time if the heap gets big. Enabling parallel marking speeds up evaluation a lot, for example (on a Ryzen 9 5900X 12-Core):

  • nix search nixpkgs from 24.3s to 18.9s.
  • Evaluating the NixOS/nix/2.21.2 flake regression test from 86.1s to 71.2s.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

If the mark stack size is too small, it greatly inhibits parallel
marking, which is very bad for performance on multi-core systems.
@edolstra edolstra changed the title Parallel mark 2 Enable parallel marking in boehm-gc Aug 7, 2025
Copy link
Contributor

@xokdvium xokdvium left a comment

Choose a reason for hiding this comment

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

Yeah, the wall clock speedup is very noticeable (16.5 vs 22.5s) for nix search nixpkgs hello --no-eval-cache.

@edolstra
Copy link
Member Author

edolstra commented Aug 7, 2025

One thing worth noting is that it makes debugging with GDB slightly more annoying, since you have to tell GDB to ignore the signals used by the stop-the-world GC:

handle SIGPWR nostop noprint
handle SIGXCPU nostop noprint

Copy link
Contributor

@xokdvium xokdvium left a comment

Choose a reason for hiding this comment

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

LGTM, but we need to remember to bring the boehm override to nixpkgs.

@xokdvium xokdvium merged commit 6b6a1e1 into master Aug 7, 2025
30 checks passed
@xokdvium xokdvium deleted the parallel-mark-2 branch August 7, 2025 10:56
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-2-31-0-released/68465/1

lf- pushed a commit to lix-project/lix that referenced this pull request Oct 2, 2025
Using parallel marking in GC speeds up evaluation a fair bit

```
Benchmark 1: ./lix-main/bin/nix search nixpkgs hello --no-eval-cache
  Time (mean ± σ):     20.740 s ±  0.046 s    [User: 17.583 s, System: 3.062 s]
  Range (min … max):   20.678 s … 20.794 s    10 runs

Benchmark 2: ./lix-parallel-marking/bin/nix search nixpkgs hello --no-eval-cache
  Time (mean ± σ):     15.037 s ±  0.080 s    [User: 19.602 s, System: 3.125 s]
  Range (min … max):   14.960 s … 15.227 s    10 runs

Summary
  ./lix-parallel-marking/bin/nix search nixpkgs hello --no-eval-cache ran
    1.38 ± 0.01 times faster than ./lix-main/bin/nix search nixpkgs hello --no-eval-cache
```

Based-on: NixOS/nix#13708
Co-authored-by: Eelco Dolstra <edolstra@gmail.com>
Change-Id: Ibc7625f21e0ee7c8ad66203eeb3aca5d83977731
@domenkozar
Copy link
Member

See #3973 (comment) for potential issues with parallel marking

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.

4 participants