Last active
August 30, 2021 14:42
-
-
Save makeittotop/38676e3291a54e47f4f6 to your computer and use it in GitHub Desktop.
changing scheduling algorithm linux procs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In Linux 2.2.x there are three classes of processes, as can be seen from the data definition for the scheduler (from linux/include/linux/sched.h): | |
/* Scheduling Policies | |
*/ | |
#define SCHED_OTHER 0 | |
#define SCHED_FIFO 1 | |
#define SCHED_RR 2 | |
SCHED_OTHER tasks are the normal user tasks (default). | |
Tasks running in SCHED_FIFO will never be preempted. They will leave the CPU only for waiting sync kernel events or if an explicit sleep or reschedule has been requested from user space. | |
Tasks running in SCHED_RR are real time (RT), but they will leave the CPU if there is another real-time task in the run queue. So the CPU power will be distributed between all SCHED_RR tasks. If at least one RT task is running, no other SCHED_OTHER task will be allowed to run in any CPU. Each RT task has an rt_priority so the SCHED_RR class will be allowed to distribute the CPU power between all the SCHED_RR tasks at will. The rt_priority of the SCHED_RR class works exactly as the normal priority field for of the SCHED_OTHER (default) class | |
[root@lic ~]# lsof -i -Pnl | grep 33001 | awk '{print $2}' | xargs -I proc chrt -p proc | |
pid 21846's current scheduling policy: SCHED_OTHER | |
pid 21846's current scheduling priority: 0 | |
pid 21846's current scheduling policy: SCHED_OTHER | |
pid 21846's current scheduling priority: 0 | |
[root@lic ~]# | |
[root@lic ~]# | |
[root@lic ~]# | |
[root@lic ~]# chrt -m | |
SCHED_OTHER min/max priority : 0/0 | |
SCHED_FIFO min/max priority : 1/99 | |
SCHED_RR min/max priority : 1/99 | |
SCHED_BATCH min/max priority : 0/0 | |
SCHED_IDLE min/max priority : 0/0 | |
[root@lic ~]# | |
[root@lic ~]# | |
[root@lic ~]# | |
[root@lic ~]# chrt -f -p 20 21846 | |
[root@lic ~]# lsof -i -Pnl | grep 33001 | awk '{print $2}' | xargs -I proc chrt -p proc | |
pid 21846's current scheduling policy: SCHED_FIFO | |
pid 21846's current scheduling priority: 20 | |
pid 21846's current scheduling policy: SCHED_FIFO | |
pid 21846's current scheduling priority: 20 | |
unix# lsof -i -Pnl | grep 33001 | awk '{print $2}' | xargs -I proc ps -p proc -o pid,ppid,etime,c,pmem,cputime,bsdstart,bsdtime,class,comm,esp,f,fname,lstart,nlwp,thcount,s,stat,state,sgi_p,sz,vsz,size,tty,wchan --no-header | |
21846 21814 21:14 23 0.1 00:05:05 14:04 5:05 FF ascp 0dd8e750 0 ascp Wed Jun 10 14:04:02 2015 5 5 S Ssl+ S * 66294 265176 244176 pts/4 futex_wait_queue_me | |
21846 21814 21:14 23 0.1 00:05:05 14:04 5:05 FF ascp 0dd8e750 0 ascp Wed Jun 10 14:04:02 2015 5 5 S Ssl+ S * 66294 265176 244176 pts/4 futex_wait_queue_me | |
unix# lsof -i -Pnl | grep 33001 | awk '{print $2}' | xargs -I proc ps -p proc -o pid,ppid,etime,c,pmem,cputime,bsdstart,bsdtime,class,comm,esp,f,fname,lstart,nlwp,thcount,s,stat,state,sgi_p,sz,vsz,size,tty,wchan --no-header | |
21846 21814 21:25 23 0.1 00:05:08 14:04 5:08 FF ascp 0dd8e750 0 ascp Wed Jun 10 14:04:02 2015 5 5 S Ssl+ S * 66294 265176 244176 pts/4 futex_wait_queue_me | |
21846 21814 21:25 23 0.1 00:05:08 14:04 5:08 FF ascp 0dd8e750 0 ascp Wed Jun 10 14:04:02 2015 5 5 S Ssl+ S * 66294 265176 244176 pts/4 futex_wait_queue_me | |
unix# lsof -i -Pnl | grep 33001 | awk '{print $2}' | xargs -I proc ps -p proc -o pid,ppid,etime,c,pmem,cputime,bsdstart,bsdtime,class,rtprio,comm,esp,f,fname,lstart,nlwp,thcount,s,stat,state,sgi_p,sz,vsz,size,tty,wchan --no-header | |
21846 21814 22:29 24 0.1 00:05:24 14:04 5:24 FF 20 ascp 0dd8e750 0 ascp Wed Jun 10 14:04:02 2015 5 5 S Ssl+ S * 66294 265176 244176 pts/4 futex_wait_queue_me | |
21846 21814 22:29 24 0.1 00:05:24 14:04 5:24 FF 20 ascp 0dd8e750 0 ascp Wed Jun 10 14:04:02 2015 5 5 S Ssl+ S * 66294 265176 244176 pts/4 futex_wait_queue_me | |
Before setting new scheduling policy, you need to find out minimum and maximum valid priorities for each scheduling algorithm, enter: | |
# chrt -m | |
Output: | |
SCHED_OTHER min/max priority : 0/0 | |
SCHED_FIFO min/max priority : 1/99 | |
SCHED_RR min/max priority : 1/99 | |
SCHED_BATCH min/max priority : 0/0 | |
How do I set SCHED_BATCH scheduling policy? | |
To set scheduling policy to SCHED_BATCH, enter: | |
# chrt -b -p 0 {pid} | |
# chrt -b -p 0 1024 | |
How do I set SCHED_FIFO scheduling policy? | |
To set scheduling policy to SCHED_FIFO, enter: | |
# chrt -f -p [1..99] {pid} | |
Set policy to SCHED_FIFO with 50 priority: | |
# chrt -f -p 50 1024 | |
# chrt -p 1024 | |
How do I set SCHED_OTHER scheduling policy? | |
To set policy scheduling policy to SCHED_OTHER, enter: | |
# chrt -o -p 0 {pid} | |
# chrt -o -p 0 1024 | |
# chrt -p 1024 | |
How do I set SCHED_RR scheduling policy? | |
To set scheduling policy to SCHED_RR, enter: | |
# chrt -r -p [1..99] {pid} | |
Set policy to SCHED_RR scheduling with 20 priority: | |
# chrt -r -p 20 1024 | |
# chrt -p 1024 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment