diff --git a/.gitignore b/.gitignore index 5303030..cffc250 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -Maximum_limit_stress_test/count_file.txt creation_time_experiment/creation_time_results.txt thread_recursive_scaling/runs/ diff --git a/Maximum_limit_stress_test/stress.c b/Maximum_limit_stress_test/stress.c deleted file mode 100644 index 7ebc6de..0000000 --- a/Maximum_limit_stress_test/stress.c +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include -#include - -#define DEFAULT_NUM_LEN 512 - -char *itoa(long num, char *strnum, size_t size){ - int isNegative = 0; - - - if(num == 0){ - strnum[0] = '0'; - strnum[1] = '\0'; - return strnum; - } - - if(num < 0){ - isNegative = 1; - num = -num; - } - - int counter = 0; - while(num > 0 && counter <(int)(size-1)){ - strnum[counter] = num % 10 + '0'; - num /= 10; - counter ++; - } - - if(isNegative){ - strnum[counter] = '-'; - counter++; - } - - strnum[counter] = '\0'; - - for(int i=0; i 0); - - - return 0; -} diff --git a/README.md b/README.md index d233cc1..0ccb0ec 100644 --- a/README.md +++ b/README.md @@ -19,16 +19,42 @@ bash creation_time_experiment/bash_test_iter.sh bash thread_recursive_scaling/run_thread_recursive.sh ``` -Enable the dangerous stress tests (timeboxed): +Enable the dangerous stress test (timeboxed): ```sh -ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 MAX_LIMIT_SECONDS=5 bash run_all_experiments.sh +ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 bash run_all_experiments.sh +``` + +## Key Commands for lifting linux kernel restrictions on alpine linux for threads & processes: + +``` +# Lift shell nproc limit +ulimit -u unlimited + +# Raise kernel PID/thread caps (temporary until reboot) +sysctl -w kernel.pid_max=131072 +sysctl -w kernel.threads-max=131072 + + +# cgroup v2 setup (Alpine Linux) +mkdir -p /sys/fs/cgroup/test +echo max > /sys/fs/cgroup/test/pids.max +echo $$ > /sys/fs/cgroup/test/cgroup.procs +``` + + + +## Clean-up commands run after tests: +``` +# Cleanup to make it non-persistent (move out, then delete) +echo $$ > /sys/fs/cgroup/cgroup.procs +rmdir /sys/fs/cgroup/test ``` ## Potential dangers -- The fork bomb and max-limit stress tests can freeze your machine or make it - unresponsive by exhausting processes/threads. +- The fork bomb can freeze your machine or make it unresponsive by exhausting + processes/threads. - You may need elevated limits (ulimit or sysctl) to run high-stress tests. - Running heavy tests on shared systems or laptops can disrupt other users and risk data loss if the system becomes unstable. diff --git a/run_all_experiments.sh b/run_all_experiments.sh index a8174dd..897dfc2 100644 --- a/run_all_experiments.sh +++ b/run_all_experiments.sh @@ -142,12 +142,6 @@ compile_fork_bomb() { "$ROOT_DIR/fork_bomb/fork_bomb.c" } -compile_max_limit() { - log "Compiling stress" - gcc -O2 -o "$ROOT_DIR/Maximum_limit_stress_test/stress" \ - "$ROOT_DIR/Maximum_limit_stress_test/stress.c" -} - compile_thread_stress() { log "Compiling thread_stress" gcc -O2 -pthread -o "$ROOT_DIR/thread_stress_test/thread_stress" \ @@ -156,13 +150,11 @@ compile_thread_stress() { compile_creation_time compile_fork_bomb -compile_max_limit compile_thread_stress # Defaults (override by env vars) ALLOW_DANGEROUS=${ALLOW_DANGEROUS:-0} FORK_BOMB_SECONDS=${FORK_BOMB_SECONDS:-5} -MAX_LIMIT_SECONDS=${MAX_LIMIT_SECONDS:-5} CREATION_TIME_ITERS=${CREATION_TIME_ITERS:-"100 1000 10000"} CREATION_TIME_SECONDS=${CREATION_TIME_SECONDS:-60} @@ -186,17 +178,6 @@ else echo "timestamp,elapsed_s,load1,load5,load15,mem_total_kb,mem_available_kb,mem_used_kb,proc_count,thread_count_total,pid,cpu_pct,rss_kb,vsz_kb,stack_kb,heap_kb,proc_threads" > "$OUT_DIR/fork_bomb.csv" fi -if [ "$ALLOW_DANGEROUS" -eq 1 ]; then - run_with_sampling \ - "max_limit_stress" \ - "cd '$ROOT_DIR/Maximum_limit_stress_test' && ./stress" \ - "$OUT_DIR/max_limit_stress.csv" \ - "$MAX_LIMIT_SECONDS" -else - log "Skipping max_limit_stress (set ALLOW_DANGEROUS=1 to run)" - echo "timestamp,elapsed_s,load1,load5,load15,mem_total_kb,mem_available_kb,mem_used_kb,proc_count,thread_count_total,pid,cpu_pct,rss_kb,vsz_kb,stack_kb,heap_kb,proc_threads" > "$OUT_DIR/max_limit_stress.csv" -fi - run_with_sampling \ "thread_recursive_scaling" \ "cd '$ROOT_DIR/thread_recursive_scaling' && ./run_thread_recursive.sh" \ diff --git a/tasks.md b/tasks.md index 77536bd..9d020b3 100644 --- a/tasks.md +++ b/tasks.md @@ -29,9 +29,6 @@ to understand how the operating system balances efficiency and isolation. - [x] Thread Recursive Scaling: Similar recursive creation using threads to compare scalability and resource usage against fork(). -- [x] Maximum Limit Stress Test: - Continuously creates processes or threads until the system refuses further creation, - revealing OS-enforced limits on concurrency. - [ ] Memory and Stability Observation(removed max forks with ulimit -u 20000): Monitors system memory usage and system responsiveness during heavy process and thread creation. @@ -59,23 +56,34 @@ Citations will include: ulimit -u unlimited # Raise kernel PID/thread caps (temporary until reboot) -sudo sysctl -w kernel.pid_max=131072 -sudo sysctl -w kernel.threads-max=131072 +sysctl -w kernel.pid_max=131072 +sysctl -w kernel.threads-max=131072 -# Lift cgroup v2 pids limit (temporary until reboot) -sudo sh -c 'echo max > /sys/fs/cgroup/pids.max' + +# cgroup v2 setup (Alpine Linux) +mkdir -p /sys/fs/cgroup/test +echo max > /sys/fs/cgroup/test/pids.max +echo $$ > /sys/fs/cgroup/test/cgroup.procs +``` + + + +## Clean-up commands run after tests: +``` +# Cleanup to make it non-persistent (move out, then delete) +echo $$ > /sys/fs/cgroup/cgroup.procs +rmdir /sys/fs/cgroup/test ``` ## Crash/Stress Behavior (Runner Env Vars) The runner script uses the following environment variables to control risky experiments: -- `ALLOW_DANGEROUS=1` to enable `fork_bomb` and `max_limit_stress` (default: 0). +- `ALLOW_DANGEROUS=1` to enable `fork_bomb` (default: 0). - `FORK_BOMB_SECONDS=` to timebox `fork_bomb` runtime. -- `MAX_LIMIT_SECONDS=` to timebox `max_limit_stress` runtime. Example: ```sh -ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 MAX_LIMIT_SECONDS=5 bash run_all_experiments.sh +ALLOW_DANGEROUS=1 FORK_BOMB_SECONDS=5 bash run_all_experiments.sh ``` \ No newline at end of file