Page 134 - DCAP403_Operating System
P. 134

Unit 7: Memory Management




          In a virtual memory system, it is common to map between virtual addresses and physical   Notes
          addresses by means of a data structure called 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 those unique to the accessing
          process. Physical addresses are those unique to the CPU, i.e., RAM.

          The page number of an address is usually found from the most significant bits of the address; the
          remaining bits yield the offset of the location within the page. The page table is normally indexed
          by page number and contains information on whether the page is currently in main memory, and
          where it is in main memory or on disk.
          Conventional page tables are sized to the virtual address space and store the entire virtual address
          space description of each process. Because of the need to keep the virtual-to-physical translation

          time low, a conventional page table is structured as a fixed, multi-level hierarchy, and can be very
          inefficient at representing a sparse virtual address space, unless the allocated pages are carefully

          aligned to the page table hierarchy.
          7.6 Segmentation

          It is very common for the size of program modules to change dynamically. For instance, the
          programmer may have no knowledge of the size of a growing data structure. If a single address
          space is used, as in the paging form of virtual memory, once the memory is allocated for modules
          they cannot vary in size. This restriction results in either wastage or shortage of memory. To
          avoid the above problem, some computer systems are provided with many independent address
          spaces. Each of these address spaces is called a segment. The address of each segment begins with
          0 and segments may be compiled separately. In addition, segments may be protected individually
          or shared between processes. However, segmentation is not transparent to the programmer like
          paging. The programmer is involved in establishing and maintaining the segments.
          Segmentation is one of the most common ways to achieve memory protection like paging. An
          instruction operand that refers to a memory location includes a value that identifi es a segment
          and an offset within that segment. A segment has a set of permissions, and a length, associated
          with it. If the currently running process is allowed by the permissions to make the type of
          reference to memory that it is attempting to make, and the offset within the segment is within the
          range specifi ed by the length of the segment, the reference is permitted; otherwise, a hardware
          exception is delivered.
          In addition to the set of permissions and length, a segment also has associated with it information
          indicating where the segment is located in memory. It may also have a flag indicating whether

          the segment is present in main memory or not; if the segment is not present in main memory,
          an exception is delivered, and the operating system will read the segment into memory from
          secondary storage. The information indicating where the segment is located in memory might
          be the address of the first location in the segment, or might be the address of a page table for the


          segment. In the first case, if a reference to a location within a segment is made, the offset within
          the segment will be added to address of the fi rst location in the segment to give the address in
          memory of the referred-to item; in the second case, the offset of the segment is translated to a
          memory address using the page table.
          A memory management unit (MMU) is responsible for translating a segment and offset within
          that segment into a memory address, and for performing checks to make sure the translation can
          be done and that the reference to that segment and offset is permitted.











                                           LOVELY PROFESSIONAL UNIVERSITY                                   127
   129   130   131   132   133   134   135   136   137   138   139