How Java I/O Works Internally at Lower Level? - HowToDoInJava
Buffer Handling and Kernel vs User Space
Buffers, and how buffers are handled, are the basis of all I/O. The very term "input/output" means nothing more than moving data in and out of buffers. Just keep this in your mind all the time. Usually, processes perform I/O by requesting of the operating system that data to be drained from a buffer (write operation) or that a buffer be filled with data (read operation). That's whole summary of I/O concepts. The machinery inside the operating system that performs these transfers can be incredibly complex, but conceptually, it's very straightforward and we are going to discuss a small part of it in this post.
The image above shows a simplified 'logical' diagram of how block data moves from an external source, such as a hard disk, to a memory area inside a running process (e.g. RAM). First of all, the process requests that its buffer be filled by making the read() system call. This call results in the kernel issuing a command to the disk controller hardware to fetch the data from disk. The disk controller writes the data directly into a kernel memory buffer by DMA without further assistance from the main CPU. Once the disk controller finishes filling the buffer, the kernel copies the data from the temporary buffer in kernel space to the buffer specified by the process; when it requested the read() operation.
One thing to notice is that the kernel tries to cache and/or prefetch data, so the data being requested by the process may already be available in kernel space. If so, the data requested by the process is copied out. If the data isn't available, the process is suspended while the kernel goes about bringing the data into memory.
Read full article from How Java I/O Works Internally at Lower Level? - HowToDoInJava
No comments:
Post a Comment