• Stefy Lanza (nextime / spora )'s avatar
    video: malloc_trim host RAM after each clip (stop glibc arena from hoarding decode buffers) · 6bbc2d31
    Stefy Lanza (nextime / spora ) authored
    The video pipeline is reused across clips (model CPU offload keeps weights in host
    RAM), so the per-request teardown that trims the heap — _free_pipeline_vram ->
    _trim_cpu_ram — never runs between clips. Each generation allocs ~1 GB of
    decode/latent/offload buffers; Python frees them but glibc keeps the pages in its
    arena, so RSS drifts up clip-by-clip (seen ~34 -> 47 GB) and peaks over the
    max_ram_gb cap. The cap can't reclaim it: the only resident model is the protected
    live one, so there's nothing idle to evict (and ram_leak_watch is off).
    
    Fix: after each successful generation, drop the decode buffers (frames/frame_np),
    gc, and malloc_trim the freed heap back to the OS. Logs RSS before/after so a
    RESIDUAL reference leak (RSS not returning to baseline after trim) is visible to
    chase separately. Failure paths already trim via _free_pipeline_vram.
    Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_01RdMufYvtTbtGDWsiZVoXce
    6bbc2d31
video.py 166 KB