首页 > 试题广场 >

What are the extra costs incur

[问答题]

What are the extra costs incurred by the creation and scheduling of a process,as compared to the cost of a cloned thread?

推荐

Answer:In Linux,creation of a thread involves only the creation of some very simple data structures to describe the new thread.Space must be reserved for the new thread's execution context its saved registers,its kernel stack page and dynamic information such as its security

profile and signal state but no new virtual address space is created.Creating this new virtual address space is the most expensive part of the creation of a new process.The entire page table of the parent process must be copied,with each page being examined so that copy-on-write semantics can be achieved and so that reference counts to physical pages can be updated.The parent process's virtual memory is also affected by the process creation:any private read/write pages owned by the parent must be marked read-only so that copy-on-write can happen(copy-on-write relies on a page fault being generated when a write to the page occurs). Scheduling of threads and processes also differs in this respect.The decision algorithm performed when deciding what process to run next is the same regardless of whether the process is a fully independent process or just a thread,but the action of context-switching to a separate process is much more costly than switching to a thread.A process requires that the CPU's virtual memory control registers be updated to point to the new virtual address space's page tables. in both cases-creation of a process or context switching between processes the extra virtual memory operations have a significant cost.On many CPUs,changing page tables or swapping between page tables is not cheap:all or part of the virtual address translation look-aside buffers in the CPU must be purged when the page tables are changed.These costs are not incurred when creating or scheduling between threads.


发表于 2018-05-05 21:04:41 回复(0)