Collection
zero Useful+1
zero

storage system

Announce Upload video
An important part of a computer
Storage system refers to all kinds of programs and data stored in the computer storage device , control components and management information scheduling equipment (hardware) and algorithms (software). [1]
Chinese name
storage system [2]
Foreign name
Storage System [3]
Core
storage [4]
Features
Computer Information Memory [2]
Role
Write and read information (programs and data) required for computer operation [2]

brief introduction

Announce
edit
Storage system is one of the important parts of computer. The storage system provides the ability to write and read the information (programs and data) required by the computer to realize the information memory function of the computer. modern computer system Commonly used register Cache Multi level storage architecture of main storage and external storage. [2]
The core of computer storage system is storage Memory is an indispensable memory device for storing programs and data in computers. [4]
Internal memory (referred to as memory) mainly stores the programs and data required by the current work of the computer, including cache (referred to as cache) and main memory. At present, memory is mainly composed of Semiconductor memory External memory (External memory for short) mainly includes magnetic memory, optical memory and semiconductor memory. The storage media include hard disk, optical disk, magnetic tape and mobile memory. [2]
Modern computer system Multilevel storage system The structure is shown in Figure 6-1. The higher the top, the closer to the CPU, the faster the memory speed, the smaller the capacity, and the higher the price per unit. This kind of organization can better solve the contradiction between storage capacity, speed and cost, and provide a layer of storage that is logically equivalent to the cheapest in price and capacity, while the access speed is close to the fastest layer of storage in the storage system. [2]
Figure 6-1

development

Announce
edit
It has been more than half a century since IBM made the first hard disk in 1956. In the past half century, storage media and storage systems have made great progress. [5]
In the early days, data storage generally used disk arrays and other devices as peripherals, which were stored around servers through direct connection. In recent years, with the development of network technology, the data reading range of the server has also been greatly expanded, and the current network storage has gradually been realized. Compared with traditional storage, network storage has more prominent advantages. It is not only easy to install and cheap, but also can expand storage devices on a large scale, thus effectively meeting the storage space requirements of massive data storage. However, network storage consumes a lot of network resources, which is a difficult problem. For this reason, SAN storage architecture has gradually emerged. [6]

Traditional storage system

At present, there are three main architectures of traditional storage systems, including DAS, NAS and SAN. [5]
one DAS (Direct Attached Storage)
As the name implies, this is a storage method that directly connects the hard disk and other storage media to the host through the bus adapter. There is usually no network device between the storage device and the host. It can be said that DAS is the most original and basic storage architecture, and it is also most common on personal computers and servers. DAS has the advantages of simple architecture, low cost, high read and write efficiency; The disadvantage is that the capacity is limited and difficult to share, so it is easy to form an "information island". [5]
two NAS (Network Attached Storage, network storage system)
NAS is a network storage system that provides a file level access interface. It usually uses NFS, SMB/CIFS and other network file sharing protocols for file access. NAS supports simultaneous access by multiple clients, providing servers with large capacity centralized storage, which also facilitates data sharing during service. [5]
three SAN (StorageAreaNetwork)
adopt Optical switches High speed network devices such as, etc. set up a special storage network between servers and storage devices such as disk arrays to provide high-performance storage systems. [5]
The difference between SAN and NAS is that it provides a block level access interface, and generally does not provide a file system at the same time. Generally, servers need to map SAN storage to local disks through SCSI and other access protocols, and then use them after creating file systems on them. At present, mainstream enterprise NAS or SAN storage products can generally provide terabytes of storage capacity, and high-end storage products can also provide up to several petabytes of storage capacity. [5]

Distributed storage system

Big data has led to explosive growth of data volume. Traditional centralized storage (such as NAS or SAN) cannot meet the requirements of big data in terms of capacity and performance. Therefore, distributed storage with excellent scalability has become the mainstream architecture of big data storage. Distributed storage mostly uses common hardware devices as infrastructure, so the storage cost per unit capacity has been greatly reduced. In addition, distributed storage also has different degrees of advantages in performance, maintainability and disaster tolerance. [5]
Distributed storage system Key technical problems to be solved include scalability, data redundancy Data consistency , global namespace cache, etc. In terms of architecture, distributed storage can generally be divided into C/S (Client Server) architecture and P2P (Peer to Peer) architecture. Of course, there are also some distributed storage in which these two architectures exist at the same time. [5]
Another common problem faced by distributed storage is how to organize and manage member nodes, and how to establish the mapping relationship between data and nodes. The dynamic addition or departure of member nodes is basically a normal state in distributed systems. [5]
Eric Brewer proposed the distributed system design in 2000 CAP theory It is pointed out that a distributed system cannot guarantee consistency, availability and partition tolerance at the same time. Therefore, any distributed storage system can only optimize two elements according to its specific business characteristics and requirements. Of course, in addition to the three dimensions of consistency, availability and partition tolerance, a distributed storage system often has different trade-offs in feature design according to the specific business, such as whether to need a cache module, whether to support a common file system interface, etc. [5]

cloud storage

cloud storage It is an online storage system provided by a third-party operator, such as an online disk for personal users and an enterprise oriented file, block or object storage system. The cloud storage operator is responsible for the deployment, operation and maintenance of the data center, and provides data storage to customers in the form of services. Cloud storage as cloud computing It is an extension and an important component of, providing data storage services of "on-demand allocation, pay as you go". Therefore, users of cloud storage do not need to build their own data center and infrastructure, nor need to care about the management and maintenance of the underlying storage system, and can dynamically expand or reduce their demand for storage capacity according to their business needs. [5]
Cloud storage centrally and uniformly deploys and manages storage systems through operators, reducing the cost of data storage, thus lowering the entry threshold of big data industry, and providing the possibility for small and medium-sized enterprises to enter the big data industry. For example, Dropbox, a famous online file storage service provider, is based on AWS (Amazon Web Services). Before the rise of cloud storage, it was almost impossible to start a startup like Dropbox. [5]
In fact, the storage systems used behind cloud storage mostly adopt distributed architecture, and cloud storage has encountered new problems and requirements in design due to its more new application scenarios. For example, most cloud storage management systems and access interfaces need to solve how to support multi tenant access, while in multi tenant environments, it is inevitable to solve a series of problems such as security and performance isolation. In addition, like cloud computing, cloud storage needs to solve a common problem about trust - how to technically ensure the privacy and security of enterprise business data on the third-party storage service platform is indeed a technical challenge that must be solved. [5]
Providing storage as a service to users, cloud storage generally adheres to simple and easy-to-use features on the access interface. For example, Amazon's S3 storage uses standard HTTP protocol . A simple REST interface is used to access data. Users can obtain, store, and delete data blocks through HTTP methods such as Get, Put, and Delete. For ease of operation, Amazon S3 does not provide operations such as modification or renaming; At the same time, Amazon S3 does not provide a complex data directory structure, but only a very simple hierarchical relationship; Users can create a bucket of their own, and all data is directly stored in this bucket. In addition, cloud storage also solves the problem of user sharing. The data in Amazon S3 storage is accessed and identified directly through the unique URL. Therefore, as long as other users are authorized, they can access the data through the URL. [5]
Storage virtualization It is an important technical foundation of cloud storage. It is a technology that unifies multiple isolated storage systems into an abstract resource pool by abstracting and encapsulating the physical characteristics of the underlying storage system. Through storage virtualization technology, cloud storage can realize many new features. For example, logical isolation of user data, thin configuration of storage space, etc. [5]

Hierarchy

Announce
edit
The hierarchical structure of the storage system can be divided into five levels: register Group, cache Cache Main storage Virtual memory and External memory Among them, the register group is always inside the CPU, and the programmer can access it through the register name. There is no bus operation, and the access speed is the fastest; The other four levels are all outside the CPU. Cache and main memory constitute an internal storage system. Programmers access the storage unit through bus addressing, and the access speed is lower than that of registers; Virtual memory is transparent to programmers; The external storage system has large capacity and needs to be I/O interface Exchange data with CPU, and the access speed is the slowest. [7]

