开发者

Data Copy from Kernal Space to User Space regarding reading data from disk

I want to understand how ready system call work and its design.

My understanding on reading data from disk:

  1. Process makes a system call, read, to Operating system

  2. OS coordinates with driver, hardware to fetch disk blocks into the page cache

  3. OS copy 开发者_高级运维the data from page cache to process's buffer

Am I correct?

If I'm correct, I have 2 follow-up questions

  1. Why OS needs to copy data from page cache (kernel space) into process's buffer (user space)?

    1. I saw people were talking about the copy_to_user & copy_from_user functions, it does some sanity check during the copy & prevent illegal copy. However, couldn't we just check if the copy is legal or not and return the reference to the process? If the request is legal, we return the reference. If the request is illegal, we reject.

    2. In case the process needs to write the data and we don't want the process to manipulate the kernel space (for security reason or the data is shared by other processes), we only copy data to user space at this moment.

  2. When OS copies the data from page cache to process's buffer, do physical memory hold 2 pieces of data? 1 for page cache & another for process's buffer. Or there is only 1 piece of data in physical memory, data from page cache and process's buffer map to this single piece of data?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