Skip to content

Metal: a run that runs out of heap sometimes faults or hangs instead of printing the out-of-memory error #1300

Closed as duplicate

Description

@nicolas-abril

What you did

cd bench/runtime/tree-radix   # same with tree-bitonic
bend main.bend -o main.c
cc -std=c11 -O3 -DBEND_METAL=1 -x objective-c -fobjc-arc main.c -lpthread -framework Metal -framework Foundation -o cell
./cell --gpu-build
for i in $(seq 200); do ./cell --gpu 512MB; done

--gpu 512MB is too small for either bench, so every run should end in the out-of-memory error.

What happened

Most runs print the error, but a few fault or hang instead. Over 386 runs of main's build (193 per bench):

outcome tree-radix tree-bitonic
bend: out of memory: run again with a bigger span, as in --gpu 8GB 191 192
bend: Caused GPU Address Fault Error (0000000b:kIOGPUCommandBufferCallbackErrorPageFault) 1 0
hang, killed after 30-60 s 1 1

So after a lane posts ERR_HEAP, something still runs into a bad address or a wait that never ends. The error flag heap_free checks (#1143) narrows this but doesn't close it: guarding only the sink page instead of that check went bad in 19 of 60 runs.

The file

bench/runtime/tree-radix/main.bend and bench/runtime/tree-bitonic/main.bend, unchanged.

bend --version

Bend 2.0.35 (main a950fd68)

uname -sm

Darwin arm64 (Apple M4, macOS 26.3.1)

clang --version (the first line)

Apple clang version 17.0.0 (clang-1700.6.4.2)

Activity

  1. added
    bug
    on Oct 3, 2026
  2. Lorenzobattistela commented on Nov 5, 2026

    @Lorenzobattistela
    Collaborator

    Closing as a duplicate of #1924, where we're tracking this.

    The faults and the hangs here both come from the window #1924 describes. After heap_alloc_miss posts ERR_HEAP and returns HEAP_OFF, a lane reads the error word only every 4096 steps, and until then it keeps stepping on nodes that other failing lanes overwrite.

    To check, I ran this issue's loop (--gpu 512MB) 500 times per bench on an M4 Pro. One build was 2.0.35 (a950fd68) as is. The other was the same emitted C with one change: err_spun polls the error word on every step instead of every 4096.

    build tree-radix tree-bitonic
    2.0.35 32 OOM, 390 GPU Hang Error, 39 hangs (killed at 20 s), 25 GPU Address Fault, 6 Discarded, 5 memory fault, 3 frontier drained without a result 498 OOM, 1 hang, 1 GPU Address Fault
    2.0.35, poll every step 500 OOM 500 OOM

    Closing the window removes every bad outcome, hangs included, so the fix belongs to #1924.

    On main (05c0dbae), the same loop printed the out-of-memory error in 1000 of 1000 runs per bench. err_spun still polls every 4096 steps there, so the window is still open and something since 2.0.35 only makes it rarer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions