CSE 373 OCTOBER 23 RD MEMORY AND HARDWARE

Similar documents
CSE 373 OCTOBER 25 TH B-TREES

Computer Memory. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

CSE 373: Data Structures and Algorithms. Memory and Locality. Autumn Shrirang (Shri) Mare

CSE332: Data Abstractions Lecture 7: B Trees. James Fogarty Winter 2012

1. With respect to space, linked lists are and arrays are.

Algorithm Performance Factors. Memory Performance of Algorithms. Processor-Memory Performance Gap. Moore s Law. Program Model of Memory I

CSE 326: Data Structures Splay Trees. James Fogarty Autumn 2007 Lecture 10

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

CSE 326: Data Structures B-Trees and B+ Trees

Memory Management. Kevin Webb Swarthmore College February 27, 2018

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

Preview. Memory Management

CSE373: Data Structures & Algorithms Lecture 12: Amortized Analysis and Memory Locality. Linda Shapiro Winter 2015

Section 4 SOLUTION: AVL Trees & B-Trees

Recall from Tuesday. Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS.

CS399 New Beginnings. Jonathan Walpole

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Welcome to Part 3: Memory Systems and I/O

Locality of Reference

CSE 530A. B+ Trees. Washington University Fall 2013

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

RAM, Design Space, Examples. January Winter Term 2008/09 Gerd Liefländer Universität Karlsruhe (TH), System Architecture Group

CSE 373 APRIL 17 TH TREE BALANCE AND AVL

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

B-Trees. Version of October 2, B-Trees Version of October 2, / 22

Exercise 1 : B-Trees [ =17pts]

Chapter 6 Caches. Computer System. Alpha Chip Photo. Topics. Memory Hierarchy Locality of Reference SRAM Caches Direct Mapped Associative

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

Algorithm Performance Factors. Memory Performance of Algorithms. Processor-Memory Performance Gap. Moore s Law. Program Model of Memory II

Cache introduction. April 16, Howard Huang 1

Lec 13: Linking and Memory. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

Overview of Storage & Indexing (i)

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Trees. Reading: Weiss, Chapter 4. Cpt S 223, Fall 2007 Copyright: Washington State University

Lecture 16. Today: Start looking into memory hierarchy Cache$! Yay!

Balanced Trees Part One

Practice Midterm Exam Solutions

Memory Hierarchies &

Principles of Algorithm Design

Princeton University. Computer Science 217: Introduction to Programming Systems. The Memory/Storage Hierarchy and Virtual Memory

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

Transistor: Digital Building Blocks

Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Virtual Memory. 11/8/16 (election day) Vote!

Plot SIZE. How will execution time grow with SIZE? Actual Data. int array[size]; int A = 0;

CS 61C: Great Ideas in Computer Architecture. Direct Mapped Caches

Section 05: Solutions

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9

Memory Management! Goals of this Lecture!

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

15 Sharing Main Memory Segmentation and Paging

Binary heaps (chapters ) Leftist heaps

Introduction to I/O Efficient Algorithms (External Memory Model)

The Processor Memory Hierarchy

CSCI2100B Data Structures Heaps

Dynamic Storage Allocation

CS61C : Machine Structures

CS 179: GPU Computing LECTURE 4: GPU MEMORY SYSTEMS

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

UC Berkeley CS61C : Machine Structures

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

Persistent Storage - Datastructures and Algorithms

Balanced Search Trees

Heap Compression for Memory-Constrained Java

FILE SYSTEMS. CS124 Operating Systems Winter , Lecture 23

CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019

CSE506: Operating Systems CSE 506: Operating Systems

CS61C : Machine Structures

CS61C - Machine Structures. Lecture 17 - Caches, Part I. October 25, 2000 David Patterson

ECE331: Hardware Organization and Design

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Lecture 3: B-Trees. October Lecture 3: B-Trees

Learning to Play Well With Others

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

1. AVL Trees (10 Points)

16 Sharing Main Memory Segmentation and Paging

CSE 332: Data Structures & Parallelism Lecture 12: Comparison Sorting. Ruth Anderson Winter 2019

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

Suppose you are accessing elements of an array: ... or suppose you are dereferencing pointers: temp->next->next = elem->prev->prev;

Lctures 33: Cache Memory - I. Some of the slides are adopted from David Patterson (UCB)

Memory Management! How the hardware and OS give application pgms:" The illusion of a large contiguous address space" Protection against each other"

Recall: Properties of B-Trees

CS 310: Memory Hierarchy and B-Trees

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CSC 369 Operating Systems

Disk Scheduling COMPSCI 386

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

Main Memory and the CPU Cache

CS 240 Fall Mike Lam, Professor. Priority Queues and Heaps

Memory Management. COMP755 Advanced Operating Systems

Pharmacy college.. Assist.Prof. Dr. Abdullah A. Abdullah

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

ECE 571 Advanced Microprocessor-Based Design Lecture 12

Lecture 2: Memory Systems

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CS Transform-and-Conquer

CSC258: Computer Organization. Memory Systems

Transcription:

