8. Process creation system call fork() Duplicate of the parent's page tables Create unique process descriptor for child(pidetc) Copy-on-Write Delay the copying pages exec() is called right after fork() vfork() Same as fork() except copying of parent page table Share parent's address space Child first scheme Parent is blocked until the child calls exec() or exits
11. Thread Implementation threads as same as standard processes One thread has own task_struct pid/ tgid Create clone() system call clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0); clone(SIGCHLD, 0); // fork() clone(CLONE_VFORK | CLONE_VM | SIGCHLD, 0); // vfork()
12. Kernel Threads Standard processes running in kernel space Do not have an address space(task_struct.mm is NULL) Schedulable, preemptable like normal process kthread_create() for creation
16. Process priority nice Integer value(-20~19, default 0) High nice value correspond to low priority renice, setpriority() Realtime priority Always higher priority than normal processes Integer value(0~99)
17. Process priority Priority kernel internal Integer value (0~139) nice values[-20~19] are map to [100~139] [0~99] for realtime processes
18. Fairness scheduling RR on static timeslice 100ms(0 nice) vs 95ms(1 nice) 10ms(19 nice) vs 5ms (20 nice) A user’s 100 processes vs B user’s 1process Per user based scheduling Enable when kernel build Per thread level scheduling One nice value down gets 10% more CPU power vruntime(virtual clock) Support CGroupscheduling http://www.mjmwired.net/kernel/Documentation/scheduler/sched-design-CFS.txt
19. Overview schedule() Core T T T Ruequene do_fork() wake_up_new_task() T Tß T Waitqueue Core T Ruequene Core T T Ruequene Core T T Ruequene
21. CFS policy Soft real-time policy Posix standard Priority scheduling One nice level down gets 10% more CPU power Virtual clock Conceptual time considering priority Task waiting most of time will be scheduled to run Time order is managed by Runqueue
22. Data struct task_struct http://lxr.linux.no/linux+v2.6.39/include/linux/sched.h#L1193 SCHED_NORMAL SCHED_BATCH SCHED_IDLE SCHED_FIFO SCHED_RR
29. Remaining How to determine vruntime Process selection When schedule() function is called Context switching Sleep and Wake up Cgroup Hard to understand
Hinweis der Redaktion
wake_up_new_task; in other words, the task structure is added to the scheduler queue뒤쪽에서 스케줄링에서 설명하겠지만 생성된 프로세스는 무조건 한번은 수행되도록 보장함
Check flag – for clone system call parameterDup_task_struct – 실제 복사가 이루어짐Sched_fork – 스케줄링에 관련된 내용이 복사됨(확인요함)
Vruntime – 실제 수행된 시간에 prority별로 가중치를 둔 이후, 가장 수행시간이 적은 task 위주로 수행함
Prio, normal_proi – 동적으로 변함Static_proi- 고정됨Rt_prioroty – realtime인 경우만설정, 그렇지 않은 경우 0,max 99Sched_entity를 갖는 것은 모든지 스케줄링이 될 수 있음Policy는 cpu에 동작할 때의 정책 –sched_normalCpus_allows – bitfield로 특정 cpu에서 동작하는 것을 제한Tile_slice for realtimeß
Nr_running – 현재 큐에 들어있는 태스크 갯수Load – 가중치를 고려한 테스크의 워크로드Clock은 해당 런큐가 주기적으로 스케줄링을 받도록 계산하기 위하여 사용됨Cpu_load는 이전의 워크로드를 기록 – 로드벨런싱, 그룹핑에 쓰임\\
전체 큐의 워크로드런큐 내부적으로 rb를 이용하기 때문에, 그에 필요한 노드On_rq – 현재 스케줄링이 되고 있는지 확인CFS를 구현하기 위하여 필요한 시간 값Task_struct가 sched_entity를 가지고 있기 때문에 스케줄링을 받을 수 있음
weight는 load 즉, 우선순위에 대한 가중치이고 inv_weight는 이의 역수(1/weight)에 해당하는 값이다.weight 값은 nice를 통해 지정할 수 있는 우선순위에 대응하는 값이며 (nice level 0일 때: 1024)sched.c 파일의 prio_to_weight[] 배열에 저장되어 있다.참고로 nice (우선순위) 값의 1 차이는 weight 값의 1.25 배 차이이며이는 프로세스가 CPU를 사용하는 시간에 10% 정도 영향을 준다.inv_weight값은 단지 계산을 간편하게 하기 위한 목적으로 도입된 것으로가중치 계산을 위한 나눗셈을 피하기 위해 미리 정해진 충분히 큰 수(2^32)에 나눗셈을 미리 계산해 둔 값이다.