Fine Tune kernel level

Hi all,

recently I noticed a performance issues related to the resources utilisation and I decided to fine tune the OS/linux rather than only the vLLM and RAY layer. If you have done anything similar please share.

Summary of Final State

  • Latency: 0.09s (TTFT)
  • Throughput: 52.59 tokens/s
  • Context: 262,144 tokens (Stable)
  • Concurrency & capacity: Supports up to 54 simultaneous users at the full 262,144 token context window with 115.5 tokens/s

Summary before tuning.

  • Latency: 0.10s (TTFT)
  • Throughput: 46.66 tokens/s
  • Context: 262,144 tokens (Stable)
  • Concurrency & capacity: Supports up to 54 simultaneous users at the full 262,144 token context window with 46.66 tokens/s

How I did it,

Linux Kernel & OS Optimisations
These changes were applied to the underlying DGX OS (Ubuntu 24.04 ARM64 6.17.0-1021-nvidia) to remove system jitter and maximise the performance of the unified memory bus.

CPU Fencing (Hardware Isolation)
Applied via /etc/default/grub to isolate the ARM64 Cortex-X925 Performance Cores.

  • isolcpus=10-19: Removes the 10 performance cores from the general Linux scheduler.
  • nohz_full=10-19: Enables “Tickless Mode,” stopping the kernel timer interrupt on those cores to eliminate context-switching overhead.
  • rcu_nocbs=10-19: Offloads Read-Copy-Update (RCU) locking callbacks to the efficiency cores.
  • processor.max_cstate=1: Disables deep-sleep energy saving to ensure zero wake-up latency.

Virtual Memory (VM) Subsystem
Applied via sysctl to prevent memory-to-NVMe bus contention.

  • vm.swappiness=0: strictly prohibits the kernel from moving model weights to disk.
  • vm.max_map_count=2097152: Increased to handle the massive memory mapping requirements of the 262k context window.
  • vm.dirty_ratio=5 / vm.dirty_background_ratio=2: Forces frequent, small disk writes to prevent large I/O bursts from saturating the LPDDR5X bus.
  • Huge Pages: Set to madvise to allow vLLM to manage 2MB/1GB pages without the overhead of automatic background compaction.

Networking (ConnectX-7 200G Fabric)
Applied to the InfiniBand/RoCEv2 bond0 interface.

  • net.ipv4.tcp_congestion_control=bbr: Used Google’s BBR to maximize throughput and minimize latency on the point-to-point link.
  • net.core.rmem_max=134217728 (128MB): Expanded socket buffers to handle high-bandwidth tensor transfers.
  • RoCE QoS: Configured Priority Flow Control (PFC) on priority lane 3 to ensure lossless communication during All-Reduce operations.

vLLM Engine & Model Optimisations
These settings were configured for vLLM v0.22.1rc1 to leverage the Blackwell (sm_100) hardware primitives.

Computational Backends

  • flashinfer: Enabled the Blackwell-optimized attention backend, which provides superior performance for MoE (Mixture of Experts) architectures.
  • instanttensor Loader: Utilized the unified memory architecture to map Safetensors directly from NVMe to VRAM, resulting in an 18-second cold boot for the 35B model.
  • FP8 KV-Cache: Enabled 8-bit quantization for the attention cache, doubling the available concurrency to 54x for the 262k context window.

Model-Specific Fixes (Qwen 3.6 35B)

  • Processor Realignment: Manually patched preprocessor_config.json to replace the deprecated Qwen2VLImageProcessorFast with Qwen2VLImageProcessor, resolving internal vision-init hangs.

Distributed Coordination (Ray)

  • TP=2 (Tensor Parallelism): Layers were split across both GPUs over the bond0 200G link.
  • VLLM_RPC_TIMEOUT=600000: Increased the internal timeout to 10 minutes to accommodate the heavy torch.compile graph-capturing phase required for Blackwell optimisations.
  • Dedicated Worker Locks: Enabled shared memory locking between Ray actors to stabilise distributed memory access.

I create a script finetune.sh to apply and revert the settings above.

Sharing this script only for reference needs
Adjustments and tests needed before use.

#!/usr/bin/env bash
# setup_production_fabric.sh - Production-grade tuning for NVIDIA DGX Spark (Blackwell)
set -euo pipefail

