Fair resource allocation for shared Linux systems
A lightweight resource manager that prevents any single user from monopolizing CPU and memory on multi-user Linux servers. fairshare automatically enforces per-user limits while allowing users to request additional resources dynamically when they need them.
On shared Linux systems, one user running a heavy workload can consume all available CPU and memory, leaving nothing for other users. This creates a terrible experience and reduces productivity.
fairshare allocates resources fairly across all users:
- Default: Each user gets 1 CPU core, 2GB RAM, and optional disk quota by default
- Reserved: System reserves resources for OS and background processes (2 CPUs, 4GB RAM, 4GB disk by default)
- On-demand: Users can request more resources when needed (up to 1000 CPU cores and 10000 GB RAM)
- Automatic: The system grants requests only if resources are truly available
- Fair: No user can monopolize the entire system
The easiest way to install fairshare is using the installation script:
# Download and run the installer
curl -sSL https://raw.github.com/WilliamJudge94/fairshare/main/install.sh | bashOr if you prefer to inspect the script first:
# Download the installer
wget https://raw.github.com/WilliamJudge94/fairshare/main/install.sh
# Review it
cat install.sh
# Run it
bash install.shThe installer will:
- Detect if PolicyKit is installed (automatically installs it if missing)
- Download the latest release binary for your architecture
- Install the binary and wrapper script
- Set up PolicyKit policies
- Configure default resource limits (1 CPU core, 2GB RAM per user)
- Set system reserves (2 CPUs, 4GB RAM by default)
If you prefer to build from source or are developing fairshare:
# 1. Build the release binary
cargo build --release
# 2. Run the installer (it will detect the local build and install PolicyKit if needed)
bash install.shAlternatively, use the Makefile for manual installation:
# Build and install binary and wrapper
cargo build --release
sudo make release
# Ensure PolicyKit is installed (required for fairshare to work)
# Debian/Ubuntu
sudo apt install policykit-1
# Fedora/RHEL
sudo dnf install polkit
# Arch Linux
sudo pacman -S polkit
# Setup admin defaults and PolicyKit policies (REQUIRED)
sudo fairshare admin setup --cpu 1 --mem 2/usr/local/bin/fairshare- Wrapper script (user-facing command)/usr/local/libexec/fairshare-bin- Real binary (internal use only)- PolicyKit policies - Allow passwordless execution for active users
- Systemd configuration - Default resource limits for all user slices
The wrapper script automatically detects whether you're running an admin command (requires sudo) or a regular user command (automatically uses pkexec).
- Linux with systemd (including user session support)
- PolicyKit (polkit) for privilege escalation (automatically installed by the installer if missing)
- Rust 1.70+ (only needed for building from source)
- GLIBC 2.31+ (compatible with RHEL 9, Debian 11+, Ubuntu 20.04+, and most modern distributions)
Release binaries are built with GLIBC 2.31 for maximum compatibility:
- ✅ RHEL 9+ (GLIBC 2.34)
- ✅ Debian 11+ (GLIBC 2.31)
- ✅ Ubuntu 20.04+ (GLIBC 2.31)
- ✅ Rocky Linux 9+ (GLIBC 2.34)
- ✅ AlmaLinux 9+ (GLIBC 2.34)
If you encounter GLIBC version errors, try building from source on your system.
To remove fairshare from your system:
# Using the uninstall script
curl -sSL https://raw.github.com/WilliamJudge94/fairshare/main/uninstall.sh | bash
# Or if you have the repository
bash uninstall.sh
# Or manually
sudo fairshare admin uninstall --forceRegular users can manage their own resource allocations. The wrapper script automatically handles privilege escalation via PolicyKit, so you don't need to type pkexec or sudo.
See how much CPU and memory is available and what each user is currently using.
fairshare statusView how much CPU and memory your user session has access to.
fairshare infoAsk for CPU and memory resources. The system uses smart delta-based checking - it only needs enough free resources to cover the increase from your current allocation.
fairshare request --cpu 4 --mem 8Smart Allocation Example:
- You currently have: 9GB RAM allocated
- System has: 2GB free
- You request: 10GB RAM
- Result: SUCCESS (net increase is only 1GB, which fits in the 2GB available)
Constraints:
- CPU: 1–1000 cores
- Memory: 1–10000 GB
Return your resources to the system and revert to the default allocation (1 CPU core, 2GB RAM).
fairshare releaseNote: Admin commands must be run with
sudo
Configure the default CPU, memory, and disk allocation for all users when they first log in, plus system reserves. This also installs PolicyKit policies required for passwordless user operations.
# Setup with defaults (1 CPU, 2GB RAM per user, 2 CPU reserve, 4GB RAM reserve)
sudo fairshare admin setup --cpu 1 --mem 2 --cpu-reserve 2 --mem-reserve 4
# Or use custom values
sudo fairshare admin setup --cpu 2 --mem 4 --cpu-reserve 4 --mem-reserve 8
# With optional disk quota on a specific partition
sudo fairshare admin setup --cpu 1 --mem 2 --disk 10 --disk-partition /home
# Disk quota on a different partition (e.g., /data, /mnt)
sudo fairshare admin setup --cpu 1 --mem 2 --disk 10 --disk-partition /mnt
# Disk quota with custom reserve
sudo fairshare admin setup --cpu 1 --mem 2 --disk 10 --disk-partition /home --disk-reserve 5Disk Quota Options (Optional):
Disk quotas are optional. If you don't specify --disk and --disk-partition, fairshare will only manage CPU and memory limits.
--disk <GB>: Set default disk quota per user in gigabytes (1-10000 GB)--disk-partition <path>: Mount point where quotas will be enforced (e.g.,/home,/mnt,/data)--disk-reserve <GB>: Reserve disk space for system use (default: 4GB)
Note: Both
--diskand--disk-partitionmust be specified together to enable disk quotas.
Disk Quota Requirements:
Important: Disk quotas require filesystem-level quota support to be enabled.
For quotas to work, you must:
- Enable quotas in
/etc/fstabwith mount options likeusrquotaorquota - For ext4: Enable the quota feature with
tune2fs -O quota /dev/sdXand runquotaon - For XFS: Quotas are typically enabled at mount time with
uquotaoption
Tested Filesystems:
- XFS - Fully tested and working
- ext4 - Fully tested and working
- btrfs, other filesystems - May work but not yet tested (low confidence)
What Reserves Do: System reserves ensure that CPU, memory, and disk space are always available for the operating system and background processes. Users can only allocate up to (Total - Reserved) resources.
Example on an 8 CPU, 16GB RAM, 100GB disk system:
- Total: 8 CPUs, 16GB RAM, 100GB disk
- Reserved: 2 CPUs, 4GB RAM, 4GB disk (default)
- Available for users: 6 CPUs, 12GB RAM, 96GB disk
Administrators can directly set resource allocations for any user on the system, even if that user is not currently logged in.
# Set resources by username
sudo fairshare admin set-user --user alice --cpu 4 --mem 8 --disk 8
# Set resources by UID
sudo fairshare admin set-user --user 1000 --cpu 2 --mem 4 --disk 8
# Force set without confirmation prompt (for scripts)
sudo fairshare admin set-user --user bob --cpu 10 --mem 20 --disk 40 --forceKey Features:
- Works with username (e.g., "alice") or UID (e.g., "1000")
- Checks resource availability and warns if allocation exceeds system capacity
- Prompts for confirmation when over-allocating (unless
--forceis used) - Works even when the target user is signed out
- Cannot modify root (UID 0) or system users (UID < 1000)
Resource Availability Warning:
If the allocation would exceed available resources, the command displays a warning about potential resource contention and prompts for confirmation. Use --force to skip the prompt for automated scripts.
Remove fairshare from your system and revert to standard Linux resource management.
sudo fairshare admin uninstall --forcefairshare uses a wrapper script pattern to provide a seamless user experience:
- User types:
fairshare status - Wrapper detects: Not an admin command
- Wrapper calls:
pkexec /usr/local/libexec/fairshare-bin status - PolicyKit checks: User is active → allow without password
- Binary executes: Reads
PKEXEC_UIDto identify calling user - systemd query: Only queries/modifies the calling user's slice
This architecture ensures:
- Simple UX - No
pkexecin commands - Security - Users can only manage their own resources
- Proper privilege separation - Wrapper handles escalation transparently
fairshare uses systemd as the authoritative source of truth for all resource allocations:
- Resource Tracking: All allocations are stored directly in systemd user slices (
user-{UID}.slice) - Dynamic Querying: The system queries systemd in real-time to get current allocations (no persistent state file)
- Delta-Based Checking: When you request resources, fairshare calculates the net change from your current allocation
- Privilege Escalation: Uses pkexec (PolicyKit) to allow users to modify their own slices without full root access
If you see an error that pkexec is not found, PolicyKit is not installed. Install it using:
# Debian/Ubuntu
sudo apt update && sudo apt install -y policykit-1
# Fedora/RHEL
sudo dnf install -y polkit
# Arch Linux
sudo pacman -S --noconfirm polkitAfter installing PolicyKit, fairshare should work immediately (no need to reinstall fairshare).
If PolicyKit authentication keeps prompting for password, verify that admin setup completed successfully:
sudo fairshare admin setup --cpu 1 --mem 2This installs the PolicyKit policies that allow active users to run fairshare commands without entering a password.
If you get "command not found" errors, ensure the installation completed:
# Reinstall using the install script
bash install.sh
# Or if building from source
sudo make release
# Verify installation
which fairshare # Should show /usr/local/bin/fairshare
ls -l /usr/local/libexec/fairshare-bin # Should existRemember that fairshare uses delta-based checking. Check your current allocation:
fairshare infoThen check system-wide availability:
fairshare statusYour request fails only if the net increase exceeds available resources.
After running sudo fairshare admin setup, systemd needs to reload:
sudo systemctl daemon-reloadDisk quotas require filesystem-level support. If you see quota-related warnings:
-
Check if quotas are enabled in fstab:
cat /etc/fstab | grep -E 'usrquota|quota|uquota'
-
For ext4 filesystems:
# Enable quota feature (unmount first if possible, or use -f) sudo tune2fs -O quota /dev/sdX # Turn on quotas sudo quotaon /mount/point
-
For XFS filesystems: XFS typically needs quotas enabled at mount time. Add
uquotato fstab:/dev/sdX /home xfs defaults,uquota 0 0Then remount:
sudo mount -o remount /home -
Verify quotas are working:
sudo repquota -u /mount/point
Note: fairshare has been tested with XFS and ext4 filesystems. Other filesystems (btrfs, etc.) may work but are not yet verified.
If you want a clean, preconfigured environment with systemd and cgroups available out of the box, GitHub Codespaces can be a convenient option for running and testing fairshare. Refer the Guide
This project is open source.



