Skip to content

#56 Fixed failed init leaves hugepage files behind in /dev/hugepages, blocking subsequent runs - #58

Merged
cliffburdick merged 4 commits into
mainfrom
benchmarking_hugepages_cleanup
May 6, 2026
Merged

cliffburdick merged 4 commits into
mainfrom
benchmarking_hugepages_cleanup

Conversation

@chloecrozier

Copy link
Copy Markdown
Member

Fixes #56. Two things are added:

  1. A hugepage check that runs before DPDK starts. If the system does not have enough free hugepages for the YAML config, DAQIRI exits early with a explanation/breakdown and the exact echo N | sudo tee ... command to run.
  2. A cleanup step that calls rte_eal_cleanup() and removes any leftover hugepage files from /dev/hugepages and /mnt/huge on every init error and on shutdown.

Both helpers live in the Manager base class, so anything that uses libdaqiri.so — all daqiri_bench_*, all daqiri_example_*, the Python bindings, and any external program — gets the fix without code changes. Both backends that talk to DPDK (dpdk and rdma) call the helpers from initialize() and shutdown().

Changes

Code

  • src/manager.{h,cpp}: adds two helpers to the Manager base class.

    • check_hugepage_availability() reads /sys/kernel/mm/hugepages to find how many pages are free, then adds up everything DAQIRI will need: each kind: HUGE memory region in the YAML, the dummy queues DAQIRI adds on its own, per-pool overhead, and DPDK's own fixed overhead. If the total is more than what is free, it logs each piece of the sum and prints the exact echo N | sudo tee ... command the user should run. Works for both 2 MiB and 1 GiB pages.
    • cleanup_eal() calls rte_eal_cleanup() and then deletes any leftover <file-prefix>map_* files in /dev/hugepages and /mnt/huge.
  • src/managers/dpdk/daqiri_dpdk_mgr.cpp:

    • Calls the preflight check at the top of initialize().
    • If a later step in initialize() fails before initialized_ = true is set, a small guard object runs cleanup_eal() automatically as it goes out of scope. This covers every error path without having to add cleanup at each return.
    • shutdown() now frees the rings before rte_eal_cleanup() (the previous order was wrong and could touch freed memory).
    • The destructor only frees rings when eal_initialized_ is true, so it does not touch memory that has already been cleaned up.
  • src/managers/rdma/daqiri_rdma_mgr.cpp: the same four changes as the DPDK manager — preflight at the top of initialize(), scope guard for error paths, ring frees before rte_eal_cleanup() in shutdown(), and a destructor that checks eal_initialized_.

Docs

  • docs/tutorials/benchmarking_examples.md: short "Configure hugepages first" callout pointing at the new check, plus a tighter FAQ pair (preflight path + SIGKILL-orphan cleanup).
  • docs/tutorials/system_configuration.md (DGX Spark tab): bumped hugepages=3 → hugepages=4 in the grub recipe to match the shipped Spark YAML's footprint.

Tests run

# Scenario Result Status
1 nr_hugepages=1, run daqiri_bench_raw_tx_rx_spark.yaml preflight aborts with breakdown + echo 381 | sudo tee ...; /dev/hugepages empty Pass
2 nr_hugepages=2048, run daqiri_bench_raw_sw_loopback.yaml exit 0; Removed leftover hugepage file ... lines on shutdown; HugePages_Free restored Pass
3 Intentioanlly wrong PCI BDF (0000:ff:ff.0) to force post-EAL failure Failed to get port number; scope guard runs rte_eal_cleanup(); /dev/hugepages empty Pass
4 Test 1 → Test 2 back-to-back without manual rm (the original symptom) second run starts clean — no manual intervention needed Pass
5 mkdocs build --strict clean (0.28s) Pass

How a reviewer can validate

