Nandai AI
Sign In

Running Qwen 4 35B-A3B on 16 GB MacBook Air & 24 GB M4 Pro Without Swap Thrashing

Preventing macOS kernel panics, WindowServer freezes, and SSD swap death spirals when deploying 35B MoE checkpoints on entry Apple Silicon laptops.

macOS reserves ~4.5–6 GiB for WindowServer and kernel pools. Learn exact wired limits and APFS lazy Engram settings for 16 GB Air and 24 GB M4 Pro Macs.

~869 wordsTechArticle + HowTo + Speakable JSON-LDZero-Upload Client RAM
Execution Pipeline ArchitectureLocal Browser RAM & Apple Silicon
01Measure UsableSubtract ~4.5–5.5 GiB macOSWindowServer reserve02Pick Safe Quant9.00 GiB on 16 GB Air · 12.90GiB on 24 GB Pro03Enable Lazy mmapDrop --mlock so cold Engramstays on APFS NVMe04Cap Context KVLock 32K–128K Q8_0 KV insidewired headroom
  1. Step 01 · Measure Usable

    Subtract ~4.5–5.5 GiB macOS WindowServer reserve. A 16 GB unified memory Mac does NOT provide 16 GB to Metal compute; macOS dynamically reserves ~4.5 GiB for WindowServer, unified compositor surfaces, and kernel pages, leaving ~11.5 GiB safe wired GPU ceiling.

  2. Step 02 · Pick Safe Quant

    9.00 GiB on 16 GB Air · 12.90 GiB on 24 GB Pro. Loading UD-IQ3_S (12.90 GiB) onto a 16 GB MacBook Air forces constant Metal page compression and SSD swap thrashing, cutting generation from 50+ tok/s down to <3 tok/s.

  3. Step 03 · Enable Lazy mmap

    Drop --mlock so cold Engram stays on APFS NVMe. UD-IQ2_XXS (9.00 GiB backbone, 1.55 GB/tok active read) fits inside 11.5 GiB alongside 32K Q8_0 KV (0.91 GiB) and scratch buffers, yielding a 77.4 tok/s theoretical M4 roofline.

  4. Step 04 · Cap Context KV

    Lock 32K–128K Q8_0 KV inside wired headroom. On 24 GB M4 Pro laptops (~18.5 GiB usable Metal allocation), UD-IQ3_S (12.90 GiB) pairs with 128K Q8_0 KV (2.91 GiB) and 0.75 GiB scratch (16.56 GiB total) without swap pressure.

1. Understanding macOS iogpu.wired_limit_mb and WindowServer Overhead

Linux GPU engineers accustomed to dedicated VRAM often assume a 16 GB or 24 GB Apple Silicon laptop offers nearly 100% of physical LPDDR5X to Metal compute kernels. In reality, macOS protects system responsiveness by capping maximum wired GPU allocations (historically near two-thirds to three-quarters of physical RAM by default) because WindowServer display compositing, SwiftUI surfaces, Spotlight, and audio drivers share the exact same physical memory chips.

Attempting to force 14.5 GiB of model weights plus KV cache onto a 16 GB MacBook Air without leaving breathing room forces the Mach VM subsystem into aggressive memory compression and continuous swap-in/swap-out paging against the internal NVMe SSD. That destroys both interactive UI responsiveness and token throughput while burning unnecessary SSD TBW write endurance.

Establishing a conservative usable ceiling—approximately 11.5 GiB on 16 GB Macs and 18.5 GiB on 24 GB M4 Pro systems when a browser and editor stay open—keeps Metal command buffers 100% resident in physical DRAM with zero page faults during token decode.

Usable_Mac_Budget ≈ Physical_RAM_GiB - Reserve_OS(4.5 to 5.5 GiB)
16 GB MacBook Air: 16.0 - 4.5 = 11.5 GiB safe Metal budget
24 GB M4 Pro:     24.0 - 5.5 = 18.5 GiB safe Metal budget

2. 16 GB MacBook Air Playbook: UD-IQ2_XXS & UD-IQ1_M Tuning

Running a 35B-parameter MoE architecture locally on a fanless 16 GB laptop becomes practical only when pairing dynamic 2-bit quantization with Host-RAM/APFS Engram offloading. UD-IQ2_XXS packs the 35B MoE backbone into 9.00 GiB and reads 1.55 GB per generated token. Adding a 32,768-token Q8_0 QSA KV cache (~0.66 GiB) plus 0.25 GiB Gated-DeltaNet recurrent state and 0.75 GiB Metal scratch totals 10.66 GiB—sliding comfortably inside the 11.5 GiB safe window.

On a 120 GB/s M4 MacBook Air, 1.55 GB/tok active reads yield a theoretical batch-1 ceiling of 77.4 tok/s (often settling around 48–60 tok/s sustained before thermal throttling on long continuous generations). For fanless laptops executing multi-minute bursts, clamping context to 16K–32K avoids memory pressure and keeps chassis temperatures modest.

