Advanced Parameters & Security Tuning
Production guidelines for memory sizing, thread scheduling, loopback network security, and cryptographic supply-chain verification.
1. Mobile Context Allocation & Slots (-np 1)
By default on multi-slot servers, context window memory is divided equally across slots (e.g., 256 context / 4 slots = 64 tokens per slot). On single-user mobile devices, this leads to rapid context truncation. Termux-LlamaCpp enforces -np 1 and allocates the entire 2048 token buffer directly to the active session.
llama-server \
-m model.gguf \
--host 127.0.0.1 \
--port 18080 \
-c 2048 \
-np 1 \
-t 4 \
--no-mmap
2. Android Bionic Direct Memory Loading (--no-mmap)
Standard Linux memory-mapping (mmap) on Android flash storage (/data/data/com.termux/files/...) frequently triggers kernel I/O locks, memory thrashing, and process timeouts. The --no-mmap flag instructs the llama.cpp engine to sequentially load model tensors directly into RAM, guaranteeing deterministic cold-start times (~1.8s for 1.92GB models).
3. Ed25519 Cryptographic Manifest Verification
Termux-LlamaCpp implements strict supply-chain security protocols:
- Fail-Closed Anti-Downgrade: If a signed release manifest is present, the runtime will strictly reject untrusted local build receipts.
- Symlink Traversal Prevention: Model weight paths, trust root public keys, and revocation files are verified with
is_symlink()to block TOCTOU injection. - Loopback Reverse Proxy Isolation: The native backend binds strictly to loopback
127.0.0.1:18080, protected by CORS origin filtering.
| Environment Variable | Default Value | Description |
|---|---|---|
TERMUX_LLAMA_HOME | $HOME/.termux-llama | Root installation directory for binaries and libraries. |
TERMUX_LLAMA_MODELS_DIR | $HOME/.termux-llama/models | Default model download cache directory. |
TERMUX_LLAMA_PRESET | android-arm64-dotprod | Target hardware optimization compiler preset. |
TERMUX_LLAMA_FORCE_MMAP | 0 | Set to 1 to force mmap (not recommended on Android). |