Memory Management Two - Operating Systems - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Operating Systems which includes File-System Structure, Defining, Logical File, Physical Device, Secondary, System Organized, File Control Block, Structure Consisting, Typical File Control Block etc.Key important points are: Memory Management Two, Storage-Device Hierarchy, Storage Size, Access Speed, Various Levels of Storage, Background, Many Cycles, Array of Addresses, Addressing, Requirements

Typology: Slides

2012/2013

Uploaded on 03/28/2013

ekana
ekana 🇮🇳

4

(44)

370 documents

1 / 35

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
8: Memory Management 1
OPERATING SYSTEMS
MEMORY MANAGEMENT
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23

Partial preview of the text

Download Memory Management Two - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

8: Memory Management 1

OPERATING SYSTEMS

MEMORY MANAGEMENT

8: Memory Management 2

What Is In This Chapter?

Just as processes share the CPU, they also share

physical memory. This chapter is about

mechanisms for doing that sharing.

OPERATING SYSTEM

Memory Management

8: Memory Management 4

MEMORY MANAGEMENT

  • The concept of a logical address space that is bound to a separate physical address space is central to proper memory management. - Logical address – generated by the CPU; also referred to as virtual address - Physical address – address seen by the memory unit
  • Logical and physical addresses are the same in compile-time and load- time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme Definitions

8: Memory Management 5

MEMORY MANAGEMENT

Relocatable Means that the program image can reside anywhere in physical memory.

Binding Programs need real memory in which to reside. When is the location of that

real memory determined?

  • This is called mapping logical to physical addresses.
  • This binding can be done at compile/link time. Converts symbolic to

relocatable. Data used within compiled source is offset within object

module.

Compiler : If it’s known where the program will reside, then absolute code is generated.

Otherwise compiler produces relocatable code.

Load : Binds relocatable to physical. Can find best physical location.

Execution : The code can be moved around during execution. Means flexible virtual

mapping.

Definitions

8: Memory Management 7

4 void main() 5 { 6 printf( "Hello, from main\n" ); 7 b(); 8 } 9 10 11 void b() 12 { 13 printf( "Hello, from 'b'\n" ); 14 } MEMORY MANAGEMENT Binding Logical To Physical

8: Memory Management 8