CSE 373 OCTOBER 23 RD MEMORY AND HARDWARE

MEMORY ANALYSIS Similar to runtime analysis

MEMORY ANALYSIS Similar to runtime analysis Consider the worst case

MEMORY ANALYSIS Similar to runtime analysis Rather than counting the number of operations, we count the amount of memory needed

MEMORY ANALYSIS Similar to runtime analysis Rather than counting the number of operations, we count the amount of memory needed During the operation, when does the algorithm need to keep track of the most number of things?

MEMORY ANALYSIS Breadth first search

MEMORY ANALYSIS Breadth first search The Queue keeps track of the elements that need to be analyzed next.

MEMORY ANALYSIS Breadth first search The Queue keeps track of the elements that need to be analyzed next. This is the memory we need to consider

MEMORY ANALYSIS Breadth first search The Queue keeps track of the elements that need to be analyzed next. This is the memory we need to consider At what point does the Queue have the most amount stored in it?

MEMORY ANALYSIS Breadth first search The Queue keeps track of the elements that need to be analyzed next. This is the memory we need to consider At what point does the Queue have the most amount stored in it? When the tree is at its widest how many nodes is that?

MEMORY ANALYSIS Breadth first search The Queue keeps track of the elements that need to be analyzed next. This is the memory we need to consider At what point does the Queue have the most amount stored in it? When the tree is at its widest how many nodes is that? N/2: half the nodes of a tree are leaves

MEMORY ANALYSIS Consider finding an element in a sorted linked list

MEMORY ANALYSIS Consider finding an element in a sorted linked list How much memory does this take?

MEMORY ANALYSIS Consider finding an element in a sorted linked list How much memory does this take? Don t count the data structure, only count the amount of memory that the actual algorithm uses.

MEMORY ANALYSIS Consider finding an element in a sorted linked list How much memory does this take? Don t count the data structure, only count the amount of memory that the actual algorithm uses. What does it need to keep track of?

MEMORY ANALYSIS Consider finding an element in a sorted linked list How much memory does this take? Don t count the data structure, only count the amount of memory that the actual algorithm uses. What does it need to keep track of? Just the thing we re looking for!

MEMORY ANALYSIS Consider finding an element in a sorted linked list How much memory does this take? Don t count the data structure, only count the amount of memory that the actual algorithm uses. What does it need to keep track of? Just the thing we re looking for! O(1)

MEMORY ANALYSIS We care about the asymptotic memory usage

MEMORY ANALYSIS We care about the asymptotic memory usage That is, as the input size of the data structures increases, does the amount of extra memory increase?

MEMORY ANALYSIS We care about the asymptotic memory usage That is, as the input size of the data structures increases, does the amount of extra memory increase? AVL Insert? Yes, we need to keep track of the path from the insertion to the root

HARDWARE CONSTRAINTS So far, we ve taken for granted that memory access in the computer is constant and easily accessible

HARDWARE CONSTRAINTS So far, we ve taken for granted that memory access in the computer is constant and easily accessible This isn t always true!

HARDWARE CONSTRAINTS So far, we ve taken for granted that memory access in the computer is constant and easily accessible This isn t always true! At any given time, some memory might be cheaper and easier to access than others

HARDWARE CONSTRAINTS So far, we ve taken for granted that memory access in the computer is constant and easily accessible This isn t always true! At any given time, some memory might be cheaper and easier to access than others Memory can t always be accessed easily

HARDWARE CONSTRAINTS So far, we ve taken for granted that memory access in the computer is constant and easily accessible This isn t always true! At any given time, some memory might be cheaper and easier to access than others Memory can t always be accessed easily Sometimes the OS lies, and says an object is in memory when it s actually on the disk

HARDWARE CONSTRAINTS Back on 32-bit machines, each program had access to 4GB of memory

HARDWARE CONSTRAINTS Back on 32-bit machines, each program had access to 4GB of memory This isn t feasible to provide!

HARDWARE CONSTRAINTS Back on 32-bit machines, each program had access to 4GB of memory This isn t feasible to provide! Sometimes there isn t enough available, and so memory that hasn t been used in a while gets pushed to the disk

HARDWARE CONSTRAINTS Back on 32-bit machines, each program had access to 4GB of memory This isn t feasible to provide! Sometimes there isn t enough available, and so memory that hasn t been used in a while gets pushed to the disk Memory that is frequently accessed goes to the cache, which is even faster than RAM

LOCALITY AND PAGES So, the OS does two smart things Spatial locality if you use memory index Ox371347AB, you are likely to need Ox371347AC bring both into cache These are called pages, and they are usually around 4kb

LOCALITY AND PAGES So, the OS does two smart things Spatial locality if you use memory index Ox371347AB, you are likely to need Ox371347AC bring both into cache These are called pages, and they are usually around 4kb All of the processes on your computer have access to pages in memory.

LOCALITY AND PAGES When you call new in Java, you are requesting new memory from the heap. If there isn t memory there, the JVM needs to get new memory from the OS

