In-depth understanding of computer systems 04 - storage

Table of contents

Series Article Directory

1. Storage hierarchy and storage technology

1. Storage Hierarchy

2. Storage technology

2. Disk storage

1. Disk structure

2. Disk capacity

2.1 Recording area

2.2 Disk Capacity Calculation

3. Disk operations (read and write access)

4. Logical disk block

3. Locality

Fourth, the memory hierarchy

1. Hierarchical structure theory

1.1 Basic idea of ​​memory hierarchy

1.2 Why do memory hierarchies work?

1.3 Important points

2. Cache Cache

2.1 Cache-related concepts

2.2 Mapping

3. Cache mapping example

Summarize


Series Article Directory

This series of blogs focuses on the core content of the computer system (2) course of Shenzhen University, and the reference bibliography "In-depth understanding of computer systems" (if you have any questions, please discuss and point out in the comment area, or contact me directly by private message).

The first chapter  in-depth understanding of computer system 01 - computer system roaming

The second chapter  in-depth understanding of computer systems 02 - the representation and processing of information_@李敬如的博客-CSDN博客

Chapter 3  In-depth understanding of computer systems 03 - machine-level representation of programs

Chapter 4 In-depth understanding of computer systems 04 - storage


synopsis

This blog mainly introduces the relevant knowledge of in-depth computer system chapter 6 storage.


1. Storage hierarchy and storage technology

1. Storage Hierarchy

An example storage hierarchy is as follows:

The impact of data in different locations on access speed

2. Storage technology

Random access memory (RAM) is divided into static (SRAM) and dynamic (DRAM), the differences are as follows:

Tips: Continuous means no need to refresh.

Volatile memory (RAM): RAM cannot retain data when power is turned off.

Non-volatile memory (NVM, eg flash memory): Computer memory in which stored data does not disappear when the power is turned off.

2. Disk storage

1. Disk structure

The disk consists of double-sided (default) platters
Ring tracks are densely arranged on each disk
Multiple sectors on each track , each sector separated by a gap

2. Disk capacity

2.1 Recording area

Modern disks divide cylinders into disjoint subsets called recording areas

Tips: When calculating capacity, we use the average number of sectors / tracks . The inner sector of the multi-zone record is smaller than the outer sector, and the original disk is equal

2.2 Disk Capacity Calculation

Disk capacity = ( number of bytes / sector ) x ( average number of sectors / track ) x  ( number of tracks / disk surface ) x ( number of disk surfaces / disk ) x  ( disk / disk )

Examples are as follows:

Tips: The disk surface/disc may be hidden, generally it is 2, don’t miss it. 

3. Disk operations (read and write access)

The disk access process is as follows:

Average time to access a sector  = average seek time + average rotation time + average data transfer time

Access file time = average time x number of sectors

Seek time: the time it takes for the head to move from one cylinder to another

Rotation time: After the disk rotates, the time for the target sector to reach the head

Data transfer time: the time required to transfer each sector

An example of disk access is as follows:

4. Logical disk block

¢ Modern disks convert complex physical structures into simple abstract views :
§ A set of contiguous sectors is packed into a b-sized logical disk block
¢ The mapping between logical blocks and physical blocks
§ are maintained by the disk controller (composed of hardware and firmware)
§Convert the read and write request addresses into triplets: ( disk surface , track , sector ) .
¢ Allows the controller to reserve a portion of free cylinders from each region
§ Distinguish between " formatted capacity " and " maximum capacity"

Examples of logical disk blocks are as follows:

3. Locality

Principle of locality: Programs tend to use data and instructions that are closer to their addresses in the most recent period of time.

Temporal locality: recently accessed data or instructions may be accessed in the future

Spatial locality: the area near the current access address may be accessed in the near future

Locality sample code is as follows:

Tips: For row-by-row storage, the second code has good locality when N is small (not all cases are bad). 

Fourth, the memory hierarchy

1. Hierarchical structure theory

1.1 Basic idea of ​​memory hierarchy

For each k, the faster and smaller storage device at level k acts as a cache for the larger and slower storage device at k+1 etc. (low to high)

1.2 Why do memory hierarchies work?

Due to the principle of locality , the program accesses the data of the kth layer more frequently than the data of the k+1th layer. Therefore, storage devices at layer k+1 are slower, larger, and cheaper.

1.3 Important points

The memory hierarchy builds a high-capacity storage pool that is as cheap as the underlying memory and as fast as the top-level memory .

2. Cache Cache

2.1 Cache-related concepts

Cache: A smaller, faster storage device. As a buffer for larger, slower storage devices. Solve the problem of speed matching between CPU and main memory.

Macro: Capacity -> Group -> Block

Hit: The requested data is in the Cache, improving access speed.

Miss: The requested data is not in the Cache, read from the main memory, and update the Cache.

1. Cold miss: Cache is empty at the beginning, the first reference to the block

2. Capacity miss: Occurs when the set of active cache blocks (working set) is larger than the cache

3. Conflict miss: There is an empty space available, the block also tries to occupy a filled row

Qualitative conclusions of parameters on performance:

Note: Many ways to reduce miss rate increase hit time or miss overhead (penalty)

1. Increasing the cache capacity will increase the hit rate and may increase the hit time.

2. Increasing the block size will help improve the hit rate, but if the block size is too large and the number of blocks decreases too much, the hit rate will also be reduced and the transmission time will be increased.

3. Increasing the degree of associativity helps to reduce row conflicts and improve the hit rate, but the increase in hardware complexity will increase the penalty time.

4. Increasing the group size reduces the possibility of jitter due to collision misses, but increases the cost.

A more complete optimization strategy: ​​​​[Architecture Series] Improve the Cache hit rate_槑! Blog-CSDN Blog_Methods to Improve Cache Hit Ratio

Cache example:

Cache-friendly code: principles - make full use of locality

Method: Try to repeatedly quote the same or similar data, as follows:

Make the most common cases run fast: focus on loops in core functions

Minimize the number of cache misses inside each loop: repeated references to local variables are good (temporal locality), sequential reference patterns with stride 1 are good (spatial locality)

Tips: Using Cache can speed up memory access

2.2 Mapping

Map the main memory block and Cache line in the following three ways

1. Direct association (Direct): Each main memory block is mapped to a fixed row of Cache (inflexible, low Cache utilization, prone to conflicts)

2. Set Associate (Set Associate): Each main memory block is mapped to any row in the Cache fixed group (direct between groups, full associative within a group)

3. Full Associate: each main memory block is mapped to any line of the Cache (high Cache utilization, low block conflict rate)

3. Cache mapping example

How to know which address in the memory the data item in the cache corresponds to? Storage mark tag

How to ensure that valid information is included? Valid bit Valid bit: 1 = in 0 = not in the initial value is 0

If the access sequence is: 22, 26, 22, 26, 16, 3, 16, please draw the state of the last cache and calculate its hit rate/miss rate

The final state is as follows: Hit rate 3/7 (3, 4, 7) 

Refetch 18, the state changes as follows (conflict miss changes but Miss):

Summarize

The above is the core knowledge of in-depth understanding of the sixth chapter of computer systems - storage. In the sixth chapter, it mainly focuses on the introduction of the concepts in the system (computer system information, procedures, workflow, topics, etc.).

Guess you like

Origin blog.csdn.net/weixin_51426083/article/details/125060253