ASSEMBLY LANGUAGE LISTING 000000B0: 6BC23FD9 stw %r2,-20(%sp ; main() 000000B4 37DE0080 ldo 64(%sp),%sp 000000B8 E8200000 bl 0x000000C0,%r1 ; get current addr=BC 000000BC D4201C1E depi 0,31,2,%r 000000C0 34213E81 ldo -192(%r1),%r1 ; get code start area 000000C4 E8400028 bl 0x000000E0,%r2 ; call printf 000000C8 B43A0040 addi 32,%r1,%r26 ; calc. String loc. 000000CC E8400040 bl 0x000000F4,%r2 ; call b 000000D0 6BC23FD9 stw %r2,-20(%sp) ; store return addr 000000D4 4BC23F59 ldw -84(%sp),%r 000000D8 E840C000 bv %r0(%r2) ; return from main 000000DC 37DE3F81 ldo -64(%sp),%sp STUB(S) FROM LINE 6 000000E0: E8200000 bl 0x000000E8,%r 000000E4 28200000 addil L%0,%r 000000E8: E020E002 be,n 0x00000000(%sr7,%r1) 000000EC 08000240 nop void b() 000000F0: 6BC23FD9 stw %r2,-20(%sp) 000000F4: 37DE0080 ldo 64(%sp),%sp 000000F8 E8200000 bl 0x00000100,%r1 ; get current addr=F 000000FC D4201C1E depi 0,31,2,%r 00000100 34213E01 ldo -256(%r1),%r1 ; get code start area 00000104 E85F1FAD bl 0x000000E0,%r2 ; call printf 00000108 B43A0010 addi 8,%r1,%r 0000010C 4BC23F59 ldw -84(%sp),%r 00000110 E840C000 bv %r0(%r2) ; return from b 00000114 37DE3F81 ldo -64(%sp),%sp MEMORY MANAGEMENT Binding Logical To Physical

8: Memory Management 10

EXECUTABLE IS DISASSEMBLED HERE

000020F0 6BC23FD9 stw %r2,-20(%sp) ; b 000020F4 37DE0080 ldo 64(%sp),%sp 000020F8 E8200000 bl 0x00002100,%r 000020FC D4201C1E depi 0,31,2,%r 00002100 34213E01 ldo -256(%r1),%r 00002104 E840172C bl 0x00003CA0,%r 00002108 B43A0010 addi 8,%r1,%r 0000210C 4BC23F59 ldw -84(%sp),%r 00002110 E840C000 bv %r0(%r2) 00002114 37DE3F81 ldo -64(%sp),%sp 00003CA0 6BC23FD9 stw %r2,-20(%sp) ; printf 00003CA4 37DE0080 ldo 64(%sp),%sp 00003CA8 6BDA3F39 stw %r26,-100(%sp) 00003CAC 2B7CFFFF addil L%-26624,%dp 00003CB0 6BD93F31 stw %r25,-104(%sp) 00003CB4 343301A8 ldo 212(%r1),%r 00003CB8 6BD83F29 stw %r24,-108(%sp) 00003CBC 37D93F39 ldo -100(%sp),%r 00003CC0 6BD73F21 stw %r23,-112(%sp) 00003CC4 4A730009 ldw -8188(%r19),%r 00003CC8 B67700D0 addi 104,%r19,%r 00003CCC E8400878 bl 0x00004110,%r 00003CD0 08000258 copy %r0,%r 00003CD4 4BC23F59 ldw -84(%sp),%r 00003CD8 E840C000 bv %r0(%r2) 00003CDC 37DE3F81 ldo -64(%sp),%sp 00003CE0 E8200000 bl 0x00003CE8,%r 00003CE8 E020E852 be,n 0x00000428(%sr7,%r1) MEMORY MANAGEMENT Binding Logical To Physical

8: Memory Management 11

Dynamic loading

+ Routine is not loaded until it is called

+ Better memory-space utilization; unused routine is never loaded.

+ Useful when large amounts of code are needed to handle infrequently occurring cases.

+ No special support from the OS is required - implemented through program design.

Dynamic Linking

+ Linking postponed until execution time.

+ Small piece of code, stub , used to locate the appropriate memory-resident library routine.

+ Stub replaces itself with the address of the routine, and executes the routine.

+ Operating system needed to check if routine is in processes’ memory address.

+ Dynamic linking is particularly useful for libraries.

Memory Management Performs the above operations. Usually requires hardware

support.

MEMORY MANAGEMENT More Definitions

8: Memory Management 13

MEMORY MANAGEMENT

RESIDENT MONITOR:

 Primitive Operating System.

 Usually in low memory where interrupt vectors are placed.

 Must check each memory reference against fence ( fixed or variable ) in hardware or

register. If user generated address < fence, then illegal.

 User program starts at fence -> fixed for duration of execution. Then user code has

fence address built in. But only works for static-sized monitor.

 If monitor can change in size, start user at high end and move back, OR use fence as

base register that requires address binding at execution time. Add base register to

every generated user address.

 Isolate user from physical address space using logical address space.

 Concept of "mapping addresses” shown on next slide.

SINGLE PARTITION ALLOCATION

8: Memory Management 14

MEMORY MANAGEMENT SINGLE PARTITION ALLOCATION

CPU

MEMORY

Limit

Register

Relocation

Register

<^ +

No

Logical

Address

Yes

Physical

Address

8: Memory Management 16

DYNAMIC STORAGE  (Variable sized holes in memory allocated on need.)  Operating System keeps table of this memory - space allocated based on table.  Adjacent freed space merged to get largest holes - buddy system. ALLOCATION PRODUCES HOLES OS process 1 process 2 process 3

OS

process 1 process 3

Process 2

Terminates

OS

process 1 process 3

Process 4

Starts

process 4 CONTIGUOUS ALLOCATION MEMORY MANAGEMENT

8: Memory Management 17

HOW DO YOU ALLOCATE MEMORY TO NEW PROCESSES? First fit - allocate the first hole that's big enough. Best fit - allocate smallest hole that's big enough. Worst fit - allocate largest hole. (First fit is fastest, worst fit has lowest memory utilization.)  Avoid small holes ( external fragmentation ). This occurs when there are many small pieces of free memory.  What should be the minimum size allocated, allocated in what chunk size?  Want to also avoid internal fragmentation. This is when memory is handed out in some fixed way (power of 2 for instance) and requesting program doesn't use it all. CONTIGUOUS ALLOCATION MEMORY MANAGEMENT

8: Memory Management 19

Trying to move free memory to one large block. Only possible if programs linked with dynamic relocation (base and limit.) There are many ways to move programs in memory. Swapping: if using static relocation, code/data must return to same place. But if dynamic, can reenter at more advantageous memory. COMPACTION

OS

P

P

P

OS

P

P

P

OS

P

P

P

MEMORY MANAGEMENT

8: Memory Management 20

  • Logical address space of a process can be noncontiguous; process is allocated physical memory whenever that memory is available and the program needs it.
  • Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8192 bytes).
  • Divide logical memory into blocks of same size called pages.
  • Keep track of all free frames.
  • To run a program of size n pages, need to find n free frames and load program.
  • Set up a page table to translate logical to physical addresses.
  • Internal fragmentation. PAGING MEMORY MANAGEMENT New Concept!!