Friday 7 June 2019

What will happen when application request I/O operation?


In this post, you are going to learn below things.
a.   What is Kernel space and user space?
b.   Can a user process access kernel space?
c.    What will happen when the application request IO operation

What is kernel space and user space?
System memory is divided into two regions.
a.   User space
b.   Kernel space

Kernel is the core component of operating system. Kernel component runs in kernel space and provide its services. it has full access to the memory and can able to talk to the hardware directly. No other programs, for example user applications can't access kernel space for security reasons.

User processes run in user space. Kernel manages user processes to prevent interfering one process from another.

Can a user process access kernel space?
User process can’t access kernel space directly, but via system calls, user process can access kernel space.

What will happen when the application request IO operation
When a user process request IO operation (such as read, write, and close) it performs system call. Kernel receives the system call and execute the IO operation.

Below figure explains how a read request is served?

When a user application request read operation, it internally calls the read() system call. Kernel receives this system call and request disk controller to give the data from the disk. Disk controller reads the data from disk and writes to the kernel space. Kernel copies the data from kernel space to the user space.


What is DMA?
Direct memory access (DMA) is a feature of computer systems that allows hardware (Disk Controller) to access main system memory independent of CPU ( central processing unit).

Where does jvm fall into?
Jvm is launched by user application, so it is fall into user space.

You may ask me, why are we copying the data to kernel space and reading again to user space. There are many reasons to do this, one is disk controllers do not have direct access to user space and for security (memory corruption can happen) reasons also data is copied to kernel and then back to user space. But as you see in this approach, due to two times filling of the buffer (kernel buffer and user buffer), it leads to performance problems. This can be solved by using virtual memory concept. In my next post, I am going to explain virtual memory concept.

Previous                                                 Next                                                 Home

No comments:

Post a Comment