Memory - Segment
Table of Contents
1 - About
Segments usually represent natural divisions of a program and may be created to separate:
- code (individual routines)
- and data (data tables)
2 - Articles Related
3 - Property
3.1 - Identification
A segment is identified by:
- an id value
- and an offset
3.2 - Size
The size of a memory segment is generally not fixed and may be as small as a single byte.
4 - Location
4.1 - 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
4.1.1 - Without paging
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.
4.1.2 - 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.
4.2 - 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.
5 - 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.