Home

Segmentation

Segmentation

 

 

Segmentation

Definition:

Segmentation is a memory management scheme that supports the user view of memory. A logical address space is a collection of segments. The logical address consists of segment number and offset. If the offset is legal, it is added to the segment base to produce the address in physical memory of the desired byte.

 

3.5.1 Basic Method

  • A program is a collection of segments. A segment is a logical unit such as: Main program, Procedure, Function, Method, Object, Local variables, global variables, Common block, Stack, Symbol table, arrays.

 

Segmentation is a memory-management scheme that supports this user view of memory. A logical-address space is a collection of segments. Each segment has a name and a length. The addresses specify both the segment name and the offset within the segment. The user therefore specifies each address by two quantities: a segment name and an offset. (Contrast this scheme with the paging scheme, in which the user specified only a single address, which was partitioned by the hardware into a page number and an offset, all invisible to the programmer.)

 

 

User’s View of a Program

 

For simplicity of implementation, segments are numbered and are referred

to by a segment number, rather than by a segment name. Thus, a logical address consists of a two tuple:

<segment-number ,offset>

 

 

Logical View of Segmentation

 

Normally, the user program is compiled, and the compiler automatically constructs segments reflecting the input program. A Pascal compiler might create separate segments for the following:

  • the global variables;
  • the procedure call stack, to store parameters and return addresses;
  • the code portion of each procedure or function;
  • the local variables of each procedure and function.

 

A Fortran compiler might create a separate segment for each common block. Arrays might be assigned separate segments. The loader would take all these segments and assign them segment numbers.

 

3.5.2 Segmentation Hardware

A segmented address space can be implemented by using address mapping hardware. Segment table is used for mapping the two dimensional user defined address into one dimensional physical address.

  • Segment table maps two-dimensional physical addresses; each table entry has:

 

    • Base contains the starting physical address where the segments reside in memory
    • Limit specifies the length of the segment


 

Segmentation hardware.

The use of a segment table is illustrated in Figure. A logical address consists of two parts: a segment number, s, and an offset into that segment, d. The segment number is used as an index into the segment table. The offset d of the logical address must be between 0 and the segment limit. If it is not, we trap to the operating system (logical addressing attempt beyond end of segment). If this offset is legal, it is added to the segment base to produce the address in physical memory of the desired byte. The segment table is thus essentially an array of base-limit register pairs.

  • Segment-table base register (STBR) points to the segment table‘s locationin memory

 

  • Segment-table length register (STLR) indicates number of segments usedby a program;

Segment number‗s‘ is legal, if s < STLR

Example of segmentation:


consider the situation shown in above figure. We have five segments numbered from 0 through 4. The segments are stored in physical memory as shown. The segment table has a separate entry for each segment, giving the beginning address of the segment in physical memory (or base) and the length of that segment (or limit). For example, segment 2 is 400 bytes long and begins at location 4300. Thus, a reference to byte 53 of segment 2 is mapped onto location 4300 + 53 = 4353. A reference to segment 3, byte 852, is mapped to 3200 (the base of segment 3) + 852 = 4052. A reference to byte 1222 of segment 0 would result in a trap to the operating system, as this segment is only 1,000 bytes long.

3.5.3 Protection and Sharing
Protection:

The advantage of segmentation is the association of protection with the segments. In a modern architecture, instructions are non-self-modifying, so instruction segments can be defined as read only or execute only. The memory mapping hardware will check the protection bits associated with each segment table entry to prevent illegal accesses to memory, such as attempts to write into a read-only segment, or to use an execute-only segment as data. By placing an array in its own segment, the memory-management hardware will automatically check that array indexes are legal and do not stray outside the array boundaries.

With each entry in segment table associate:
ü validation bit = 0                    illegal segment
ü validation bit = 1                      legal segment
ü read/write/execute privileges
Sharing:

o Another advantage of segmentation involves the sharing of code or data.

o Each process has a segment table associated with it, which the dispatcher uses to define the hardware segment table when this process is given the CPU.

o Segments are shared when entries in the segment tables of two different processes point to the same physical location.

For example, consider the use of a text editor in a time-sharing system. A complete editor might be quite large, composed of many segments. These segments can be shared among all users, limiting the physical memory needed to support editing tasks. Rather than n copies of the editor, we need only one copy.

 

Sharing of Segments

 

3.5.4 Fragmentation

The long-term scheduler must find and allocate memory for all the segments of a user program. This situation is similar to paging except that the segments are

of variable length; pages are all the same size. Thus, as with the variable-sized partition scheme, memory allocation is a dynamic storage-allocation problem, usually solved with a best-fit or first-fit algorithm.

Segmentation may then cause external fragmentation, when all blocks of free memory are too small to accommodate a segment. In this case, the process may simply have to wait until more memory (or at least a larger hole) becomes available, or until compaction creates a larger hole.

Source: https://www.snscourseware.org/snsct/files/CW_588c73a228aa9/SEGMENTATION.doc

Web site to visit: https://www.snscourseware.org

Author of the text: indicated on the source document of the above text

If you are the author of the text above and you not agree to share your knowledge for teaching, research, scholarship (for fair use as indicated in the United States copyrigh low) please send us an e-mail and we will remove your text quickly. Fair use is a limitation and exception to the exclusive right granted by copyright law to the author of a creative work. In United States copyright law, fair use is a doctrine that permits limited use of copyrighted material without acquiring permission from the rights holders. Examples of fair use include commentary, search engines, criticism, news reporting, research, teaching, library archiving and scholarship. It provides for the legal, unlicensed citation or incorporation of copyrighted material in another author's work under a four-factor balancing test. (source: http://en.wikipedia.org/wiki/Fair_use)

The information of medicine and health contained in the site are of a general nature and purpose which is purely informative and for this reason may not replace in any case, the council of a doctor or a qualified entity legally to the profession.

 

Segmentation

 

The texts are the property of their respective authors and we thank them for giving us the opportunity to share for free to students, teachers and users of the Web their texts will used only for illustrative educational and scientific purposes only.

All the information in our site are given for nonprofit educational purposes

 

Segmentation

 

 

Topics and Home
Contacts
Term of use, cookies e privacy

 

Segmentation