LOCALITY AND PAGES When you call new in Java, you are requesting new memory from the heap. If there isn t memory there, the JVM needs to get new memory from the OS The OS only uses memory in page sizes

LOCALITY AND PAGES When you call new in Java, you are requesting new memory from the heap. If there isn t memory there, the JVM needs to get new memory from the OS The OS only uses memory in page sizes So if you allocate 100Bytes of data, you overallocate to 4kb!

LOCALITY AND PAGES When you call new in Java, you are requesting new memory from the heap. If there isn t memory there, the JVM needs to get new memory from the OS The OS only uses memory in page sizes So if you allocate 100Bytes of data, you overallocate to 4kb! But you can use that 4kb if you need more

LOCALITY AND PAGES Secondly, the OS uses temporal locality,

LOCALITY AND PAGES Secondly, the OS uses temporal locality, Memory recently accessed is likely to be accessed again

LOCALITY AND PAGES Secondly, the OS uses temporal locality, Memory recently accessed is likely to be accessed again Bring recently used data into faster memory

LOCALITY AND PAGES Secondly, the OS uses temporal locality, Memory recently accessed is likely to be accessed again Bring recently used data into faster memory Types of memory (by speed) Register L1,L2,L3 Memory Disk The interwebs (the cloud)

LOCALITY AND PAGES The OS is always processing this information and deciding which is the best This is why arrays are faster in practice, they are always next to each other in memory

LOCALITY AND PAGES The OS is always processing this information and deciding which is the best This is why arrays are faster in practice, they are always next to each other in memory Each new node in a tree may not even be in the same page in memory!!

LOCALITY AND PAGES The OS is always processing this information and deciding which is the best This is why arrays are faster in practice, they are always next to each other in memory Each new node in a tree may not even be in the same page in memory!! Important to consider when designing and explaining design problems.

COST OF MEMORY ACCESSES Registers (128B): Instantaneous access L2 Cache (128KB): 0.5 nanoseconds L3 Cache (2MB): 7 nanoseconds Main Memory (32 GB): 100 nanoseconds

COST OF MEMORY ACCESSES Registers (128B): Instantaneous access L2 Cache (128KB): 0.5 nanoseconds L3 Cache (2MB): 7 nanoseconds Main Memory (32 GB): 100 nanoseconds Disk (TBs): 8,000,000 nanoseconds

PROCESS MEMORY How does an individual process use memory?

PROCESS MEMORY How does an individual process use memory? Many different demands Global variables Call stack Allocated variables Process code

PROCESS MEMORY

PROCESS MEMORY These different demands are not next to each other in memory little locality benefit

PROCESS MEMORY These different demands are not next to each other in memory little locality benefit Each call to new allocates wherever there is space in the heap (memory allocator) Even if two elements are created one after another, there is no guarantee that they ll both be in the same page This is especially true for java How important is caching?

COST OF MEMORY ACCESSES Registers (128B): Instantaneous access L2 Cache (128KB): 0.5 nanoseconds L3 Cache (2MB): 7 nanoseconds Main Memory (32 GB): 100 nanoseconds Disk (TBs): 8,000,000 nanoseconds This is much, much worse

LARGE AVL Suppose we are storing terabytes of data in an AVL tree

LARGE AVL Suppose we are storing terabytes of data in an AVL tree Height is about 50

LARGE AVL Suppose we are storing terabytes of data in an AVL tree Height is about 50 How many disk accesses will a find take?

LARGE AVL Suppose we are storing terabytes of data in an AVL tree Height is about 50 How many disk accesses will a find take? Between 0 and 50!

LARGE AVL Suppose we are storing terabytes of data in an AVL tree Height is about 50 How many disk accesses will a find take? Between 0 and 50! This is the difference between nanoseconds and almost half a second!

LARGE AVL Suppose we are storing terabytes of data in an AVL tree Height is about 50 How many disk accesses will a find take? Between 0 and 50! This is the difference between nanoseconds and almost half a second! If lots data is stored on the disk, O(log n) finds don t happen in practice

PROBLEMS Why is AVL so bad on disk?

PROBLEMS Why is AVL so bad on disk? Each piece of data is its own node

PROBLEMS Why is AVL so bad on disk? Each piece of data is its own node Each call of new may not place objects next to each other

PROBLEMS Why is AVL so bad on disk? Each piece of data is its own node Each call of new may not place objects next to each other Has large height, for the number of elements?

SOLUTIONS What changes might we want to make to an AVL to make it better for disk?

SOLUTIONS What changes might we want to make to an AVL to make it better for disk? Still want to keep log n height

SOLUTIONS What changes might we want to make to an AVL to make it better for disk? Still want to keep log n height Allocate more objects closer together

SOLUTIONS What changes might we want to make to an AVL to make it better for disk? Still want to keep log n height Allocate more objects closer together Have a higher branching factor so that data you want is at a lower depth

SOLUTIONS What changes might we want to make to an AVL to make it better for disk? Still want to keep log n height Allocate more objects closer together Have a higher branching factor so that data you want is at a lower depth Take advantage of page sizes