ch 3 process - data structures -

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

Upload: tass

Post on 05-Jan-2016

22 views

Category:

Documents


3 download

DESCRIPTION

제 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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Ch 3  Process - Data Structures -

1

Ch 3 Process

- Data Structures -

제 37 강 : Process (Data Structures)

Page 2: Ch 3  Process - Data Structures -

2

user

task_struct

proc

[Lions PCB] [Linux PCB]

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 LRU (Least_Recently_Used) page is

replaced.

a.out a.out

Page 3: Ch 3  Process - Data Structures -

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

[Lions] [Linux]

proc[N] file[M] inode[I]

- static allocation- arrays- not flexible (space management)

proc file inode

storage pool

- Dynamic allocation (kernel)- Central pool, linked list- flexible

Page 4: Ch 3  Process - Data Structures -

4

proc[1]

static allocation

[Lions] [Linux]

Array Linked list

proc[2]proc[3]proc[4]proc[5]

task_struct

task_struct

task_struct

procproc[]

dynamic allocation

Page 5: Ch 3  Process - Data Structures -

5

Data Structure change (3) Multiple Structs for fork

overhead

Lions’PCB

struct

[Lions] [Linux]

child copies all values(always)

files: open filesfs: file systemmm: main memory

files

tty

mm

signals

fs

files

tty

mm

signals

fs

child may copy selectively

per

thread

basic

info

per

thread

basic

info

LinuxPCB

struct

Page 6: Ch 3  Process - Data Structures -

6

Process Creation OverheadLight-weight & Heavy-weight

Child’sPrivate copy

files

tty

mm

signals

fs

files

tty

mm

signals

fs

per

thread

basic

info

(heavy-weight creation) copy everything

(light-weight creation) copy selectively No copy

for childChild share

parent’sdata

per

thread

basic

infoper

thread

basic

info

Page 7: Ch 3  Process - Data Structures -

7

clone() system call- five flags -

(1)

(1)

(1)

(0)

(0)

eg clone(10101)

UNIX process clone(11111) = UNIX fork()

Linux thread = LWP(Light-Weight Process) clone(00000) MIN data copy

copy

no copyfiles

tty

mm

signals

fsper

thread

basic

info

files

tty

signals

per

thread

basic

info

fs

mm

Page 8: Ch 3  Process - Data Structures -

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

tty

mm

signals

fsper

thread

basic

info

Page 9: Ch 3  Process - Data Structures -

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

tty

mm

signals

fsper

thread

basic

info

Page 10: Ch 3  Process - Data Structures -

10

Linux “thread”

• 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

files

tty

mm

signals

fsper

thread

basic

info

Page 11: Ch 3  Process - Data Structures -

11

CLONE(2) Linux Programmer's Manual CLONE(2)NAME clone - create a child processSYNOPSIS #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.

Page 12: Ch 3  Process - Data Structures -

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_info resides 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

kernelstack

struct task_struct{

}

thread_info

kernelstack

struct user{

}

Page 13: Ch 3  Process - Data Structures -

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];};

kernelstack

struct thread_info { task_struct *task;}

task_struct

files

tty

mm

signals

fsper

thread

basic

info

High Address