Andrew Gable

ResumeBlogPhotos

Least Amount of Threads to Start Fedora

11 October, 2014

In this OS experiment we were tasked in finding the minimum threads in Linux that the operating system will need to boot. I am using a Fedora 20 virtual machine running on VMWare Fusion 7.

The first thing I did was try to figure out how to start Fedora with no GUI. This was quite simple:

-When the GRUB boot loader appears hit the arrow key -Click the 'e' key to edit the boot of your choosing -Scroll to the line that starts with 'linux' -At the end of that line, add the number '3' -Fedora should boot in command line mode

Fedora CL Boot

Command Line Boot on Fedora 20

Then I started to do some research, for example how to find the number of threads running? ps -eLf would do the trick but it would blow my screen up. Combining it with wc -l would give me the total number of lines counted.

Running ps -eLf | wc -l gave me a number of 391 current threads running.

I wanted to change the number of max threads to 400. Then increase the number of threads until I went over the maximum thread amount found in /proc/sys/kernel/threads-max.

To change the number of threads temporarily I ran echo 400 > /proc/sys/kernel/threads-max and started to create threads by executing the command sleep 1000 & over and over to get my thread count up to 400.

Once I hit the limit bash started to give me the error -bash: fork: retry: Resource temporarily unavailable

Fork Error


This wasn't really the main goal of the experiment, I was looking to see what type of error I would get when the max thread number was exceeded. I needed to go edit the maximum number of threads in the file fork.c of the kernel code. Then recompile the code, and select that kernel when the GRUB boot loader loads. I am going to set the number of max threads to 500 in my fork.c and see if it will even load.

I edited max_threads = 500; in fork.c and built the kernel. This worked in both the GUI and command line Fedora 20. So I decreased the max_threads to 100.

With 100 threads the GUI just stopped and hung at the loading screen. I would have to shut down my Fedora Virtual Machine and restart.

Fedora Stuck

When booting into the command line interface with 100 threads, things got interesting because the operating system booted in emergency mode.

Emergency Mode

Setting 100 threads maximum the Command Line mode booted in emergency mode.

Once I exited the emergency mode I found that I logged into a shell, and was able to see that the total number of threads running in this emergency shell was 85.

When looking through the code in fork.c around line 278 it says

/*
 * we need to allow at least 20 threads to boot a system
 */
if (max_threads < 20)
    max_threads = 20;

I then decided to change the kernel code once again to max_threads = 0; to see if the kernel could truly load with only 20 threads.

Setting the max_thread count to 0 and then letting the kernel set it to 20 lead the kernel to panic. I had to "pull the plug" on my virtual and make sure to boot to the correct kernel or else it will panic while attempting to boot.

Kernel Panic

Changing the max_thread count to 20 lead to a kernel panic

The exact number of threads needed to boot according to the kernel is 20, but I was unable to boot using that number. I had success in booting in to the emergency mode shell with 100 threads, but it seems like you will still need more to launch the command line smoothly.

© 2024 Andrew Gable