The Linux Process Journey — “kdevtmpfs”
“kdevtmpfs” is a kernel thread which was created using the “kthread_run” function (https://elixir.bootlin.com/linux/v6.2-rc1/source/drivers/base/devtmpfs.c#L474). “kdevtmpfs” creates a devtmpfs which is a tmpfs-based filesystem (/dev). The filesystem is created during bootup of the system, before any driver code is registered. In case a driver-core requests a device node it will result in a node added to this filesystem. (https://elixir.bootlin.com/linux/v6.2-rc1/source/drivers/base/devtmpfs.c#L3).
We can see the specific line of code that is used in order to create the mounting point “/dev” (https://elixir.bootlin.com/linux/v6.2-rc1/source/drivers/base/devtmpfs.c#L377). The mountpoint is created using the function “init_mount” (https://elixir.bootlin.com/linux/v6.2-rc1/source/fs/init.c#L16). A nice fact is that it is part of “init_*” functions which are routines that mimic syscalls but don’t use file descriptors or the user address space. They are commonly used by early init code (https://elixir.bootlin.com/linux/v6.2-rc1/source/fs/init.c#L3).
Thus, we can say the “kdevtmpfs” is responsible for managing the “Linux Device Tree”. Also, by default the name created for nodes under the filesystem is based on the device name (and owned by root) — as shown in the screenshot below (taken from copy.sh based Linux). By the way, not all devices have a node in “/dev” think about network devices ;-)
See you in my next writeup ;-)
You can follow me on twitter — @boutnaru (https://twitter.com/boutnaru).