Repository navigation
io_uring partial completions + verified GPU/tier/cache hardening notes (static reading of v2.2.0) #3126
CraterCrest
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi all, and thanks for building Colibrì!
I was reading through the storage /
io_uringlayer and several of the engine and GPU backends inv2.2.0, and wanted to check a few edge-case, resource-lifetime, and optimization items with you before opening any PRs.Transparency: This review is from static reading of the
v2.2.0snapshot (2026-11-21), AI-assisted with manual line-by-line verification of every code path below. I have not built or run the Linux/GPU test suites or benchmarks yet, and I have not written patches yet. Line numbers below refer tov2.2.0.Part 1 — Storage &
io_uring(c/colibri.c,c/uring.h,c/gguf.h,c/compat.h)1. Partial
io_uringcompletion from the primary drive is fatalIn
uring_reap(c/colibri.c:4515-4542), a CQE counts as served only whencqe.res >= r->expect(L4520). A short or failed completion gets a synchronouspread_full(r->primary_fd, ...)retry only when it came from a mirror (if (!served && r->rep)atL4521).When the read came from the primary (
r->rep == 0), a short completion (0 <= cqe.res < r->expect) or transient-EINTR/-EAGAINfalls straight tol->error = cqe.res < 0 ? -cqe.res : EIO;(L4538), and for demand loads (fatal = 1frompipe_dispatchatL4708),uring_finalize_loadcallsexit(1)(L4558).By contrast, all blocking read paths already handle short reads and
EINTR:mir_pread/pread_full(c/colibri.c:3419-3468)st_pread_full(c/st.h:493-514)O_DIRECTpath falls back tomir_pread -> pread_fullwhenr < need(c/colibri.c:3709-3726).While short reads on local NVMe/ext4 are rare, they can occur on FUSE, 9p/DrvFs, network filesystems, or under signal/pressure conditions.
Proposed fix:
uring_reapto primary reads (r->rep == 0) on short completions (cqe.res >= 0 && cqe.res < r->expect) and-EINTR/-EAGAIN, resuming fromgot = cqe.res > 0 ? cqe.res : 0viapread_full(r->primary_fd, (char*)r->buf + got, r->expect - got, r->off + got, ...).r->primary_fd(buffered, matching the mirror fallback) is also safe if the initial submission useddfd(O_DIRECT), where the remaining offset/length may not be 4 KiB-aligned.-EIO,-EBADF) and real EOF (pread_fullreturning-1) would still fail fast as before.c/tests/test_uring.cviauring_add_readwithlen < expect.2. Latent: failed or partial
uring_submit_batch/uring_load_addcan leave stale SQEsuring_batch_reset(c/colibri.c:4370-4372) only zeroesb->nload = 0; b->nreq = 0;without checking whethersq_head == sq_tailor draining prior completions.In
pilot_uring_batch(c/colibri.c:8074-8147):uring_submit_batchreturns< 0(L8123-8128), loads are markeddone = 1with error,uring_finalize_loadreturns-1immediately, andecache_hidereleases theESlots — whilecoli_uring_prep_read(c/uring.h:111) had already advanced*r->sq_tail. On the nextpilot_uring_batch,coli_uring_enter(c/uring.h:117-121) submits those stale SQEs pointing to freed/reused slabs and collidinguser_data(1..old_nreq).coli_uring_enter(c/uring.h:115-125) returnsnonn >= 0, anduring_submit_batch(c/colibri.c:4544) only checks< 0, so a partialio_uring_enter(0 <= n < submit) would also leave unsubmitted SQEs behind.uring_load_add(c/colibri.c:4485-4512), if a lateruring_add_readfails after earlier reads for the same load succeeded,uring_load_errorsetsl->done = 1and returnsli >= 0(not-1).pilot_uring_batch(L8113-8119) only checksli < 0, so it appends that load todone[], submits those partial SQEs, and releasesdstwithout waiting for them.With the current constants (
URING_LOAD_MAX = 64,URING_REQ_MAX = 512), the ring does not overflow in normal operation, so this is primarily a missing invariant unlessio_uring_enterfails/partially submits or a mid-loaduring_add_readerrors out.3. Small notes on
gguf.h/compat.h/COLI_MMAPgguf_read_f32(c/gguf.h:425-436) allocates the full rawt->nbytesbuffer before dequantizing row-by-row intodst(e.g.,c/qwen36.c:3078,c/qwen38_core.h:1300,c/mistral_vision.h:235); chunked reads likeqwen_mtp_dense(c/qwen36.c:4828-4869) would cut peak temporary RAM for large F16/BF16 dense/vision tensors.gguf_advise(c/gguf.h:415-422) is gated with&& !defined(_WIN32)even thoughc/compat.h:128-132+c/compat_prefetch_win.himplementposix_fadvise(..., POSIX_FADV_WILLNEED).compat_pread(c/compat.h:150-181) and overlappedgguf_read(c/gguf.h:395-401) allocate/close an OS event per read (CreateEventA/CloseHandle).COLI_MMAP(c/colibri.c:3556-3584) callsmap_of_fd(L3250-3277, takingg_map_mtx) 6 times per expert.Part 2 — Verified Bugs, Error-Path Leaks & Hardening Items
4. Ignored
pthread_createfailures (c/colibri.c,c/kimi_k3.c)c/colibri.c:4685-4699(pipe_init): Ignorespthread_create's return value (L4697) and unconditionally setsg_pp.started = 1(L4698). If thread creation fails under thread limits/RLIMIT_NPROC/memory pressure,pipe_dispatch()(L4703-4723) queues jobs with no active workers, andpipe_wait()spins forever insched_yield()(L4752) or blocks forever inpthread_cond_wait(L4747-4748). (pilot_spawnatL8203-8205also ignorespthread_createerrors.) Note thatmoe_vk(L6678-6686) andmoe(L7374-7385) enterif (g_pipe)before callingpipe_init, so the caller also needs a synchronous fallback for that batch.c/kimi_k3.c:2133-2145(lp_start): Ifpthread_createfails afteri >= 1workers are already running (L2139-2144), it setsg_k3_pipe = 0; g_lp.nth = i;to fall back, while still settingg_lp.started = 1and leaving thoseithreads idle inlp_main.5.
qwen36_tier.cupload-failure budget clamp & swap accounting (c/qwen36_tier.c:459-460, 1989-2031)c/qwen36_tier.c:459-460),G.budget[hd] = G.used[hd];permanently shuts off all future fills and promotions for the lifetime of the process, even if the failure was transient.L459),G.used[hd] -= qt_ebytes(layer);executes unconditionally on failure — even though LFRU swaps (v_eid >= 0) skip incrementingG.used[hd]inenqueue_locked(L1989, L1993).G.mx,enqueue_locked(L1991-1995) also runsmalloc+stage(), andstream_promote_locked(L2015-2031) scansnl * neslots and clears residency without notifying/draining readers (L2028-2030).6. Vulkan / CUDA / Metal error-path leaks and missing failure checks
c/backend_vulkan.c):VKCHECK(L114-115) returns0without cleanup. Insidealloc_buf_mt()(L1261-1282), only memory-type failure (mt < 0atL1270) destroys*buf; failures invkAllocateMemory(L1278),vkBindBufferMemory(L1279), orvkMapMemory(L1280) leak the buffer/memory handles before callers zero them (L3981-3984,L4010-4021).coli_vk_xb_expert_new(L5533-5549) allocates a new descriptor pool on every iteration of an unboundedfor (;; k++)loop ifvkAllocateDescriptorSetspersistently fails.coli_vk_init(L1574-1580) leavesG.instalive if device enumeration finds no devices.vk_tier.c&vk_chain.c:vkt_init(c/vk_tier.c:3441-3444) returns0without freeingT.s/T.grpor destroying already-initialized mutex/condvars ifpthread_cond_initorpthread_createfails;push_done(L466-472) leaves a slot stuckqueued = 1permanently ifrealloc(T.done, ...)fails.ev_init(c/vk_chain.c:2173-2182) leaks previously createdVkEventhandles ifvkCreateEventfails mid-ring (L2179).c/backend_cuda.cu,c/backend_cuda_dsv4.cu,c/cu_xb.cu):COLI_CUDA_PROFILE=1inc/backend_cuda.cu:2854-2989andDSV4_WO_KPROF=1inc/backend_cuda_dsv4.cu:2680-2741), events are created up front and destroyed only at the end (L2989/L2741), leaking them on every earlyreturn 0failure path (backend_cuda.cu:2861, 2878, 2887, 2936, 2965, 2973, 2976, 2977;backend_cuda_dsv4.cu:2688-2732).cu_open(c/cu_xb.cu:137-143),cu_dev2_open_env(L196-202), andcu_grow(L698-709) chain CUDA/pinned allocations with||/&&and return0without freeing earlier partial allocations on failure.c/backend_metal.mm:1259-1279):coli_metal_matmuldoes not check fornilreturns fromwrap(),newBufferWith*,commandBuffer, orcomputeCommandEncoderbeforememcpy(y, [by contents], ...)and returning1.7. Windows TUI attachment command quoting (
c/tui.c:3347-3352)In
att_reader(), the POSIX branch (c/tui.c:3353-3366) carefully single-quote-escapespy,rd, andpath, whereas the#ifdef _WIN32branch (L3347-3352) interpolatespy,rd, and user-suppliedpathunescaped inside""%s" "%s" "%s" 2>NUL"passed to_wpopen(cmd.exe). Filenames containing",&,|,%, or^break the reader invocation or allowcmd.exemetacharacter interpretation.8.
lora.hleaks,snprintflength handling, andjson_parse/CLOCK_REALTIMEnotesc/lora.h(lora_loadL136-L201,lora_saveL229-L274):lora_loadcallsjson_parse(txt, &arena)(L136) and copies all fields out intoLoraAdapter, but never callsjson_free(md)orfree(arena)on either the success path (L201) or any of the early error returns (L143-L195).a,a->t,t->A,t->B,a->lut,hdr,buf, andmjlackNULLchecks before writes (L168, L171, L198-L199, L249).lora_saveaccumulateshn += snprintf(hdr + hn, hcap - hn, ...)(L233-L246) andmn += snprintf(mj + mn, mcap - mn, ...)(L262-L268) without checking for truncation beforememcpy(buf + 8, hdr, hn)(L249).json_parse()callers (c/json.h:39-46, 206-211):j_dup()allocates each string separately and leavesp.arenaunused, so callers that onlyfree(arena)withoutjson_free()leak the parsed tree (e.g.c/colibri.c:2019-2030,c/st_gguf.h:670-680).CLOCK_REALTIMEcondvar waits: Aside fromc/colibri.calready usingCLOCK_MONOTONICfor timings,pthread_cond_timedwaitstill usesCLOCK_REALTIMEagainst default-initialized condvars inc/vk_tier.c:446-448, 516,c/backend_vulkan.c:244-245, andc/qwen36_selected_loader.h:79-81(where a backward wall-clock jump delays cancellation checks inqsl_wait).c/colibri.c):m->elast[layer][...]andm->eaccess_clockare written withoutg_pilot_mxin decode (L6880, L7021) while read underg_pilot_mxinpilot_realload(L8034-8036).c/glm53.c:1424-1434): Six buffers (qa..valid) are allocated withoutNULLchecks beforememset(valid, 1, (size_t)seen)(L1434), while onlyqh/ahare checked atL1454.Part 3 — Verified CPU Hot-Path Optimization Opportunities (Bit-Identical Outputs)
(Excluding intentional trade-offs like
IDOT=0exact defaults andPREFETCH=0in parallel-read engines.)c/mimo.cmoe_cpumissingmxfp4_qxhoisting + per-tile OpenMPxmalloc(c/mimo.c:1403-1472,c/quant.h:1498-1590):quant.halready extractedmxfp4_qx+matmul_mxfp4_i8_prespecifically for bit-identical activation-quantization hoisting (used inc/kimi_k3.c:2170-2190). WhenMIMO_IDOT=1,mimo.cstill passesmatmul_mxfp4_i8inside#pragma omp parallel forperBLOCK_ROWS = 256tile (L1430, L1456), re-quantizing the same activation rows2 * up_blocks+down_blockstimes per expert.MIMO_IDOT, wheneverr > 4in prefill, each 256-row OpenMP task callsxmalloc/free(L1441-1442, L1464-1465) instead of using per-thread/preallocated scratch.c/kimi_k3.cK3_PIPEpolls misses withusleep(50)(c/kimi_k3.c:619, 2216-2222):K3_PIPEis on by default (L619, L1204). Waiting forg_lp.ready[qof[j]]viausleep(50)adds OS timer slack on every blocking miss; a condition signal (or brief spin beforepthread_cond_wait) would wake immediately whenexpert_readfinishes.c/olmoe.cprefill drops weight-sharing whenIDOT=1(c/olmoe.c:615-621, 1853-1865) &c/inkling.cCPU per-pair loop (c/inkling.c:3161-3193, 3543-3572):olmoe.cprefill (moe_by_expert), enablingIDOT=1falls back to single-row calls (moe_expert_rowifFUSED3=1, or per-rowmatmul_qinmatmul_q_rows), rereading weightsntimes from RAM and quantizingxs[t]twice (gate+up) whenFUSED3=0.inkling.c, the Metal branch (L3458-L3470) and asyncxg64path accumulate into pair slots before summing in order, whereas the standard CPU MoE loop (L3543-L3572) runs every(token, expert)pair withS = 1.bpe_pieceper-pair heap churn (c/qwen36.c:532-544,c/qwen38.c:278-335):"a\x1fb"lookup key on every adjacent pair check insidewhile (sc > 1)(qwen38.ccallsbpe_pair_ranktwice per merge pass). A stack buffer (with heap fallback only for oversized tokens) would eliminate thousands of small alloc/free calls on long prompts.c/glm53.clinearO(cap)slot lookup (c/glm53.c:1801-1810, 2281-2296):slot_findandexpert_block_reservelinearly scancache->nslots rather than maintaining a directby_expertindex (whileexpert_slotatL2227appears to be unused legacy code, since local inference usesexpert_block_read).Questions
io_uringcompletions on the primary drive be retried viapread_fulllike the mirror path, or is failing fast intentional there?io_uringretry/reset,pipe_init, Vulkan/CUDA/Metal error cleanup,qwen36_tier.c,lora.h, Windows_wpopenquoting) would you like isolated PRs for?mimo.cmxfp4_qxhoisting + scratch,qwen36/qwen38bpe_piecestack buffer,kimi_k3.cpipe wakeup)?Happy to prepare small, focused PRs (with unit tests / benchmarks on Linux & Windows where applicable) once you confirm which items are welcome. Thanks!
All reactions