Linux process has many properties that define its metadata.
task_struct is the C Structure that stores various properties of processes
It stores pid, state, tgid, mm(pointer to mm_struct, which defines memory metadata of the process, we will see in another article), active_mm, and so on.
Scheduler uses this metadata for various reasons regarding scheduling.
But the process also has executable code, right? Where is that code stored?
task_struct does not store the executable code of a process, but Linux has a complex mechanism to store the executable code of a process.
Linux stores the process in Virtual Memory.
Virtual Memory contains RAM and disk addresses, and these are represented by virtual addresses. vm_area_struct defines these addresses; one process can have multiple vm_area_struct instances, and all these struct entries are registered in another structure named mm_struct.
How does Linux store processes in virtual memory, and how does it map to primary memory? All this information we will see in another article in detail.
This article focuses on when code is loaded into RAM, then how it is represented in RAM, and how the Linux kernel treats it.
This is a very high-level explanation about how Linux treats executable code. We will discuss everything in detail in upcoming articles.
So Linux treats each process as pages in RAM.
One process may have multiple pages associated with it, but each page is of 4 KB in size.
Each process has one separate Page Table.
In upcoming chapters, we will see how Linux manages these page tables and how it becomes a tree.
Now, back to pages, once a page is loaded into RAM, it has a base address also called as page frame address. Linux uses this address for process execution, because each page is 4 KB. Linux also knows where the code ends in RAM
PTE is the main thing that defines the process.
By using PTE, Linux defines how the executable code can be accessible.
This is how Linux maps executable code in RAM.
In the next chapters, we will see the entire process of how Linux stores processes in virtual memory and how a process is given to the CPU for execution.
Leave a Reply