-
Notifications
You must be signed in to change notification settings - Fork 0
Process Priority Tiers
The Linux Swap Optimizer uses a sophisticated process categorization system to optimize system performance by assigning appropriate CPU and I/O priorities to different types of processes. This ensures that critical applications receive the resources they need while maintaining overall system stability.
Purpose: Machine learning and AI workloads require maximum resources for optimal performance.
Processes Included:
- Python (for AI/ML frameworks)
- Jupyter (notebooks)
- Ollama, Llama (local LLMs)
- TensorFlow, PyTorch (ML frameworks)
Priority Settings:
- CPU Priority (nice): -10 (very high priority)
- I/O Priority: Class 1 (realtime), Level 4
Rationale: AI/ML workloads are computationally intensive and benefit from maximum CPU and I/O resources. These processes often handle large datasets and model training/inference, which require consistent performance.
Purpose: Development environments need responsive performance for developer productivity.
Processes Included:
- VS Code, Cursor, VSCodium
- JetBrains suite (IntelliJ IDEA, PyCharm, WebStorm, PHPStorm, CLion, Rider, DataGrip, RubyMine, GoLand)
- Text editors (Vim, Neovim, Emacs, Nano, Gedit, Kate, Geany)
- Other editors (Atom, Sublime Text, Android Studio)
Priority Settings:
- CPU Priority (nice): -5 (high priority)
- I/O Priority: Class 1 (realtime), Level 4
Rationale: IDEs are interactive applications where responsiveness directly impacts developer productivity. High I/O priority ensures smooth file operations and code completion.
Purpose: User-facing applications that benefit from good responsiveness but aren't critical.
Processes Included:
- Web browsers (Firefox, Chrome, Chromium, Brave, Opera)
- Email clients (Thunderbird, Evolution)
- Communication apps (Discord, Slack, Telegram, Zoom, Teams, Skype)
- Media players (VLC, MPV, MPlayer)
Priority Settings:
- CPU Priority (nice): -2 (slightly elevated priority)
- I/O Priority: Class 2 (best-effort), Level 4
Rationale: Interactive applications need good responsiveness for user experience but don't require the extreme priority of development tools.
Purpose: Standard applications that don't fit into other categories.
Processes Included:
- All other applications not in specific categories
- General user applications
- Standard system tools
Priority Settings:
- CPU Priority (nice): 0 (default priority)
- I/O Priority: Class 2 (best-effort), Level 7
Rationale: These processes receive standard system priority, ensuring fair resource allocation without special treatment.
Purpose: System services and background tasks that should not interfere with user applications.
Processes Included:
- System services (systemd, cron, rsyslog)
- Network services (NetworkManager, bluetooth)
- Print services (CUPS)
- Discovery services (Avahi)
Priority Settings:
- CPU Priority (nice): 5 (lower priority)
- I/O Priority: Class 3 (idle), Level 0
Rationale: Background services should yield to user-facing applications to maintain system responsiveness.
The nice value ranges from -20 (highest priority) to 19 (lowest priority), with 0 being the default.
-20 ──────────────────────────────────────── 19
↑ ↑
Highest Priority Lowest Priority
Our Implementation:
- AI: -10 (very high)
- IDE: -5 (high)
- Interactive: -2 (slightly elevated)
- Normal: 0 (default)
- Background: 5 (lower)
I/O priority has three classes and levels within each class:
Classes:
- Class 1: Realtime (highest)
- Class 2: Best-effort (default)
- Class 3: Idle (lowest)
Levels (0-7, lower is higher priority within class):
- 0: Highest priority within class
- 7: Lowest priority within class
Our Implementation:
- AI: Class 1, Level 4 (realtime, medium)
- IDE: Class 1, Level 4 (realtime, medium)
- Interactive: Class 2, Level 4 (best-effort, medium)
- Normal: Class 2, Level 7 (best-effort, low)
- Background: Class 3, Level 0 (idle, highest within idle)
The system categorizes processes using the following logic:
def _categorize_process(proc):
proc_name = proc.info['name'].lower()
# Check AI processes (highest priority)
for ai_proc in config['ai_processes']:
if ai_proc in proc_name:
return 'ai'
# Check IDE processes (high priority)
for ide_proc in config['ide_processes']:
if ide_proc in proc_name:
return 'ide'
# Check interactive processes (medium priority)
for app in config['interactive_processes']:
if app in proc_name:
return 'interactive'
# Check background processes (low priority)
for bg_proc in config['background_processes']:
if bg_proc in proc_name:
return 'background'
# Default to normal priority
return 'normal'You can customize the process lists in /etc/swap-optimizer/config.json:
{
"ai_processes": [
"python", "jupyter", "ollama", "llama", "tensor", "torch"
],
"ide_processes": [
"code", "cursor", "idea", "pycharm", "webstorm", "phpstorm",
"clion", "rider", "datagrip", "rubymine", "appcode",
"goland", "android-studio", "vscode", "atom", "sublime",
"emacs", "vim", "nvim", "neovim", "nano", "gedit",
"kate", "kwrite", "geany", "code-insiders", "codium"
],
"interactive_processes": [
"firefox", "chrome", "chromium", "brave", "opera",
"thunderbird", "evolution", "discord", "slack", "telegram",
"zoom", "teams", "skype", "vlc", "mpv", "mplayer"
],
"background_processes": [
"systemd", "cron", "anacron", "atd", "rsyslog",
"dbus", "NetworkManager", "bluetooth", "cups", "avahi"
]
}Control whether all processes are optimized using the optimize_all_apps setting:
{
"optimize_all_apps": true
}-
true: Optimize all processes across all categories (default) -
false: Only optimize AI and IDE processes (legacy mode)
sudo python3 /opt/swap-optimizer/swap_optimizer.py --statusOutput includes:
{
"process_categories": {
"ai": 2,
"ide": 0,
"interactive": 1,
"normal": 205,
"background": 19
},
"total_processes": 227
}# Watch process priorities
watch -n 1 'ps -eo pid,ni,comm | head -20'
# View I/O priorities
sudo ionice -p $(pgrep python)To add a custom process to a specific category:
- Edit
/etc/swap-optimizer/config.json - Add the process name to the appropriate array
- Restart the service
{
"ai_processes": [
"python", "jupyter", "ollama", "llama", "tensor", "torch",
"my-custom-ai-app"
]
}To modify priority settings, edit the priority_settings dictionary in swap_optimizer.py:
priority_settings = {
'ai': {'nice': -10, 'ionice_class': 1, 'ionice_level': 4},
'ide': {'nice': -5, 'ionice_class': 1, 'ionice_level': 4},
'interactive': {'nice': -2, 'ionice_class': 2, 'ionice_level': 4},
'normal': {'nice': 0, 'ionice_class': 2, 'ionice_level': 7},
'background': {'nice': 5, 'ionice_class': 3, 'ionice_level': 0}
}- AI Workloads: 20-30% faster training/inference
- IDE Responsiveness: Elimination of input lag
- Application Switching: Smoother transitions
- System Responsiveness: Better overall feel
- Background Tasks: Reduced interference with foreground apps
The priority system ensures:
- Critical processes get resources when needed
- Background tasks don't starve user applications
- Fair distribution among similar-priority processes
- Adaptive adjustment based on system load
Symptom: A process isn't receiving expected priority
Solutions:
- Check if process name matches configuration
- Verify
optimize_all_appsis enabled - Check process permissions
- Review logs for errors
# Check process name
ps aux | grep process-name
# Check current priority
ps -eo pid,ni,comm | grep process-name
# Check logs
sudo journalctl -u swap-optimizer -fSymptom: Processes not being categorized correctly
Solutions:
- Verify process name matches configuration exactly
- Check for case sensitivity (matching is case-insensitive)
- Ensure process is running when checking
- Review categorization algorithm logs
# Test categorization
python3 -c "
from swap_optimizer import SwapOptimizer
opt = SwapOptimizer()
categories = opt._get_all_user_processes()
for cat, procs in categories.items():
print(f'{cat}: {len(procs)}')
"Symptom: System lag after priority changes
Solutions:
- Disable general optimization temporarily
- Reduce priority differences between tiers
- Check for priority conflicts
- Restore original settings
# Disable general optimization
# Edit config.json: "optimize_all_apps": false
sudo systemctl restart swap-optimizer
# Restore original settings
sudo python3 /opt/swap-optimizer/swap_optimizer.py --restore- Test Gradually: Start with default settings and adjust incrementally
- Monitor Performance: Watch system behavior after changes
- Customize for Workload: Tailor process lists to your specific needs
- Use Dry-Run: Test changes before applying them
- Keep Backups: Save working configurations
The system can be extended to dynamically adjust priorities based on:
- Process CPU usage
- Memory consumption
- I/O patterns
- User activity
Different users can have different priority configurations:
# User-specific config
~/.config/swap-optimizer/user-config.jsonFor more advanced control, integrate with Linux cgroups:
# Create cgroup for AI processes
sudo cgcreate -g cpu,memory:/ai
# Assign process to cgroup
sudo cgclassify -g cpu,memory:/ai $(pgrep python)- Architecture.md - System design and components
- Configuration-Guide.md - Configuration reference
- Performance-Tuning.md - Advanced optimization strategies
Last Updated: 2026-07-03 Version: 2.0.0