When an even lighter footprint is needed alongside heavy IDE processes or Docker containers, dropping to UD-IQ1_M (7.60 GiB, 1.35 GB/tok) reclaims 1.40 GiB immediately while pushing theoretical decode speed toward 88.9 tok/s on 120 GB/s M4 Air silicon.

16 GB MacBook Air Memory Breakdown: UD-IQ1_M vs. UD-IQ2_XXS
Allocation ComponentUD-IQ1_M + 64K Q8 KVUD-IQ2_XXS + 32K Q8 KV
35B MoE Backbone Weights7.60 GiB9.00 GiB
QSA KV Cache (Q8_0) + 0.25 GiB GDN1.58 GiB (64K)0.91 GiB (32K)
Metal Compute Scratch Buffer0.75 GiB0.75 GiB
Total Wired Residency (<= 11.5 GiB)9.93 GiB (SAFE)10.66 GiB (SAFE)

3. 24 GB M4 Pro Playbook: Unlocking UD-IQ3_S & 128K Context

Stepping up to the 24 GB MacBook Pro or Mac mini M4 Pro changes two critical parameters simultaneously: usable GPU budget rises from ~11.5 GiB to ~18.5 GiB, and unified memory bandwidth more than doubles from 120 GB/s to 273 GB/s. That jump unlocks UD-IQ3_S (12.90 GiB backbone, 2.45 GB/tok active read), eliminating 2-bit syntax quirks on complex TypeScript, Python, and SQL generation.

With 12.90 GiB allocated to the 35B MoE weights, ~5.60 GiB remains cleanly inside the 18.5 GiB envelope. Allocating 131,072 tokens of Q8_0 KV (2.66 GiB) plus 0.25 GiB Gated-DeltaNet state and 0.75 GiB Metal compute scratch lands at exactly 16.56 GiB—preserving nearly 2 GiB of safety cushion while operating at a 111.4 tok/s theoretical roofline.

Note that jumping to 262,144 tokens on a 24 GB M4 Pro works strictly if you switch KV cache precision down to Q4_0 (1.41 GiB QSA + 0.25 GiB GDN = 1.66 GiB context, wait: 256K Q4_0 is ~2.81 GiB + 0.25 = 3.06 GiB, totaling 16.71 GiB!). That allows 256K repository context fits inside 24 GB Macs without touching swap.

4. Essential Flags: --no-mlock, Lazy Engram, and Activity Monitor Guards

Never blindly combine --mlock with large GGUF checkpoints on 16–24 GB Apple Silicon machines. Locking an entire unified GGUF file in non-pageable physical RAM prevents macOS from keeping cold Engram embeddings cleanly backed by APFS NVMe pages, directly triggering out-of-memory kills when Safari or VS Code spikes memory.

Instead, keep --no-mlock enabled alongside -ot "engram=CPU" and -ngl 99. macOS keeps actively executing Metal MoE buffers wired via MTLStorageModeShared while allowing cold Engram row pages to stream transparently through the APFS page cache. Monitor Activity Monitor’s Memory Pressure graph during initial 32K prefill: steady green pressure with <500 MB Swap Used confirms healthy residency; yellow/red pressure or multi-gigabyte Swap Used means you must drop context length or step down one quant tier.

Actionable Checklist
  • Watch Activity Monitor Memory Pressure: must remain Green under active decode.
  • Always use --no-mlock on 16 GB and 24 GB Macs running lazy Engram offload.
  • Set batch size -b 512 -ub 256 to constrain temporary Metal prefill scratch peaks.
  • Avoid UD-IQ4_XS (20.40 GiB) on 24 GB Macs; reserve it for 36–48 GB+ systems.

5. Copy-Paste Verified Launch Recipes for 16 GB Air & 24 GB M4 Pro

Below are clean, production-safe llama-server invocations matching our 16 GB and 24 GB residency calculations. Notice the pairing of FlashAttention (-fa on), quantized KV (-ctk q8_0 -ctv q8_0), reduced micro-batch size (-ub 256) to prevent temporary Metal activation spikes during large prompt ingestion, and explicit Host-CPU Engram routing.

Before finalizing your local setup, plug your exact Mac model and desired token context into /tools/gguf-vram-calculator to confirm utilization stays strictly below safe wired limits.

# 16 GB MacBook Air (UD-IQ2_XXS, 32K Q8_0 KV):
llama-server -m Qwen4-35B-A3B-UD-IQ2_XXS.gguf -c 32768 -ctk q8_0 -ctv q8_0 -fa on -ot "engram=CPU" --no-mlock -b 512 -ub 256 -ngl 99

# 24 GB M4 Pro (UD-IQ3_S, 128K Q8_0 KV):
llama-server -m Qwen4-35B-A3B-UD-IQ3_S.gguf -c 131072 -ctk q8_0 -ctv q8_0 -fa on -ot "engram=CPU" --no-mlock -b 512 -ub 256 -ngl 99

