Docsity

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

Partial preview of the text

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

Operating Systems

Lecture 21:

Memory Management

Storage-Device Hierarchy

Access speed Cost Storage size

Background

  • Program must be brought from disk to memory and placed within a process to run
  • Main memory and registers are the only storage that the CPU can access
  • Register access in 1 CPU clock (or less), main memory takes many cycles
  • Memory as an array of addresses

Addressing

Memory Management

Requirements (cont’)

  • Sharing
  • Logical organization
    • Memory is organized linearly (usually), programs are written in modules
    • Modules can be written and compiled independently, different degrees of protection given to modules (read- only, execute-only)
  • Physical organization
    • Cannot leave the programmer with the responsibility to manage memory

Partitioning

  • An early method of managing memory
    • Pre-virtual memory
    • Not used much now
  • But, it will clarify the later discussion of virtual

memory if we look first at partitioning

  • Virtual Memory has evolved from the partitioning methods

Fixed Partitioning

  • Equal-size partitions (see fig 7.3a)
    • Any process whose size is less than or equal to the partition size can be loaded into an available partition
  • The operating system can swap a

process out of a partition

  • If none are in a ready or running state

Question

  • What are the main problems with a fixed

partition?

Question

  • How can we “solve” these

problems?

  • Use unequal size partitions
    • Still fixed sizes
    • The Problem is lessen but not solved

Placement Algorithm

  • Equal-size
    • Placement is trivial (no options)
  • Unequal-size
    • Can assign each process to the smallest partition within which it will fit
    • Queue for each partition
    • Processes are assigned in such a way as to minimize wasted memory within a partition

Remaining Problems with Fixed

Partitions?

Problems with Fixed Partitions

  • The number of active processes is limited by

the system (to the pre-determined number of

partitions)

  • A large number of very small process will not

use space efficiently

  • Solutions?

Dynamic Partitioning Example

  • External Fragmentation
  • Memory external to all

processes is fragmented

  • Can resolve using

compaction

  • OS moves processes so that they are contiguous
  • Time consuming and wastes CPU time

OS (8M)

P (20M)

P (14M)

P (18M)

Empty (56M)

Empty (4M)

P4(8M) Empty (6M)

P (14M) Empty (6M)

Refer to Figure 7.4 Docsity.com

Allocation

Allocation algorithms: Best-fit algorithm Next fit First fit (Worst fit)