--- name: ram-optimizer description: Use this skill when the user asks to "optimize RAM", "boost memory", "setup ZRAM", "compress memory", "increase effective RAM", "low memory optimization", or mentions RAM compression/memory optimization for any Linux server or system. Works for local machines and remote SSH servers. version: 1.0.0 --- # RAM Optimizer Skill This skill optimizes Linux system memory by setting up ZRAM compressed swap, enabling KSM (Kernel Samepage Merging), and applying sysctl optimizations for low-memory systems. ## What It Does 1. **ZRAM Setup**: Creates compressed RAM-based swap (typically 2:1 to 3:1 compression ratio) 2. **KSM Enablement**: Deduplicates identical memory pages 3. **Sysctl Tuning**: Optimizes kernel memory management parameters 4. **Optional**: Removes traditional disk swap to free space and improve performance ## When To Use This Skill Activate this skill when the user: - Asks to optimize RAM/memory on a Linux system - Mentions running low on memory - Wants to set up ZRAM or memory compression - Needs to boost a server with limited RAM - Mentions "effective memory" or "RAM compression" ## Supported Systems - Ubuntu/Debian (apt-based) - Fedora/RHEL/CentOS (dnf/yum-based) - Arch Linux (pacman-based) ## Usage Instructions ### For Local Machine Simply run the skill and it will detect and optimize the local system. ### For Remote SSH Server Provide SSH credentials in one of these formats: - `SSH IP: x.x.x.x, SSH User: username, SSH Pass: password` - Or mention the server details in your request ## Configuration Options The user may request these customizations: - **ZRAM percentage**: Default is 75% of RAM. User can request 50%, 100%, etc. - **Compression algorithm**: Default is `lz4` (fastest). Alternatives: `zstd` (better compression), `lzo` - **Keep or remove disk swap**: Default removes disk swap. User can request to keep it. - **Install monitoring**: User can request Conky (desktop widget) or btop (terminal monitor) ## Implementation Steps When this skill is invoked, follow these steps: ### Step 1: Detect Target System ```bash # For local: cat /etc/os-release free -h # For remote: ssh user@host 'cat /etc/os-release; free -h' ``` ### Step 2: Install ZRAM Tools ```bash # Ubuntu/Debian apt install -y zram-tools # Fedora dnf install -y zram # Arch pacman -S zram-generator ``` ### Step 3: Configure ZRAM ```bash # /etc/default/zramswap (Debian/Ubuntu) ALGO=lz4 PERCENT=75 PRIORITY=100 ``` ### Step 4: Enable KSM ```bash echo 1 > /sys/kernel/mm/ksm/run echo 1000 > /sys/kernel/mm/ksm/sleep_millisecs ``` ### Step 5: Apply Sysctl Optimizations ```bash # /etc/sysctl.d/99-lowram.conf vm.swappiness=100 vm.vfs_cache_pressure=200 vm.compaction_proactiveness=30 vm.overcommit_memory=1 vm.overcommit_ratio=50 vm.ksm.run=1 ``` ### Step 6: Start ZRAM Service ```bash systemctl enable --now zramswap.service ``` ### Step 7: (Optional) Remove Disk Swap ```bash swapoff /swapfile rm /swapfile sed -i '/\/swapfile/d' /etc/fstab ``` ## Expected Results | Metric | Typical Value | |--------|---------------| | Compression ratio | 2:1 to 3:1 | | RAM reduction | ~40% average | | CPU overhead | 1-3% | | Effective memory | Physical × 2 | ## Verification Commands ```bash # Show ZRAM status zramctl # Show swap status swapon --show # Show memory free -h # Show compression efficiency cat /sys/block/zram0/mm_stat ``` ## Troubleshooting - **ZRAM won't start**: Check if another swap is using high priority - **High CPU usage**: Switch to lz4 algorithm (fastest) - **Low compression ratio**: Try zstd algorithm for better compression - **Out of memory still**: Increase PERCENT to 100 or add physical RAM