NETW3005 Memory Management. Reading For this lecture, you should have read Chapter 8 (Sections 1-6). NETW3005 (Operating Systems) Lecture 07 – Memory.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
CS 311 – Lecture 21 Outline Memory management in UNIX
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Multiprocessing Memory Management
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Memory Management Chapter 5.
Operating System Concepts
Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program User programs go through several steps before.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Chapter 8: Main Memory.
Chapter 8 Main Memory Bernard Chen Spring Objectives To provide a detailed description of various ways of organizing memory hardware To discuss.
Chap 8 Memory Management. Background Program must be brought into memory and placed within a process for it to be run Input queue – collection of processes.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 346, Royden, Operating System Concepts Operating Systems Lecture 24 Paging.
Memory Management -1 Background Swapping Memory Management Schemes
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 8 Operating Systems.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Swapping and Contiguous Memory Allocation. Multistep Processing of a User Program User programs go through several steps before being run. Program components.
Lecture 13 L.Mohammad R.Alkafagee1.  The concept of a logical address space that is bound to a separate physical address space is central to proper memory.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
Memory Management. Process must be loaded into memory before being executed. Memory needs to be allocated to ensure a reasonable supply of ready processes.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies Objectives To provide a detailed description.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
Chapter 4 Storage Management (Memory Management).
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
CE Operating Systems Lecture 14 Memory management.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
1 Memory Management Basics. 2 Program P Basic Memory Management Concepts Address spaces Physical address space — The address space supported by the hardware.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
CS6502 Operating Systems - Dr. J. Garrido Memory Management – Part 1 Class Will Start Momentarily… Lecture 8b CS6502 Operating Systems Dr. Jose M. Garrido.
Virtual Memory From course notes University of Waikato. Some material by Tony McGregor Other material from: The Architecture.
NETW3005 Virtual Memory. Reading For this lecture, you should have read Chapter 9 (Sections 1-7). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory2.
Memory Management Chapter 5 Advanced Operating System.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Operating Systems Lecture 31 Syed Mansoor Sarwar.
Memory management The main purpose of a computer system is to execute programs. These programs, together with the data they access, must be in main memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition, Chapter 8: Memory- Management Strategies.
Main Memory CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
Chapter 9: Memory Management
Chapter 2 Memory and process management
Chapter 8: Main Memory.
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Main Memory Background Swapping Contiguous Allocation Paging
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Lecture 3: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 542: Operating Systems
Page Main Memory.
Presentation transcript:

NETW3005 Memory Management

Reading For this lecture, you should have read Chapter 8 (Sections 1-6). NETW3005 (Operating Systems) Lecture 07 – Memory Management2

This lecture – memory management Background – general concepts Getting programs/data into memory Logical and physical addresses Memory allocation methods Paging Segmentation NETW3005 (Operating Systems) Lecture 07 – Memory Management3

Recap on storage hierarchy NETW3005 (Operating Systems) Lecture 07 – Memory Management4 Cache Storage Main Memory Secondary Storage (hard disk) access speed increases access time decreases cost increases capacity decreases PRIMARY STORAGE: can be referenced directly by CPU Must be loaded into memory before being referenced

The instruction execution cycle The CPU fetches an instruction from main memory, according to the value of the program counter. The instruction may require other main memory locations to be accessed, for loading or storing contents of registers. NETW3005 (Operating Systems) Lecture 07 – Memory Management5

Memory unit Responsible for accessing main memory. Doesn’t know or care what the data being accessed are actually used for. NETW3005 (Operating Systems) Lecture 07 – Memory Management6

Memory management Deals with how to get processes into main memory, and the organisation of that memory. Non-trivial task. –The memory unit accesses addresses in primary memory, e.g –Source code refers to symbols. variables: e.g. count. procedures: e.g. get_next_item. NETW3005 (Operating Systems) Lecture 07 – Memory Management7

Address binding Symbols need to be converted into addresses. Technically, we talk of symbols being bound to addresses. Symbols can be converted into addresses at one of several points. NETW3005 (Operating Systems) Lecture 07 – Memory Management8

Address binding (continued) Compile time. Link time. Load time. Run time. NETW3005 (Operating Systems) Lecture 07 – Memory Management9

