About
segment implementation in virtual memory.
Segments usually represent natural divisions of a program and may be created to separate:
- code (individual routines)
- and data (data tables)
Certain segments may even be shared between programs. See: shared memory
Articles Related
Property
Identification
A virtual segment is identified by:
- an id value
- and an virtual address
Size
The size of a memory segment is generally not fixed and may be as small as a single byte.
Location
Translation
The memory management unit (MMU) is responsible to translate a segment and offset into a memory address.
An address is associated with a segment that indicates where the segment is located in memory. The meaning of the address differs with the use or not of paging.
The address might be:
- without paging: the address of the first location in the segment,
- with paging: the address of a page table for the segment
Without paging
When a segment does not have a page table associated with it, the address of the first location in the segment is usually an address in main memory (in those situations, no paging is done).
The offset within the segment will be added to address of the first location in the segment to give the address in memory of the referred-to item.
With Paging
The address is an address in a paged address space. The offset of the segment is translated to a memory address using the page table.
Main memory or not
Segments may also have a flag indicating whether the segment is present in main memory or not; if a segment is accessed that is not present in main memory, an exception is raised, and the operating system will read the segment into memory from secondary storage.
Permission
A segment has:
- a length (size)
- and a set of permissions associated with it.
A process is only allowed to make a reference into a segment if the type of reference is allowed by the permissions, and the offset within the segment is within the range specified by the length of the segment. Otherwise, a hardware exception such as a segmentation fault is raised.