Cache memory

Cache memory The original meaning of Cache is Access speed More than average Random access memory (RAM) A faster type of RAM. Generally speaking, it is not used as system main memory Dynamic random access memory (DRAM) technology, but using expensive but faster SRAM (SRAM) technology. [1]
Cache memory is a primary memory between main memory and CPU, which is composed of static memory chip (SRAM). It has small capacity but is much faster than main memory. Its most important indicator is its hit rate. The scheduling and transmission of information between cache memory and main memory is automatically carried out by hardware. [1]
Composition
Cache memory mainly consists of the following three parts: [1]
  1. one
    Cache memory: store instructions and data transferred from main memory. [1]
  2. two
    Address translation part: establish directory table to realize the conversion from main memory address to cache address. [1]
  3. three
    Replacement part: When the cache is full, replace the data according to a certain strategy, and modify the directory table in the address translation part. [1]
working principle
Cache memory is usually composed of high-speed memory Associative memory , replacement logic circuit and corresponding control circuit. In computer systems with cache memory, the address of the processor accessing the main memory is divided into three fields: line number, column number, and group address. Therefore, the main memory is logically divided into several lines: each line is divided into several storage unit groups; Each group contains several or dozens of words. The high-speed memory is also correspondingly divided into storage unit groups of rows and columns. Both have the same number of columns and the same size of groups, but the number of rows in high-speed memory is much less than that in main memory. [1]
Associative memory is used for address association and has a storage unit with the same number of rows and columns as high-speed memory. When a row storage unit group in a column of the main memory is called into an empty storage unit group in the same column of the high-speed memory, the storage unit in the location corresponding to the associative memory records the row number of the transferred storage unit group in the main memory. [1]
When the processor accesses the main memory, the hardware first automatically decodes the column number field of the access address, so as to compare all the row numbers of the associative memory column with the row number field of the access main memory address. If they are the same, it indicates that the main memory unit to be accessed has been in the high-speed memory, which is called hit. The hardware maps the address of the main memory to the address of the high-speed memory and performs the access operation; If they are all different, it indicates that the unit is not in the high-speed memory, which is called failure. The hardware will perform the operation of accessing the main memory and automatically transfer the main memory unit group where the unit is located to the empty storage unit group in the same column of high-speed memory, and at the same time, store the line number of the group in the main memory into the unit in the corresponding position of associative memory. [1]
When a failure occurs and there is no empty position in the corresponding column of high-speed memory, a group in the column will be eliminated to make room for the new incoming group, which is called replacement. The rule to determine the replacement is called the replacement algorithm. The commonly used replacement algorithms include the most recently unused algorithm (LRU), first in first out (FIFO), and random algorithm (RAND). The replacement logic circuit performs this function. In addition, when the write main memory operation is executed, the hit and failure are processed separately to maintain the consistency of the main memory and high-speed memory contents. [1]
Address mapping and translation
address mapping It refers to the correspondence between the address of a data in main memory and the address in cache. The following describes three address mapping methods: [1]
1. Fully connected mode
The rule of address mapping in fully associative mode is that any block in the main memory can be mapped to any block in the Cache. Its basic implementation ideas are: 1) Main memory and cache are divided into data blocks of the same size; 2) A data block in main memory can be loaded into any space in the cache. [1]
The directory table is stored in the associative memory, including three parts: the block address of the data block in the main memory, the block address and the effective bit (also called load bit) after being stored in the cache. Because it is fully associative, the capacity of the directory table should be the same as the number of cached blocks. [1]
The advantage of the fully connected mode is that the hit rate is relatively high, and the cache storage space utilization rate is high; The disadvantage is that when accessing the relevant memory, you have to compare it with the whole content every time, which is low speed and high cost, so there are few applications. [1]
2. Direct connection mode
The address mapping rule of the direct association mode is that a block in the main storage can only be mapped to a specific block in the Cache. The basic realization idea is: [1]
1) Main memory and cache are divided into data blocks of the same size; [1]
2) The main memory capacity shall be an integer multiple of the cache capacity. The main memory space shall be divided into zones according to the cache capacity. The number of blocks in each zone of main memory is equal to the total number of blocks in the cache; [1]
3) When a block in an area of main memory is stored in the cache, it can only be stored in a location with the same block number in the cache. [1]
The data blocks with the same block number in each area of main memory can be respectively transferred to the address with the same block number in the cache, but at the same time, only the blocks in one area can be stored in the cache. Since the two fields of the primary and cached block number and the address within the block are identical, only the area code of the imported block is recorded during directory registration. The directory table is stored in a high-speed small capacity memory and includes two fields: the area code and the effective bit of the data block in main memory. The capacity of the directory table is the same as the number of cached blocks. [1]
The advantage of the direct connection mode is that the address mapping mode is simple. When accessing data, you only need to check whether the area codes are equal, so you can get faster access speed and simple hardware devices; The disadvantages are frequent replacement operations and low hit rate. [1]
3. Group Associated Image Mode
The address image rule of group associated image mode is that a block in the main memory can only be stored in any block with the same group number in the cache. The basic realization idea is: [1]
1) Main memory and cache are divided into blocks according to the same size; [1]
2) Main memory and cache are grouped according to the same size: [1]
3) The main memory capacity is an integer multiple of the cache capacity. The main memory space is divided into zones according to the size of the cache area. The number of groups in each zone in the main memory is the same as the number of groups in the cache; [1]
4) When the data in main memory is transferred into the cache, the group numbers of main memory and cache should be the same, that is, a block in each area can only be stored in the space of the same group number in the cache, but the blocks in the group can be stored at will, that is, the direct image mode is used from the group in main memory to the group in the cache: the full associative image mode is used inside two corresponding groups. [1]
The conversion between main memory address and cache address is composed of two parts: group address is accessed by address in direct mapping mode; The block address is fully connected and accessed by content. [1]
The advantage of group associative mapping is that the collision probability of blocks is relatively low, the utilization rate of blocks is greatly improved, and the failure rate of blocks is significantly reduced. The disadvantage is that the implementation difficulty and cost are higher than that of direct mapping. [1]

