Process Segments and VMA
Under Linux, a process can execute in two modes - user mode and kernel mode. A process usually executes in user mode, but can switch to kernel mode by making system calls. When a process makes a system call, the kernel takes control and does the requested service on behalf of the process. The process is said to be running in kernel mode during this time. When a process is running in user mode
User Mode Segments
The code segment consists of the code - the actual executable program. The code of all the functions we write in the program resides in this segment.
The Data segment consists of the initialized global variables of a program.
The BSS(block started by symbol) consists of the uninitialized global variables of a process.
The automatic variables (or local variables) will be allocated on the stack.
Heam Segment will store all dynamically allocated data.
Memory-related data structures in the kernel
Each virtual memory area (VMA) is a contiguous range of virtual addresses; these areas never overlap.
Each memory segment above (e.g., heap, stack) corresponds to a single VMA.
The mmap
contains the pointer to the list of VMAs (Virtual Memory Areas) related to this process. Full usage of the process address space occurs very rarely.
The kernel keeps track of the segments which have been allocated to a particular process using the above structures. For each segment, the kernel allocates a VMA. It keeps track of these segments in the mm_struct
structures.
what are the different ways the Linux can swich from User Space to Kernel Space & vice-versa ?
There are 2 situations when Linux can switch from user Space
to Kernel Space:-
1) by doing System calls
2) When interrupt comes (to handle interrupt)
Linux can switch from kernel Space to User space:-
1) process in kernel mode is preempted.
2) After completion of Interrupt handler / System call
How to see the module information?
# modinfo -p
No comments:
Post a Comment