[PR #116] [MERGED] Fix malloc graph search skipping overlapping alias ranges #124

Closed
opened 2026-10-26 22:24:47 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Comfy-Org/comfy-aimdo/pull/116
Author: @rattus128
Created: 9/15/2026
Status: ✅ Merged
Merged: 9/15/2026
Merged by: @rattus128

Base: master ← Head: dev/alias-range-search-review


📝 Commits (4)

  • 293de00 Fix malloc graph search skipping overlapping alias ranges
  • 9ea5e09 Assert physical page reuse in overlapping alias regression
  • cc93975 Reuse cleanup scan to find the earlier conflicting alias
  • 5cf9974 Simplify overlapping alias search cleanup

📊 Changes

2 files changed (+45 additions, -3 deletions)

View changed files

📝 src/malloc-graph.c (+9 -3)
➕ tests/malloc-graph-overlapping-alias-cuda.py (+36 -0)

📄 Description

Supersedes #113 with the maintainer review cleanup applied on top. The contributor's three commits are retained unchanged; the cleanup is a separate commit by @rattus128.

The malloc-graph allocator can extend its virtual range even when an existing range satisfies the allocation. This wastes virtual address space and can contribute to exhausting the fixed arena while physical graph memory remains well below that limit.

During a candidate scan, physical_live includes both pre-existing live pages and pages temporarily marked live by that scan. When a repeated physical page is encountered within the candidate, advancing by j + 1 skips overlapping windows that no longer contain the earlier occurrence.

For example, with the free mapping [0, 1, 2, 0, 1, 3] and a four-page request, the window starting at virtual index 2 is valid: [2, 0, 1, 3]. Advance past the earlier occurrence on a temporary alias collision; retain the existing advancement otherwise. This preserves the requirement that a returned range contain distinct, available physical pages.

The standalone GPU regression creates that layout with small allocations. It verifies virtual and physical reuse and checks distinct values per page for unintended physical aliasing. No model is required.

Validation:

  • The submitted GPU regression was previously verified failing on stock and passing with the fix on Windows / RTX 5090, Torch 2.14.0+cu130, AIMDO 0.5.3.
  • The reviewed cleanup was checked against a brute-force reference over 1,572,864 allocation-search cases, including live pages and rogue virtual/physical masks.
  • src/malloc-graph.c passes a C11 syntax check.

Contribution agreement

  • I agree that these contributions are licensed under GPLv3.
  • I grant Comfy Org the relicensing rights described in CONTRIBUTING.md.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Comfy-Org/comfy-aimdo/pull/116 **Author:** [@rattus128](https://github.com/rattus128) **Created:** 9/15/2026 **Status:** ✅ Merged **Merged:** 9/15/2026 **Merged by:** [@rattus128](https://github.com/rattus128) **Base:** `master` ← **Head:** `dev/alias-range-search-review` --- ### 📝 Commits (4) - [`293de00`](https://github.com/Comfy-Org/comfy-aimdo/commit/293de007b8d19c354f7dac3bc7f2e70abf597fe8) Fix malloc graph search skipping overlapping alias ranges - [`9ea5e09`](https://github.com/Comfy-Org/comfy-aimdo/commit/9ea5e09110bdbe7ca0b59872e528f49e7d63c254) Assert physical page reuse in overlapping alias regression - [`cc93975`](https://github.com/Comfy-Org/comfy-aimdo/commit/cc939758fada84282edd7aa5626d61e35c68c040) Reuse cleanup scan to find the earlier conflicting alias - [`5cf9974`](https://github.com/Comfy-Org/comfy-aimdo/commit/5cf9974d72378bb140c73224abe04f0b9b1f33a7) Simplify overlapping alias search cleanup ### 📊 Changes **2 files changed** (+45 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/malloc-graph.c` (+9 -3) ➕ `tests/malloc-graph-overlapping-alias-cuda.py` (+36 -0) </details> ### 📄 Description Supersedes #113 with the maintainer review cleanup applied on top. The contributor's three commits are retained unchanged; the cleanup is a separate commit by @rattus128. The malloc-graph allocator can extend its virtual range even when an existing range satisfies the allocation. This wastes virtual address space and can contribute to exhausting the fixed arena while physical graph memory remains well below that limit. During a candidate scan, `physical_live` includes both pre-existing live pages and pages temporarily marked live by that scan. When a repeated physical page is encountered within the candidate, advancing by `j + 1` skips overlapping windows that no longer contain the earlier occurrence. For example, with the free mapping `[0, 1, 2, 0, 1, 3]` and a four-page request, the window starting at virtual index 2 is valid: `[2, 0, 1, 3]`. Advance past the earlier occurrence on a temporary alias collision; retain the existing advancement otherwise. This preserves the requirement that a returned range contain distinct, available physical pages. The standalone GPU regression creates that layout with small allocations. It verifies virtual and physical reuse and checks distinct values per page for unintended physical aliasing. No model is required. Validation: - The submitted GPU regression was previously verified failing on stock and passing with the fix on Windows / RTX 5090, Torch 2.14.0+cu130, AIMDO 0.5.3. - The reviewed cleanup was checked against a brute-force reference over 1,572,864 allocation-search cases, including live pages and rogue virtual/physical masks. - `src/malloc-graph.c` passes a C11 syntax check. ## Contribution agreement - [x] I agree that these contributions are licensed under GPLv3. - [x] I grant Comfy Org the relicensing rights described in CONTRIBUTING.md. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-26 22:24:47 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Comfy-Org/comfy-aimdo#124
No description provided.