https://github.com/1999azzar/swap-management
A comprehensive Linux swap management utility that provides control over ZRAM, ZSWAP, disk swap, and system swap parameters.
https://github.com/1999azzar/swap-management
linux memory-management swap
Last synced: about 1 month ago
JSON representation
A comprehensive Linux swap management utility that provides control over ZRAM, ZSWAP, disk swap, and system swap parameters.
- Host: GitHub
- URL: https://github.com/1999azzar/swap-management
- Owner: 1999AZZAR
- Created: 2025-01-08T17:28:16.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-11T13:13:42.000Z (over 1 year ago)
- Last Synced: 2025-02-11T14:25:26.700Z (over 1 year ago)
- Topics: linux, memory-management, swap
- Language: Shell
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Swap Manager - Enhanced
A powerful, safety-first Linux swap management utility with a modern terminal UI for controlling ZRAM, ZSWAP, disk swap, and system parameters.
## Features
- **Context-Aware Terminal UI**: Dynamic menus that adapt based on your system's current state (Enable/Disable toggles).
- **Proactive Dependency Check**: Validates required tools (`bc`, `mkswap`, etc.) on startup.
- **Advanced ZRAM Management**:
- Temporary or persistent configuration via systemd.
- **Live Algorithm Switching**: Detects and changes compression algorithms (lz4, zstd, etc.) on the fly.
- Proactive module loading for algorithm discovery.
- **Robust ZSWAP Configuration**:
- **Instant Runtime Updates**: Apply changes immediately via sysfs without rebooting.
- **Crypto-API Integration**: Scans `/proc/crypto` to list only kernel-supported compressors.
- Dual-layer persistence (Runtime + GRUB).
- **Disk Swap Suite**:
- **Dynamic Resizing**: Safely resize swap files with data integrity checks.
- **Priority Management**: Live and persistent swap priority control.
- **Safety Guardrails**: Verifies `swapoff` success before file deletion; automatic `/etc/fstab` backups.
- **Swap Aggressiveness Control**: 3 optimized presets (Aggressive, Moderate, Conservative) + custom settings.
- **Auto-Configuration**: Intelligent RAM-based scaling (0.1x - 3.0x multiplier).
## Prerequisites
- **Root access** (Required for memory/swap operations)
- **Linux Kernel**: Support for ZRAM/ZSWAP
- **Core Utils**: `bc`, `modprobe`, `mkswap`, `fallocate`
- **Bootloader**: GRUB (for persistent ZSWAP settings)
## Installation
### Automated Installation
```bash
wget -q https://github.com/1999AZZAR/swap-management/raw/main/install.sh -O install.sh && bash install.sh
```
### Manual Installation
1. Download the script:
```bash
sudo wget -O /usr/local/bin/swap-manager https://raw.githubusercontent.com/1999AZZAR/swap-management/main/swap_manager.sh
```
2. Make it executable:
```bash
sudo chmod +x /usr/local/bin/swap-manager
```
3. (Optional) Create alias:
```bash
echo "alias swap='sudo swap-manager'" >> ~/.bashrc && source ~/.bashrc
```
## Usage
Run the utility:
```bash
swap
```
### Main Menu Overview
1. **Auto Configuration**: Set recommended ZRAM/ZSWAP ratios based on RAM size.
2. **Configure Swap Aggressiveness**: Tune swappiness and cache pressure.
3. **ZRAM Management**: Toggle ZRAM and change compression algorithms.
4. **ZSWAP Management**: Context-aware toggle for ZSWAP and runtime compressor tuning.
5. **Disk Swap Management**: Add/Remove swap, change priority, or resize files.
6. **Check System Status**: Detailed report of RAM, ZRAM, ZSWAP, and Disk Swap.
## Configuration & Logs
| Path | Purpose |
| ---------------------------------- | --------------------------- |
| `/etc/swap-manager/` | Configuration directory |
| `/var/log/swap-manager.log` | Operation logs for auditing |
| `/etc/systemd/system/zram.service` | Persistent ZRAM unit |
## Safety Notes ⚠️
- **Memory Pressure**: Resizing or disabling swap during high memory usage may lead to OOM (Out of Memory) conditions.
- **Bootloader**: ZSWAP changes are applied to GRUB; ensure you verify bootloader updates if using a non-standard configuration.
- **Backups**: The script automatically backs up `/etc/fstab` before modifications.
## License
MIT License