2014년 11월 29일 토요일

Zygote in Chromium

When I begin to investigate Chromium, I have been known that the Zygote is used in Chromium. In fact, I had heard the Zygote as a word in the Android. But I don`t know accuracy about that. So After I read articles and codes, I can understand why the Chromium use the Zygote.


Upper picture shows  the Browser Process create the Zygote and other processes.
At first the Browser Process create the Zygote with fork and exec.
When we create a child process, we usually use "fork" command. A "fork" is copy all about  parent`s memory . Code, Stack, Data and Heap. It means both parent and child`s statuses are same. But sometimes it would be very dangerous.

When you make a new tab Chrome (usually) starts a new process for that tab. How is this done? It would seem natural to just fork(), but fork can't be used safely in the presence of threads. fork only forks the current thread but other threads may be holding locks (including e.g. inside glibc or in the allocator) which would never be released after the fork.
from https://code.google.com/p/chromium/wiki/LinuxZygote 

As quoted article say, if forked process would be locked by parent`s  another thread. It is not expected situation. But if parent process does not have any thread, this dangerous situation is disappeared. The Zygote has no threads, till new process has launched. It`s a just like a proxy. When parent process`s all resources are derived to child process, system library`s status is same. This is very important fact. Because when child process is created with "fork + exec", it has a possible that both using system library`s versions are different. Assume when parent process is running, one of using library is upgraded. Then between new installed library and using library by parent process has a version gap. Some api would be changed. And later child process has been launched with new version library. It would cause a crash.

 In conclusion, the Browser Process launch the Zygote prcoess with "fork+exec" rather than only "fork", for preventing thread lock. And the between Browser process and Zygote process are able to use same version libraries because when the Browser process is launched, the Zygote process is also launched. When the Browser process send a creating new child message through the IPC to the Zygote process, the Zygote fork a child process with "fork". It is for maintaining same version library between a parent and a child processes. This is why the Chromium use the Zygote.






댓글 없음:

댓글 쓰기