当前位置:网站首页>CPU process priority
CPU process priority
2022-06-24 13:23:00 【Chen Bucheng I】
One . brief introduction
The way process priorities work has not changed much since their invention , Whether it's just one cpu Era , Or multicore cpu Time , Are occupied by the control process cpu The length of time . That is, in the same scheduling cycle , Higher priority processes take longer , Low priority processes take up less time .
The most familiar priority setting method on the system is nice and renice command .
Two .NICE value
nice The value should be familiar Linux/UNIX People know the concept of , We all know that it is a reaction process “ priority ” State value , Its value range is 40-20 to 19-0, altogether 40 A level . The smaller the value , The said process ” priority ” The higher the , And the greater the value “ priority ” The lower the .
We can go through nice Command to execute a command to be executed nice Value settings , The method is :
in addition , Use renice Command can control a running process nice Value adjustment , We can also use, for example top、ps Wait for the command to view the process nice value , I won't say more about the specific method , You can refer to the relevant manpage.
What we need to pay attention to is , I'm using it here nice Worth the title , Not priority (priority) The idea that . Of course ,nice and renice Of man In the manual , It also says priority The concept , But I want to stress that , Please don't confuse these two concepts in the system , One is nice value , One is priority value , They are inextricably linked , But for the current Linux system , They are not the same concept .
Have you figured out PR Values and NI The difference in value ? without , Then we can first figure out what is nice value .
nice Although the value is not priority, But it does affect the priority of the process .
In English , If we describe a person nice, That generally means that this person is more popular . What kind of people have good luck ? Often humility 、 A polite person . such as , You and a nice Go to lunch with people , Ordered two identical meals , I served one first and then ,nice The one who usually says :“ You eat first, you eat first !”, This is good popularity , This man nice! But if the other one comes late , So this nice People are going to be hungry . What does this ? The more nice The worse the ability of people to seize resources , And the less nice The stronger the preemptive ability of people . This is it. nice The meaning of value size ,nice The lower the value , It means that the less the process is nice, preemption cpu The stronger the ability to , The higher the priority . In the original use O1 The scheduling of Linux On , We'll also put nice The value is called static priority , This is basically in line with nice Value characteristics , Namely nice When the value is set , Unless we use renice Change it , Otherwise it will remain unchanged . and priority The value of is in the previous kernel O1 The performance on the scheduler will change , So it's also called dynamic priority .
3、 ... and . priority
Simple understanding nice After the concept of value , Let's see what is priority value , Namely ps As seen in the order PRI Value or top As seen in the order PR value .nice Namely top Medium NI value
In kernel , The value range of process priority is 140 Priority ranges , The value range is from 0-139, The smaller the value , The higher the priority .nice It's worth it 40-20 To 19-0, The priority range mapped to the actual is 100-139.
Under normal circumstances , The priority of any process is this value , Even if we pass nice and renice The command adjusts the priority of the process , Its value range will not exceed 100-139 The scope of the , Unless the process is a real-time process , Then its priority value will become 0-99 One of this range . There's a message here , That is, the current Linux Is an operating system that already supports real-time processes .
Simply speaking , The real-time operating system needs to ensure that the relevant real-time processes respond in a short time , There won't be a long delay , It also requires minimum interrupt delay and process switching delay . For such needs , General process scheduling algorithm , Whether it's O1 still CFS Are insatiable , So when the kernel is designed , The real-time process is mapped separately 100 Priority , These priorities are higher than those of normal processes (nice value ), This ensures that the real-time process has the highest distress record , Always ahead of the line to be dealt with .
The scheduling algorithms of real-time processes are also different , They use simpler scheduling algorithms to reduce scheduling overhead . in general ,Linux The processes running in the system can be divided into two categories :
Four . Real time process
Non real time processes The main difference between them is that they are distinguished by priority . All priority values are in 0-99 Within the scope of , It's all real-time processes , and 100-139 In scope are non real time processes . Can be used in the system chrt Order to see 、 Set the real-time priority state of a process . Let's take a look first chrt Use of commands :
Let's first focus on the Policy options part , You will find that the system provides for a variety of processes 5 Two scheduling strategies . But what is not stated here is , These five scheduling strategies are used for two processes respectively , The scheduling strategy that can be used for real-time processes is :SCHED_FIFO、SCHED_RR, For non real-time processes :SCHED_OTHER、SCHED_OTHER、SCHED_IDLE.
The overall priority strategy of the system is : If there are real-time processes to be executed in the system , Priority is given to the execution of real-time processes . Until the real-time process exits or voluntarily gives up CPU when , Will schedule the execution of non real-time processes . The priority range that real-time processes can specify is 1-99, The method of executing a program to be executed in real time is :
Just said ,SCHED_RR and SCHED_FIFO They are all real-time scheduling strategies , Can only be set for real-time processes . For all real-time processes , High priority ( Namely priority Small number ) The process must ensure that it executes before the process with low priority .SCHED_RR and SCHED_FIFO The scheduling strategy will only work when the priorities of two real-time processes are the same , The difference is as the name suggests :
SCHED_FIFO: Scheduling in a first in first out queue , With the same priority , Whoever executes first will be dispatched first , Unless it quits or actively releases CPU.
SCHED_RR: Multiple processes with the same priority are processed in the way of time slice rotation . The length of the time slice is 100ms.
边栏推荐
- hands-on-data-analysis 第三单元 模型搭建和评估
- 用一个软件纪念自己故去的母亲,这或许才是程序员最大的浪漫吧
- 几种常见的DoS攻击
- The 35 "top 100 counties" of tmall 618 agricultural products come from the central and western regions and Northeast China
- How does Argo family bucket make Devops easier?
- How to efficiently analyze online log
- Sqlserver 2000 has long-lasting vitality
- Sinomeni vine was selected as the "typical solution for digital technology integration and innovative application in 2021" of the network security center of the Ministry of industry and information te
- 如何化解35岁危机?华为云数据库首席架构师20年技术经验分享
- openGauss内核:简单查询的执行
猜你喜欢

MySQL foreign key impact

我从根上解决了微信占用手机内存问题

On the value foam of digital copyright works from the controversial nature of "Meng Hua Lu"

C语言中常量的定义和使用

I have fundamentally solved the problem of wechat occupying mobile memory

Internet of things? Come and see Arduino on the cloud

CVPR 2022 | 美團技術團隊精選論文解讀

谁是鱼谁是饵?红队视角下蜜罐识别方式汇总

物联网?快来看 Arduino 上云啦

About the hacked database
随机推荐
Getting started with the lvgl Library - colors and images
简述聚类分析
Comparator 排序函数式接口
[log service CLS] Tencent cloud log service CLS accesses CDN
手把手教你用AirtestIDE无线连接手机!
Integrate the authorization interface code of intra city distribution account of multiple express companies nationwide - Express 100
RAID5 array recovery case tutorial of a company in Shanghai
初中级开发如何有效减少自身的工作量?
我真傻,招了一堆只会“谷歌”的程序员!
TCP triple handshake
Use terminal to activate CONDA service in pypharm (the ultimate method is definitely OK)
爱可可AI前沿推介(6.24)
How to create a new empty branch in the web development process of easyrtc?
【数据挖掘】期末复习(样卷题目+少量知识点)
Integrated API interface code of domestic express companies for intra city distribution and ordering - Express 100
LVGL库入门教程 - 颜色和图像
IIS WCF 808 port service access exception
不用Home Assistant,智汀也开源接入HomeKit、绿米设备?
实现领域驱动设计 - 使用ABP框架 - 更新操作实体
Gateway processing flow of zuul source code analysis