# --- Configuration ---
MODEL_DIR="/home/geo/.cache/huggingface/hub/models--Qwen--Qwen3.6-35B-A3B-FP8"
PERF_CORES="10-19"
EFF_CORES="0-9"
BOND_IFACE="bond0"

log() { echo -e "\033[1;32m[$(date +%H:%M:%S)] $*\033[0m"; }
warn() { echo -e "\033[1;33m[WARN] $*\033[0m"; }

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root (sudo)."
   exit 1
fi

apply_optimizations() {
    log ">>> Starting Full Production Alignment..."

    # 1. Hardware Fencing (CPU Isolation)
    log "[1/6] Configuring CPU Isolation (GRUB)..."
    if ! grep -q "isolcpus" /etc/default/grub; then
        sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"/GRUB_CMDLINE_LINUX_DEFAULT="\1 isolcpus='"$PERF_CORES"' nohz_full='"$PERF_CORES"' rcu_nocbs='"$PERF_CORES"' processor.max_cstate=1 arm_pmu.max_features=0"/' /etc/default/grub
        update-grub || grub-mkconfig -o /boot/grub/grub.cfg
        warn "CPU Isolation configured. A REBOOT is required to activate this fencing."
    else
        log "CPU Isolation already configured in GRUB."
    fi

    # 2. Virtual Memory & Bus Tuning (Persistent)
    log "[2/6] Applying Persistent Sysctl (Memory/Network)..."
    cat > /etc/sysctl.d/99-blackwell-perf.conf <<EOF
# Prevent bus contention
vm.swappiness = 0
vm.max_map_count = 2097152
vm.overcommit_memory = 1
vm.dirty_background_ratio = 2
vm.dirty_ratio = 5
vm.zone_reclaim_mode = 0
vm.panic_on_oom = 1
# 200G Fabric Tuning
net.core.netdev_max_backlog = 500000
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
net.core.somaxconn = 65535
net.ipv4.tcp_rmem = 4096 87380 134217728
net.ipv4.tcp_wmem = 4096 65536 134217728
net.ipv4.tcp_congestion_control = bbr
net.core.default_qdisc = fq
EOF
    sysctl --system

    # 3. Transparent Huge Pages
    log "[3/6] Setting THP to madvise..."
    echo madvise > /sys/kernel/mm/transparent_hugepage/enabled
    echo madvise > /sys/kernel/mm/transparent_hugepage/defrag

    # 4. Storage & Interrupts
    log "[4/6] Optimizing NVMe and IRQ Affinity..."
    if [ -d "/sys/block/nvme0n1/queue" ]; then
        echo none > /sys/block/nvme0n1/queue/scheduler
        echo 1024 > /sys/block/nvme0n1/queue/max_sectors_kb
        echo 4096 > /sys/block/nvme0n1/queue/read_ahead_kb
    fi
    systemctl stop irqbalance && systemctl disable irqbalance
    # Move interrupts to efficiency cores (mask 0x3ff)
    for irq in /proc/irq/*; do
        if [ -d "$irq" ]; then echo "3ff" > "$irq/smp_affinity" 2>/dev/null; fi
    done

    # 5. Model-Specific Fixes (Qwen 3.6)
    log "[5/6] Patching Qwen 3.6 Model Configs..."
    if [ -d "$MODEL_DIR" ]; then
        find "$MODEL_DIR" -name "preprocessor_config.json" -exec sed -i 's/Qwen2VLImageProcessorFast/Qwen2VLImageProcessor/g' {} +
    else
        warn "Model directory not found, skipping patch."
    fi

    # 6. Limits (Persistent)
    log "[6/6] Increasing System Limits..."
    cat > /etc/security/limits.d/blackwell.conf <<EOF
* soft    memlock         unlimited
* hard    memlock         unlimited
* soft    nofile          1048576
* hard    nofile          1048576
EOF

    log ">>> Production Alignment Complete."
    log ">>> PLEASE REBOOT to finalize the CPU Hardware Fence."
}

revert_optimizations() {
    log ">>> Reverting Changes..."
    rm -f /etc/sysctl.d/99-blackwell-perf.conf
    rm -f /etc/security/limits.d/blackwell.conf
    sed -i 's/ isolcpus=.*arm_pmu.max_features=0//' /etc/default/grub
    update-grub || grub-mkconfig -o /boot/grub/grub.cfg
    systemctl enable irqbalance && systemctl start irqbalance
    log ">>> Reverted. Please reboot."
}

case "${1:-}" in
    --apply)  apply_optimizations ;;
    --revert) revert_optimizations ;;
    *) echo "Usage: sudo $0 {--apply|--revert}"; exit 1 ;;
esac

How to use it:

To apply all the production-grade kernel and model optimizations:

sudo ./setup_production_fabric.sh --apply

To revert all changes to the system default:

sudo ./setup_production_fabric.sh --revert

What this script applies

  • CPU Hardware Fence: Strictly reserves Cores 10-19 for vLLM, moving everything else to Cores 0-9.
  • Tickless Performance: Disables kernel timer interrupts on the Performance Cores.
  • Unified Memory Safety: Disables swap and sets low dirty-page flush ratios to protect the LPDDR5X bus from NVMe interference.
  • 200G Fabric Optimisation: Enables BBR and expands TCP buffers to 128MB for the InfiniBand link.
  • Model Patching: Automatically fixes the Qwen2VLImageProcessorFast deprecation bug in your model files.
  • Storage Throughput: Bypasses kernel I/O scheduling for the local NVMe drive.

How I started the model.

 docker exec -d spark-ray bash -c "
    HF_HUB_OFFLINE=1 \
    RAY_ADDRESS=10.10.10.1:6379 \
     VLLM_RPC_TIMEOUT=600000 \
      vllm serve Qwen/Qwen3.6-35B-A3B-FP8 \
         --tensor-parallel-size 2 \
         --max-model-len 262144 \
         --gpu-memory-utilization 0.8 \
         --kv-cache-dtype fp8 \
        --attention-backend flashinfer \
        --load-format instanttensor \
        --enable-prefix-caching \
        --enable-chunked-prefill \
        --distributed-executor-backend ray"

m

@geo.politis your CPU fencing might not be correct. If you check which cores are P and which ones are E the mapping is like:

0-4 E
10-14 E

5-9 P
15-19 P

Here’s output of lscpu:

elsaco@spark2:~$ lscpu -e=CPU,CORE,SOCKET,NODE,MAXMHZ,MINMHZ
CPU CORE SOCKET NODE    MAXMHZ    MINMHZ
  0    0      0    0 2808.0000  338.0000
  1    1      0    0 2808.0000  338.0000
  2    2      0    0 2808.0000  338.0000
  3    3      0    0 2808.0000  338.0000
  4    4      0    0 2808.0000  338.0000
  5    0      0    0 3900.0000 1378.0000
  6    1      0    0 3900.0000 1378.0000
  7    2      0    0 3900.0000 1378.0000
  8    3      0    0 3900.0000 1378.0000
  9    4      0    0 3900.0000 1378.0000
 10    5      0    0 2808.0000  338.0000
 11    6      0    0 2808.0000  338.0000
 12    7      0    0 2808.0000  338.0000
 13    8      0    0 2808.0000  338.0000
 14    9      0    0 2808.0000  338.0000
 15    5      0    0 3900.0000 1378.0000
 16    6      0    0 3900.0000 1378.0000
 17    7      0    0 3900.0000 1378.0000
 18    8      0    0 3900.0000 1378.0000
 19    9      0    0 3900.0000 1378.0000

A proper setting would be isolcpus=5-9,15-19


From System Overview — NVIDIA DGX Spark Porting Guide

Our ARM SoC features a hybrid architecture consisting of 2 clusters.

Each cluster has 5 high-performance cores (ARM v9.2, Cortex-X925) with 2MB L2 cache each, and 5 high-efficiency cores (ARM v9.2, Cortex-A725) with 512KB L2 cache each. The high-performance cluster features 16MB L3 cache, while the high-efficiency cluster is equipped with an 8MB L3 cache.

We don’t use TCP across the 200G links, they should use NCCL.

@geo.politis thank you for your script idea!

One remark though: to remain valid over time rather than as a monolithic script, the tuning could be split across:

  1. setup_hardware_fabric.sh # CPU fencing, VM, network, NVMe, IRQ
  2. setup_vllm_engine.sh # vLLM flags, backends, distributed config
  3. fix_qwen_preprocessor.sh # one-off model patch (or ideally, upstream fix)

Different distro’s exists as of today to run customized/optimized versions of vLLM (/w patches) and specific model patches. E.g.:

Your topic post/this forum thread would be ideal to capture and document tuning and tweaks.