Region Manipulation
Region Manipulation
Region Manipulation
3. Allocate a region:
The kernel allocates a new region during fork system call.
The kernel contains a region table whose entries appear either on a free linked list or on an active linked list.
When it allocates a region table entry, the kernel removes the first available entry from the free list, places it on
the active list, locks the region, and marks its type (shared or private).
Internally, the kernel invokes the algorithm growreg to change the size of a region.
When a region expands, the kernel makes sure that the virtual addresses of the expanded region do not overlap
those of another region and that the growth of the region does not cause the process size to become greater than
the maximum allowed virtual memory space.
The kernel never invokes growreg to increase the size of a shared region that is already attached to several
processes;
6. Loading a Region
If the kernel does not support demand paging, it must copy the executable file into memory, loading the process
regions at virtual addresses specified in the executable file.
It may attach a region at a different virtual address from where it loads the contents of the file, creating a gap in
the page table.
To load a file into a region, loadreg accounts for the gap between the virtual address where the region is attached
to the process.
The starting virtual address of the region data and expands the region according to the amount of memory the
region requires.
If the kernel is loading a text region that can be shared by several processes, it is possible that another process
could find the region and attempt to use it before its contents were fully loaded.
The kernel checks a region state flag to see if the region is completely loaded and, if the region is not loaded, the
process sleeps.
At the end of loadreg, the kernel awakens processes that were waiting for the region to be loaded and changes the
region state to valid and in memory.
7. Freeing a Region
When a region is no longer attached to any processes, the kernel can free the region and return it to the list of free
regions.
If the region is associated with an inode, the kernel releases the inode using algorithm iput, corresponding to the
increment of the inode reference count in allocreg.
The kernel releases physical resources associated with the region, such as page tables and memory pages.
For example, suppose the kernel wants to free the stack region, assuming the region reference count is 0, it
releases the 7 pages of physical memory and the page table.