Memory Segmentation in Operating Systems (MSOS)


MSOS:   SOLD       




One of the essential aspects of memory management in operating systems is the separation between the user’s logical view of memory and how the physical memory is actually mapped. This separation allows the system to distinguish between logical memory and physical memory.

Segmentasi Memori

1. Basic Concept of Memory Segmentation

How do users perceive memory mapping? Do they see memory as a linear collection of bytes, some containing instructions and others containing data, or is there a different perspective? Programmers prefer to view memory as a collection of segments of varying sizes, rather than a linear sequence of bytes.

When writing a program, we often think of it as a collection of subroutines, procedures, functions, or variables. There may be structures like tables, arrays, stacks, etc. Each module or data element can be referenced by a name without needing to know its actual memory address. Segments are identified by an offset added to the base address of each segment.

Segmentation is a memory management technique that divides memory into segments. The logical address space consists of these segments, each having a name and length. Users refer to segments using two values: the segment name (or number) and the offset within the segment, differing from paging, where only one address is needed.

Typically, segments are assigned numbers for easy reference, and a logical address space is defined as a tuple (segment-number, offset). Compilers automatically create segments for global variables, stacks for procedures, and portions of code for each function.

2. Hardware Support for Segmentation

Though users use two-dimensional addressing, physical memory is still addressed linearly. Segment tables map the logical addresses into physical addresses. Each entry in the segment table contains a base (starting address) and a limit (size) for the segment.

Gambar 4-10. Alamat Logis

3. Maintenance and Sharing

Grouping segments makes it easier to maintain them. Segments can be labeled as read-only, execute-only, or writable. Hardware ensures protection by checking segment protection bits, preventing illegal memory access. Segments also enable code or data sharing, with each process having its segment table. Two different processes can share segments by pointing to the same physical location.

4. Fragmentation Issues

Segmentation can lead to external fragmentation since segments vary in size. The system must allocate contiguous memory blocks, and if space is insufficient, processes might have to wait or memory may need to be compacted.

Virtual Memory Overview

Virtual memory separates logical memory from physical memory, allowing a program to execute without having all its parts in physical memory simultaneously. It supports large programs exceeding the available physical memory.

1. Definition and Benefits

Virtual memory improves:

  • Reduced I/O operations.
  • More efficient memory usage.
  • Increased system responsiveness.
  • Ability to serve more users simultaneously.

2. Implementation

Virtual memory uses demand paging or demand segmentation. Parts of a process are swapped in and out of memory as needed, allowing efficient multiprogramming.

3. Page Tables and Multilevel Paging

Large logical address spaces require multilevel page tables to manage memory efficiently. For example, a system with a 32-bit address space may use multilevel tables to break the mapping into manageable pieces, reducing the memory required for page tables.


Gambar 4-5. Alamat logis

Gambar 4-7. Penterjemahan alamat untuk arsitektur pemberian halaman dua tingkat 32-bit logis

4. Inverted Page Tables

An inverted page table contains one entry per physical page frame rather than per logical page, optimizing memory usage.

Gambar 4-8. Tabel halaman yang dibalik

5. Page Sharing

Programs can share code to save memory. For example, multiple instances of a text editor can share the same code but maintain separate data pages.

Gambar 4-9. Berbagi kode pada lingkungan berhalaman

Memory Addressing with Segment Offset (8086/80286 Example)

Processors like the 8086 use 16-bit addressing but can access 1MB of memory using a 20-bit segmented addressing system. Each segment is 64KB, and offsets within segments allow for overlapping memory access.

Conversion from Segment:Offset to Physical Address

The segment address is shifted left by 4 bits and added to the offset to form the 20-bit physical address. For example, to convert 1357h:2468h:

  1. Multiply the segment 1357h by 10h (hexadecimal shift).
  2. Add the offset 2468h. This method efficiently converts logical addresses to absolute physical addresses.

This is a brief translation and summary of the original article. Let me know if you need more details on any section!


Post a Comment

Previous Next

نموذج الاتصال