# Performance & Stability Optimizations

# Performance & Stability Optimizations

This page documents the specific kernel and hardware tweaks applied to Terra (Ryzen 5950X / Ubuntu 24.04) to optimize for container performance, storage throughput, and long-term stability.

## 🛡️ Stability & Power Management (The "Golden Config")

### Typical Current Idle (UEFI)
*   **Setting:** Advanced > AMD CBS > CPU Common > Power Supply Idle Control = "Typical Current Idle"
*   **Benefit:** Prevents the Ryzen "Sleep of Death" where the PSU cuts power during deep C-state transitions. Essential for 24/7 server stability on X570 boards.

### Processor C-State Limit (Kernel)
*   **Driver:** `processor.max_cstate=1`
*   **Benefit:** Software-side enforcement of the Idle fix. Limits the CPU to C1 (Halt/Idle) instead of deeper sleep states (C6), preventing interrupt processing delays and hardware hangs.
*   **Configuration:** Added to `GRUB_CMDLINE_LINUX_DEFAULT` in `/etc/default/grub`.

### 65W Eco Mode (Manual PBO)
*   **Settings:** PPT: 88, TDC: 60, EDC: 90
*   **Benefit:** Drastically reduces thermals (peak temps dropped from ~90°C to 58°C) without significant impact on multi-core performance. Ideal for 4U rackmount chassis airflow.
*   **Configuration:** UEFI > Precision Boost Overdrive > Manual.

## ⚡ CPU & Power Performance

### AMD P-State (Active Mode)
*   **Driver:** `amd_pstate=active` (EPP - Energy Performance Preference)
*   **Benefit:** Allows the kernel to communicate directly with the Zen 3 power management controller. Enables a wider frequency range (550MHz - 5000MHz).

### IRQ Balancing
*   **Service:** `irqbalance` (Installed/Enabled)
*   **Benefit:** Distributes hardware interrupts (HBA, NVMe, NIC) across all threads, preventing Core 0 bottlenecks.

## 🧠 Memory Tuning

### Speed & Stability
*   **Configuration:** Currently hard-coded to **2133MHz** at **AUTO** voltage.
*   **Note:** Troubleshooting in Feb 2026 confirmed that 3000MHz at 1.35V caused instantaneous reboots. Stability requires sticking to JEDEC defaults for now.

### Static Hugepages
*   **Setting:** `hugepages=2048` (Reserving 4GB total as 2MB pages)
*   **Benefit:** Reduces TLB misses for memory-heavy apps like Minecraft and Postgres.

## 💾 I/O & Network Tuning (sysctl)

### ZFS Write Buffering
*   **Settings:** `vm.dirty_background_bytes = 268435456`, `vm.dirty_bytes = 1073741824`
*   **Benefit:** Prevents the kernel from buffering too much data in RAM before flushing to ZFS, eliminating system-wide UI/process stutter.

### Fluent-bit Batching (ClickHouse)
*   **Setting:** `Flush 60` in `fluent-bit.conf`
*   **Benefit:** Reduced ClickHouse CPU usage from 80% spikes to <5% by reducing transaction frequency and optimizing ZFS write contiguousness.

## 🎮 GPU Optimization (Quadro P2200)

### Persistence Mode
*   **Command:** `sudo nvidia-smi -pm 1`
*   **Benefit:** Eliminates the 2-second initialization delay for AI inference and transcoding containers.