1 / 13

Ch 3 Process - Data Structures -

제 37 강 : Process (Data Structures). Ch 3 Process - Data Structures -. Data Structure change (1) don’t divide PCB for swapping. ‘Process’  ‘Task’ & ‘Thread’ (Linux) Lions: Segment based swapping PCB  ( proc & user) Linux: Paging based swapping

tass
Download Presentation

Ch 3 Process - Data Structures -

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 제37강 : Process (Data Structures) Ch 3 Process- Data Structures -

  2. Data Structure change (1)don’t divide PCBfor swapping • ‘Process’  ‘Task’ & ‘Thread’ (Linux) • Lions: Segment based swapping PCB  (proc & user) • Linux: Paging based swapping LRU (Least_Recently_Used) page is replaced. [Linux PCB] [Lions PCB] proc task_struct user a.out a.out

  3. Data Structure change (2)Static Dynamic Allocation • Lions: space -- static allocation (kernel coding time) • Linux: space -- dynamically allocated on-demand kernel manages space pool proc file inode proc[N] file[M] inode[I] storage pool - static allocation - arrays - not flexible (space management) - Dynamic allocation (kernel) - Central pool, linked list - flexible [Lions] [Linux]

  4. Array  Linked list static allocation dynamic allocation proc[] proc proc[1] task_struct proc[2] proc[3] proc[4] task_struct proc[5] task_struct [Lions] [Linux]

  5. Data Structure change (3)Multiple Structs for fork overhead files files per thread basic info fs per thread basic info Lions’ PCB struct fs Linux PCB struct tty tty mm mm signals signals child may copy selectively child copies all values (always) files: open files fs: file system mm: main memory [Linux] [Lions]

  6. Process Creation OverheadLight-weight & Heavy-weight files per thread basic info fs (heavy-weight creation) copy everything Child’s Private copy tty files mm per thread basic info fs signals tty mm signals (light-weight creation) copy selectively No copy for child Child share parent’s data per thread basic info

  7. clone() system call- five flags - (1) files files no copy per thread basic info (0) per thread basic info fs fs eg clone(10101) tty (1) tty mm (0) mm copy signals signals (1) UNIX process clone(11111) = UNIX fork() Linux thread = LWP(Light-Weight Process) clone(00000) MIN data copy

  8. struct task_struct { volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ struct thread_info *thread_info; unsigned long flags; /* per process flags, defined below */ int prio, static_prio; struct list_head tasks; struct mm_struct*mm; struct task_struct *parent; /* parent process */ struct list_head children; /* list of my children */ struct list_head sibling; /* linkage in my parent's children list */ struct tty_struct*tty; /* ipc stuff */ struct sysv_sem sysvsem; /* CPU-specific state of this task */ struct thread_struct thread; /* file system information */ struct fs_struct *fs; /* open file information */ struct files_struct *files; /* namespace */ struct namespace *namespace; /* signal handlers */ struct signal_struct*signal; struct sighand_struct *sighand; }; files per thread basic info fs tty mm signals

  9. struct task_struct { volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */ struct thread_info *thread_info; unsigned long flags; /* per process flags, defined below */ int prio, static_prio; struct list_head tasks; struct mm_struct*mm; struct task_struct *parent; /* parent process */ struct list_head children; /* list of my children */ struct list_head sibling; /* linkage in my parent's children list */ struct tty_struct*tty; /* ipc stuff */ struct sysv_sem sysvsem; /* CPU-specific state of this task */ struct thread_struct thread; /* file system information */ struct fs_struct *fs; /* open file information */ struct files_struct *files; /* namespace */ struct namespace *namespace; /* signal handlers */ struct signal_struct*signal; struct sighand_struct *sighand; }; files per thread basic info fs tty mm signals

  10. files Linux “thread” per thread basic info fs tty mm • Linux has no “true” thread • Allows clone() with “minimum data copy” flag • Child shares data with parent through pointers • Low overhead for process creation • clone(“minimum data copy”) = “LWP” = “thread” • clone() can specify where new thread belongs to • man clone signals

  11. CLONE(2) Linux Programmer's Manual CLONE(2) NAME clone - create a child process SYNOPSIS #include <sched.h> int clone(int (*fn)(void *), void *child_stack, int flags, void *arg); _syscall2(int, clone, int, flags, void *, child_stack) DESCRIPTION clone creates a new process, just like fork(2). Unlike fork(2), these calls allow the child process to share parts of its execution context with the calling process, such as the memory space, the table of file descriptors, and the table of signal handlers. (Note that on this manual page, "calling process" normally corresponds to "parent process".) Main use of clone is to implement threads: multiple threads of control in a program that run concurrently in a shared memory space. When the child process is created with clone, it executes the function application fn(arg). (This differs from fork(2), where execution continues in the child from the point of the fork(2) call.) The fn argument is a pointer to a function that is called by the child process at the beginning of its execution. The arg argument is passed to the fn function. When the fn(arg) function application returns, the child process terminates. The integer returned by fn is the exit code for the child pro cess. The child process may also terminate explicitly by calling exit(2) or after receiving a fatal signal.

  12. Data Structure change (4)PCB separates from kernel stack • struct user was small (Lions)  task_struct is big (Linux) • Linux • task_struct does not share space with kernel_stack * instead, thread_inforesides in kernel_stack page * thread_info is much smaller than task_struct * thread_info has pointer to task_struct * thread_info is for thread; task_struct for task thread_info struct task_struct { } struct user { } kernel stack kernel stack

  13. /* this struct shares the supervisor stack pages */ struct thread_info{ struct task_struct*task; /* main task structure */ struct exec_domain *exec_domain; /* execution domain */ unsigned long flags; /* low level flags */ unsigned long status; /* thread-sync flags */ u32 cpu; /* current CPU */ s32 preempt_count; struct restart_block /*restart_block; u8 supervisor_stack[0]; }; task_struct struct thread_info { task_struct *task;} files per thread basic info fs tty mm kernel stack signals High Address

More Related