Memory: Hardware and Allocation Summer 2011 Cornell University 1 - - PowerPoint PPT Presentation

memory hardware and allocation
SMART_READER_LITE
LIVE PREVIEW

Memory: Hardware and Allocation Summer 2011 Cornell University 1 - - PowerPoint PPT Presentation

CS 4410 Operating Systems Memory: Hardware and Allocation Summer 2011 Cornell University 1 Today How the memory is shared among the ready processes? Memory Address protection Logical vs Physical Address Contiguous memory


slide-1
SLIDE 1

1

CS 4410 Operating Systems

Memory: Hardware and Allocation

Summer 2011 Cornell University

slide-2
SLIDE 2

2

Today

  • How the memory is shared among the ready

processes?

  • Memory
  • Address protection
  • Logical vs Physical Address
  • Contiguous memory allocation
slide-3
SLIDE 3

3

Storage Hierarchy

Registers Cache (L1, L2, L3) Memory Hard Disk

slide-4
SLIDE 4

4

Memory

  • A large array of words.
  • Word = 4 or 8 bytes.
  • One address for every

word.

  • Content:
  • Instructions
  • Data
slide-5
SLIDE 5

5

Instruction execution cycle

  • Fetch instruction from memory.
  • The PC saves its address.
  • Decode instruction.
  • Fetch operants form memory.
  • Execute the instruction.
  • Store result in memory.
  • Program and data should be in Memory to

become useful.

slide-6
SLIDE 6

6

Memory Management

  • Is memory shared between processes? How?
  • Monoprogramming
  • Only one process is ready and loaded into memory.
  • It shares the memory space with the OS.
  • Is it efficient?
  • Multiprogramming
  • Fixed or variable partitions for every ready process.
  • 2 problems: relocation, protection. Solutions?
  • Timesharing
  • Swapping

Entire process (code, data) is transferred from disk to memory, and vice versa.

  • Virtual Memory

Processes can run when they are partially in the memory.

slide-7
SLIDE 7

7

Memory Management

  • What about the memory addresses?
  • Monoprogramming

– The physical addresses are known to the programmer.

  • Multiprogramming

– The physical addresses are known at the loading time.

  • Timesharing

– The physical addresses are known at the execution. – The CPU understands logical addresses. – The Memory understands physical addresses.

slide-8
SLIDE 8

8

Memory Management

  • Basic concerns:
  • Allocation
  • Relocation
  • Protection
slide-9
SLIDE 9

9

Hardware address protection

  • Multitasking OS
  • Multiple processes loaded in the memory.
  • Each process has a separate memory space.
  • HW+OS are responsible for address protection.

OS process process process

25600 30004 42094 88000 30004 12090

base limit

slide-10
SLIDE 10

10

Logical vs Physical Address

  • Multitasking OS
  • Memory management: Swap, Virtual Memory
  • Logical Address
  • Address generated by the CPU
  • Address loaded into PC
  • Address used in a program
  • Physical Address
  • Address seen by the memory unit
slide-11
SLIDE 11

11

Address Binding

  • Logical → Physical
  • Execution time
  • Logical Address ↔ Virtual Address
  • Memory-Management Unit (MMU)
  • Hardware device
  • Run-time mapping

CPU memory +

14000 Relocation register Logical address 346 Physical address 14346

slide-12
SLIDE 12

12

Dynamic Loading

  • Using Virtual memory:
  • Better memory-space utilization
  • The main program is loaded into memory.
  • A routing of the program is not loaded until it is

called.

  • It is users' responsibility.
slide-13
SLIDE 13

13

Dynamic Linking

  • Using Virtual memory:
  • Without this, each program should include a

copy of its language library.

  • It waists disk and memory space.
  • With Dynamic Linking:
  • A stub substitutes a library-routine reference.
  • When stub is executed:

– It checks if the routine is in the memory. – If not, the program loads the routine.

slide-14
SLIDE 14

14

Contiguous Memory Allocation

  • Share memory between OS and multiple processes.
  • Each process is contained in a single contiguous section in memory.
  • Memory protection:
  • CPU scheduler selects process for execution.
  • The dispatcher loads the relocation and limit registers.

CPU < + memory limit register relocation register trap: addressing error logical address no yes physical address

slide-15
SLIDE 15

15

Allocation Strategies

  • Fixed-sized partitions
  • The degree of multiprogramming is bound by the number of

partitions.

  • Variable-partition scheme
  • The OS keeps a table indicating which parts of memory are

available and which are occupied.

  • The OS tries to fit the memory demands of a process in the

available memory space.

  • Dynamic storage allocation problem:

– First fit – Best fit – Worst fit

slide-16
SLIDE 16

16

Fragmentation

  • External fragmentation
  • First-fit, Best fit
  • There is enough total memory space to satisfy a request but

the available spaces are small and not contiguous.

  • Solution 1: Break the physical memory into fixed-sized blocks

and allocate memory in units based on block size.

  • Internal fragmentation: the allocated memory is slightly

larger than the requested memory.

  • Solution 2: Compaction
slide-17
SLIDE 17

17

Today

  • How the memory is shared among the ready

processes?

  • Memory
  • Address protection
  • Logical vs Physical Address
  • Contiguous memory allocation