read() system call: how to transfer data to userspace.
Posted: Fri Jan 22, 2021 1:18 pm
Hey everyone,
I was wondering how an OS handles read (or write) calls, especially for microkernels. At some point an user process wants to read from a file or pipe or whatever.
It does by calling the read syscall while specifying a buffer for the result and then it blocks until the work is done. The kernel then signals the filesystem to perform the read operation on a disk or on whatever the process wants to read from. While waiting for the data, another user process could be running, so the virtual address space could be different. So how does the OS transfer the data from the filesystem back to the calling process?
I could think of copying the data first to a buffer in kernel space, then switch context and copy it back to the calling process. However that seems to be inefficient, especially when dealing with large amounts of data. Or another way could be to map the page of the user space buffer to the file system, but that would result in issues with protection and isolation of tasks, especially for microkernels.
Could someone tell me more about how this is commonly done? Or maybe tell me where I can find fore information about this?
Thanks a lot.
I was wondering how an OS handles read (or write) calls, especially for microkernels. At some point an user process wants to read from a file or pipe or whatever.
It does by calling the read syscall while specifying a buffer for the result and then it blocks until the work is done. The kernel then signals the filesystem to perform the read operation on a disk or on whatever the process wants to read from. While waiting for the data, another user process could be running, so the virtual address space could be different. So how does the OS transfer the data from the filesystem back to the calling process?
I could think of copying the data first to a buffer in kernel space, then switch context and copy it back to the calling process. However that seems to be inefficient, especially when dealing with large amounts of data. Or another way could be to map the page of the user space buffer to the file system, but that would result in issues with protection and isolation of tasks, especially for microkernels.
Could someone tell me more about how this is commonly done? Or maybe tell me where I can find fore information about this?
Thanks a lot.