Memory Management

  • Aim Of Chapter:

    • This chapter provides you with overview of the fundamental mechanisms used in Memory Management (MM) in any operating system
  • Memory management: the task of dividing the computer memory in order to accommodate processes
  • Any MM System Should Provide:

    • Relocation:

      • Ability to allocate memory for swapped processes when they came back into memory
    • Protection:

      • Ability to protect process memory from interference by other processes. Programs in other processes shouldn’t be able to reference memory locations in a process without permissions
      • The memory protection requirement must be satisfied by the processor rather than OS
    • Sharing:

      • Ability to allow several processes to access to access same portion of main memory
    • Logical Organization:

      • Ability to deal with programs as modules
      • Advantages of this feature:

        • Modules can be written and compiled independently
        • Few data overhead will be added to specify the module degree of protection
        • Sharing modules is more easier to the user because it’s his way to view the problem
      • Segmentation is the most readily MM mechanism that satisfies these conditions
    • Physical Organization:

      • Ability to organize flow of information between main memory and secondary memory
      • If this task is assigned to the programmer many disadvantages appear as:

        • The main memory available for a program plus it’s data may be insufficient

          • So the programmer will solve this problem using overlaying in which the program data should be organized in a way that all modules could share them
        • In multiprogramming environments, programmer doesn’t know amount of free space
  • Before reading the coming info read the table at the next page first
  • Fixed Partitioning:

    • Disadvantages:

      • If a program size doesn’t fit with the partition size, programmer should design the program with use of overlays so that only one portion of the program need to be in memory
      • The number of fixed partitions specify the number of active processes (not suspended)
    • These disadvantages are lessened by dynamic partitioning
    • This technique is not used nowadays and one of the successful OS that did use it was early IBM mainframe OS OS/MFT (Multiprogramming with a Fixed number of Tracks)
  • Dynamic Partitioning:

    • OS that was using this technique IBM’s mainframe OS, OS/MVT (Multithreading Variable # of Tracks)
    • Problem of external fragmentation is solved using compaction: from time to time OS shift processes so they are contiguous and free the unused memory in one block (this is time consuming and wasteful of processor time) also the MM should supply reallocation because all the processes will be shifted
    • Placement algorithms: First Fit, Best Fit and Next Fit

      • Next Fit: begins to scan memory from the location of the last placement and choose next suitable block
  • When using First-Fit compaction is needed frequently because at the end of the memory space is quickly broken up into small fragments
  • Memory Management Techniques:

  • Buddy Systems:

    • Here, the memory blocks are available of size words, , where:

      • smallest size block that is allocated
      • largest size block that is allocated; generally is the size of entire available memory
    • A modified form of buddy systems is used for UNIX kernel memory allocation
  • Logical address: reference to memory location independent of the current assignment of data to memory
  • Relative address: reference to memory location relative to known point usually a value in processor register
  • Physical address (absolute address): actual location in main memory
  • Working mechanism is displayed in the below figure:

  • One of advantage of the relative addressing is that each process image is isolated by the contents of base and bounds registers and safe from unwanted access by other processes
  • Simple Paging:

    • Before read this section please read the row of the simple paging in the previous table
    • OS holds the free frames in a list
    • Page Table is a table for each process that shows the frame location for each of the process pages
    • Within a program each logical address consists of a page number and offset within this page
    • The processor uses the page number/offset to produces frame/offset
    • Page size (hence frame size) is recommended to be a power of 2
    • Hardware Calculations for accessing memory using logical address n/m:

      • Extract page # as left most n bits of the logical address
      • Use page number as an index into the process page table to find it’s frame # k
      • The starting physical address of the frame is . The physical address of referenced byte is that number plus the offset
  • Simple Segmentation:

    • Before read this section please read the row of the simple segmentation in the previous table
    • Process segments could vary is length. Also there’s a max. segment length
    • Here the logical address consists of segment number and offset
    • Here the programmer should divide the program into segments and should take care of max. length
    • Address translation in segmentation:

      • Extract segment # as the left most n bits of the logical address
      • Use segment # as an index in the process segment table to find segment physical address
      • Compare offset (right most m bits) with the length of the segment
      • The desired physical address is the sum of the starting physical address of segment + offset
  • Buffer Overflow:

  • Buffer overflow occurs when a processes attempts to store data beyond the limits of a fixed-size buffer and consequently overwrites adjacent memory location. These locations could hold other program variables or data
  • The buffer could be located into: stack, heap or in the data section of the process
  • Stack overflow is a type of buffer overflow attacks
  • Further reading (Fuzzy): How could attacker break a password and get into the system (page 334)
  • Countermeasures:

  • Compile-time defines, which aim to harden programs to resist attacks in new programs
  • Run-time defines, which aims to detect and abort attacks in existing programs

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s