Memory

Memory, also known as internal memory or main memory, is made of semiconductor devices. It is one of the important components of a computer and the storage space that can be directly addressed by the CPU. It is characterized by fast access rate. All programs in the computer run in memory, so the performance of memory has a great impact on the computer. The function of memory is to temporarily store the operation data in CPU and the data exchanged with external memory such as hard disk. As long as the computer is running, the CPU will transfer the data to the memory for calculation. When the calculation is completed, the CPU will transmit the results. [1]
Programs we usually use, such as Windows operating system Typing software, game software, etc. are generally installed on external storage such as hard disk, but their functions cannot be used only for this reason. They must be transferred into memory to run in order to really use their functions. We usually input a paragraph of text or play a game in memory. Just like in a study, the bookshelf and bookcase for storing books are equivalent to the external storage of the computer, and the desk we work on is the memory. Usually, we store a large amount of data to be permanently saved in external memory, and put some temporary or small amount of data and programs in memory. Of course, the performance of memory will directly affect the running speed of the computer. [1]
Memory includes read-only memory (ROM) and Random access memory (RAM). [1]
Read only memory (ROM)
Read only memory (ROM). When ROM is manufactured, information (data or programs) is stored and stored permanently. These information can only be read, not written. Even if the machine is powered off, the data will not be lost. ROM is generally used to store basic programs and data of the computer, such as BIOS ROM. Its physical shape is generally a DIP integrated block. [1]
Random Access Memory (RAM)
Random Access Memory (RAM) means that data can be read or written from RAM. When the machine is powered off, the data stored in it will be lost. The memory module (SIMM) we usually purchase or upgrade is used as the memory of the computer. It is a small circuit board that gathers the RAM chips together and plugs them into the memory slot in the computer to reduce the space occupied by the RAM chips. [1]
Final introduction Physical storage And storage address space. They are two different concepts, but because they have a very close relationship and use B, KB, MB and GB to measure their capacity, it is easy to have confusion in understanding. Physical memory refers to a specific memory chip that actually exists. For example, the memory module inserted on the motherboard and the ROM chip loaded with the system BIOS, the display RAM chip and the ROM chip loaded with the display BIOS on the display card, and the RAM chip and ROM chip on various adapter cards are all physical memories. The storage address space refers to the range of memory encoding (encoding address). Encoding is to assign a number to each physical storage unit (a byte), which is usually called "addressing". The purpose of assigning a number to a storage unit is to find it easily and complete data reading and writing, which is called "addressing". Therefore, some people also call the storage address space "addressing space". [1]
The size of the storage address space is not necessarily equal to the size of the physical memory. To illustrate this problem, take an example: there are 17 rooms on a floor, whose numbers are 801-817. The 17 rooms are physical, and the address space uses a three bit code, which ranges from 800 to 899, with a total of 100 addresses. It can be seen that the address space is larger than the actual number of rooms. For computers above 386, the address bus is 32 bits, so the address space can reach 2B, or 4GB. [1]
Non volatile storage (NVM)
Non volatile memory, NVM )Because of its high integration, low power consumption, nonvolatility, byte addressing and other characteristics, it has been widely concerned. Academics and industry have developed some new nonvolatile storage media and technologies, such as magnetic memory (MRAM), spin transfer torque memory (STT-RAM), phase change memory (PCM), resistive RAM (RRAM), ferroelectric RAM (FERAM), etc. The table lists the main parameters of several mainstream new memory devices. It can be seen from the table that nonvolatile memory has good performance in terms of integration and reading speed, and is a candidate for building potential new memory devices. But nonvolatile storage also has several obvious disadvantages: 1) It has a large write delay, which is one order of magnitude larger than the corresponding storage medium, and the write delay is greater than the read delay, that is, the read and write are inconsistent; 2) Although the read operation of nonvolatile storage is faster than the write operation, it is still slower than the read operation of traditional storage media; 3) The write life of nonvolatile storage is limited. In the case of continuous write, the storage unit will fail soon. [1]

disk

disk It is the most commonly used external memory. It packs a round magnetic disk in a square sealed box. The purpose of this is to prevent the disk surface from being scratched and causing data loss. The data information stored on the disk can be saved for a long time and reused. Disk has floppy disk and Hard disk At present, floppy disks have been basically eliminated. Hard disks are widely used in computers. We can compare them to large warehouses where computers store data and information. [1]
Types and composition of hard disks
The types of hard disks mainly include SCSI, IDE and now popular SATA Etc. The production of any kind of hard disk has certain standards. With the upgrading of the corresponding standards, the hard disk production technology is also upgrading. For example, the SCSI standard has gone through SCSI-1, SCSI-2 and SCSI-3. At present, we often Web server The Ultra l-160 is based on the SCSI-3 standard. The IDE follows the ATA standard, and the current popular SATA is an upgraded version of the ATA standard. IDE is a parallel port device, while SATA is a serial port. SATA is developed to replace IDE. [1]
Generally speaking, no matter what kind of hard disk is, it is composed of disk, magnetic head, disk spindle, control motor, magnetic head controller, data converter, interface, buffer, etc. [1]
Figure 2-6
The hard disk structure is shown in Figure 2-6. All discs are fixed on a rotating shaft, which is the disc spindle. All disks are absolutely parallel. There is a magnetic head on the storage surface of each disk. The distance between the magnetic head and the disk is smaller than the diameter of the hair. All the heads are connected to a head controller, which is responsible for the movement of each head. The magnetic head can move radially along the radius direction of the disc (actually in the oblique tangential direction). Each magnetic head must also be coaxial at the same time, that is, from the positive upward direction, all the magnetic heads are overlapped at any time (however, there is an independent technology of multiple magnetic heads, which can be exempted from this limitation). The disk rotates at a high speed from thousands of revolutions per minute to tens of thousands of revolutions per minute, so that the head can read and write data to the designated position on the disk. [1]
How Hard Disks Work
1. Disk surface
The disk of hard disk generally uses aluminum alloy as the substrate, and high-speed hard disk may also use glass as the substrate. Each disk of a hard disk has two sides, the upper side and the lower side. Generally, each disk can be used to store data and become an effective disk. There are also very few hard disks with an odd number of sides. Each such valid disk has a disk number, numbered sequentially from top to bottom and from 0. In the hard disk system, the disk surface number is also called the head number, because each effective disk has a corresponding read/write head. There are 2~14 disks in the disk group of hard disk, usually 2~3 disks, so the disk surface number (head number) is 0~3 or 0~5. [1]
2. Track
The disk is divided into many concentric circles during low-level formatting. These concentric circle tracks are called Track (Track), information is recorded in these tracks in the form of pulse train. Tracks are numbered sequentially from outside to inside, starting from 0. Each disk surface of the hard disk has 300~1024 tracks, and the new high-capacity hard disk has more tracks on each side. Each track does not record data continuously, but is divided into segments of arcs. The angular speed of these arcs is the same, but because the radial lengths are different, the linear speed is also different. The linear speed of the outer ring is greater than that of the inner ring, that is, at the same speed, the length of the circular arc crossed by the outer ring in the same time period is greater than that of the circular arc crossed by the inner ring. Each arc is called a sector. The sector is numbered from 1. The data in each sector is read or written as a unit at the same time. The magnetic track is invisible, but some magnetized areas on the disk surface are magnetized in a special form Disk format The planning has been completed by. [1]
3. Cylindrical surface
The same track on all disks forms a cylinder, usually called a cylinder. The heads on each cylinder are numbered from top to bottom, starting from 0. The reading/writing of data is carried out according to the cylinder, that is, when the head reads/writes data, it first starts from the 0 head in the same cylinder, and then downward on different disks of the same cylinder, that is, the head. Only after all the heads of the same cylinder have been read/written, the head will be transferred to the next cylinder (concentric cylinder and then inward cylinder), Because the magnetic head can be selected only through electronic switching, and the cylinder must be selected through mechanical switching. When the magnetic head moves to the adjacent track during electronic switching, the speed is much faster than when the mechanical switching is performed. Therefore, the data read/write is performed according to the cylinder rather than the disk, thus improving the read/write efficiency of the hard disk. [1]
A piece of hard disc drive The number of cylinders (or the number of tracks on each disk) depends on the width of each track (also related to the size of the head), and also depends on the step between tracks determined by the positioning mechanism. [1]
4. Sector
The operating system stores information on the hard disk in the form of sector. Each sector includes two main parts: sector identifier and data segment for storing data (usually 512B). [1]
The sector identifier, also known as the sector header, includes three numbers that make up the three-dimensional address of the sector: 1) Disk number: the head (or disk) where the sector is located 2) Cylinder number: the track, which determines the radial direction of the head; 3) Sector number: the position on the track, also known as the block number, which determines the position of the data on the disk circle. [1]
The sector header also includes a field, in which there is a mark that identifies whether the sector can reliably store data. Some hard disk controllers also record an indicator in the sector header, which can guide the disk to the replacement sector or track when the original sector fails. Finally, the sector header is marked with Cyclic redundancy check (CRC) value is used as the end for the controller to check the reading of sector header to ensure accuracy. [1]
a sector The data segment of is used to store data information, including data and error correction code (ECC) for protecting data. During the initial preparation, the computer will fill 512 virtual information bytes (the storage location of actual data) and ECC numbers corresponding to these virtual information bytes into this section. [1]

