Download presentation
Presentation is loading. Please wait.
Published byTrevor Butler Modified over 9 years ago
2
Introduction: Memory Management 2 Ideally programmers want memory that is large fast non volatile Memory hierarchy small amount of fast, expensive memory – cache some medium-speed, medium price main memory gigabytes of slow, cheap disk storage Memory manager handles the memory hierarchy
3
Disk-based storage in computers Memory/storage hierarchy Combining many technologies to balance costs/benefits Recall the memory hierarchy and virtual memory lectures
4
Memory/storage hierarchies Balancing performance with cost Small memories are fast but expensive Large memories are slow but cheap Exploit locality to get the best of both worlds locality = re-use/nearness of accesses allows most accesses to use small, fast memory Capacity Performance
5
Computer Memory Hierarchy
6
An Example Memory Hierarchy registers on-chip L1 cache (SRAM) main memory (DRAM) local secondary storage (local disks) Larger, slower, and cheaper (per byte) storage devices remote secondary storage (tapes, distributed file systems, Web servers) Local disks hold files retrieved from disks on remote network servers. Main memory holds disk blocks retrieved from local disks. off-chip L2 cache (SRAM) L1 cache holds cache lines retrieved from the L2 cache memory. CPU registers hold words retrieved from L1 cache. L2 cache holds cache lines retrieved from main memory. L0: L1: L2: L3: L4: L5: Smaller, faster, and costlier (per byte) storage devices
7
7 Memory Management Virtual (or logical) address vs. Physical address Memory Management Unit (MMU) Set of registers and mechanisms to translate virtual addresses to physical addresses Processes (and CPU) see virtual addresses Virtual address space is same for all processes, usually 0 based Virtual spaces are protected from other processes MMU and devices see physical addresses CPU MMU MemoryI/O Devices Logical Addresses Physical Addresses
8
Definition of Virtual Memory Virtual memory is a concept that, allows a computer and its operating system, to use a very large range of memory or storage addresses for stored data. The computing system maps the programmer's virtual addresses to real hardware storage addresses (Hard Disks). In addition to managing the mapping of virtual storage addresses to real storage addresses, a computer implementing virtual memory or storage also manages storage swapping between active storage (RAM) and hard disk or other high volume storage devices
9
Virtual Memory Virtual memory is a feature of an operating system (OS) that allows a computer to compensate for shortages of physical memory by temporarily transferring pages of data from random access memory (RAM) to disk storage.
10
All modern general-purpose computer operating systems use virtual memory techniques for ordinary applications, such as word processors, spreadsheets, multimedia players, accounting, etc Older operating systems, such as DOS of the 1980s, or many mainframe operating systems of the 1960s, had no virtual memory functionality. Embedded Systems and other special-purpose computer systems which require very fast, very consistent response time do not generally use virtual memory.
11
Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time A process may be swapped in and out of main memory such that it occupies different regions A process may be broken up into pieces that do not need to located contiguously in main memory All pieces of a process do not need to be loaded in main memory during execution 11
12
How Does it Work? Memory Management Unit (MMU) Hardware component responsible for handling accesses to memory requested by the (CPU). One of Its functions include translation of virtual addresses to physical addresses (Virtual Memory management),
13
Virtual memory Virtual Memory provides expansion of Main Memory by ‘overflowing’ data and program code onto Magnetic Disk. The area on disk reserved for this purpose is known as the Swap Space Dividing main memory into Frames (pages)
14
Pages The RAM physical memory subdivided into 4kb-64kb pages. 512MB/4K = 131072 pg Page Table provides a look up whereby the logical page number can be exchanged for the physical frame number. It is an Array of (PTE).
15
Process Process When programs are using the CPU at the same time, each running program and the data structures needed to manage it. Addresses Addresses A Load Instruction A Store Instruction Fetching an Instruction
17
Virtual Memory Address Translation Maximum Virtual Address space: Size of a program address is determined by the maximum size of the virtual address space. The number of bits in a virtual address is the log base 2 (log 2 ) of this value. Maximum Physical Address space: The amount of real memory that the system can support determined the number of bits needed to address the physical memory. The size of physical address is log base 2 (log 2 ) of this value. Size of a Page: This is the size of a virtual memory page and a physical memory frame. It is always a power of 2 (2 x )
18
Page number and page offset A virtual address is therefore split into two parts. The more significant part gives the page number. The less significant part gives the address of the byte within the page. The less significant part is also called the “page offset.” The number of bits allocated to the page offset should be able to address every byte in the page. Therefore, in our example. Since we have 4 KB = 2 12 byte page tables, we need 12 bits for page offset. Likewise for the physical address.
19
Virtual Address can be represented as: 13 bits 10 bits page number offset Physical Address can be represented as: 13 bits 10 bits Frame address offset
20
Page Fault The memory manager locates the missing page in secondary memory. The page is loaded into primary memory, usually causing another page to be unloaded. The page table in the memory manager is adjusted to reflect the new state of the memory. The processor re-executes the instructions which caused the page fault.
21
Translation Look-aside Buffer The TLB tends to be fully associative. The TLB uses write-back. Therefore, needs a dirty bit to indicate if the page is dirty Or have a Read or Write Permission bit This is because a TLB miss is very costly, and is to be avoided.
23
MEMORY PERFORMANCE COMPARISON
24
Page Replacement Policies: 3 major page replacement policies: FIFO LRU OPT
25
FIFO FIFO(first in first out) : With FIFO, the oldest page in memory is selected for replacement Example: 2 3 2 1 5 2 4 5 3 2 5 2 22 *2*22555 *5*53333 33332222 *2*255 111444442
26
LRU: (least recently used) LRU Policy- a policy that selects the page that has gone unused for the longest period of time. 2 3 2 1 5 2 4 5 3 2 5 2 23 *2*215 *2*24 *5*532 *5*5 *2*2 23215245325 321524533
27
OPT(optimal replacement policy) In this policy we will replace the memory with the page address which we will not use in the near future.
28
How to Access the Virtual Memory in your Computer? 1
29
2 3
30
4RAM Virtual Mem. 1GB 1536MB 2048MB 2GB3072MB4096MB 3GB4644MB6144MB
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.