Dynamic linking and loading When a source program is compiled, the code for the functions provided by the language (e.g. C++ standard template libraries) needs to be incorporated into the object program. This can be done statically or dynamically. NETW3005 (Operating Systems) Lecture 07 – Memory Management10

Dynamic linking and loading (2) Static linking — done at link or load time. Dynamic linking — done at run-time. – A ‘stub’ containing a pointer is included in place of the code for each routine. –When the stub is referenced, the pointer is initialised. –If the routine is already loaded, use it, other- wise load the routine. NETW3005 (Operating Systems) Lecture 07 – Memory Management11

Advantages of dynamic linking Saving on memory space – don’t need multiple copies of the same routines. Saving on load time – only need to load a routine once. Ease of updating libraries (e.g. to fix bugs, change versions, etc). NETW3005 (Operating Systems) Lecture 07 – Memory Management12

Logical and physical addresses A logical address is one referred to in a piece of executable code (e.g. to refer to a variable or a location). The CPU executes instructions involving logical addresses. A physical address is the address which is actually sent to the memory unit. NETW3005 (Operating Systems) Lecture 07 – Memory Management13

The memory-management unit The logical address space of a process runs from 0 to the memory limit of the process. Physical address space runs from 0 to the size of main memory. The memory management unit (MMU) maps between the two. NETW3005 (Operating Systems) Lecture 07 – Memory Management14

The memory-management unit (2) It takes a logical address generated by the CPU, and adds a number N to compute the physical address. The number is held in a relocation register To move a process in memory, just change the relocation register. NETW3005 (Operating Systems) Lecture 07 – Memory Management15

Run-time binding and multitasking Run-time binding is useful for saving on memory –Only load modules when they’re needed. –Allow several processes to share one copy of a module. NETW3005 (Operating Systems) Lecture 07 – Memory Management16

Run-time binding and multitasking There are also many benefits that relate to a multitasking scenario. –Until now, our multitasking scenario has involved switching between processes resident in main memory. –However, while a process is waiting for the CPU, there’s no reason for it to be in main memory. NETW3005 (Operating Systems) Lecture 07 – Memory Management17

CPU and memory as resources Multitasking means allowing several processes to take turns to use the CPU. Processes can also take turns to be allocated a region of memory. NETW3005 (Operating Systems) Lecture 07 – Memory Management18

Swapping Processes are swapped in and out of main memory from/to a backing store. Swapping is done by the memory manager, which is a module of the kernel. The memory manager needs to work in synch with the CPU scheduler. NETW3005 (Operating Systems) Lecture 07 – Memory Management19

Memory allocation and protection Processes are not allowed to access each other’s address space (except under special circumstances). How is this rule implemented? Each process has an associated relocation register and limit register. NETW3005 (Operating Systems) Lecture 07 – Memory Management20

Memory allocation and protection NETW3005 (Operating Systems) Lecture 07 – Memory Management21 main memory CPU limit register < no TRAP: addressing error relocation register physical address logical address +

Allocating memory for processes How to organise memory allocation for many processes? A simple method – divide memory into a number of fixed-size partitions. Problems? NETW3005 (Operating Systems) Lecture 07 – Memory Management22

Allocating memory for processes A more complex method: –Each free region of memory is termed a hole. –When a process arrives, we find a hole big enough to put it into. –If the hole is bigger than the process, we keep a record of the new (smaller) hole. NETW3005 (Operating Systems) Lecture 07 – Memory Management23

Algorithms for choosing a hole There are three different methods –First-fit: allocate the first hole you find that’s big enough. –Best-fit: find the hole that leaves the small- est leftover hole. –Worst-fit: find the hole that leaves the biggest leftover hole. NETW3005 (Operating Systems) Lecture 07 – Memory Management24

Advantages/disadvantages? First-fit: quickest but possibly non- optimal. Best-fit: exhaustive search. Also you end up creating very small holes. Worst-fit: exhaustive search. You might not use the large holes as effectively as you could. NETW3005 (Operating Systems) Lecture 07 – Memory Management25

External fragmentation If memory is broken into many holes, there might be enough memory in total to fit a particular process, but not all in one place. NETW3005 (Operating Systems) Lecture 07 – Memory Management26 P0 P1 holes