Access Principle

Announce
edit

stack

stack It is a space for recording call paths and parameters when C language programs run: including function call framework, passing parameters, saving return addresses and providing local variable space. [1]
Basic knowledge of stack
1. Stack related register
1) Esp: stack top pointer; [1]
2) Ebp: base address pointer (ebp is used in C language to record the base address of the current function call); [1]
3) Cs: eip points to the address of the next instruction in two cases; [1]
(1) Sequential execution: always points to the next instruction with consecutive addresses; [1]
(2) Jump/Branch: When such an instruction is executed, the cs: eip value will be modified according to the program needs; [1]
4) Call: push the current cs: eip value to the top of the stack, and cs: eip points to the entry address of the called function; [1]
5) Ret: pop the value of cs: eip saved here from the top of the stack and put it into cs: eip; [1]
6) Iret: pop the values of cs: eip and flags originally saved here from the top of the stack, and put them into cs: eip and flags Flag register Medium. [1]
2. Stack operation
1) Push: The pointer at the top of the stack decreases by 4 bytes (32 bits): [1]
2) Pop: The stack top pointer increases by 4 bytes (32 bits). [1]
Use of stack during function call
The operation of the stack in the function call process is shown in Figure 3. A main function calls a sub function. The specific steps of the call process are described as follows: [1]
  1. one
    Before executing the call, the esp points to the top of the stack and the ebp points to the bottom of the stack; [1]
  2. two
    When the call is executed, the original value of cs: eip is saved to the top of the stack, and then the value of cs: eip points to the entry address of the called program; [1]
  3. three
    Enter the called program, the first instruction: pushl% ebp, the second instruction: movl% esp,% ebp; [1]
  4. four
    After entering the called program, the stack can be used for routine operations such as pushing and pushing; [1]
  5. five
    Exit the called program. The first instruction is movl% ebp,% esp, the second instruction is popl% ebp, and the third instruction is ret. At this time, exit from the called program and restore the address to the eip through ret. [1]
