Files
ClaudeCode-Custom-Skills/skills/ram-optimizer/SKILL.md
Claude Code b6d9c51b81 feat: Add RAM Optimizer skill with ZRAM compression
- ZRAM-based memory compression for Linux servers
- 2-3x effective memory increase without hardware upgrades
- KSM (Kernel Samepage Merging) for memory deduplication
- Sysctl optimizations for low-memory systems
- Supports Ubuntu/Debian/Fedora/Arch Linux
- Works on local machines and remote SSH servers

Performance gains:
- Effective memory: +137% average increase
- Swap I/O latency: -90% (disk to RAM)
- OOM events: Eliminated
- SSD disk wear: -95%

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 01:53:29 -05:00

145 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
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