Memory segmentation
   HOME

TheInfoList



OR:

Memory segmentation is an
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...

operating system
memory management Memory management is a form of Resource management (computing), resource management applied to computer memory. The essential requirement of memory management is to provide ways to dynamically allocate portions of memory to programs at their re ...
technique of division of a
computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as Computer program, pr ...

computer
's primary memory into segments or sections. In a
computer system A computer is a machine that can be programmed to Execution (computing), carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as C ...
using segmentation, a reference to a memory location includes a value that identifies a segment and an offset (memory location) within that segment. Segments or sections are also used in
object file An object file is a computer file containing object code, that is, machine code output of an Assembly language#Assembler, assembler or compiler. The object code is usually Relocation (computing), relocatable, and not usually directly executable. T ...
s of compiled programs when they are linked together into a program image and when the image is loaded into memory. Segments usually correspond to natural divisions of a program such as individual routines or data tables so segmentation is generally more visible to the programmer than
paging In computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as Co ...

paging
alone. Segments may be created for program modules, or for classes of memory usage such as
code In communications and information processing, code is a system of rules to convert information—such as a letter (alphabet), letter, word, sound, image, or gesture—into another form, sometimes data compression, shortened or secrecy, secret ...
and data segments. Certain segments may be shared between programs. Segmentation was originally invented as a method by which
system software System software is software designed to provide a platform for other software. Examples of system software include operating systems (OS) like macOS, Linux, Android and Microsoft Windows, computational science software, game engines, search engin ...
could isolate software processes ( tasks) and data they are using. It was intended to increase reliability of the systems running multiple processes simultaneously. In a x86-64 architecture it is considered legacy and most x86-64-based modern system software don't use memory segmentation. Instead they handle programs and their data by utilizing memory-paging which also serves as a way of memory protection. However most x86-64 implementations still support it for backward compatibility reasons.


Hardware implementation

In a system using segmentation, computer memory addresses consist of a segment id and an offset within the segment. A hardware
memory management unit A memory management unit (MMU), sometimes called paged memory management unit (PMMU), is a computer hardware unit having all computer memory, memory references passed through itself, primarily performing the translation of virtual address, virtua ...
(MMU) is responsible for translating the segment and offset into a physical address, and for performing checks to make sure the translation can be done and that the reference to that segment and offset is permitted. Each segment has a length and set of permissions (for example, ''read'', ''write'', ''execute'') associated with it. A
process A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic. Things called a process include: Business and management *Business process A business process, business method ...
is only allowed to make a reference into a segment if the type of reference is allowed by the permissions, and if 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 In computing, a segmentation fault (often shortened to segfault) or access violation is a Fault (computing), fault, or failure condition, raised by hardware with memory protection, notifying an operating system (OS) the software has attempted to ...
is raised. Segments may also be used to implement
virtual memory In computing, virtual memory, or virtual storage is a Memory management (operating systems), memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "cr ...
. In this case each segment has an associated flag indicating whether it 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 An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...

operating system
will read the segment into memory from secondary storage. Segmentation is one method of implementing
memory protection Memory protection is a way to control memory access rights on a computer, and is a part of most modern instruction set architectures and operating systems. The main purpose of memory protection is to prevent a process (computing), process from acc ...
.
Paging In computer A computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as Co ...
is another, and they can be combined. The size of a memory segment is generally not fixed and may be as small as a single
byte The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable un ...
. Segmentation has been implemented several ways on various hardware, with or without paging. Intel x86 memory segmentation does not fit either model and is discussed separately below, and also in greater detail in a separate article.


Segmentation without paging

Associated with each segment is information that indicates where the segment is located in memory— the ''segment base''. When a program references a memory location, the offset is added to the segment base to generate a physical memory address. An implementation of virtual memory on a system using segmentation without paging requires that entire segments be swapped back and forth between main memory and secondary storage. When a segment is swapped in, the operating system has to allocate enough contiguous free memory to hold the entire segment. Often memory fragmentation results if there is not enough contiguous memory even though there may be enough in total.


Segmentation with paging

