Skip to content

Commit 3874652

Browse files
authored
Merge pull request #1 from ricsdeol/feature/device-ui
feat(phase4): swap device management — Devices tab with swapon/swapoff/reset
2 parents 37dde9f + 4d880d5 commit 3874652

File tree

11 files changed

+2370
-47
lines changed

11 files changed

+2370
-47
lines changed

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ Phase 4 → swapon/swapoff via nix, devices UI, root check
6969
Phase 5 → create-swap wizard, tokio::process::Command, disk space validation
7070
```
7171

72-
## Before committing
72+
## After implementing all phases
7373

74-
Run these and fix any issues before creating a commit:
74+
Run these and fix any issues after implement all phases:
7575

7676
```bash
7777
cargo build # must compile clean (zero warnings)

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ tokio = { version = "1.51.1", features = ["full"] }
1010
tokio-util = "0.7.18"
1111
futures = "0.3.32"
1212
sysinfo = "0.38.4"
13-
nix = { version = "0.31.2", features = ["process", "signal", "mount"] }
13+
nix = { version = "0.31.2", features = ["process", "signal", "mount", "user"] }
1414
color-eyre = "0.6.5"
1515
human_bytes = "0.4.3"
1616
glob = "0.3.3"

docs/devices.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Devices Tab
2+
3+
The Devices tab (press `3` or navigate with `Tab`) shows all active swap devices and lets you activate, deactivate, or reset them.
4+
5+
## Requirements
6+
7+
Control operations (`o`, `f`, `r`) require root. Run as:
8+
9+
```
10+
sudo swaptop
11+
```
12+
13+
If you run without root, you can still view device status — only control is restricted.
14+
15+
## Columns
16+
17+
| Column | Description |
18+
|--------|-------------|
19+
| Path | Device path (e.g. `/dev/sda2`, `/swapfile`) |
20+
| Type | `Partition`, `File`, `Zram`, or `DynamicPager` |
21+
| Total | Total swap capacity |
22+
| Used | Currently used swap |
23+
| % | Usage percentage |
24+
| Pri | Kernel priority (higher = preferred) |
25+
| Status | `ACTIVE`, `INACTIVE`, `⏳ ...`, `✓ OK`, or `✗ ERROR` |
26+
27+
## Keybindings
28+
29+
| Key | Action |
30+
|-------------|--------|
31+
| `j` / `` | Move selection down |
32+
| `k` / `` | Move selection up |
33+
| `o` | Activate selected device (`swapon`) |
34+
| `f` | Deactivate selected device (`swapoff`) |
35+
| `r` | Reset selected device (`swapoff` + 100ms + `swapon`) |
36+
| `s` | Confirm action (when modal is open) |
37+
| `Esc` | Cancel confirmation modal |
38+
| `Tab` / `1-4` | Switch tabs |
39+
| `q` | Quit |
40+
41+
## Status Indicators
42+
43+
- **`ACTIVE`** — device is currently active as swap
44+
- **`INACTIVE`** — device is known but not currently active
45+
- **`⏳ ...`** — operation in progress (swapon/swapoff running)
46+
- **`✓ OK`** — last operation succeeded
47+
- **`✗ ERROR`** — last operation failed (check statusbar for details)
48+
49+
## Reset Operation
50+
51+
Reset (`r`) performs `swapoff` followed by `swapon` with a 100ms pause. This forces the kernel to move all swap pages back to RAM and then re-enable the device, which clears fragmentation. Use it when swap usage is high but actual data could be consolidated.
52+
53+
**Note:** Reset requires enough free RAM to hold all data currently in that swap device. If RAM is too full, `swapoff` will fail with an error.
54+
55+
## Platform Notes
56+
57+
On **macOS**, swap is managed automatically by `dynamic_pager`. The Devices tab shows the active swapfiles but control operations are unavailable.

0 commit comments

Comments
 (0)