This article has participated in the Denver Nuggets Creators Camp 3 “More Productive writing” track, see details: Digg project | creators Camp 3 ongoing, “write” personal impact.

preface

When we are used to running the ps command, we will see a lot of “strange” processes, and most of these processes are the system kernel process. Many students know little about it, so today I will sort out an introductory system process for you, hoping to help you understand the operating system process.

In daily operations and maintenance, it is common to see some strange system processes that have a high resource footprint. And I always hear business line students ask “XXX what process is this? Why open so many?”

While these system-level kernel processes are enclosed in brackets and perform auxiliary functions (such as writing caches to disk), the unbraced processes are user-executed processes (such as PHP, nginx, etc.).

As shown below:

Here are 10 common system processes:

  • kswapd0
  • kjournald
  • pdflush
  • kthreadd
  • migration
  • watchdog
  • events
  • kblockd
  • aio
  • rpciod

1 kswapd0

The system will wake up KSWAPD every certain time to see if the memory is tight. If not, sleep. In KSWAPD, There are two thresholds,pages_hige and PAGes_low. When the number of free pages falls below pages_low, the KSWAPd process scans memory and releases 32 free pages at a time until the number of free pages reaches Pages_high.

2 kjournald

Journal: Logs metadata changes on all file systems, the slowest mode.

Ordered: The default mode that records only metadata changes to the file system and logs them before changes are made.

Writeback: The fastest mode, which also records only modified metadata and relies on the standard file system write process to write data to hard disk

3 pdflush

Pdflush is used to synchronize the contents of memory with the file system.

For example, when a file is modified in memory, PDFlush writes it back to disk. When the number of dirty pages in memory exceeds 10%, PDFlush backs them up. This ratio can be adjusted through the vm.dirty_background_ratio option in /etc/sysctl.conf, which defaults to 10.

4 kthreadd

There is only one kernel thread, and its function is to manage the scheduling of other kernel threads.

Created during kernel initialization, it loops through a function called kthreadd, which runs the kthreads maintained in the global kthread_create_list. You can call kthread_create to create a kthread that will be added to the kthread_CREATE_list and weak up the kthreadd_task. Kthreadd calls the old interface when executing kthreads — kernel_thread runs a kernel thread named “kthread” to run the created kthreads. The executed kthreads are removed from kthread_create_list. And kthreadD constantly calls scheduler to free up the CPU. This thread cannot be closed.

5 migration

Migration_thread () : migration_thread() : migration_thread() : migration_thread() : migration_thread() : migration_thread() : migration_thread() : migration_thread()

A 2.6 kernel load balancing process that automatically loads (one per CPU) at system startup, sets itself to a real-time process with SCHED_FIFO, and then checks runqueue::migration_queue for requests waiting to be processed. If not, Sleep in TASK_INTERRUPTIBLE until you wake up and check again. Migration_thread () is simply an interface for CPU binding and CPU power management functions. This thread is an important part of the scheduling system.

6 watchdog

This kernel thread has a total of 32, from watchdog/0 to watchdog/31, each processor check should be a watchdog kernel thread, watchdog is used to monitor the operation of the system, automatically restart the system when the system failure, Includes a kernel watchdog module and a user-space watchdog program.

Under the Linux kernel, the basic working principle of watchdog is as follows: After the watchdog is started (that is, the /dev/watchdog device is started), if no write operation is performed within a specified interval (1 minute), the hardware watchdog circuit or software timer restarts the system. Each write operation causes the timer to be reset.

7 events

There are 32 such kernel threads, from events/0 to events/31, and each processor should check one Events kernel thread. Many hardware and software events (such as power outages and file changes) are converted to events and distributed to threads interested in the corresponding events for response.

8 kblockd

There are 32 such kernel threads, from kblockd/0 to kblockd/31, and each processor should check one Kblockd kernel thread. Block devices used to manage the system, which periodically activate block device drivers within the system. If you have a block device, these threads cannot be removed.

9 aio

There are 32 such kernel threads, from AIO /0 to AIO /31. Each processor should check one AIO kernel thread, which manages I/O instead of the user process, to support user-mode AIO (asynchronous I/O) and should not be shut down.

10 rpciod

There are 32 such kernel threads, ranging from RPCIod /0 to RPCIOD /31. Each processor should have one RPCIOD kernel thread. It is used as the daemon of the remote procedure call service and is used to start THE I/O service from the client.

conclusion

Process is a very important concept in operating system, all the data running on the system will exist as a process type. In Linux: when any event is triggered, the system will define it as a process, so process is the only implementation of Linux programs.