Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Interview cold knowledge, Redhat Red Hat/CentOS server linux internal verification system


Jun 01, 2021 Article blog


Table of contents


This article shares the programmer's interview with a cold knowledge of the system during verification within Linux. Hope to let everyone grow a little knowledge.

Background

Linux's scheduling policies include SCHED_FIFO and SCHED_RR and SCHED_OTHER

  • SCHED_FIFO (Round-robin thread scheduling policy) and SCHED_RR are "real-time" policies. I mplement fixed-priority real-time scheduling as specified by POSIX standards. T asks that follow these policies preempt all other tasks. Because they are preemption, if they do not release the CPU, it is easy to keep some low-level tasks from being performed.

  • SCHED_FIFO difference between SCHED_RR and SCHED_RR is that in tasks of the same priority, SCHED_RR perform round-robin assignments, each of which gets the same cpu time slice policy. And SCHED_FIFO requires the task to actively discard the cpu time slice.

  • SCHED_OTHER is a common circular time-sharing scheduling policy that schedules tasks for a certain time based on other tasks running in the system.

SCHED_RR and SCHED_FIFO issues:

The two real-time scheduling strategies in Red Hat Enterprise Linux Live have one main characteristic: until they are preempted by higher priority threads or until their "sleep/sleep or execute I/O" threads run. If it is SCHED_RR in SCHED_RR the same priority SCHED_RR, the operating system may preempt one thread and allow another thread to execute.

POSIX specification does not specify a policy that allows low-priority threads to get any CPU time.

This feature of real-time threading means that it is easy to write an application that dominates 100% of the CPU. A t first glance, it may seem like a good idea to squeeze out the server, but in fact, it causes a lot of problems with the operating system. T he operating system is responsible for managing system-wide resources and CPU-based resources, and must periodically review the data structure that describes those resources and perform internal management activities on them. If the kernel is monopolized by SCHED_FIFO threads, it cannot perform housekeeping tasks, and eventually the entire system becomes unstable, which can lead to a crash.

The interrupt handler runs with a thread with SCHED_FIFO priority (default: 50). A cpuxiao hao x thread with or a policy higher than the interrupt handler thread may prevent the interrupt handler from running and cause the program to starve to death and fail by waiting for data emitted by the interrupt.

Red Hat/CentOS Special Policy/Real-Time Throttle Mechanism

In the Red Hat Enterprise Real-Time System kernel, there is a real-time throttling /SCHED_FIFOSCHED_RR scheduling policy that restricts real-time scheduling.

Red Hat Enterprise's real-time Linux kernel comes with a protection mechanism that allows system administrators to allocate resource quotas for real-time tasks. The introduction of this quota mechanism is a protection mechanism.

This mechanism is controlled by two parameters in the /proc file system.

/proc/sys/kernel/sched_rt_period_us defines time periods in microseconds, equivalent to 100% CPU resource bandwidth. T he default value is 1,000,000 s (1 second). Changing this time period carefully, too long or too small, can be dangerous.

/proc/sys/kernel/sched_rt_runtime_us the total bandwidth available for all real-time tasks. T he default value is 950,000μs (0.95 s), which is 95% of cpu bandwidth. S etting this value to -1 means that real-time tasks can take up to 100% cpu time. This can only be configured if real-time tasks in a particular scenario are well-designed and have no obvious pitfalls, such as unlimited polling loops.

The default value for the real-time tuning mechanism defines 95% of the CPU time, meaning that 95% of the cpu time slices can be used in real-time tasks. T he remaining 5% will be used for non-real-time tasks (tasks running under SCHED_OTHER similar scheduling policies). A lso note that if a single real-time task takes up 95% of the CPU time slot, the remaining real-time tasks on that CPU will not run. The remaining 5% of CPU time is used only by non-real-time tasks.

Setting the default values has two benefits: rogue real-time tasks do not lock the system by not allowing non-real-time tasks to run, and real-time tasks, on the other hand, have up to 95% of their available CPU time, which may maximize performance.

Smart practices RT_RUNTIME_GREED

Although SCHED_FIFOSCHED_RR/实时节流机制 works by avoiding real-time tasks that could cause the system to hang, advanced users may want to allow real-time tasks to continue to run without the scarcity of non-real-time tasks and to keep the system idle.

When enabled, this feature checks whether non-real-time tasks are starving to death before limiting them. If a real-time task is restricted, it is immediately lifted when the system is idle or at the beginning of the next cycle, whichever comes first.

RT_RUNTIME_GREED enabled by the following command:

#echo RT_RUNTIME_GREED> /sys/kernel/debug/sched_features

To have all CPU cores have the same rt_runtime disable NO_RT_RUNTIME_SHARE logic:

#echo NO_RT_RUNTIME_SHARE> /sys/kernel/debug/sched_features

When these two options are set, the user guarantees that all non-RT tasks on the CPU have a certain amount of running time, while keeping the real-time task running as much as possible.

Hope this cold knowledge is helpful to everyone, students interested in Linux can take a look at the tutorial:

Linux tutorial: https://www.w3cschool.cn/linux/

Linux Microsyscope: https://www.w3cschool.cn/minicourse/play/linuxcourse

Linux should learn this: https://www.w3cschool.cn/linuxprobe/