Docsity

Operating Systems CS 414: Sharing Main Memory -- Segmentation - Prof. Sang Son, Study notes of Operating Systems

Toggle sidebar
bg1
CS 414 : Operating Systems
UNIVERSITY OF VIRGINIA
Department of Computer Science
Spring 2008
Topic 12: Sharing Main Memory -- Segmentation
g
Goal: let several processes co-exist in memory.
g
Issues:
g
Transparency: No process should need to be aware of the fact that memory is shared.
Each must run regardless of the number and/or locations of processes.
g
Protection: processes must not be able to corrupt each other.
g
Efficiency (both of CPU and memory) shouldn’t be degraded badly by sharing. After
all, what is the purpose of sharing?
g
Simple uniprogramming with a single segment per process:
g
Highest memory holds OS.
g
Process is allocated memory starting at 0, up to the OS area.
g
When loading a process, just bring it in at 0.
g
Relocation.
g
Because several processes share memory, we can’t predict in advance where a process
will be loaded in memory. This is similar to a compiler’s inability to predict where a
subroutine will be after linking.
g
Relocation adjusts a program to run in a different area of memory. Linker is an example
of static relocation used to combine modules into programs.
g
Static relocation
g
Highest memory holds OS.
g
Processes allocated memory starting at 0, up to the OS area.
— 12.1 —
pf3
pf4

Partial preview of the text

Download Operating Systems CS 414: Sharing Main Memory -- Segmentation - Prof. Sang Son and more Study notes Operating Systems in PDF only on Docsity!

CS 414 : Operating Systems

UNIVERSITY OF VIRGINIA

Department of Computer Science

Spring 2008

Topic 12: Sharing Main Memory -- Segmentation

g Goal: let several processes co-exist in memory. g Issues: g Transparency: No process should need to be aware of the fact that memory is shared. Each must run regardless of the number and/or locations of processes. g Protection: processes must not be able to corrupt each other. g Efficiency (both of CPU and memory) shouldn’t be degraded badly by sharing. After all, what is the purpose of sharing?

g Simple uniprogramming with a single segment per process: g Highest memory holds OS. g Process is allocated memory starting at 0, up to the OS area. g When loading a process, just bring it in at 0.

g Relocation. g Because several processes share memory, we can’t predict in advance where a process will be loaded in memory. This is similar to a compiler’s inability to predict where a subroutine will be after linking. g Relocation adjusts a program to run in a different area of memory. Linker is an example of static relocation used to combine modules into programs.

g Static relocation g Highest memory holds OS. g Processes allocated memory starting at 0, up to the OS area.

g When a process is loaded, relocate it so that it can run in its allocated memory area g Problem: not much protection; hard to relocate later, once it starts running.

g Dynamic relocation: instead of changing the addresses of a program before it’s loaded, change the address dynamically during every reference. g Under dynamic relocation, each program-generated address (called a logical or virtual address) is translated in hardware to a physical or real address. This happens as part of each memory reference. g Dynamic relocation leads to two views of memory, called address spaces. g A good case of a problem solved by indirection. What is the name of the game? Flexi- bility -- to move things around freely.

g Base & limit relocation: g Two hardware registers: base address for process, limit register that indicates the last valid address the process may generate. g Each process must be allocated contiguously in real memory. g On each memory reference, the virtual address is compared to the limit register, then ad- ded to the base register. A limit violation results in an error trap. g Each process appears to have a completely private memory of size equal to the limit re- gister plus 1. Processes are protected from each other. No address relocation is neces- sary when a process is loaded. g OS runs with relocation turned off (a bit in the processor status word controls reloca- tion). It is called unmapped. Why is it necessary? g OS must prevent users from turning off relocation or modifying the base and limit regis- ters g Problem: how do you get kernel bit on when you jump? g Base & limit is cheap -- only 2 registers -- and fast -- the add and compare can be done in parallel.

g Problem with base & limit relocation: g Only one segment. How can two processes share code while keeping private data areas (e.g. shared editor)?

g Where is 242 in physical memory? g Suppose the PC was 242 and SP was 7650. What will they contain after the execution of PUSH #3106? g What will be in physical address 3650? g What will be lowest address that will incur address violation? g Which portions of the virtual and physical address spaces are used by this process?

g Managing segments: g Keep copy of segment table in process control block. g When creating process, allocate space for segment, fill in PCB bases and limits. g When switching contexts, save segment table in old process’s PCB, reload it from new process’s PCB. g When process dies, return segments to free pool. g When there’s no space to allocate a new segment: g Compact memory (move all segments, update bases) to get all free space together. g Or, swap one or more segments to disks to make space (must bring segments back in before letting process run). g To enlarge segment: g See if space above segment is free. If so, update limit and use that space. g Or, move the segment above this one to disk, in order to make the memory free. g Or, move this segment to disk and bring it back into a larger hole (or, maybe just copy it to a larger hole).

g Advantage of segmentation? g Problem: g External fragmentation: segments of many different sizes, have to be allocated contigu- ously. This problem also applies to base and limit schemes. g Solution?