16 GB MacBook Air vs. 24 GB MacBook Pro M4 Pro Safe Memory Allocation Matrix

16 GB MacBook Air vs. 24 GB MacBook Pro M4 Pro Safe Memory Allocation Matrix
Mac Configuration & Usable CeilingRecommended Qwen 4 QuantContext Budget & Observed Behavior
16 GB M3/M4 Air (~11.5 GiB usable)UD-IQ1_M (7.60 GiB, 1.35 GB/tok)64K Q8_0 KV (1.58 GiB) fits; zero swap; fastest 16 GB draft mode
16 GB M3/M4 Air (~11.5 GiB usable)UD-IQ2_XXS (9.00 GiB, 1.55 GB/tok)32K Q8_0 KV (0.91 GiB) fits; 77.4 tok/s theoretical M4 roofline
16 GB M3/M4 Air (~11.5 GiB usable)UD-IQ3_S (12.90 GiB) — UNSAFEExceeds usable limit -> triggers heavy APFS swap & UI stutter
24 GB M4 Pro (~18.5 GiB usable)UD-IQ3_S (12.90 GiB, 2.45 GB/tok)128K Q8_0 KV (2.91 GiB) = 16.56 GiB total; 111.4 tok/s roofline
24 GB M4 Pro (~18.5 GiB usable)UD-IQ4_XS (20.40 GiB) — UNSAFEExceeds 24 GB UMA ceiling unless raised dangerously via sysctl

Connected Workflows & Technical References

Launch pre-configured interactive sandboxes or read paired Academy, Guide, and GGUF specifications.

Verify 16/24 GB Mac Fit →
FOUNDER_999_LOCK · 67% OFF ALL-IN-ONE PRO

Run Every Studio Unlimited at $9.99/mo (Web Cloud + 5 Apple Silicon Macs)

Consolidate $130+/mo of separate writing, PDF, citation, cutout, video, and 1-second charting subscriptions into one local-first workspace — backed by a 14-day refund window and 1-click cancel.

Publisher & Creator Partner Network
Embed Zero-Upload Tools & Earn 40% Recurring

Add our 1-line Shadow DOM widget to your blog or share your partner link for 40% monthly / 30% annual recurring revenue.

More in Local Apple Silicon AI, Zero-Upload Privacy & Post-Quantum Web Security (8 Sibling Playbooks)

All 84 Articles →
FAQ · DIRECT ANSWERS

Local Apple Silicon AI, Zero-Upload Privacy & Post-Quantum Web Security — FAQ

05 Questions
Why does UD-IQ3_S (12.90 GiB) fail on a 16 GB MacBook Air?
macOS reserves ~4.5 GiB for WindowServer and kernel buffers, leaving ~11.5 GiB usable GPU pool. Loading 12.90 GiB plus KV cache triggers heavy SSD swap thrashing.
Which Qwen 4 quant runs cleanly on a 16 GB MacBook Air?
UD-IQ2_XXS (9.00 GiB) with 32K Q8_0 KV or UD-IQ1_M (7.60 GiB) with 64K Q8_0 KV fits safely inside the ~11.5 GiB usable budget with --no-mlock lazy Engram.
How much context fits on a 24 GB M4 Pro with Qwen 4 UD-IQ3_S?
128K context in Q8_0 KV fits comfortably (16.56 GiB total vs ~18.5 GiB usable), and 256K fits cleanly if KV is quantized to Q4_0 (~16.71 GiB total).
Should I use --mlock on 16–24 GB Apple Silicon Macs?
No. Always leave --mlock off (--no-mlock) when using APFS lazy Engram offloading so macOS can keep cold Engram pages cleanly backed on SSD without forcing OOM kills.
What batch flags prevent temporary Metal scratch spikes during prefill?
Capping logical/physical micro-batches with -b 512 -ub 256 keeps intermediate activation buffers under ~0.75 GiB during long prompt ingestion.
Founder Pro $9.99/mo · 67% Off1-tap Stripe Checkout · Instant ?ref= Free Months · 40% Recurring Partner Payouts
1. Subscribe in 1 TapFOUNDER_999_LOCK

Unlock All 19 Pro Studios + Mac App

Lock $9.99/mo Founder Pro (reg. $29.99 — 67% off), $119/yr Web Annual (-34%), or $299/yr 5-Mac + Web Pro.

Redeem Code
2. Get 6 Months FreeZERO OTP

Mint Your ?ref= Link Instantly

Give friends 67% off ($9.99/mo). Every paid friend adds 30 days of Pro free to your account (up to 6 months).

Dashboard: /refer · Rules

3. Creator & Publisher Cash90-DAY COOKIE

Earn 40% Monthly · 30% Annual

Earn 40% recurring monthly until cancel + 30% annual & every renewal, or embed our free tools with data-ref.