Skip to content

Commit e8f7b7b

Browse files
committed
Add MEMZ memory analyzer with complete documentation and wiki
1 parent 8c830bb commit e8f7b7b

11 files changed

Lines changed: 2429 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 623 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "memz"
3+
version = "1.0.0"
4+
edition = "2024"
5+
authors = ["Nima Naseri <nerdnull@proton.me>"]
6+
description = "Advanced Linux memory analyzer with PSS tracking"
7+
repository = "https://github.com/naseridev/memz"
8+
keywords = ["memory", "linux", "monitoring", "system"]
9+
categories = ["command-line-utilities"]
10+
11+
[dependencies]
12+
ratatui = "0.28"
13+
crossterm = "0.28"
14+
anyhow = "1.0"
15+
thiserror = "1.0"
16+
17+
[target.'cfg(target_os = "linux")'.dependencies]
18+
libc = "0.2"
19+
20+
[profile.release]
21+
opt-level = 3
22+
lto = true
23+
codegen-units = 1
24+
strip = true

README.md

Lines changed: 231 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,231 @@
1-
# memz
2-
Advanced Linux memory analyzer
1+
# MEMZ
2+
3+
Advanced Linux memory analyzer with real-time process tracking and system-level memory profiling.
4+
5+
## Overview
6+
7+
MEMZ is a terminal-based memory analysis tool designed for Linux systems. It provides detailed visibility into memory usage patterns by parsing kernel procfs data and presenting it through an interactive TUI interface. The tool focuses on accurate memory accounting using Proportional Set Size (PSS) metrics rather than traditional RSS measurements.
8+
9+
**Target Use Case**: System administrators and developers who need precise memory usage data for debugging, performance analysis, or capacity planning on Linux servers and workstations.
10+
11+
## Features
12+
13+
- **Process Memory Tracking**: Real-time PSS, RSS, shared, and private memory metrics per process
14+
- **System-Level Statistics**: Total memory, swap, cache, and buffer monitoring
15+
- **Physical Memory Mapping**: Kernel vs userspace memory distribution breakdown
16+
- **Shared Memory Analysis**: Quantifies memory sharing efficiency across processes
17+
- **NUMA Awareness**: Per-node memory statistics on NUMA systems
18+
- **Interactive Navigation**: Sortable process lists, multiple view modes, keyboard-driven interface
19+
20+
## System Requirements
21+
22+
- Linux kernel 4.14+ (for smaps_rollup support)
23+
- Root privileges (required for /proc access)
24+
- Terminal with UTF-8 support
25+
26+
## Installation
27+
28+
### Prerequisites
29+
30+
**Operating System**: Linux only (tested on kernel 4.14+)
31+
32+
**Rust Toolchain**:
33+
```bash
34+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
35+
```
36+
37+
**System Requirements**:
38+
- Linux kernel 4.14 or newer (for `/proc/[pid]/smaps_rollup`)
39+
- Root access (sudo)
40+
- UTF-8 capable terminal
41+
42+
### Build Steps
43+
44+
1. Clone or extract the project:
45+
46+
```bash
47+
git clone https://github.com/naseridev/memz.git
48+
```
49+
50+
```bash
51+
cd memz
52+
```
53+
54+
2. Build the release binary:
55+
```bash
56+
cargo build --release
57+
```
58+
59+
The compiled binary will be at `target/release/memz`.
60+
61+
### Verification
62+
63+
Check kernel version:
64+
```bash
65+
uname -r
66+
```
67+
68+
Ensure you have 4.14 or higher. Older kernels lack `smaps_rollup` and will cause the tool to fail.
69+
70+
## Usage
71+
72+
### Starting MEMZ
73+
74+
Run with sudo (root privileges required):
75+
```bash
76+
sudo ./target/release/memz
77+
```
78+
79+
The terminal will switch to an alternate screen showing live memory data.
80+
81+
### Interface Layout
82+
83+
The TUI is divided into three sections:
84+
85+
1. **Top Panel**: System-wide memory statistics (RAM, swap, cache)
86+
2. **Middle Panel**: Main content area (changes based on view mode)
87+
3. **Bottom Panel**: Keyboard controls
88+
89+
### Keyboard Controls
90+
91+
| Key | Action |
92+
|-----|--------|
93+
| `q` | Quit the application |
94+
| `n` | Cycle through sort modes (PSS -> RSS -> Shared -> PID) |
95+
| `v` | Switch view mode (Processes -> Memory Map -> Shared Memory) |
96+
| Up/Down | Scroll one line up/down |
97+
| PgUp/PgDn | Scroll one page up/down |
98+
99+
### View Modes
100+
101+
#### 1. Processes View (Default)
102+
103+
Displays a table of running processes with columns:
104+
- **PID**: Process identifier
105+
- **Name**: Process name from `/proc/[pid]/comm`
106+
- **PSS**: Proportional Set Size (accurate memory usage)
107+
- **RSS**: Resident Set Size (may overcount shared memory)
108+
- **Shared**: Total shared memory pages
109+
- **Private**: Memory unique to this process
110+
- **Swap**: Swapped-out memory
111+
- **Delta**: PSS change since last refresh (megabytes)
112+
113+
Processes are sorted by the current sort mode (default: PSS descending).
114+
115+
#### 2. Memory Map View
116+
117+
Shows physical memory distribution:
118+
- Kernel reserved space
119+
- Process private/shared memory
120+
- Page cache and buffers
121+
- Slab allocator usage
122+
- Free memory
123+
124+
On NUMA systems, displays per-node memory statistics.
125+
126+
#### 3. Shared Memory View
127+
128+
Analyzes memory sharing across processes:
129+
- Total shared memory (clean + dirty pages)
130+
- Sharing efficiency percentage (memory saved by sharing)
131+
132+
## Understanding Memory Metrics
133+
134+
### PSS vs RSS
135+
136+
**RSS (Resident Set Size)**: Total physical memory used by a process, including fully counted shared libraries. Multiple processes sharing the same library will have overlapping RSS values.
137+
138+
**PSS (Proportional Set Size)**: RSS adjusted for shared pages. If a page is shared by N processes, each process accounts for 1/N of that page. PSS provides accurate per-process memory usage without double-counting.
139+
140+
**Rule of thumb**: Sum of all RSS values exceeds total system memory usage. Sum of all PSS values matches actual memory consumption.
141+
142+
### Memory Types
143+
144+
- **Shared Clean**: Unmodified pages shared between processes (e.g., read-only library code)
145+
- **Shared Dirty**: Modified pages shared between processes (e.g., shared memory segments)
146+
- **Private Clean**: Unmodified pages unique to one process
147+
- **Private Dirty**: Modified pages unique to one process (stack, heap)
148+
149+
## Screenshots
150+
151+
### Processes View
152+
![Processes View](docs/screenshots/processes.png)
153+
154+
### Memory Map View
155+
![Memory Map](docs/screenshots/memory_map.png)
156+
157+
### Shared Memory Analysis
158+
![Shared Memory](docs/screenshots/shared.png)
159+
160+
## Troubleshooting
161+
162+
### "Unsupported operating system"
163+
164+
MEMZ only works on Linux. It reads from `/proc`, which doesn't exist on macOS or Windows.
165+
166+
### "This tool requires root privileges"
167+
168+
Run with `sudo`. Non-root users cannot access `/proc/[pid]/smaps_rollup` for all processes.
169+
170+
### "Kernel version X.X detected... requires 4.14+"
171+
172+
Your kernel lacks `smaps_rollup` support. Options:
173+
1. Upgrade kernel (recommended)
174+
2. Modify the code to use `/proc/[pid]/smaps` (slower, but works on older kernels)
175+
176+
### Terminal display issues
177+
178+
Ensure your terminal supports UTF-8 and has sufficient size (minimum 80x24 recommended).
179+
180+
### High CPU usage
181+
182+
MEMZ refreshes every second. On systems with thousands of processes, parsing `/proc` can be CPU-intensive. This is expected behavior.
183+
184+
## Performance Characteristics
185+
186+
- **Memory overhead**: ~5-10 MB for the tool itself
187+
- **Refresh rate**: 1 second (hardcoded in `main.rs`)
188+
- **Scaling**: Parses O(N) processes; 1000 processes = ~50ms collection time on modern hardware
189+
190+
## Limitations
191+
192+
- Linux-only (requires procfs)
193+
- Cannot track memory outside procfs (kernel internal structures, DMA buffers)
194+
- PSS calculation is a kernel estimation, not exact
195+
- Requires root (no workaround for security-restricted systems)
196+
- No historical data persistence (resets on restart)
197+
198+
## Use Cases
199+
200+
### Development
201+
- Identify memory leaks during testing
202+
- Compare memory footprint of different implementations
203+
- Verify memory usage matches expectations
204+
205+
### System Administration
206+
- Diagnose out-of-memory conditions
207+
- Plan memory capacity for workloads
208+
- Monitor memory consumption trends
209+
210+
### Performance Analysis
211+
- Evaluate cache/buffer effectiveness
212+
- Analyze memory sharing in containerized environments
213+
- Debug swap usage patterns
214+
215+
## Advanced Tips
216+
217+
### Comparing PSS vs RSS
218+
219+
Press `n` to cycle to RSS sort mode. Compare the "Process PSS" and "RSS" values in the top panel. The difference represents overcounted shared memory.
220+
221+
### Monitoring specific processes
222+
223+
Start MEMZ, then note the PID of your target process. Press `n` until sorted by PID, then scroll to find it. The Delta column shows memory growth over time.
224+
225+
### NUMA awareness
226+
227+
On multi-socket servers, the Memory Map view shows per-node statistics. Uneven distribution may indicate NUMA placement issues.
228+
229+
## Technical Documentation
230+
231+
For implementation details, architecture, and in-depth technical documentation, see [WIKI](README.wiki.md).

0 commit comments

Comments
 (0)