Algorithms and Data Structures 大数据处理


the essence of knowledge FnT TCS 2:4 Algorithms and Data Structures for External Memory Jeffrey Scott VitterAlgorithms and Data Structures for External Memory Jeffrey Scott Vitter Data sets in large applications are often too massive to fit completely inside the computer's internal memory. The resulting input/output communication (or I/O) between fast internal memory and slower external memory (such as disks) can be a major performance bottleneck. Algorithms and Data Structures for External Memory surveys the state of the art in the design and analysis of external memory (or EM) algorithms and data structures, where the goal is to exploit locality in order to reduce the I/O costs. A variety of EM paradigms are considered for solving batched and online problems efficiently in external memory. Algorithms and Data Structures for External Memory describes several useful paradigms for the design and implementation of efficient EM algorithms and data structures. The problem domains considered include sorting, permuting, FFT, scientific computing, computational geometry, graphs, databases, geographic information systems, and text and string processing. Algorithms and Data Structures for External Memory is an invaluable reference for anybody interested in, or conducting research in the design, analysis, and implementation of algorithms and data structures. This book is originally published as Foundations and Trends® in Theoretical Computer Science Volume 2 Issue 4, ISSN: 1551-305X. Foundations and Trends® in Theoretical Computer Science 2:4 Algorithms and Data Structures for External Memory Jeffrey Scott Vitter now now TCSv2n4.qxd 4/24/2008 11:56 AM Page 1 Algorithms and Data Structures for External Memory Algorithms and Data Structures for External Memory Jeffrey Scott Vitter Department of Computer Science Purdue University West Lafayette Indiana, 47907–2107 USA jsv@purdue.edu Boston – Delft Foundations and Trends R in Theoretical Computer Science Published, sold and distributed by: now Publishers Inc. PO Box 1024 Hanover, MA 02339 USA Tel. +1-781-985-4510 www.nowpublishers.com sales@nowpublishers.com Outside North America: now Publishers Inc. PO Box 179 2600 AD Delft The Netherlands Tel. +31-6-51115274 The preferred citation for this publication is J. S. Vitter, Algorithms and Data Structures for External Memory, Foundation and Trends R in Theoretical Computer Science, vol 2, no 4, pp 305–474, 2006 ISBN: 978-1-60198-106-6 c 2008 J. S. Vitter All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, mechanical, photocopying, recording or otherwise, without prior written permission of the publishers. Photocopying. In the USA: This journal is registered at the Copyright Clearance Cen- ter, Inc., 222 Rosewood Drive, Danvers, MA 01923. Authorization to photocopy items for internal or personal use, or the internal or personal use of specific clients, is granted by now Publishers Inc. for users registered with the Copyright Clearance Center (CCC). The ‘services’ for users can be found on the internet at: www.copyright.com For those organizations that have been granted a photocopy license, a separate system of payment has been arranged. Authorization does not extend to other kinds of copy- ing, such as that for general distribution, for advertising or promotional purposes, for creating new collective works, or for resale. In the rest of the world: Permission to pho- tocopy must be obtained from the copyright owner. Please apply to now Publishers Inc., PO Box 1024, Hanover, MA 02339, USA; Tel. +1-781-871-0245; www.nowpublishers.com; sales@nowpublishers.com now Publishers Inc. has an exclusive license to publish this material worldwide. Permission to use this content must be obtained from the copyright license holder. Please apply to now Publishers, PO Box 179, 2600 AD Delft, The Netherlands, www.nowpublishers.com; e-mail: sales@nowpublishers.com Foundations and Trends R in Theoretical Computer Science Volume 2 Issue 4, 2006 Editorial Board Editor-in-Chief: Madhu Sudan Department of CS and EE MIT, Stata Center, Room G640 32 Vassar Street, Cambridge MA 02139, USA madhu@mit.edu Editors Bernard Chazelle (Princeton) Oded Goldreich (Weizmann Inst.) Shafi Goldwasser (MIT and Weizmann Inst.) Jon Kleinberg (Cornell University) L´aszl´oLov´asz (Microsoft Research) Christos Papadimitriou (UC. Berkeley) Prabhakar Raghavan (Yahoo! Research) Peter Shor (MIT) Madhu Sudan (MIT) ´Eva Tardos (Cornell University) Avi Wigderson (IAS) Editorial Scope Foundations and Trends R in Theoretical Computer Science will publish survey and tutorial articles in the following topics: • Algorithmic game theory • Computational algebra • Computational aspects of combinatorics and graph theory • Computational aspects of communication • Computational biology • Computational complexity • Computational geometry • Computational learning • Computational Models and Complexity • Computational Number Theory • Cryptography and information security • Data structures • Database theory • Design and analysis of algorithms • Distributed computing • Information retrieval • Operations Research • Parallel algorithms • Quantum Computation • Randomness in Computation Information for Librarians Foundations and Trends R in Theoretical Computer Science, 2006, Volume 2, 4 issues. ISSN paper version 1551-305X. ISSN online version 1551-3068. Also available as a combined paper and online subscription. Foundations and Trends R in Theoretical Computer Science Vol. 2, No. 4 (2006) 305–474 c 2008 J. S. Vitter DOI: 10.1561/0400000014 Algorithms and Data Structures for External Memory Jeffrey Scott Vitter Department of Computer Science, Purdue University, West Lafayette, Indiana, 47907–2107, USA, jsv@purdue.edu Abstract Data sets in large applications are often too massive to fit completely inside the computer’s internal memory. The resulting input/output communication (or I/O) between fast internal memory and slower external memory (such as disks) can be a major performance bottle- neck. In this manuscript, we survey the state of the art in the design and analysis of algorithms and data structures for external memory (or EM for short), where the goal is to exploit locality and parallelism in order to reduce the I/O costs. We consider a variety of EM paradigms for solving batched and online problems efficiently in external memory. For the batched problem of sorting and related problems like per- muting and fast Fourier transform, the key paradigms include distribu- tion and merging. The paradigm of disk striping offers an elegant way to use multiple disks in parallel. For sorting, however, disk striping can be nonoptimal with respect to I/O, so to gain further improvements we discuss distribution and merging techniques for using the disks inde- pendently. We also consider useful techniques for batched EM problems involving matrices, geometric data, and graphs. In the online domain, canonical EM applications include dictionary lookup and range searching. The two important classes of indexed data structures are based upon extendible hashing and B-trees. The paradigms of filtering and bootstrapping provide convenient means in online data structures to make effective use of the data accessed from disk. We also re-examine some of the above EM problems in slightly different settings, such as when the data items are moving, when the data items are variable-length such as character strings, when the data structure is compressed to save space, or when the allocated amount of internal memory can change dynamically. Programming tools and environments are available for simplifying the EM programming task. We report on some experiments in the domain of spatial databases using the TPIE system (Transparent Par- allel I/O programming Environment). The newly developed EM algo- rithms and data structures that incorporate the paradigms we discuss are significantly faster than other methods used in practice. Preface I first became fascinated about the tradeoffs between computing and memory usage while a graduate student at Stanford University. Over the following years, this theme has influenced much of what I have done professionally, not only in the field of external memory algorithms, which this manuscript is about, but also on other topics such as data compression, data mining, databases, prefetching/caching, and random sampling. The reality of the computer world is that no matter how fast com- puters are and no matter how much data storage they provide, there will always be a desire and need to push the envelope. The solution is not to wait for the next generation of computers, but rather to examine the fundamental constraints in order to understand the limits of what is possible and to translate that understanding into effective solutions. In this manuscript you will consider a scenario that arises often in large computing applications, namely, that the relevant data sets are simply too massive to fit completely inside the computer’s internal memory and must instead reside on disk. The resulting input/output communication (or I/O) between fast internal memory and slower external memory (such as disks) can be a major performance ix x Preface bottleneck. This manuscript provides a detailed overview of the design and analysis of algorithms and data structures for external memory (or simply EM ), where the goal is to exploit locality and parallelism in order to reduce the I/O costs. Along the way, you will learn a variety of EM paradigms for solving batched and online problems efficiently. For the batched problem of sorting and related problems like per- muting and fast Fourier transform, the two fundamental paradigms are distribution and merging. The paradigm of disk striping offers an elegant way to use multiple disks in parallel. For sorting, however, disk striping can be nonoptimal with respect to I/O, so to gain fur- ther improvements we discuss distribution and merging techniques for using the disks independently, including an elegant duality property that yields state-of-the-art algorithms. You will encounter other useful techniques for batched EM problems involving matrices (such as matrix multiplication and transposition), geometric data (such as finding inter- sections and constructing convex hulls) and graphs (such as list ranking, connected components, topological sorting, and shortest paths). In the online domain, which involves constructing data structures to answer queries, we discuss two canonical EM search applications: dictionary lookup and range searching. Two important paradigms for developing indexed data structures for these problems are hash- ing (including extendible hashing) and tree-based search (including B-trees). The paradigms of filtering and bootstrapping provide con- venient means in online data structures to make effective use of the data accessed from disk. You will also be exposed to some of the above EM problems in slightly different settings, such as when the data items are moving, when the data items are variable-length (e.g., strings of text), when the data structure is compressed to save space, and when the allocated amount of internal memory can change dynamically. Programming tools and environments are available for simplifying the EM programming task. You will see some experimental results in the domain of spatial databases using the TPIE system, which stands for Transparent Parallel I/O programming Environment. The newly developed EM algorithms and data structures that incorporate the paradigms discussed in this manuscript are significantly faster than other methods used in practice. Preface xi I would like to thank my colleagues for several helpful comments, especially Pankaj Agarwal, Lars Arge, Ricardo Baeza-Yates, Adam Buchsbaum, Jeffrey Chase, Michael Goodrich, Wing-Kai Hon, David Hutchinson, Gonzalo Navarro, Vasilis Samoladas, Peter Sanders, Rahul Shah, Amin Vahdat, and Norbert Zeh. I also thank the referees and edi- tors for their help and suggestions, as well as the many wonderful staff members I’ve had the privilege to work with. Figure 1.1 is a modified version of a figure by Darren Vengroff, and Figures 2.1 and 5.2 come from [118, 342]. Figures 5.4–5.8, 8.2–8.3, 10.1, 12.1, 12.2, 12.4, and 14.1 are modified versions of figures in [202, 47, 147, 210, 41, 50, 158], respec- tively. This manuscript is an expanded and updated version of the article in ACM Computing Surveys, Vol. 33, No. 2, June 2001. I am very appre- ciative for the support provided by the National Science Foundation through research grants CCR–9522047, EIA–9870734, CCR–9877133, IIS–0415097, and CCF–0621457; by the Army Research Office through MURI grant DAAH04–96–1–0013; and by IBM Corporation. Part of this manuscript was done at Duke University, Durham, North Carolina; the University of Aarhus, ˚Arhus, Denmark; INRIA, Sophia Antipolis, France; and Purdue University, West Lafayette, Indiana. I especially want to thank my wife Sharon and our three kids (or more accurately, young adults) Jillian, Scott, and Audrey for their ever- present love and support. I most gratefully dedicate this manuscript to them. West Lafayette, Indiana —J.S.V. March 2008 Contents 1 Introduction 1 1.1 Overview 4 2 Parallel Disk Model (PDM) 9 2.1 PDM and Problem Parameters 11 2.2 Practical Modeling Considerations 14 2.3 Related Models, Hierarchical Memory, and Cache-Oblivious Algorithms 16 3 Fundamental I/O Operations and Bounds 21 4 Exploiting Locality and Load Balancing 25 4.1 Locality Issues with a Single Disk 26 4.2 Disk Striping and Parallelism with Multiple Disks 27 5 External Sorting and Related Problems 29 5.1 Sorting by Distribution 31 5.2 Sorting by Merging 38 5.3 Prefetching, Caching, and Applications to Sorting 42 5.4 A General Simulation for Parallel Disks 52 5.5 Handling Duplicates: Bundle Sorting 53 5.6 Permuting 54 5.7 Fast Fourier Transform and Permutation Networks 54 xiii xiv Contents 6 Lower Bounds on I/O 57 6.1 Permuting 57 6.2 Lower Bounds for Sorting and Other Problems 61 7 Matrix and Grid Computations 65 7.1 Matrix Operations 65 7.2 Matrix Transposition 66 8 Batched Problems in Computational Geometry 69 8.1 Distribution Sweep 71 8.2 Other Batched Geometric Problems 76 9 Batched Problems on Graphs 77 9.1 Sparsification 80 9.2 Special Cases 81 9.3 Sequential Simulation of Parallel Algorithms 81 10 External Hashing for Online Dictionary Search 83 10.1 Extendible Hashing 84 10.2 Directoryless Methods 87 10.3 Additional Perspectives 87 11 Multiway Tree Data Structures 89 11.1 B-trees and Variants 89 11.2 Weight-Balanced B-trees 92 11.3 Parent Pointers and Level-Balanced B-trees 93 11.4 Buffer Trees 95 12 Spatial Data Structures and Range Search 99 12.1 Linear-Space Spatial Structures 102 12.2 R-trees 103 Contents xv 12.3 Bootstrapping for 2-D Diagonal Corner and Stabbing Queries 107 12.4 Bootstrapping for Three-Sided Orthogonal 2-D Range Search 110 12.5 General Orthogonal 2-D Range Search 112 12.6 Other Types of Range Search 114 12.7 Lower Bounds for Orthogonal Range Search 116 13 Dynamic and Kinetic Data Structures 119 13.1 Dynamic Methods for Decomposable Search Problems 119 13.2 Continuously Moving Items 121 14 String Processing 123 14.1 Inverted Files 123 14.2 String B-Trees 124 14.3 Suffix Trees and Suffix Arrays 127 14.4 Sorting Strings 127 15 Compressed Data Structures 129 15.1 Data Representations and Compression Models 130 15.2 External Memory Compressed Data Structures 133 16 Dynamic Memory Allocation 139 17 External Memory Programming Environments 141 Conclusions 145 Notations and Acronyms 147 References 151 1 Introduction The world is drowning in data! In recent years, we have been deluged by a torrent of data from a variety of increasingly data-intensive applica- tions, including databases, scientific computations, graphics, entertain- ment, multimedia, sensors, web applications, and email. NASA’s Earth Observing System project, the core part of the Earth Science Enterprise (formerly Mission to Planet Earth), produces petabytes (1015 bytes) of raster data per year [148]. A petabyte corresponds roughly to the amount of information in one billion graphically formatted books. The online databases of satellite images used by Microsoft TerraServer (part of MSN Virtual Earth) [325] and Google Earth [180] are multiple ter- abytes (1012 bytes) in size. Wal-Mart’s sales data warehouse contains over a half petabyte (500 terabytes) of data. A major challenge is to develop mechanisms for processing the data, or else much of the data will be useless. For reasons of economy, general-purpose computer systems usually contain a hierarchy of memory levels, each level with its own cost and performance characteristics. At the lowest level, CPU registers and caches are built with the fastest but most expensive memory. For internal main memory, dynamic random access memory (DRAM) is 1 2 Introduction Fig. 1.1 The memory hierarchy of a typical uniprocessor system, including registers, instruc- tion cache, data cache (level 1 cache), level 2 cache, internal memory, and disks. Some sys- tems have in addition a level 3 cache, not shown here. Memory access latency ranges from less than one nanosecond (ns, 10−9 seconds) for registers and level 1 cache to several mil- liseconds (ms, 10−3 seconds) for disks. Typical memory sizes for each level of the hierarchy are shown at the bottom. Each value of B listed at the top of the figure denotes a typical block transfer size between two adjacent levels of the hierarchy. All sizes are given in units of bytes (B), kilobytes (KB, 103 B), megabytes (MB, 106 B), gigabytes (GB, 109 B), and petabytes (PB, 1015 B). (In the PDM model defined in Chapter 2, we measure the block size B in units of items rather than in units of bytes.) In this figure, 8 KB is the indicated physical block transfer size between internal memory and the disks. However, in batched applications we often use a substantially larger logical block transfer size. typical. At a higher level, inexpensive but slower magnetic disks are used for external mass storage, and even slower but larger-capacity devices such as tapes and optical disks are used for archival storage. These devices can be attached via a network fabric (e.g., Fibre Channel or iSCSI) to provide substantial external storage capacity. Figure 1.1 depicts a typical memory hierarchy and its characteristics. Most modern programming languages are based upon a program- ming model in which memory consists of one uniform address space. The notion of virtual memory allows the address space to be far larger than what can fit in the internal memory of the computer. Programmers have a natural tendency to assume that all memory references require the same access time. In many cases, such an assumption is reasonable (or at least does not do harm), especially when the data sets are not large. The utility and elegance of this programming model are to a large extent why it has flourished, contributing to the productivity of the software industry. 3 However, not all memory references are created equal. Large address spaces span multiple levels of the memory hierarchy, and accessing the data in the lowest levels of memory is orders of magnitude faster than accessing the data at the higher levels. For example, loading a register can take a fraction of a nanosecond (10−9 seconds), and accessing internal memory takes several nanoseconds, but the latency of access- ing data on a disk is multiple milliseconds (10−3 seconds), which is about one million times slower! In applications that process massive amounts of data, the Input/Output communication (or simply I/O) between levels of memory is often the bottleneck. Many computer programs exhibit some degree of locality in their pattern of memory references: Certain data are referenced repeatedly for a while, and then the program shifts attention to other sets of data. Modern operating systems take advantage of such access patterns by tracking the program’s so-called “working set”—avague notion that roughly corresponds to the recently referenced data items [139]. If the working set is small, it can be cached in high-speed memory so that access to it is fast. Caching and prefetching heuristics have been developed to reduce the number of occurrences of a “fault,” in which the referenced data item is not in the cache and must be retrieved by an I/O from a higher level of memory. For example, in a page fault, an I/O is needed to retrieve a disk page from disk and bring it into internal memory. Caching and prefetching methods are typically designed to be general-purpose, and thus they cannot be expected to take full advan- tage of the locality present in every computation. Some computations themselves are inherently nonlocal, and even with omniscient cache management decisions they are doomed to perform large amounts of I/O and suffer poor performance. Substantial gains in performance may be possible by incorporating locality directly into the algorithm design and by explicit management of the contents of each level of the memory hierarchy, thereby bypassing the virtual memory system. We refer to algorithms and data structures that explicitly manage data placement and movement as external memory (or EM ) algorithms and data structures. Some authors use the terms I/O algorithms or out-of-core algorithms. We concentrate in this manuscript on the I/O 4 Introduction communication between the random access internal memory and the magnetic disk external memory, where the relative difference in access speeds is most apparent. We therefore use the term I/O to designate the communication between the internal memory and the disks. 1.1 Overview In this manuscript, we survey several paradigms for exploiting local- ity and thereby reducing I/O costs when solving problems in external memory. The problems we consider fall into two general categories: (1) Batched problems, in which no preprocessing is done and the entire file of data items must be processed, often by streaming the data through the internal memory in one or more passes. (2) Online problems, in which computation is done in response to a continuous series of query operations. A common tech- nique for online problems is to organize the data items via a hierarchical index, so that only a very small portion of the data needs to be examined in response to each query. The data being queried can be either static, which can be pre- processed for efficient query processing, or dynamic, where the queries are intermixed with updates such as insertions and deletions. We base our approach upon the parallel disk model (PDM) described in the next chapter. PDM provides an elegant and reason- ably accurate model for analyzing the relative performance of EM algo- rithms and data structures. The three main performance measures of PDM are the number of (parallel) I/O operations, the disk space usage, and the (parallel) CPU time. For reasons of brevity, we focus on the first two measures. Most of the algorithms we consider are also efficient in terms of CPU time. In Chapter 3, we list four fundamental I/O bounds that pertain to most of the problems considered in this manuscript. In Chapter 4, we show why it is crucial for EM algorithms to exploit locality, and we discuss an automatic load balancing technique called disk striping for using multiple disks in parallel. 1.1 Overview 5 Our general goal is to design optimal algorithms and data struc- tures, by which we mean that their performance measures are within a constant factor of the optimum or best possible.1 In Chapter 5, we look at the canonical batched EM problem of external sorting and the related problems of permuting and fast Fourier transform. The two important paradigms of distribution and merging — as well as the notion of duality that relates the two — account for all well-known external sorting algorithms. Sorting with a single disk is now well under- stood, so we concentrate on the more challenging task of using multiple (or parallel) disks, for which disk striping is not optimal. The challenge is to guarantee that the data in each I/O are spread evenly across the disks so that the disks can be used simultaneously. In Chapter 6, we cover the fundamental lower bounds on the number of I/Os needed to perform sorting and related batched problems. In Chapter 7, we discuss grid and linear algebra batched computations. For most problems, parallel disks can be utilized effectively by means of disk striping or the parallel disk techniques of Chapter 5, and hence we restrict ourselves starting in Chapter 8 to the concep- tually simpler single-disk case. In Chapter 8, we mention several effec- tive paradigms for batched EM problems in computational geometry. The paradigms include distribution sweep (for spatial join and find- ing all nearest neighbors), persistent B-trees (for batched point loca- tion and visibility), batched filtering (for 3-D convex hulls and batched point location), external fractional cascading (for red-blue line segment intersection), external marriage-before-conquest (for output-sensitive convex hulls), and randomized incremental construction with grada- tions (for line segment intersections and other geometric problems). In Chapter 9, we look at EM algorithms for combinatorial problems on graphs, such as list ranking, connected components, topological sort- ing, and finding shortest paths. One technique for constructing I/O- efficient EM algorithms is to simulate parallel algorithms; sorting is used between parallel steps in order to reblock the data for the simu- lation of the next parallel step. 1 In this manuscript we generally use the term “optimum” to denote the absolute best possible and the term “optimal” to mean within a constant factor of the optimum. 6 Introduction In Chapters 10–12, we consider data structures in the online setting. The dynamic dictionary operations of insert, delete, and lookup can be implemented by the well-known method of hashing. In Chapter 10, we examine hashing in external memory, in which extra care must be taken to pack data into blocks and to allow the number of items to vary dynamically. Lookups can be done generally with only one or two I/Os. Chapter 11 begins with a discussion of B-trees, the most widely used online EM data structure for dictionary operations and one-dimensional range queries. Weight-balanced B-trees provide a uniform mechanism for dynamically rebuilding substructures and are useful for a variety of online data structures. Level-balanced B-trees permit maintenance of parent pointers and support cut and concatenate operations, which are used in reachability queries on monotone subdivisions. The buffer tree is a so-called “batched dynamic” version of the B-tree for efficient implementation of search trees and priority queues in EM sweep line applications. In Chapter 12, we discuss spatial data structures for mul- tidimensional data, especially those that support online range search. Multidimensional extensions of the B-tree, such as the popular R-tree and its variants, use a linear amount of disk space and often perform well in practice, although their worst-case performance is poor. A non- linear amount of disk space is required to perform 2-D orthogonal range queries efficiently in the worst case, but several important special cases of range searching can be done efficiently using only linear space. A use- ful design paradigm for EM data structures is to “externalize” an effi- cient data structure designed for internal memory; a key component of how to make the structure I/O-efficient is to “bootstrap” a static EM data structure for small-sized problems into a fully dynamic data structure of arbitrary size. This paradigm provides optimal linear-space EM data structures for several variants of 2-D orthogonal range search. In Chapter 13, we discuss some additional EM approaches useful for dynamic data structures, and we also investigate kinetic data struc- tures, in which the data items are moving. In Chapter 14, we focus on EM data structures for manipulating and searching text strings. In many applications, especially those that operate on text strings, the data are highly compressible. Chapter 15 discusses ways to develop data structures that are themselves compressed, but still fast to query. 1.1 Overview 7 Table 1.1 Paradigms for I/O efficiency discussed in this manuscript. Paradigm Section Batched dynamic processing 11.4 Batched filtering 8 Batched incremental construction 8 Bootstrapping 12 Buffer trees 11.4 B-trees 11, 12 Compression 15 Decomposable search 13.1 Disk striping 4.2 Distribution 5.1 Distribution sweeping 8 Duality 5.3 External hashing 10 Externalization 12.3 Fractional cascading 8 Filtering 12 Lazy updating 11.4 Load balancing 4 Locality 4.1 Marriage before conquest 8 Merging 5.2 Parallel block transfer 4.2 Parallel simulation 9 Persistence 11.1 Random sampling 5.1 R-trees 12.2 Scanning (or streaming) 2.2 Sparsification 9 Time-forward processing 11.4 In Chapter 16, we discuss EM algorithms that adapt optimally to dynamically changing internal memory allocations. In Chapter 17, we discuss programming environments and tools that facilitate high-level development of efficient EM algorithms. We focus primarily on the TPIE system (Transparent Parallel I/O Environment), which we use in the various timing experiments in this manuscript. We conclude with some final remarks and observations in the Conclusions. Table 1.1 lists several of the EM paradigms discussed in this manuscript. 2 Parallel Disk Model (PDM) When a data set is too large to fit in internal memory, it is typically stored in external memory (EM) on one or more magnetic disks. EM algorithms explicitly control data placement and transfer, and thus it is important for algorithm designers to have a simple but reasonably accurate model of the memory system’s characteristics. A magnetic disk consists of one or more platters rotating at con- stant speed, with one read/write head per platter surface, as shown in Figure 2.1. The surfaces of the platters are covered with a mag- netizable material capable of storing data in nonvolatile fashion. The read/write heads are held by arms that move in unison. When the arms are stationary, each read/write head traces out a concentric circle on its platter called a track. The vertically aligned tracks that correspond to a given arm position are called a cylinder. For engineering reasons, data to and from a given disk are typically transmitted using only one read/write head (i.e., only one track) at a time. Disks use a buffer for caching and staging data for I/O transfer to and from internal memory. To store or retrieve a data item at a certain address on disk, the read/write heads must mechanically seek to the correct cylinder and then wait for the desired data to pass by on a particular track. The seek 9 10 Parallel Disk Model (PDM) platter track arms read/write head spindle (a) (b) tracks Fig. 2.1 Magnetic disk drive: (a) Data are stored on magnetized platters that rotate at a constant speed. Each platter surface is accessed by an arm that contains a read/write head, and data are stored on the platter in concentric circles called tracks. (b) The arms are physically connected so that they move in unison. The tracks (one per platter) that are addressable when the arms are in a fixed position are collectively referred to as a cylinder. time to move from one random cylinder to another is often on the order of 3 to 10 milliseconds, and the average rotational latency, which is the time for half a revolution, has the same order of magnitude. Seek time can be avoided if the next access is on the current cylinder. The latency for accessing data, which is primarily a combination of seek time and rotational latency, is typically on the order of several milliseconds. In contrast, it can take less than one nanosecond to access CPU registers and cache memory — more than one million times faster than disk access! Once the read/write head is positioned at the desired data location, subsequent bytes of data can be stored or retrieved as fast as the disk rotates, which might correspond to over 100 megabytes per second. We can thus amortize the relatively long initial delay by transferring a large contiguous group of data items at a time. We use the term block to refer to the amount of data transferred to or from one disk in a single I/O operation. Block sizes are typically on the order of several kilobytes and are often larger for batched applications. Other levels of the memory hierarchy have similar latency issues and as a result also 2.1 PDM and Problem Parameters 11 use block transfer. Figure 1.1 depicts typical memory sizes and block sizes for various levels of memory. Because I/O is done in units of blocks, algorithms can run con- siderably faster when the pattern of memory accesses exhibit locality of reference as opposed to a uniformly random distribution. However, even if an application can structure its pattern of memory accesses and exploit locality, there is still a substantial access gap between internal and external memory performance. In fact the access gap is growing, since the latency and bandwidth of memory chips are improving more quickly than those of disks. Use of parallel processors (or multicores) further widens the gap. As a result, storage systems such as RAID deploy multiple disks that can be accessed in parallel in order to get additional bandwidth [101, 194]. In the next section, we describe the high-level parallel disk model (PDM), which we use throughout this manuscript for the design and analysis of EM algorithms and data structures. In Section 2.2, we con- sider some practical modeling issues dealing with the sizes of blocks and tracks and the corresponding parameter values in PDM. In Section 2.3, we review the historical development of models of I/O and hierarchical memory. 2.1 PDM and Problem Parameters We can capture the main properties of magnetic disks and multiple disk systems by the commonly used parallel disk model (PDM) introduced by Vitter and Shriver [345]. The two key mechanisms for efficient algo- rithm design in PDM are locality of reference (which takes advantage of block transfer) and parallel disk access (which takes advantage of multiple disks). In a single I/O, each of the D disks can simultaneously transfer a block of B contiguous data items. PDM uses the following main parameters: N = problem size (in units of data items); M = internal memory size (in units of data items); B = block transfer size (in units of data items); 12 Parallel Disk Model (PDM) D = number of independent disk drives; P = number of CPUs, where M
还剩190页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 6 金币 [ 分享pdf获得金币 ] 1 人已下载

下载pdf

pdf贡献者

blue_kite

贡献于2012-11-24

下载需要 6 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf