A lightweight C program suite for stress testing system memory allocation and usage.
This project provides two command-line utilities for memory stress testing:
stress
- Allocates memory usingmalloc()
and fills it with dummy datastress-file
- Creates a temporary file and maps it into memory usingmmap()
Both are useful for:
- Testing system memory limits
- Simulating memory-intensive applications
- Load testing in containerized environments
- Memory stress testing scenarios
- Testing different memory allocation strategies
- Support for human-readable size formats (K, M, G, T suffixes)
- Cross-platform compatibility
- Lightweight and minimal dependencies
- Shared parsing logic between both programs
- Docker support for containerized testing
- Two different memory allocation approaches
- GCC compiler
- Make (optional, for using Makefile)
# Build both programs
make
# Build only malloc version
make stress-only
# Build only file mapping version
make stress-file-only
# Malloc version
gcc -Wall -Wextra -std=c99 -O2 -o stress stress.c parse.c
# File mapping version
gcc -Wall -Wextra -std=c99 -O2 -o stress-file stress-file.c parse.c
./stress <size>
./stress-file <size>
Both programs accept the same size parameter format:
- Plain numbers (bytes):
1048576
- With suffixes:
1M
,512K
,2G
,1T
- Optional 'B' suffix:
1MB
,512KB
# Allocate 100MB using malloc
./stress 100M
# Create and map 1GB file into memory
./stress-file 1G
# Allocate exactly 1048576 bytes
./stress 1048576
./stress-file 1048576
- Parse and validate the size parameter
- Allocate memory using
malloc()
- Fill the memory with dummy data ('A' characters)
- Display confirmation message
- Wait indefinitely (press Ctrl+C to terminate)
- Parse and validate the size parameter
- Create a temporary file in
/tmp/
- Extend the file to the specified size
- Fill the file with dummy data
- Map the file into memory using
mmap()
- Touch all memory pages to load them into physical memory
- Display confirmation message
- Wait indefinitely (press Ctrl+C to terminate)
- Cleanup temporary file on exit
A Dockerfile is included for containerized usage.