Implementing Address Spaces: Base + Limit Registers

Slide Note
Embed
Share

Address spaces, base + limit registers, and contiguous allocation are essential concepts in operating systems. Real mode memory addresses lack isolation between processes and pose limitations on multitasking. Virtual memory introduces virtual address spaces, requiring translation to physical addresses by the Memory Management Unit. Implementing address spaces using base + limit registers enable process isolation and ease of relocation. Each process gets its independent virtual address space, enhancing security and facilitating memory management.


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.



Uploaded on May 13, 2024 | 2 Views


Presentation Transcript


  1. Address Spaces, Base + Limit Registers, and Contiguous Allocation David Ferry CSCI 3500 Operating Systems Saint Louis University St. Louis, MO 63103 1

  2. Recall: Real Mode Memory Addresses seen at the processor are the physical addresses in hardware: No isolation between processes No isolation between OS and userspace Limited multi-tasking (swapping and partitioning) Relocation is difficult OS Program 3 OS OS Program 2 Save Load Program 1 Load Program 2 Program 1 Program 2 Program 1 Program 1 CSCI 3500 - Operating Systems 2

  3. Virtual Memory: Virtual Address Spaces Virtual Address Space Physical Memory (RAM) 0xFFFF .stack Programs see and use virtual memory addresses at the CPU Addresses must be translated between virtual and physical by hardware called the Memory Management Unit (MMU) Translation must be fast- doing everything in software would be too slow- need HW acceleration 0xFFFF Operating System .heap .data Kernel Space User Space .text 0x0 Program Virtual Address Space Program .stack 0xFFFF Library .heap .data Program 0x0 0x0 .text

  4. Implementing Address Spaces with Base + Limit Registers Two special CPU registers keep track of each process start (base) and size (limit) Registers are only modifiable by the OS Data becomes part of process context and is swapped in context switches All memory accesses are checked against base and limit Out-of-range accesses are errors (e.g. segfault) 0xFFFF Operating System Program Limit = 0x2000 Program Base = 0x1000 Program 0x0 CSCI 3500 - Operating Systems 4

  5. Base + Limit Advantages (over Real Mode) Each process has an independent virtual address space Implements process isolation Programs cannot maliciously or accidentally interfere with each other or the OS Relocation is now easy Add the base register to every address leaving the CPU No need to modify programs when loaded Put many programs in memory 0xFFFF Operating System Limit Program Base Limit Program Base Limit Program Base CSCI 3500 - Operating Systems 5

  6. Base + Limit Relocation Example Virtual Address Space Operating System 0xFFFF .stack .heap .data Program Physical Address: Virtual Address: 0x2123 0x0123 ADD .text Program 0x0 Library Program Base Register: 0x2000 CSCI 3500 - Operating Systems 6

  7. Base + Limit Isolation Example Suppose Base = 0x2000 and Limit = 0x3000 Physical Address: Virtual Address: 0x1E00 -0x0200 < ERROR ADD Base Register: Base Register: 0x2000 0x2000 CSCI 3500 - Operating Systems 7

  8. Base + Limit Isolation Example Suppose Base = 0x2000 and Limit = 0x3000 Physical Address: Physical Address: 0x3500 0x3500 Virtual Address: 0x1500 > < ERROR ADD Base Register: Base Register: Limit Register: 0x2000 0x2000 0x3000 CSCI 3500 - Operating Systems 8

  9. Where do we allocate programs? We now have a mechanism for loading many programs dynamically In real mode we usually only had one program, or at most a few programs that were carefully managed by hand We don t want the user to have to manually manage where to put programs in memory Can the machine allocate memory space for us? One fundamental limitation: Programs must be contiguous CSCI 3500 - Operating Systems 9

  10. Contiguous Allocation: Fragmentation Base + Limit scheme requires programs to be contiguous (continuous, with no gaps) in memory 0x4000 At the end of the sequence we have 0x2000 bytes free but only 0x1000 bytes of contiguous memory Operating System Operating System Operating System Operating System 0x3000 Program B 0x500 Program B 0x500 Program B 0x500 The memory space is fragmented Program A 0x1500 Program A 0x1500 Compaction could move programs around, but this is slow and causes interference Program C 0x500 0x0

  11. Placement Algorithms No single best approach to placing programs in memory: Minimize fragmentation? Keep big chunks available? Optimize for speed? We can view memory placement as a type of bin packing algorithm with heuristics corresponding to the above concerns: Best Fit Worst Fit First Fit CSCI 3500 - Operating Systems 11

Related


More Related Content