zramctl
Manage ZRAM devices
TLDR
Check if zram is enabled
Enable zram with a dynamic number of devices (use zramctl to configure devices further)
Enable zram with exactly 2 devices
Find and initialize the next free zram device to a 2 GB virtual drive using LZ4 compression
List currently initialized devices
SYNOPSIS
zramctl [options] [<device>]
zramctl [-f | --find] [options]
zramctl [-a | -d | -s | -c | -r | -i] <device> [<size>]
zramctl [-n] [<number>]
zramctl [-p | -h | -v]
PARAMETERS
-a, --activate <device>
Activate the specified zram device as a swap device.
-d, --deactivate <device>
Deactivate and free the specified zram device, removing it from swap.
-s, --size <device> [<size>]
Set the uncompressed size of the specified zram device. If <size> is omitted, displays the current size.
-n, --count [<number>]
Create or remove zram devices to match the specified count. If <number> is omitted, displays the current number of active zram devices.
-c, --compact <device>
Triggers a memory compaction for the specified zram device, attempting to free unused pages.
-i, --info <device>
Display detailed information and statistics for the specified zram device. This is the default action when a device is specified without other options.
-f, --find
Find an unused zram device and output its path (e.g., /dev/zram0).
-p, --json
Output information in JSON format, useful for scripting.
-r, --reset <device>
Reset the specified zram device, freeing all allocated memory and returning it to an uninitialized state.
-h, --help
Display a help message and exit.
-v, --version
Output version information and exit.
DESCRIPTION
zramctl is a command-line utility designed to simplify the management and configuration of Zram devices on Linux systems. Zram (previously called compcache) creates a compressed RAM-based block device, primarily used for swap space. By compressing memory pages before writing them to this device, Zram effectively allows a system to use more memory than physically available, improving responsiveness and reducing disk I/O when swap is needed.
zramctl provides a convenient interface to initialize, set size, activate, deactivate, and monitor the status of Zram devices without directly interacting with kernel modules or low-level sysfs entries. It abstracts away the complexities of modprobe, mkswap, swapon, and swapoff for Zram-specific operations, making it easier for users and system administrators to leverage the benefits of compressed swap.
CAVEATS
Zram uses RAM, so setting an excessively large size can lead to out-of-memory issues or system instability if the system runs low on actual physical RAM.
Compression and decompression consume CPU cycles. While generally efficient, heavy swap usage on Zram devices can increase CPU load. Performance depends on the chosen compression algorithm (configurable via kernel modules, not directly by zramctl).
zramctl typically requires root privileges to modify or activate devices.
DEFAULT BEHAVIOR
When called without any options and a <device> argument (e.g., zramctl /dev/zram0), zramctl defaults to displaying information about that specific device, similar to zramctl -i <device>.
AUTOMATIC DEVICE CREATION
If zramctl is run with options that require a zram device (e.g., -a, -s), and no specific device is provided, it often tries to find or create an available device automatically, especially when combined with --find or when no zram devices currently exist.
PERSISTENT CONFIGURATION
zramctl itself does not provide a mechanism for persistent configuration across reboots. For automatic zram setup at boot, system-specific init scripts (e.g., systemd units like zramswap.service) or other configuration methods are typically used.
HISTORY
Zram itself (originally compcache) was introduced into the Linux kernel in version 3.14. zramctl is a relatively modern utility, often part of the util-linux project, which bundles essential system utilities. Its development aimed to provide a more convenient and standardized interface for managing zram devices, abstracting the manual steps previously required (loading modules, setting sizes via sysfs, mkswap, swapon). Its inclusion in util-linux signifies its adoption as a standard tool for zram management.