Memory Management(2)

Memory Management(2)

Relocation and Protection
  • Principles
    • Relocation: when a program is run, it does not know in advance which partition/addresses it will occupy
      • Cannot simply generate static addresses that are absolute
      • Addresses should be relative to where the program has been loaded
      • Relocation must be solved in an operating system that allows processes to run at changing memory locations
    • Protection: once you can have two programs in memory at the same time, protection must be enforced
  • Address Types
    • A logical address is a memory address seen by the process
      • It is independent of the current physical memory assignment
    • A physical address refers to an actual location in main memory
    • The logical address space must be mapped onto the machine’s physical address space
  • Approaches
    1. Static “relocation” at compile time: a process has to be located at the same location every single time(impractical)
    2. Dynamic relocation at load time
      • An offset is added to every logical address to account for its physical location in memory
      • Slows down the loading of a process, does not account for swapping
    3. Dynamic relocation at runtime
      • Base and limit registers (requires hardware support)(L14 - p10)
        • Two special purpose registers in CPU(the MMU)
          • base register stores the start address of the partition
          • the limit register holds the size of the partition
        • At runtime
          • base register is added to logical address to generate the physical address
          • the resulting address is compared against the limit register
      • Dynamic partitioning
        • A variable number of partitions of which the size and starting address can change over time
        • A process is allocated the exact amount of contagious memory it requires, thereby preventing internal fragmentation

        • Swapping
          • holds some of the processes on the drive and shuttles processes between the drive and main memory as necessary 
          • Reasons for swapping:
            • some processes only run occasionally 
            • we have more processes than partition
            • a process’s memory requirements have changed
            • total amount of memory that is required for the processes exceeds the available memory
          • Difficulties
            • The exact memory requirements may not be known in advance(heap and stack grow dynamically)
            • External fragmentations
              • Swapping a process out of memory will create “a hole”
              • A new process may not use the entire “hole”, leaving a small unused block
              • A new process may be too large for a given a “hole”

              • The overhead of memory compaction to recover holes can be prohibitive and requires dynamic relocation
          • Question: How to keep track of available memory
            • Linked lists
              • consists of a number of entries, each one of them contains data items(start of memory block, size, free/allocated flag)
              • Each link contains a pointer to the next in the chain

            • Bitmaps
              • Memory is split into blocks of say 4K size
                • A bitmap is set up so that each bit
                  • is 0 -> free
                  • is 1 -> the block is used
              • Trade-off exists between size of the bitmap and the size of blocks exists
                • The size of bitmaps can become prohibitive for small blocks and may make searching the bitmap slower
                • Larger blocks may increase internal fragmentation
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值