Figure 3

Principle of locality

so-called Principle of locality When the CPU accesses the memory, whether it is to access instructions or data, the memory units accessed are gathered in a small continuous area. [1]
Locality usually has two forms: [1]
Temporal locality: If an information item is being accessed, it will probably be accessed again in the near future. Program loops, stacks, etc. are the causes of time locality. [1]
Spatial locality: The information to be used recently is likely to be close to the information being used now in the spatial address. [1]
All levels of modern computer system, from hardware to operating system, and then to application program, have been designed using the principle of locality. In the hardware layer, the locality principle allows computer designers to save recently referenced instructions and data items by introducing small and fast cache memory, thus improving the access speed to main memory. At the operating system level, the locality principle allows the system to use main memory as the cache recently referenced in the virtual address space, and the locality principle also allows the system to use main memory to cache Disk File System The most recently used disk block in. Locality also plays an important role in the design of application programs. For example, Web browsers place recently referenced documents on local disks, making use of time locality. A large number of Web servers put the recently requested documents in the front-end disk cache. These caches can meet users' requests for these documents without any interference from the server. [1]
Here are three examples to illustrate the locality of the program's data reference. [1]
Example 1:
int sumvec(int v[N])
{
int i=0,sum=0;
for(int i=0; i
{
sum+=v[i];
}
return sum;
}
In the above code, the variable sum is referenced once in each loop iteration, which has time locality. The elements of array v are read in sequence according to the order in which they are stored in memory, so they have spatial locality, but each array element is only accessed once, so they do not have temporal locality. It can be seen that the sumvec function's access to data has both spatial locality and temporal locality. [1]
Example 2:
int sumarrayros(int v[M][N])
{
int i=0; j=0; sum=0;
for(i=0;i
for(j=0;j
{
sum+=v[i] [j];
}
return sum;
}
In the above code, the elements of array v are accessed in step 1, so it has good spatial locality (array elements are stored in line order). [1]
Example 3:
int sum array ros(int v[M][N])
{
inti=0; j=0; sum=0;
for(j=0;j
for(i=0;i
{
sum+=v[i][j];
}
return sum;
}
In the above code, the elements of array v are accessed according to step N, so its spatial locality is poor. [1] In conclusion, the following conclusions can be drawn:
1) Programs that repeatedly reference the same variable have good time locality; [1]
2) For programs with reference patterns with a step size of k, the smaller the step size, the better the spatial locality. A program that skips around in memory with a large step size will have poor spatial locality; [1]
3) For fetching instructions, loops have good temporal and spatial locality. The smaller the loop body, the more iterations of the loop, and the better the locality. [1]