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:
Priority Settings:
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:
Priority Settings:
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:
Priority Settings:
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:
Priority Settings:
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:
Priority Settings:
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:
I/O priority has three classes and levels within each class:
Classes:
Levels (0-7, lower is higher priority within class):
Our Implementation:
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 --status
Output 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:
/etc/swap-optimizer/config.jsonRestart the service
:::json
{
"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}
}
The priority system ensures:
Symptom: A process isn't receiving expected priority
Solutions:
optimize_all_apps is enabledReview logs for errors
:::bash
ps aux | grep process-name
ps -eo pid,ni,comm | grep process-name
sudo journalctl -u swap-optimizer -f
Symptom: Processes not being categorized correctly
Solutions:
Review categorization algorithm logs
:::bash
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:
Restore original settings
:::bash
sudo systemctl restart swap-optimizer
sudo python3 /opt/swap-optimizer/swap_optimizer.py --restore
The system can be extended to dynamically adjust priorities based on:
Different users can have different priority configurations:
# User-specific config
~/.config/swap-optimizer/user-config.json
For 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)
Last Updated: 2026-07-03
Version: 2.0.0