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:
Process makes a system call, read, to Operating system
OS coordinates with driver, hardware to fetch disk blocks into the page cache
OS copy 开发者_高级运维the data from page cache to process's buffer
Am I correct?
If I'm correct, I have 2 follow-up questions
Why OS needs to copy data from page cache (kernel space) into process's buffer (user space)?
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.
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.
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?
精彩评论