Dynamically reduce server memory usage by replacing the hardcoded 1000 client pool size with a runtime configurable value (e.g., 64 or 128).
Saves over 2.5 GB of memory for df_bridge_r and df_channel_r services.
The name DofSlim is a portmanteau. The capital S directly denotes Server. Combined with Slim, it encapsulates the project's mission to reduce the memory footprint of the Dof server, effectively making it "slim".
The original df_bridge_r and df_channel_r binaries statically allocate memory for 1000 client objects at startup (each approximately 1.25 MB in size). Even if your actual concurrent connections are far fewer (e.g., dozens or hundreds), the program still reserves 1.3–2.5 GB of virtual memory, leading to significant resource waste.
This project uses LD_PRELOAD hooking to dynamically patch the following hardcoded constants before the program starts:
Client pool size: 1000 → custom_value
Loop boundary: 999 → custom_value - 1
Memory offset calculation: 4 + 0x140060 * 1000 → 4 + 0x140060 * custom_value
✅ Runtime-configurable client pool size via CLIENT_POOL_SIZE environment variable (default: 1000)
✅ Supports df_bridge_r and df_channel_r
✅ Safe patching: Only modifies constants directly related to client count
✅ Significant memory reduction:
CLIENT_POOL_SIZE=3 → saves ~2.5 GB physical memory
✅ Overflow-safe: Uses saturating_sub to prevent crashes when client_num = 0
-
Prerequisites
Rust toolchain (rustc >= 1.70)
cargo
Target system: 32-bit Linux (original binaries are elf32-i386) -
Steps
# Clone the repository git clone https://github.com/llnut/DofSlim.git cd DofSlim # Build the 32-bit shared library for df_bridge_r cargo build --release --target i686-unknown-linux-gnu --features bridge # Build the 32-bit shared library for df_channel_r cargo build --release --target i686-unknown-linux-gnu --features channel # Output file ls -lh target/i686-unknown-linux-gnu/release/libdofslim.so
💡 On 64-bit systems, install 32-bit toolchain first:
sudo yum install glibc-devel.i686 rustup target add i686-unknown-linux-gnu
-
Set client pool size (optional)
# Default is 1000; adjust based on your needs export CLIENT_POOL_SIZE=64 # or 128, 256, etc.
-
Launch services with LD_PRELOAD
# For df_bridge_r LD_PRELOAD=/path/to/target/i686-unknown-linux-gnu/release/libdofslim.so ./df_bridge_r # For df_channel_r LD_PRELOAD=/path/to/target/i686-unknown-linux-gnu/release/libdofslim.so ./df_channel_r
-
Verify it works
Check stderr output:
[df_bridge_hook] Patched client pool size to 64 [df_channel_hook] Patched client pool size to 64Monitor memory usage (compare with unpatched version):
# Check virtual (VSZ) and physical (RSS) memory ps -o pid,vsz,rss,cmd -p $(pgrep df_bridge_r)
| Variable | Description | Default |
|---|---|---|
| CLIENT_POOL_SIZE | Maximum number of concurrent clients | 1000 |
📝 Recommended values:
Single-person server: 3
Small server: 10 or 20
Medium server: 256
Full compatibility: 1000
- If CLIENT_POOL_SIZE is unset or invalid, the program falls back to 1000 and behaves identically to the original.
- Tested and stable for values from 3 to 1000.
MIT License