Internal fragmentation The operating system has to keep a table of all the currently available holes in memory. If we keep very many small holes, we’ll end up with a huge amount of house- keeping to do. To avoid creating tiny holes, we sometimes allocate more memory than a process needs. NETW3005 (Operating Systems) Lecture 07 – Memory Management27

Non-contiguous memory allocation The allocation methods described so far have all required the memory allocated for a process to be contiguous. Obviously, noncontiguous allocation has advantages. One way of providing noncontiguous allocation is through paging. NETW3005 (Operating Systems) Lecture 07 – Memory Management28

Background NETW3005 (Operating Systems) Lecture 07 – Memory Management29 physical memory logical memory backing store PAGES FRAMES

Paging The CPU generates addresses which the paging hardware breaks into two components: –A page number (identifying a page); –An offset (an address within that page). Each process is allocated a certain number of pages. NETW3005 (Operating Systems) Lecture 07 – Memory Management30

Paging NETW3005 (Operating Systems) Lecture 07 – Memory Management31 CPU addres s p off PAGE TABLE f off logical addres s physical address memory

Paging The page table also stores a valid/invalid bit, which is set to invalid for out-of-range memory references. Paging is a way of implementing run- time address binding. NETW3005 (Operating Systems) Lecture 07 – Memory Management32

Paging example NETW3005 (Operating Systems) Lecture 07 – Memory Management33 page table CPU page0 page1 page2 page3 0 1 v 1 4 v 2 3 v 3 6 v page3 page1 page2 page0 memory

Some questions What about external fragmentation? –This scheme eliminates it. What about internal fragmentation? –Each process is allocated a discrete number of pages. So on average half a page per process How big should pages be? –Small, but not so small that the disk I/O and housekeeping become too much. NETW3005 (Operating Systems) Lecture 07 – Memory Management34

More questions How many page tables do we need? –One for each process. (Because they’re all going to have a Page0.) How does the O/S keep track of a process’ page table? –It keeps a copy in its PCB. (Remember I said that the PCB contains ‘memory management information’...) NETW3005 (Operating Systems) Lecture 07 – Memory Management35

Implementing paging The fastest/most expensive way of implementing pages is to store the page table in a set of special-purpose registers. But this isn’t feasible if the page table is big (as it normally is). NETW3005 (Operating Systems) Lecture 07 – Memory Management36

Implementing paging The alternative is to store the page table in main memory. This could slow things down because we now need two memory accesses. The solution is to keep a cache of page table entries that have been used recently, in a special set of parallel- access registers called associative registers. NETW3005 (Operating Systems) Lecture 07 – Memory Management37

Segmentation In the paging scheme above, it’s the hardware that partitions a CPU- generated address into pages. But there are some reasons for allowing a process to partition its own address space. NETW3005 (Operating Systems) Lecture 07 – Memory Management38

Segmentation NETW3005 (Operating Systems) Lecture 07 – Memory Management39 subroutine stack SQRT main program symbol table logical address space A segmentation allocation scheme supports this view of memory.

Implementing segmentation In segmentation, a logical address is a pair. These are mapped onto physical add- resses by the segmentation hardware, using a segment table. NETW3005 (Operating Systems) Lecture 07 – Memory Management40

Implementing segmentation Each entry in the table has a segment base (the starting physical address) and a segment limit (the size of the segment). Segments can be stored non-contiguously. Like the page table, the segment table can either be put into fast registers or main memory. NETW3005 (Operating Systems) Lecture 07 – Memory Management41

Advantages of segmentation Makes protection and sharing easy to deal with (as all items in a given segment are likely to have the same protection status). You just need one protection bit per segment. It just makes it easier to write machine code (and thus to write compilers.) NETW3005 (Operating Systems) Lecture 07 – Memory Management42

Disadvantages of segmentation External fragmentation is back, but less severely. Some schemes (e.g. MULTICS) use paging and segmentation. The idea is that a memory reference is a segment base plus segment offset, where the segment offset is itself broken into two components: a page number and a page offset. NETW3005 (Operating Systems) Lecture 07 – Memory Management43

Next Lecture Virtual Memory Chapter 9 (Sections 1-7)