Build inside the container, then walk through the checklist. After each run, check /dev/hugepages and /mnt/huge are empty (no map_* files left behind).

  • Build — cmake -S . -B build -DBUILD_SHARED_LIBS=ON -DDAQIRI_BUILD_PYTHON=OFF -DDAQIRI_MGR="dpdk socket rdma" then cmake --build build -j (run inside the container as the current user). Build succeeds with no errors.
  • Preflight aborts on too few hugepages — set nr_hugepages=1, then run daqiri_bench_raw_gpudirect ./examples/daqiri_bench_raw_tx_rx_spark.yaml --seconds 1. Exit is non-zero, the log shows the per-piece breakdown and an echo N | sudo tee ... recipe, /dev/hugepages and /mnt/huge are empty, and HugePages_Free in /proc/meminfo is unchanged.
  • Clean run cleans up after itself — set nr_hugepages=2048, then run daqiri_bench_raw_gpudirect ./examples/daqiri_bench_raw_sw_loopback.yaml --seconds 5. Exit is 0, the log shows Removed leftover hugepage file ... lines on shutdown, /dev/hugepages and /mnt/huge are empty, and HugePages_Free returns to 2048.
  • Post-EAL failure path — copy examples/daqiri_bench_raw_tx_rx_spark.yaml, replace the PCIe BDFs with bogus values (e.g. 0000:ff:ff.0), and run the bench against that file. The log shows Failed to get port number, the scope guard fires rte_eal_cleanup(), and /dev/hugepages and /mnt/huge are empty.
  • Back-to-back runs (the original bug) — run the failing case from the second checkbox, then run the clean case from the third checkbox without any manual rm. The second run starts cleanly with no Cannot allocate memory or stale-file errors.
  • Docs build — mkdocs build --strict is clean.

Comment thread docs/tutorials/benchmarking_examples.md Outdated

??? failure "Insufficient free hugepages: x MiB free, ~y MiB required for this config."

DAQIRI's preflight check has caught a hugepage shortfall before EAL was initialized, so no files were left in `/dev/hugepages`. The critical log prints a breakdown (kind:HUGE MRs, dummy queues, per-pool overhead, EAL fixed overhead) and the exact `echo N | sudo tee ...` command to allocate enough pages — copy-paste it. See [Configure hugepages first](#configure-hugepages-first) for the full sizing guide and persistent grub recipe.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We shouldn't mention EAL here since it's an implementation detail.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I removed the reference and pushed the changes.

@cliffburdick
cliffburdick merged commit 3eb6151 into main May 6, 2026
2 checks passed
@cliffburdick
cliffburdick deleted the benchmarking_hugepages_cleanup branch May 6, 2026 20:37
dleshchev added a commit that referenced this pull request May 12, 2026
* #56 - Default-init MemoryRegionConfig::adj_size_ and ttl_size_ to 0

The hugepage preflight added by #58 reads MemoryRegionConfig::adj_size_
before any backend populates it, falling back to buf_size_ only when
adj_size_ == 0. Since these fields had no default initializer,
construction left them with indeterminate values, so the fallback rarely
fired. On configs with kind: huge memory regions, the preflight would
multiply num_bufs by garbage and demand petabytes of hugepages, aborting
init before rte_eal_init().

Reproduces on origin/main with every DPDK bench that has a CPU-side huge
memory region (HDS, reorder, reorder_quantize). tx_rx was unaffected
because its memory regions are all kind: device.

Default-init adj_size_ and ttl_size_ to 0 so the existing fallback path
in estimate_required_hugepages() works as intended.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Denis Leshchev <dleshchev@nvidia.com>

* #44 - Gate num_bufs auto-bump to queue-backed memory regions

The auto-bump added by #48 iterates every MemoryRegionConfig and bumps
num_bufs to 3x the NIC ring whenever it falls below 1.5x ring. That
logic is correct for MRs that back an RX or TX queue's mempool --
undersizing those deadlocks the worker once the ring fills, which is
exactly what #44 set out to prevent. But the bump fires unconditionally,
including on MRs that aren't bound to any queue.

The reorder configs intentionally use small num_bufs with large
buf_size for the reorder target -- e.g.
daqiri_bench_raw_tx_rx_reorder_seq_1024.yaml sets
Reorder_RX_GPU.num_bufs=128 with buf_size=2031616 (~260 MiB total)
because each buffer holds one fully reordered batch and the region
isn't a queue mempool. The bump inflates this to ~50 GiB, which the
device cannot DMA-map and init fails:

  [WARN] MR 'Reorder_RX_GPU' had num_bufs=128 ... Bumping to 24576
  [CRITICAL] Could not DMA map EXT memory: -1 err=Invalid argument
  [CRITICAL] Failed to map MRs

Collect the names of MRs referenced by any RX/TX queue's mrs_ list, and
only bump those. Reorder targets and any future auxiliary MRs are left
at the user-configured num_bufs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Denis Leshchev <dleshchev@nvidia.com>

---------

Signed-off-by: Denis Leshchev <dleshchev@nvidia.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

[BUG] Failed init leaves hugepage files behind in /dev/hugepages, blocking subsequent runs

2 participants