Instead of a memory location, the segment information includes the address of a
page table A page table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual addresses and physical addresses. Virtual addresses are used by the program executed by the accessing Process ( ...
for the segment. When a program references a memory location the offset is translated to a memory address using the page table. A segment can be extended by allocating another memory page and adding it to the segment's page table. An implementation of
virtual memory In computing, virtual memory, or virtual storage is a Memory management (operating systems), memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "cr ...
on a system using segmentation with paging usually only moves individual pages back and forth between main memory and secondary storage, similar to a paged non-segmented system. Pages of the segment can be located anywhere in main memory and need not be contiguous. This usually results in a reduced amount of input/output between primary and secondary storage and reduced memory fragmentation.


History

The
Burroughs Corporation The Burroughs Corporation was a major American manufacturer of business equipment. The company was founded in 1886 as the American Arithmometer Company. In 1986, it merged with UNIVAC, Sperry UNIVAC to form Unisys. The company's history parallel ...
B5000 computer was one of the first to implement segmentation, and "perhaps the first commercial computer to provide virtual memory" based on segmentation. The later B6500 computer also implemented segmentation; a version of its architecture is still in use today on the Unisys ClearPath Libra servers. The GE-645 computer, a modification of the GE-635 with segmentation and paging support added, was designed in 1964 to support
Multics Multics ("Multiplexed Information and Computing Service") is an influential early time-sharing operating system based on the concept of a single-level store, single-level memory.Dennis M. Ritchie, "The Evolution of the Unix Time-sharing System", ...
. The
Intel iAPX 432 The iAPX 432 (''Intel Advanced Performance Architecture'') is a discontinued computer architecture In computer engineering, computer architecture is a description of the structure of a computer system made from component parts. It can sometim ...
, begun in 1975, attempted to implement a true segmented architecture with memory protection on a microprocessor. The 960MX version of the
Intel i960 Intel's i960 (or 80960) was a RISC-based microprocessor design that became popular during the early 1990s as an embedded system, embedded microcontroller. It became a best-selling CPU in that segment, along with the competing AMD 29000. In spite ...
processors supported load and store instructions with the source or destination being an "access descriptor" for an object, and an offset into the object, with the access descriptor being in a 32-bit register and with the offset computed from a base offset in the next register and from an additional offset and, optionally, an index register specified in the instruction. An access descriptor contains permission bits and a 26-bit object index; the object index is an index into a table of object descriptors, giving an object type, an object length, and a physical address for the object's data, a page table for the object, or the top-level page table for a two-level page table for the object, depending on the object type.
Prime A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only wa ...
, Stratus,
Apollo Apollo, grc, Ἀπόλλωνος, Apóllōnos, label=genitive , ; , grc-dor, Ἀπέλλων, Apéllōn, ; grc, Ἀπείλων, Apeílōn, label=Arcadocypriot Greek Arcadocypriot, or southern Achaeans (tribe), Achaean, was an ancient ...
,
IBM System/38 The System/38 is a discontinued minicomputer and midrange computer manufactured and sold by IBM. The system was announced in 1978. The System/38 has 48-bit computing, 48-bit addressing, which was unique for the time, and a novel database#Integrat ...
, and
IBM AS/400 The IBM AS/400 (Application System/400) is a family of midrange computers from IBM announced in June 1988 and released in August 1988. It was the successor to the System/36 and System/38 platforms, and ran the OS/400 operating system. Lower-cost b ...
(including
IBM i IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS in 2 ...
) computers use memory segmentation.


Examples


S/370 architecture

In the
IBM System/370 The IBM System/370 (S/370) is a model range of IBM mainframe computers announced on June 30, 1970, as the successors to the IBM System/360, System/360 family. The series mostly maintains backward compatibility with the S/360, allowing an easy ...
models with virtual storage (DAT) and 24-bit addresses,
control register A control register is a processor register which changes or controls the general behavior of a Central processing unit, CPU or other digital device. Common tasks performed by control registers include interrupt control, switching the addressing ...
0 specifies a segment size of either 64 KiB or 1 MiB and a page size of either 2 KiB or 4 KiB; control register 1 contains a Segment Table Designator (STD), which specifies the length and real address of the segment table. Each segment table entry contains a page table location, a page table length and an invalid bit. IBM later expanded the address size to 31 bits and added two bits to the segment table entries: ;Segment-Protection Bit :Segment is read-only ;Common-Segment Bit :The segment is shared between address spaces; this bit is set to optimize TLB use Each of IBM's DAT implementations includes a translation cache, which IBM called a Translation Lookaside Buffer (TLB). While Principles of Operation discusses the TLB in general terms, the details are not part of the architecture and vary from model to model. Starting with the 3031, 3032 and 3033 processor complexes, IBM offered a feature called ''Dual-address Space'' (DAS), which allows a program to switch between the translation tables for two address spaces, referred to as ''primary address space'' (CR1) and ''secondary address space'' (CR7), and to move data between the address spaces subject to protection key. DAS supports a translation table to convert a 16-bit address space number (ASN) to an STD, with privileged instructions to load the STD into CR1 (primary) or CR7 (secondary).


x86 architecture

The memory segmentation used by early x86 processors, beginning with the
Intel 8086 The 8086 (also called iAPX 86) is a 16-bit computing, 16-bit microprocessor chip designed by Intel between early 1976 and June 8, 1978, when it was released. The Intel 8088, released July 1, 1979, is a slightly modified chip with an external 8-bit ...
, does not provide any protection. Any program running on these processors can access any segment with no restrictions. A segment is only identified by its starting location; there is no length checking. The segment starting address granularity is 16 bytes and the offset is 16 bits, supporting segment sizes up to 64 KiB, so segments can (and often do) overlap and each physical address can be denoted by 4096 segment–offset pairs (allowing for address offset wrap-around). Segmentation in the
Intel 80286 The Intel 80286 (also marketed as the iAPX 286 and often called Intel 286) is a 16-bit computing, 16-bit microprocessor that was introduced on February 1, 1982. It was the first 8086-based CPU with separate, non-multiplexed address bus, address ...
and later provides protection: with the introduction of the 80286, Intel retroactively named the sole operating mode of the previous x86 CPU models "
real mode Real mode, also called real address mode, is an operating mode of all x86-compatible Central processing unit, CPUs. The mode gets its name from the fact that addresses in real mode always correspond to real locations in memory. Real mode is char ...
" and introduced a new "
protected mode In computing, protected mode, also called protected virtual address mode, is an operational mode of x86-compatible central processing unit A central processing unit (CPU), also called a central processor, main processor or just Processor (com ...
" with protection features. For backward compatibility, all x86 CPUs start in "real mode" with no memory protection, fixed 64 KiB segments, and only 20-bit (1024 KiB) addressing. An 80286 or later processor must be switched into another mode by software in order to use its full address space and advanced MMU features. The
Intel 80386 The Intel 386, originally released as 80386 and later renamed i386, is a 32-bit microprocessor introduced in 1985. The first versions had 275,000 transistorsx86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging mod ...
architecture does not use segmentation in long mode (64-bit mode). In a x86-64 architecture it is considered legacy and most x86-64-based modern system software don't use memory segmentation. Instead they handle programs and their data by utilizing memory-paging which also serves as a way of memory protection. Though most x86-64 implementations still support it for backward compatibility reasons. Four of the segment registers: CS, SS, DS, and ES are forced to 0, and the limit to 264. The segment registers FS and GS can still have a nonzero base address. This allows operating systems to use these segments for special purposes.


See also

*
Memory management (operating systems) In operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), s ...
*
Virtual address space In computing, a virtual address space (VAS) or address space is the set of ranges of virtual addresses that an operating system makes available to a process. The range of virtual addresses usually starts at a low address and can extend to the hig ...
*
Virtual memory In computing, virtual memory, or virtual storage is a Memory management (operating systems), memory management technique that provides an "idealized abstraction of the storage resources that are actually available on a given machine" which "cr ...
*
Data segment In computing, a data segment (often denoted .data) is a portion of an object file or the corresponding address space of a program that contains initialized static variables, that is, global variables and static local variables. The size of this seg ...
*
BSS Segment In computer programming, the block starting symbol (abbreviated to .bss or bss) is the portion of an object file, executable, or assembly language code that contains static variable, statically allocated variables that are declared but have not bee ...
* x86 memory segmentation *
Segmentation fault In computing, a segmentation fault (often shortened to segfault) or access violation is a Fault (computing), fault, or failure condition, raised by hardware with memory protection, notifying an operating system (OS) the software has attempted to ...
* Flat memory model


Notes


References


External links

*IA-32 Intel Architecture Software Developer’s Manual Volume 3A: System Programming Guide. http://www.intel.com/products/processor/manuals/index.htm. *Operating Systems: Internals and Design Principles by William Stallings. Publisher: Prentice Hall. . . {{application binary interface Memory management