Buffer, control method therefor and computer system
By caching write commands in the cache and actively sending dirty data to the memory controller, the problem of insufficient cache capacity of the memory controller and frequent read-write switching is solved, improving memory access efficiency and processor operating performance.
Patent Information
- Application Number
- PCT/CN2024/081735
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-21
- Filing Date
- 2024-03-14
- Publication Date
- 2024-09-26
AI Technical Summary
In the existing technology, due to frequency and delay limitations of the memory controller, the cache capacity is small and the number of read and write switches is high, resulting in reduced memory access efficiency. In particular, the delay of read commands is obvious, which affects the operating efficiency of the processor.
By caching the write data of write commands in the cache and proactively sending dirty data to the memory controller before the cache line is allocated to a new memory address, the appropriate timing is selected to reduce the number of read and write switches and latency, and improve memory access. efficiency.
It effectively improves the memory controller's read and write command scheduling efficiency, reduces read latency, and improves the overall performance of memory access.
Smart Images

Figure CN2024081735_26092024_PF_FP
Abstract
Description
Buffer and control method thereof, and computer system
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on March 21, 2023, with application number 202310311769.4 and application name “Cache and its control method, computer system”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The embodiments of the present application relate to the field of storage technology, and more particularly to a cache, a control method thereof, and a computer system. Background Art
[0003] The memory controller is responsible for scheduling and executing the read and write commands of the processor to access the memory. For read commands and write commands, the processor usually needs to process the result of the read command, that is, the read data. If the read command is executed slowly and the data access speed is slow, the processor's operating efficiency will be reduced. The write command only needs to write the data to the memory, and the result of the write has less impact on the processor operation. Therefore, relatively speaking, the delay of the read command is easier to perceive than the delay of the write command.
[0004] Due to frequency and latency considerations, the memory controller itself has a small internal queue depth and a small cache capacity. If only the memory controller performs read and write scheduling, the number of read and write switches will be relatively high, and the read and write switching overhead will have a greater impact on performance, so the efficiency of memory access will decrease.
[0005] Summary of the Invention
[0006] Embodiments of the present application provide a cache and a control method thereof, and a computer system to improve the efficiency of memory access of the computer system.
[0007] In order to achieve the above objectives, the technical solutions adopted in this application are as follows:
[0008] In a first aspect, an embodiment of the present application provides a method for controlling a cache, wherein the cache is connected to a memory controller, and the cache includes multiple cache lines. The method includes: storing write data of a received write command in the cache line; before the cache line is assigned to a new memory address, sending dirty data stored in the cache line to the memory controller, where dirty data refers to write data to be written to the memory.
[0009] The embodiment of the present application provides a control method for the cache, wherein the cache can cache the write data of the write command, thereby enhancing the ability of the memory controller to cache commands, and has a certain scheduling capability for the write data of the cached write command, that is, before the cache line is assigned to the new memory address, the dirty data is actively sent to the memory controller, rather than passively sending the dirty data to the memory controller after the cache line is assigned to the new memory address. Since the memory controller has limited scheduling of read and write commands, when the cache passively sends the dirty data to the memory controller, the timing of sending is not controlled, which is likely to cause the memory controller to have more read and write switches when scheduling read and write commands, resulting in reduced memory access efficiency. The control method provided in the embodiment of the present application can cache the dirty data before the cache line is assigned to the new memory address. , actively select the time to send the cached dirty data to the memory controller to write into the memory, so that a scheduling method with higher memory access efficiency or a method with smaller read latency can be selected. For example, when there are fewer read commands in the read queue, the dirty data is sent to the memory controller to write into the memory. If the dirty data is passively sent to the memory controller and the timing is uncontrollable, then there is a greater possibility that the dirty data passively sent to the memory controller will affect the execution of the read commands in the read queue when writing into the memory. Therefore, the solution provided in the embodiment of the present application can select the appropriate time to actively send the dirty data to the memory controller before the cache line is assigned to the new memory address, which can reduce the impact on the execution of the read command, thereby helping the memory controller to improve the efficiency of read and write command scheduling, reduce the number of read and write switches, and improve memory access efficiency.
[0010] In one possible implementation, before the cache line is assigned to a new memory address, sending the dirty data stored in the cache line to the memory controller includes: before the cache line is assigned to the new memory address, when the number of read commands in the read queue of the memory controller is less than a first set value, sending the dirty data stored in the cache line to the memory controller.
[0011] The control method of the cache provided in the embodiment of the present application actively sends the dirty data stored in the cache line to the memory controller for writing into the memory when the number of read commands in the read queue of the memory controller is less than a first set value before the cache line is assigned to a new memory address. When the number of read commands in the read queue is small, the dirty data is sent to the memory controller for writing into the memory. This can reduce the interference of write commands on read commands, reduce the number of read-write switches, reduce read latency, and improve memory access efficiency.
[0012] In one possible implementation, before the cache line is assigned to a new memory address, sending the write command stored in the cache line to the memory controller includes: before the cache line is assigned to the new memory address, when the number of dirty cache lines reaches a second set value, sending the dirty data stored in the cache line to the memory controller.
[0013] The control method of the cache provided by the embodiment of the present application, before the cache line is assigned to a new memory address, if the number of dirty cache lines in the cache reaches a second set value, the dirty data stored in the cache line is actively sent to the memory controller to be written into the memory, wherein the dirty cache line refers to the cache line that stores dirty data, and the second set value can be set according to the total number of cache lines in the cache. Assuming that the status of all cache lines is dirty, if new data or commands arrive at the cache, then there must be a dirty cache line to be replaced, that is, assigned to a new address, and the replacement of the dirty cache line will cause the dirty data stored therein to be converted into a write command sent to the memory controller, then the dirty data is passively sent to the memory controller, which may cause the efficiency of the memory controller in scheduling read and write commands to be reduced, and the dirty data is written into the memory. The memory may affect the execution of the read command, resulting in read latency; if the number of dirty cache lines in the cache is small, then when new data or commands arrive at the cache, they may be allocated to clean cache lines, so that no replacement occurs and no dirty data is passively sent to the memory controller. In other words, the more dirty cache lines there are, the greater the possibility that dirty data will be passively sent to the memory controller. Therefore, the second setting value here can be set according to the total number of cache lines, for example, set to 1 / 2 or 2 / 3 of the total number of cache lines. This can keep the number of clean cache lines in the cache at a high level, reduce the occurrence of dirty data being passively sent to the memory controller, thereby avoiding writing dirty data into the memory to affect the execution of read commands and improve the efficiency of memory access.
[0014] In a possible implementation, sending the dirty data stored in the cache line to the memory controller includes: selecting, based on a memory address currently accessed by the memory controller, dirty data whose target address and the currently accessed memory address are located in the same storage column and sending the dirty data to the memory controller.
[0015] Select dirty data whose target address and the currently accessed memory address are located in the same storage column and send it to the memory controller. In this way, after the dirty data is sent to the memory controller, the dirty data can be written to the memory without switching storage columns, thereby reducing the process of switching storage columns once. Since switching storage columns will cause delays when accessing memory, which reduces access efficiency, sending dirty data whose target address and the currently accessed memory address are located in the same storage column to the memory controller can improve memory access efficiency.
[0016] In one possible implementation, sending dirty data stored in a cache line to a memory controller includes: selecting, based on a memory address currently accessed by the memory controller, dirty data whose target address and the currently accessed memory address are located in the same memory bank and sending the dirty data to the memory controller, thereby reducing the delay caused by switching of the memory banks and improving memory access efficiency.
[0017] In one possible implementation, sending a write command stored in a cache row to a memory controller includes: selecting dirty data whose target address is located in the same row as the currently accessed memory address based on the memory controller, and sending the dirty data to the memory controller. Since all data in the same row will be pre-read during the memory access process, that is, when accessing data in the same row, even if data located in different storage columns is read, the latency is relatively low, and the efficiency of executing commands in the same row is high. Therefore, sending dirty data whose target address is located in the same row as the currently accessed memory address to the memory controller can reduce the latency caused by switching rows and improve memory access efficiency.
[0018] In one possible implementation, before sending the dirty data stored in the cache line to the memory controller, the method further includes: obtaining operating status information of the memory controller, the operating status information including the number of read commands in the read queue of the memory controller and the memory address currently being accessed by the memory controller.
[0019] In one possible implementation, the cache includes multiple groups, each group includes multiple cache lines, and storing the write data of the received write command in the cache line includes: allocating the write data of the received write command whose target address is located in the same line to the cache line cache of the same group, so that when scheduling the write command according to the memory address currently being accessed by the memory controller, the dirty data located in the same line can be efficiently matched, thereby improving the scheduling efficiency.
[0020] In one possible implementation, the cache includes multiple groups, each group includes multiple cache lines, and storing the write data of the received write command in the cache line includes: allocating the received write command whose target address is located in the same line to the cache line caches of multiple adjacent groups. Since the number of cache lines in a cache group is limited, if the amount of write data of the write command located in the same line is too large and all the cache lines in a group are occupied, when new data or commands arrive at the cache, the dirty data of a dirty cache line will be passively sent to the memory controller. To avoid this situation, the write data of the write command located in the same line can also be allocated to the cache line caches of several adjacent groups. On the one hand, it can improve the cache capacity and avoid passively sending dirty data to the memory controller. On the other hand, it can quickly match the write commands located in the same line in several adjacent groups, which can improve the access efficiency of the memory.
[0021] In a second aspect, an embodiment of the present application further provides a cache, which is used to execute the control method provided by any implementation of the first aspect.
[0022] In a third aspect, an embodiment of the present application further provides a computer system, which includes a processor, a memory, and the cache provided in the second aspect, wherein the processor, the memory, and the cache are connected via a bus. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] FIG1 is a schematic diagram of an electronic device provided in an embodiment of the present application;
[0024] FIG2 is a schematic diagram of a memory provided in an embodiment of the present application;
[0025] FIG3 is another schematic diagram of a memory provided in an embodiment of the present application;
[0026] FIG4 is a schematic diagram of an electronic device provided in an embodiment of the present application;
[0027] FIG5 is a schematic diagram of another electronic device provided in an embodiment of the present application;
[0028] FIG6 is a schematic diagram of a mapping between a memory and a buffer provided in an embodiment of the present application;
[0029] FIG7 is a schematic diagram of the structure of a buffer provided in an embodiment of the present application;
[0030] FIG8 is a schematic diagram of physical address mapping provided in an embodiment of the present application;
[0031] FIG9 is a flow chart of a control method provided in an embodiment of the present application;
[0032] FIG10 is a flow chart of another control method provided in an embodiment of the present application;
[0033] FIG11 is a flow chart of another control method provided in an embodiment of the present application;
[0034] FIG12 is a flow chart of another control method provided in an embodiment of the present application;
[0035] FIG13 is a flow chart of another control method provided in an embodiment of the present application;
[0036] FIG14 is a flow chart of another control method provided in an embodiment of the present application;
[0037] FIG15 is a flow chart of another control method provided in an embodiment of the present application;
[0038] FIG16 is a flow chart of another control method provided in an embodiment of the present application;
[0039] FIG17 is a schematic diagram of a physical address provided in an embodiment of the present application;
[0040] FIG18 is a schematic diagram of mapping a physical address to a buffer according to an embodiment of the present application;
[0041] FIG19 is a schematic diagram of another physical address mapping to a buffer according to an embodiment of the present application;
[0042] FIG20 is a flow chart of another control method provided in an embodiment of the present application;
[0043] FIG21 is a flow chart of another control method provided in an embodiment of the present application;
[0044] FIG22 is a schematic diagram of another buffer provided in an embodiment of the present application;
[0045] FIG. 23 is another flow chart of a buffer control method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments.
[0047] In the following, the terms "first," "second," etc., are used for descriptive convenience only and should not be understood as indicating or implying relative importance or implicitly specifying the number of the technical features indicated. Thus, a feature defined as "first," "second," etc. may explicitly or implicitly include one or more of the features. In the description of this application, unless otherwise specified, "plurality" means two or more. For example, "plurality of processing units" refers to two or more processing units.
[0048] Furthermore, in the embodiments of the present application, "upper," "lower," "left," and "right" are not limited to being defined relative to the orientation of the components schematically shown in the drawings. It should be understood that these directional terms can be relative concepts. They are used for relative description and clarification, and may change accordingly based on changes in the orientation of the components in the drawings. In the drawings, the thickness of layers and regions is exaggerated for clarity, and the dimensional ratios between the components in the drawings do not reflect the actual dimensional ratios.
[0049] In the embodiments of this application, unless otherwise specified or limited, the term "connection" should be understood in a broad sense. For example, "connection" can mean fixed connection, detachable connection, or integration; it can mean direct connection or indirect connection through an intermediate medium. In addition, the term "electrical connection" can mean direct electrical connection or indirect electrical connection through an intermediate medium.
[0050] In the embodiments of the present application, the term "module" generally refers to a functional structure divided according to logic. The "module" can be implemented by pure hardware or a combination of hardware and software. In the embodiments of the present application, "and / or" describes the association relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, B exists alone, and A and B exist at the same time.
[0051] In the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0052] A computer system consists of two parts: hardware and software. For example, the hardware system includes the central processing unit, motherboard, memory, input and output devices, power supply, etc., while the software system includes system software and application software.
[0053] In 1945, John von Neumann proposed the concept of "stored program." Computers based on this concept are generally referred to as von Neumann computers. A von Neumann computer consists of five major components: input devices, output devices, memory, an arithmetic unit (APU), and a controller. The APU performs arithmetic and logical operations and temporarily stores intermediate results within the APU. The controller controls and directs the input and execution of programs and data, as well as the processing of computational results. Memory stores data and programs. Input devices, such as keyboards, mice, microphones, and scanners, convert familiar information into a computer-readable format. Output devices, such as monitors, printers, and speakers, convert computer computational results into familiar information. Currently, the controller and APU of a computer are combined into one, collectively referred to as the central processing unit (CPU), hereinafter referred to as the processor or CPU. Input and output devices are referred to as I / O equipment.
[0054] Memory is a component used to store programs and various data. Memory has three key performance indicators: speed, capacity, and cost. Generally speaking, higher speeds come with higher costs, while larger capacity reduces speed. Computer systems typically employ a multi-level storage system, combining memories of varying storage capacities, read / write speeds, and costs into a hierarchical structure, such as cache, main memory, and auxiliary memory. Management software and supporting hardware organically integrate these memories into a unified whole, allowing programs and data to be distributed hierarchically across these various memories.
[0055] Main memory, also known as internal memory, allows for direct data exchange with the CPU. It stores programs and data, and is also known as memory. Computer programs run in memory, and the performance of this memory affects the overall performance of the computer. During computer operation, the operating system transfers data from memory to the CPU for computation. A computer cannot function properly without memory.
[0056] Memory is a crucial component of a storage system, capable of exchanging data with the CPU, cache, and auxiliary storage. Memory parameters such as capacity, bandwidth, and cost constrain the development of computer systems. The computer system referred to in the embodiments of this application can be a computer, but it can also refer to mobile devices such as mobile phones and tablets.
[0057] Taking the electronic device as a computer system as an example, FIG1 shows a schematic diagram of the architecture of the electronic device provided by an embodiment of the present application. As shown in FIG1 , the electronic device 100 may include at least a processor 101, a memory controller 102, and a memory 103. It should be noted that in the computer system provided by the embodiment of the present application, in addition to the components shown in FIG1 , the electronic device 100 may also include other components such as a communication interface and a disk as auxiliary storage, which are not limited here.
[0058] The processor 101 is the computing core and control unit of the electronic device 100. The processor 101 may include multiple cores 104. An operating system and other software programs are installed in the processor 101, enabling the processor 101 to access the memory 103, cache, and disk. In an embodiment of the present application, the core 104 in the processor 101 may be a central processing unit (CPU), an artificial intelligence (AI) processor, a digital signal processor (DSP), a neural network processor, or other application-specific integrated circuits (ASICs). The memory controller 102 is a bus circuit controller that controls the memory 103 within the electronic device 100 and is used to manage and plan data transmission from the memory 103 to the core 104. Data can be exchanged between the memory 103 and the core 104 through the memory controller 102. The memory controller 102 may be a separate chip connected to the core 104 via the system bus. The memory controller 102 may also be integrated into the processor 101 or built into the north bridge. The embodiments of the present application do not limit the specific location of the memory controller 102. In practical applications, the memory controller 102 can control necessary logic to write data into the memory 103 or read data from the memory 103.
[0059] The memory 103 is the internal memory of the electronic device 100, which is usually used to store various running software in the operating system, input and output data, and information exchanged with external memory. The processor 101 can access the memory 103 at high speed through the memory controller 102 and perform read and write operations on any storage unit in the memory 103. Usually, dynamic random access memory (DRAM) is used as the memory.
[0060] As shown in Figure 2, a schematic diagram of a DRAM is shown. A channel is an independently accessible storage space that can include one or more storage ranks. Typically, a channel includes a storage space of a certain capacity and hardware circuitry for accessing the storage space. This hardware circuitry can include control logic, interfaces, and other related circuitry.
[0061] A channel can be composed of memory ranks. A memory rank refers to memory chips connected to the same chip select signal. Memory chips are also called chips. Because these chips are connected to the same chip select signal, the memory controller 102 can write to the chips in the same memory rank. Chips in the same memory rank also share the same control signal.
[0062] Each storage column can include one or more banks. For example, a storage column can include four banks, or even eight banks. A DRAM bank includes one or more memory arrays, each of which includes multiple memory cells arranged in rows and columns. Alternatively, each memory array can include multiple sub-arrays, each of which includes multiple memory cells arranged in rows and columns. A memory cell can be used to store 1 bit of data, such as a "0" or a "1." Row and column decoders can be used to locate any memory cell in the memory array.
[0063] 1 and 2 , the memory controller 102 may respond to a memory access request from the processor 101 . For example, the access request may include a read command or a write command to access a specific storage unit, read data stored in the storage unit, or write data to the storage unit.
[0064] The memory request initiated by the processor 101 will first be placed in the request queue, and then the memory controller 102 will translate the memory request initiated by the processor and send it to the DRAM queue for execution. Usually, the request sent by the processor 101 includes an address. After the address is parsed, information such as the channel number, rank number, bank number, row number, and column number can be obtained.
[0065] The processor 101 accesses the memory based on the address, that is, the memory actually stores two pieces of information: one is the address, and the other is the data stored at the address.
[0066] For example, in FIG3 , 0000 to 0007 are addresses of memory cells, and A to H are stored data. The processor accesses data according to the address. For example, if H is to be read, the memory cell corresponding to the address 0007 should be accessed.
[0067] Before reading or writing data, the memory controller must first send a row active command to open a specific row in the memory array. To access data in a DRAM cell, a precharge operation must first be performed. Accordingly, before the memory controller 102 sends a row active command to access a specific row, it must send a precharge command to precharge the bank containing the row.
[0068] After sending a row activation command, the memory controller waits for a row cycle time before sending a second row activation command to access another row. The row cycle time is the sum of the precharge time and the row activation time. Because the row must be activated before accessing a specific address, there is a delay when switching between rows in the same bank and switching between ranks.
[0069] In addition, although the data bus between the processor and DRAM is bidirectional, for write commands, the processor outputs data through the data line, which is the output direction, and for read commands, the processor inputs data through the data bus, which is the input direction. In addition to the read and write data, read and write commands also require reading the data clock accompanying the data. Therefore, there will be a certain delay each time the read and write direction is switched, which is called the bus turnaround time. Therefore, generally speaking, read commands and write commands are usually processed in batches separately to avoid frequent read and write switching.
[0070] With the advancement of integrated circuit technology, processor performance continues to increase and operating speeds are getting faster and faster. At the same time, the application areas of computers continue to expand, and the size of system software and application software is getting larger and larger. Objectively, large-capacity memory is needed to support software operation. Considering the two factors of cost and capacity, DRAM, such as Double Data Rate Synchronous Dynamic Random Access Memory (DDR), is currently widely used in computers as memory. However, compared with the operating speed of the processor, DDR is relatively slow and cannot meet the speed requirements of high-performance processors.
[0071] As mentioned in the previous example, programs run in memory. When the processor needs to run a program, it first loads the executable program from auxiliary storage into memory and then begins execution. There are a number of general-purpose registers within the processor. If the processor needs to add 1 to a data point (assuming address A), it generally follows three steps:
[0072] Step 1: The processor reads the data at address A from memory into internal general register x0.
[0073] Step 2: Increment general register x0 by 1.
[0074] Step 3: The processor writes the value of general register x0 to memory.
[0075] However, due to the large difference between the speed of general-purpose registers and the speed of memory, the speed of general-purpose registers can be tens or even hundreds of times faster than that of memory. In the three steps mentioned in the above example, steps 1 and 3 require access to memory, which is actually very slow and the processor needs to wait for a long time. If the speed of memory can be increased, the performance of the computer system can be greatly improved. However, memory usually uses DDR and has a large capacity. If faster materials are used to prepare memory and the capacity is not required to be reduced, the cost will increase significantly. Therefore, a compromise method is adopted, that is, to configure a storage device with faster speed but smaller capacity, so that its cost will not be too high and the access speed can be improved. This storage device is the cache mentioned in the above example.
[0076] According to the characteristics of the von Neumann computer, data has temporal locality and spatial locality when the processor is running. Temporal locality means that if a piece of data is currently being used, it is very likely to be used again in the next period of time; spatial locality means that if a piece of data is currently being used, the data around it (near the same address) is very likely to be used again in the next period of time.
[0077] Based on the above-mentioned locality principle, a high-speed cache memory (cache for short) can be configured between the processor and the memory to improve the running speed of the processor. Only a small amount of instructions or data that the processor needs to use recently and the addresses of the memory units where they are stored are copied to the faster cache for use by the processor.
[0078] In hardware, as shown in Figure 4, a cache is typically placed between the processor and memory to cache memory data. When the processor attempts to read or store data from memory, it first checks the cache to see if the data at the corresponding address is cached there. If the data is cached there, this is called a hit, and the data is directly retrieved from the cache and returned to the processor. Because caches are fast, they can reduce processor latency and improve operational efficiency.
[0079] If you are writing data to the memory, then if the data to be overwritten is in the cache, then you can overwrite the data in the cache. The cache will choose the right time to write the overwritten data to the memory. If the data to be overwritten is not in the cache, then you can write the data directly to the memory, or write it to the cache first and then write it to the memory.
[0080] The speed of the cache also affects the performance of the system to a certain extent. Generally, the speed of the cache can reach 1ns, which is almost comparable to the speed of the processor's general registers. However, when the cache does not contain the data the processor needs, this situation is called a miss, and it still needs to wait for the data to be loaded from the memory.
[0081] To further improve performance, computer systems incorporate multiple levels of cache. The cache mentioned above is called the L1 cache (first-level cache). Referring to Figure 5, an L2 cache can be connected behind the L1 cache, and an L3 cache can be connected between the L2 cache and the main memory, and so on. Furthermore, more cache levels can be configured. Higher levels of cache have slower speeds and larger capacity, but are still faster than main memory. Through multiple levels of cache, the speed difference between each level and main memory gradually decreases. The last level of cache before main memory is usually called the last level cache (LLC). In the example above, the LLC is the L3 cache.
[0082] When the processor attempts to load data from a certain address, it first checks the L1 cache for a hit. If so, the data is returned to the processor. If the L1 cache misses, the processor continues to search the L2 cache. If the L2 cache hits, the data is returned to the L1 cache and the processor. If the L2 cache also misses, the processor continues to search the L3 cache. If the L3 cache hits, the data is returned to the L1 cache, L2 cache, and the processor. If the L3 cache also misses, the processor then needs to load the data from main memory and return it to the L3 cache, L2 cache, L1 cache, and the processor.
[0083] Therefore, the data stored in the cache is actually a subset of the data in the main memory. So for a piece of data in the main memory, it can be divided into three types according to how many locations in the cache can hold this data, see Figure 6: First, if there is only one location in the cache that can hold this data, it is a direct-mapped cache; second, if there are multiple locations in the cache that can hold this data, it is a set-associative cache; third, if any location in the cache can hold this data, it is a fully-associative cache.
[0084] Referring to Figure 7, the structure of a cache is similar to that of memory, also including addresses and stored data. However, in addition to the stored data, the cache also contains tags, which are the physical memory address information of the stored data. Because the addressing information issued by the processor is always issued for physical memory, the cache must store not only the data information but also the address corresponding to the data. This allows the cache to search for the corresponding data in physical memory based on the physical memory address information. A row consisting of a tag and its corresponding data is called a cache line. Of course, to speed up searches, the cache generally also contains a valid bit to mark whether the cache line stores valid data.
[0085] A cache is divided into S sets, each with E cache lines. A cache line consists of a valid bit, a tag, and data. The data portion consists of B storage cells. In modern processors, this storage unit is typically in bytes (usually 8 bits), which is also the smallest addressable unit. The data portion is the actual data at the memory address to be cached, while the tag is used to search the cache line. The valid bit is usually one bit, indicating whether the cache line is valid. For example, when the valid bit is 1, it is valid, and if the valid bit is 0, it is invalid.
[0086] Next, we will describe how a memory physical address is mapped to a cache line. Assuming the physical address is m bits, the addressing range is 000…00 to FFF…FF (m bits). Referring to Figure 8, we assume the memory physical address is divided into three intervals: tag, set index, and block offset. The tag interval includes the high-order t bits of the physical address, the set index interval includes the middle s bits of the physical address, and the block offset interval includes the low-order b bits of the physical address.
[0087] The cache consists of S sets, each set consists of E cache lines, and the data portion of each cache line consists of B storage units, where S = 2 s , B=2 b .
[0088] The physical address of a memory cell is divided into three intervals: tag, set index and block offset. The set index is the middle s bits of the physical address, which determines which set of cache the memory cell is mapped to, and the block offset is the lower b bits of the physical address, which determines which of the B memory cells in the cache line the memory cell is mapped to. Since multiple memory addresses may be mapped to the same cache line, the tag (the high t bits of the physical address) is used to verify whether the cache line is the memory cell that the processor wants to access.
[0089] When the processor accesses the cache, it first finds the cache set that may store the data at the address based on the set index of the physical address. After finding the set, it compares the tag of the physical address with the tags of multiple cache lines in the determined cache set to find out whether there is a cache line with a matching tag. If a matching cache line is found and the valid bit of the cache line is 1, the corresponding data in the cache line is found based on the block offset of the physical address.
[0090] It can be seen from this that the storage unit of the memory can be mapped to a specified cache line according to the set index and tag of its physical address, and the specified storage unit in the cache line where its data is stored can be determined according to the block offset of the physical address. Conversely, when searching whether the memory data is cached in the cache, it can also be searched in the cache according to the physical address of the memory storage unit.
[0091] Cache can improve processor efficiency. As mentioned in the previous example, the memory controller schedules processor access requests. Due to frequency and latency considerations, the queue depth within the memory controller (DDR Memory Controller, DDC) is relatively small. If only the DDR memory controller (hereinafter referred to as the memory controller) performs read and write scheduling, the number of read and write switches will be relatively high. The overhead of read and write switches has a significant impact on memory performance, for example, it will waste read and write bandwidth and lead to reduced computer system performance.
[0092] To increase the memory controller's command scheduling capability, one possible implementation method is to increase the queue depth and separate the memory controller's read command queue and write command queue. This allows for separate arbitration of read commands and write commands. This doubles the command cache capacity at the same frequency, facilitating the memory controller's read and write command scheduling and reducing the overhead of read-write switching.
[0093] For example, if the memory controller's queue depth is 64 and read and write commands share the same queue, a 64-to-1 arbitrator is required to arbitrate from the 64 read or write commands, obtaining the command with higher access efficiency and scheduling it to the memory for execution. However, in this case, more read or write commands cannot be cached. If two queues with a depth of 64 are set up, one for caching read commands and the other for caching write commands, then a 64-to-1 arbitrator can select a read command from the read command queue, and another 64-to-1 arbitrator can select a write command from the write commands. Then, a 2-to-1 arbitrator can select one of the selected read and write commands for execution. This is equivalent to scheduling from 128 commands. Although this method can improve cache capacity to a certain extent, the improvement is limited, and it also increases arbitration pipeline.
[0094] For read commands and write commands, the processor usually needs to perform further processing on the result of executing the read command, that is, the read data. If the read command is executed slowly and the data is accessed slowly, the processor's operating efficiency will be reduced. The write command only needs to write the data to the memory, and the result of the write has less impact on the processor's operation. Therefore, relatively speaking, the delay of the read command is easier to perceive than the delay of the write command. Therefore, the memory controller gives priority to processing read commands when scheduling commands, reducing the impact of write commands on read commands and reducing read delays. This requires increasing the cache capacity of write commands.
[0095] Since the queue depth of the memory controller is limited, in order to enhance the scheduling capability, an embodiment of the present application provides an implementation method for using the last level cache to cache a portion of the write commands, thereby enhancing the caching capability of the write commands.
[0096] For example, a portion of the LLC cache lines is used as a write command cache for the memory controller, storing write data for write commands and thus increasing the memory controller's ability to cache write commands. However, the memory controller cannot actively schedule write commands cached in the LLC and can only passively receive write commands sent by the LLC to the memory controller. Therefore, while this approach can increase write command caching capacity, it only improves scheduling efficiency to a limited extent.
[0097] For example, cache line 0 in LLC stores the write data of a write command, DATA1. When cache line 0 does not store data, the state of cache line 0 is clean. After storing DATA1, the state of cache line 0 changes to dirty. DATA1 is also called dirty data, that is, data that is inconsistent with the data in the memory and needs to be written to the memory. If cache line 0 in the dirty state is assigned to other addresses and stores data corresponding to other addresses, the DATA1 stored in cache line 0 needs to be kicked out to the memory controller. This scheduling method is to passively kick out the stored dirty data when cache line 0 is assigned to another address. It is a passive scheduling method. Although it can increase the cache capacity of write commands, it does not control the timing of the dirty data being passively kicked out to the memory controller. It may still affect the scheduling and execution of read commands, causing read delays.
[0098] For example, assume that cache line 0 stores dirty data, recorded as DATA1. The LLC receives multiple commands, such as five read commands. If one of the commands is assigned to cache line 0, then DATA1 stored in cache line 0 will be kicked to the memory controller and converted into a write command to write DATA1 to the memory. When these five read commands are sent to the memory controller for execution, they may be blocked by the write of DATA1. The read-write switching takes time, which will increase the latency of these five read commands.
[0099] The reason for the read delay here is that when executing a read command, the memory controller receives dirty data that is passively kicked out to the memory controller by the LLC and needs to write the dirty data into the memory. Before this, if a suitable opportunity is found to actively send the dirty data stored in the dirty cache line to the memory controller, when a new command arrives, since the dirty data has been kicked out of the LLC, the state of the cache line has become clean, and the dirty data will not be passively kicked to the memory controller when the new command arrives. This can avoid delays in the execution of read commands caused by write data and improve memory access efficiency.
[0100] For example, referring to FIG9 , an embodiment of the present application provides a buffer control method, including:
[0101] S210: Storing the write data of the received write command into the cache line.
[0102] S230: Before the cache line is allocated to a new memory address, send dirty data stored in the cache line to a memory controller, where the dirty data refers to write data to be written into the memory.
[0103] Among them, the cache can be the last level cache (LLC) provided by the embodiment of the present application. When a new write command arrives at the cache, the cache assigns the write command to the cache line storage, and the state of this cache line changes from clean to dirty. Before the dirty cache line is assigned to a new memory address, the dirty data stored in the cache line is sent to the memory controller. In this way, when a new command arrives at the cache, since the dirty data stored in the cache line has been sent to the memory controller, the state of the cache line is changed to a clean state, then the dirty data will not be passively kicked out to the memory controller when a new command arrives, thereby avoiding the writing of dirty data passively sent to the memory controller affecting the execution of the read command.
[0104] Since the timing when the cache passively sends the write command to the memory controller is uncontrollable, the memory controller may be executing a read command. In this case, the write command sent to the memory controller may affect the timing of the read command being executed and the subsequent read commands. Therefore, the method provided in the embodiment of the present application can actively find a suitable time to actively send dirty data to the memory controller before the write command cache line is assigned to a new memory address, rather than passively sending dirty data to the memory controller when the cache line is assigned to the new memory address. By actively scheduling write commands, the situation where the cache passively sends dirty data to the memory controller is reduced, and the writing of dirty data to the memory is avoided to affect the execution of the read command in the memory controller, thereby reducing read latency and improving memory access efficiency.
[0105] Next, the control method of the buffer provided by this application is introduced in conjunction with a specific embodiment. For example, refer to Figure 10, which shows a flow chart of a control method of a buffer provided by an embodiment of this application. The buffer here can refer to LLC. The control method includes:
[0106] S310: Storing the write data of the received write command into the cache line.
[0107] S320: Determine whether the conditions for actively scheduling a write command are met.
[0108] S330: Before the cache line is allocated to a new memory address, dirty data stored in the cache line is sent to a memory controller, where the dirty data refers to write data to be written into the memory.
[0109] The solution provided in the embodiment of the present application determines whether the conditions for actively scheduling a write command are met before the cache line that has stored dirty data is allocated to a new memory address. If the conditions for actively scheduling a write command are met, the dirty data stored in the cache line is sent to the memory controller. This prevents the dirty data from being sent to the memory controller at an uncontrollable time, avoids writing dirty data into the memory and affecting the execution of the read command, and can improve the memory access efficiency.
[0110] Before sending a write command to the memory controller, it is necessary to determine whether a condition for actively scheduling the write command is met. If the condition is met, the cache actively sends the dirty data to the memory controller. For example, with reference to FIG11 , S320 includes:
[0111] S320a: Determine whether the number of read commands in the read queue of the memory controller is less than a first set value.
[0112] Exemplarily, the conditions for actively scheduling write commands may include: whether the number of read commands in the read queue of the memory controller is less than a first set value. If so, it indicates that there are fewer read commands in the memory controller, and it is considered that the conditions for actively scheduling write commands are met.
[0113] When the memory controller is in an idle state or the number of read commands in the read command queue is small, the memory controller can reduce read latency by scheduling read commands and write commands. Since the overall number of reads is small and the execution efficiency is high, when the number of read commands is less than the first set value, it is deemed that the conditions for actively scheduling write commands are met. Before the cache line is assigned to a new memory address, when the number of read commands in the read queue of the memory controller is less than the first set value, the cache sends the dirty data to the memory controller. In this way, the process of writing dirty data to the memory has less impact on the read command (because the number of read commands is small) and has less impact on the access efficiency of the memory. The first set value can be set according to the performance of the memory and the memory controller.
[0114] In the above example, the condition for actively scheduling write commands is that the number of read commands in the read queue of the memory controller is less than the first set value. In addition, the embodiment of the present application also provides another situation where active scheduling can be performed.
[0115] When the cache is caching data, if a cache line has already stored data and is in a dirty state, the stored data is dirty data. If this cache line is to be assigned to a new memory address to store the data corresponding to the new memory address, that is, the new memory address data must replace the previous dirty data. In order to maintain data consistency, before the dirty cache line is replaced, the dirty data needs to be sent to the memory controller and written into the memory to transform the cache line into a clean state. These replacements may be carried out according to some strategies, such as replacing the least used data. However, we can understand that, assuming that all cache lines are in a dirty state, if new data or commands arrive at the cache, then a dirty cache line will inevitably be replaced. If the dirty data of the replaced dirty cache line is passively sent to the memory controller, it will be converted into a write command to write the dirty data to the memory to maintain data consistency. Writing the dirty data to the memory may cause the memory controller to schedule read and write commands in a different order. For example, a read command is originally to be executed, but after the dirty data is sent to the memory controller, a write command is executed to write the dirty data to the memory. This reduces the efficiency of the memory controller in scheduling read and write commands. Writing dirty data to the memory may affect the execution of the read command, resulting in a delay. If the number of dirty cache lines in the cache is small, then when new data or commands arrive at the cache, they may be assigned to a cache line in a clean state. In this way, no replacement occurs, and no dirty data is passively sent to the memory controller. Therefore, in a possible implementation, referring to FIG. 12 , S320 may include:
[0116] S320b: Determine whether the number of dirty cache lines in the cache reaches a second set value.
[0117] In this embodiment, the conditions for actively scheduling write commands include: whether the number of cache lines in the cache that are in a dirty state is greater than a second set value. When the number of dirty cache lines is large, for example, greater than the second set value, it is considered that the conditions for actively scheduling write commands are met.
[0118] For example, when there are a large number of dirty cache lines in the cache, for example, assuming that 1 / 2 of the cache lines are dirty, then when a new command enters the cache, there is a 1 / 2 chance that the new command will be assigned to a dirty cache line. In this way, the dirty data in the dirty cache line will be passively sent to the memory controller and converted into a write command, writing the dirty data to the memory. This will affect the execution of read commands and the efficiency of memory access. If the number of dirty cache lines is small, the probability of replacement will be reduced. If all cache lines are in a clean state, then replacement will not occur. Therefore, the more dirty cache lines there are, the greater the possibility of replacement, and the greater the possibility of passively sending dirty data to the memory controller.
[0119] Therefore, when the number of occupied cache lines of the cache reaches a second set value, it is deemed that the conditions for actively scheduling write commands are met. Before the cache line is assigned to a new memory address, when the number of dirty cache lines reaches a second set value, the dirty data of the cache line is sent to the memory controller. Here, the second set value can be set according to the performance of the cache. For example, the second set value can be 1 / 2, or 2 / 3 of the number of cache lines of the cache, etc.
[0120] Whether the number of read commands in the read queue of the memory controller is less than the first set value is a condition for actively scheduling write commands provided by an embodiment of the present application. Before this, it is necessary to obtain the operating status information of the memory controller. In addition, when actively sending dirty data to the memory controller, a more efficient method can be selected according to the memory address being accessed by the memory controller to selectively send dirty data stored in dirty cache lines to improve memory access efficiency.
[0121] For example, referring to FIG13 , before S320 , the control method further includes:
[0122] S311: Acquire operation status information of the memory controller, where the operation status information includes the number of read commands in the read queue of the memory controller and the memory address currently being accessed by the memory controller.
[0123] Obtaining operating status information of the memory controller, such as the number of read commands in a read queue of the memory controller, a memory address currently being accessed by the memory controller, etc. After obtaining the number of read commands, dirty data can be proactively sent to the memory controller when the number of read commands in the read queue is small, for example, less than a first set value.
[0124] As mentioned in the above examples, when accessing memory, switching between different rows in the same storage bank for access, and switching between different storage columns in the same channel for access, will result in efficiency loss. In order to avoid such efficiency loss, in the solution provided in the embodiment of the present application, when the cache actively sends dirty data to the memory controller, when obtaining the memory address that the memory controller is accessing, the dirty data whose target address is located in the same row as the memory unit currently being accessed by the memory controller can be sent to the memory controller, or, in the absence of a write command for the same row, the write command whose target address is located in the same storage bank or the same storage column can be sent to the memory controller. This can reduce the efficiency loss caused by switching rows, switching storage banks, or switching storage columns. The target address here refers to the target address of the write command. For example, the write command includes write data and a target address. When the cache caches the write command, a cache row is determined according to the target address, and this cache row is used to cache the write data of the write command.
[0125] For example, referring to FIG. 14 , in one possible implementation, S330 , before the cache line is assigned to a new memory address, sending a write command cached by the cache line to the memory controller may include:
[0126] S330a: Before the cache line is allocated to a new memory address, according to the memory address currently accessed by the memory controller, dirty data whose target address is located in the same row as the currently accessed memory address is selected and sent to the memory controller.
[0127] The write commands located on the same row are sent to the memory controller. In this way, no matter whether the current command is a write command or a read command, after the previous command is executed, there is no need to switch rows. The write command actively sent to the memory controller by the cache can be executed, and the address of the write command is located on the same row as the address of the previous command, thereby reducing the overhead caused by switching rows and improving memory access efficiency.
[0128] In one possible implementation, the commands cached by the cache cannot match a write command located in the same row as the memory address being accessed by the memory controller. In this case, the cache can choose a write command located in the same bank as the memory address being accessed.
[0129] For example, referring to FIG. 15 , in one possible implementation, S330 , before the cache line is assigned to a new memory address, sending a write command cached by the cache line to the memory controller may include:
[0130] S330b: Before the cache line is allocated to the new memory address, according to the memory address currently accessed by the memory controller, a write command whose target address and the currently accessed memory address are located in the same memory bank is selected and sent to the memory controller.
[0131] In another possible implementation, the commands cached by the cache cannot match a write command located in the same row as the memory address being accessed by the memory controller. In this case, the cache can choose a write command located in the same storage column (rank) as the memory address being accessed.
[0132] For example, referring to FIG. 16 , in a possible implementation, S330 , before the cache line is assigned to a new memory address, sending a write command cached by the cache line to the memory controller may include:
[0133] S330c: Before the cache line is allocated to a new memory address, according to the memory address currently accessed by the memory controller, dirty data whose target address and the currently accessed memory address are located in the same storage column are selected and sent to the memory controller.
[0134] For example, when there is no dirty data located in the same storage bank as the address of the currently accessed memory unit, sending the dirty data located in the same storage column as the address of the currently accessed memory unit to the memory controller can also reduce the overhead of switching storage columns. After executing the access request of the same storage column, switching the storage column access can also reduce the number of switches and improve memory access efficiency.
[0135] Combined with the above example, we know that when accessing memory, switching rows and storage columns will cause delays. When the cache actively schedules write commands to the memory controller, it can improve memory access efficiency by sending dirty data located in the same row or the same storage column (rank) to the memory controller. In other words, when scheduling write commands, commands with adjacent addresses should be scheduled together as much as possible.
[0136] For example, if row1 and row2 are located in the same bank, if the target address of data DATA1 is located in row1, the target address of data DATA2 is located in row2, and the target address of data DATA3 is also located in row1, if data DATA1, data DATA2 and data DATA3 are written into the memory in sequence, then first accessing row1, then switching to access row2, and then switching to access row1 will incur the overhead of two row switches. However, if data DATA1 and DATA3 with target addresses in the same row are first written into row1, and then switching to writing data DATA2 into row2, then only the overhead of one row switch will be incurred. Therefore, the delay caused by switching rows can be reduced and access efficiency can be improved.
[0137] To implement such a scheduling method, two prerequisites need to be ensured. First, the address being accessed by the memory controller should be determined based on the operating status information of the memory controller, including the row being accessed, the storage bank being accessed, the storage column (rank), etc. In this way, when scheduling a write command, the dirty data of the address adjacent to the target address and the address being accessed is sent to the memory controller, which can reduce the switching overhead and reduce the delay. The adjacent addresses here include addresses in the same row as the address being accessed, as well as addresses in the same storage bank (bank) or the same storage column (rank); secondly, it should also be possible to determine in which storage column (rank), which storage bank (bank) and which row the address to be accessed by the dirty data cached in the cache row of the cache is located, so that the dirty data of the address adjacent to the address being accessed can be efficiently selected and sent to the memory controller.
[0138] As mentioned in the above example, the physical address of the memory can be mapped to a specific cache line according to the set index part and the tag part of the physical address of the memory. The tag field is the high bit of the physical address of the memory, and the set index field is the middle bit of the memory address. In order to facilitate the scheduling of write commands and improve the access efficiency of the memory, the embodiment of the present application provides another mapping method. As shown in Figure 17, taking a 32-bit physical address as an example, in a possible implementation method, after the physical address is parsed by the memory controller, bit 0 is the data width (DW), bits 1 to 3 are used to indicate the bank address, bits 4 to 13 are used to indicate the column address, bits 14 to 31 are used to indicate the row address, and bit 31 is used to indicate the storage column address.
[0139] When the cache maps the physical address of the memory, as shown in Figure 18, the physical address is divided into a tag, a set index, and a block offset. Bits 0-5 are the block offset, bits 6-22 are the set index, and bits 23-31 are the tag. As can be seen, when the cache stores data or commands, bits 6-22 of the physical address determine which set it is stored in. This means that bits 2-9 of the column address and bits 0-8 of the row address determine which set it is stored in. This means that commands or data located in the same row can be placed in any set.
[0140] To this end, an embodiment of the present application provides a new physical address mapping method, wherein, referring to Figure 19, the row address in the physical address is used as a set index, the storage column (rank) address, the storage bank address and the high bit of the column address in the physical address are used as tags, and the low bit of the column address and the data bit width are used as block offsets. In this way, when mapping to cache lines according to the physical address, it can be ensured that the write data of write commands with the same row address will be placed in the same set. In this way, when scheduling write commands, dirty data with target addresses located in the same row can be found in the same set, which can improve the efficiency of scheduling.
[0141] Based on this, on the basis of the above example, referring to FIG. 20 , S210 includes:
[0142] S210a: Allocate the write data of the received write commands whose target addresses are located in the same row to cache lines of the same group for storage.
[0143] For example, the row address in the memory physical address is used as the set index, the storage column (rank) address, the storage bank address and the high bit of the column address in the physical address are used as the tag, and the low bit of the column address and the data bit width are used as the block offset. In this way, when mapping to the cache line according to the physical address, it can be ensured that the write data of the write commands with the same row target address will be placed in the same group (set). In this way, when scheduling the write commands, the write commands located in the same row can be found in the same group, or, according to the memory address, the write commands adjacent to the memory address (located in the same row, the same storage bank or the same storage column) can be found for scheduling, which can improve the efficiency of scheduling.
[0144] In one possible implementation, for a cache, the number of cache lines in a set is limited. For example, if a set includes 8 cache lines, and these 8 cache lines store the write data of 8 write commands whose addresses are located on the same line, when the 9th write command whose address is located on this line enters the cache, the write data stored in a dirty cache line among the 8 cache lines will be kicked out to the memory controller. This will again cause the cache to passively kick the write data to the memory controller, which is what we want to avoid.
[0145] For example, in a possible implementation, referring to FIG. 21 , S210 includes:
[0146] S201b: Allocate the write data of the received write commands whose target addresses are located in the same row to cache lines of a plurality of adjacent groups for storage.
[0147] In order to avoid the commands in the same row from being kicked together, the row address can be hashed, and the data or commands in the same row can be distributed to several adjacent groups (sets). For example, after XORing the low bit of the row address with a part of the column address, the data or commands in the same row can be distributed to several adjacent groups (sets). For example, the low 2 bits of the row address are XORed with the high 2 bits of the column address, and the write data of the write command in the same row can be distributed to 4 adjacent groups (sets) for storage; if the low 4 bits of the row address are XORed with the high 4 bits of the column address, as shown in Figure 22, the write data of the write command in the same row can be distributed to 16 adjacent groups (sets) for storage, which can avoid the write data of the write commands in the same row from being kicked together in the same group (set).
[0148] For example, still taking the above-mentioned 32-bit physical address as an example, when mapping, the storage column (rank) address, the storage bank address, and the 5th to 9th bits of the column address, the 4th to 16th bits of the row address, and the XOR of the 0th to 3rd bits of the row address with the 6th to 9th bits of the column address are used as tags, and the 0th to 4th bits of the column address and the data bit width are used as set indexes. In this way, when the cache stores write data, the write data of the write commands with addresses in the same row can be stored in 16 adjacent sets, which can improve the efficiency of finding data or commands in the same row, storage bank, or storage column (rank). In this way, when scheduling write commands, commands in the same row, storage bank, or storage column (rank) can be centrally scheduled, reducing the overhead generated by switching.
[0149] 23 , the method flow provided in the embodiment of the present application is introduced by taking a write command entering LLC as an example.
[0150] S401: The buffer receives a write command.
[0151] S402: Map the received write command to the cache line according to the set mapping relationship.
[0152] S403: Determine whether it is a hit.
[0153] S404: If a hit occurs, rewrite the data in the hit cache line.
[0154] For example, if the write command is to rewrite the data in storage unit A in the memory to 0, if storage unit A in the memory has a corresponding cache in the buffer, when the write command enters the buffer, it can find the corresponding cache line according to the set index (set index), tag (tag), etc. of the address of storage unit A, and then locate a specific data in the cache line according to the block index (block offset) of the address of storage unit A, and rewrite it to 0, thus completing the data writing, and then write it into the memory at the appropriate time.
[0155] S405: If missing, allocate a new cache line for the write command.
[0156] The new cache line here is a cache line determined according to the set index (set index) and tag (tag) of the address of the write command.
[0157] S406: Before the cache line is allocated to a new memory address, determine whether a condition for actively scheduling a write command is met.
[0158] The conditions for actively scheduling write commands here may include: the number of read commands from the memory controller is less than a first set value, or the number of dirty cache lines in the cache is greater than a second set value.
[0159] S407 , if the conditions for actively scheduling a write command are met, the dirty data of the cache line is sent to the memory controller, and the state of the cache line is changed to clean.
[0160] If the conditions for actively scheduling a write command are met, the write data of the write command is sent to the memory controller for execution.
[0161] S408: If the condition for actively scheduling the write command is not met, the dirty data of the cache line is passively sent to the memory controller according to a conventional cache control strategy.
[0162] If the conditions for actively scheduling a write command are not met, the cache line is assigned to a new command or data according to a conventional cache control strategy, or the write command is passively sent to the memory controller in response to a cache maintenance operation command.
[0163] An embodiment of the present application further provides a cache, which is arranged between a processor and a memory, wherein the cache is used to execute the cache control method provided by each of the aforementioned embodiments.
[0164] An embodiment of the present application further provides a computer system, such as the computer system shown in FIG. 4 or 5 , wherein the computer system includes a processor, a memory, and a cache, wherein the processor, the memory, and the cache are connected via a bus.
[0165] Those skilled in the art will appreciate that, in one or more of the examples above, the functions described herein may be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions may be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any medium that facilitates the transmission of a computer program from one place to another. The storage medium may be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0166] Finally, it should be noted that the above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A buffer control method, characterized in that: The cache is connected to a memory controller, the cache includes a plurality of cache lines, and the method includes: storing the received write data of the write command into the cache line; Before the cache line is allocated to a new memory address, dirty data stored in the cache line is sent to the memory controller, where the dirty data refers to the write data to be written into the memory.
2. The buffer control method according to claim 1, characterized in that: Before the cache line is assigned to a new memory address, sending the dirty data stored in the cache line to the memory controller includes: Before the cache line is allocated to a new memory address, when the number of read commands in the read queue of the memory controller is less than a first set value, the dirty data stored in the cache line is sent to the memory controller.
3. The buffer control method according to claim 1, characterized in that: Before the cache line is assigned to a new memory address, sending the dirty data stored in the cache line to the memory controller includes: Before the cache line is allocated to a new memory address, when the number of dirty cache lines reaches a second set value, the dirty data stored in the cache line is sent to the memory controller, and the dirty cache line is the cache line storing the dirty data.
4. The buffer control method according to claim 2 or 3, characterized in that: The sending the dirty data stored in the cache line to the memory controller comprises: According to the memory address currently accessed by the memory controller, dirty data whose target address and the currently accessed memory address are located in the same storage column are selected and sent to the memory controller.
5. The buffer control method according to claim 2 or 3, characterized in that: The sending the dirty data stored in the cache line to the memory controller comprises: According to the memory address currently accessed by the memory controller, dirty data whose target address and the currently accessed memory address are located in the same storage bank are selected and sent to the memory controller.
6. The buffer control method according to claim 2 or 3, characterized in that: The sending the dirty data stored in the cache line to the memory controller comprises: According to the memory address currently accessed by the memory controller, dirty data whose target address and the currently accessed memory address are located in the same row are selected and sent to the memory controller.
7. The buffer control method according to any one of claims 1 to 6, characterized in that: Before sending the dirty data stored in the cache line to the memory controller, the method further includes: The operating status information of the memory controller is obtained, where the operating status information includes the number of read commands in the read queue of the memory controller and the memory address currently being accessed by the memory controller.
8. The buffer control method according to any one of claims 1 to 6, characterized in that: The cache includes a plurality of groups, each of the groups includes a plurality of cache lines, and storing the write data of the received write command into the cache lines includes: The write data of the received write commands whose target addresses are located in the same row are allocated to the cache row of the same group for storage.
9. The buffer control method according to any one of claims 1 to 6, characterized in that: The cache includes a plurality of groups, each of the groups includes a plurality of cache lines, and storing the write data of the received write command into the cache lines includes: The write data of the received write command whose target address is located in the same row are allocated to the cache lines of the adjacent plurality of groups for storage.
10. A buffer, characterized in that: The buffer is used to execute the method according to any one of claims 1 to 9.
11. A computer system, characterized in that: The computer system comprises a processor, a memory and the buffer as claimed in claim 10, wherein the processor, the memory and the buffer are connected via a bus.
Citation Information
Patent Citations
Buffer, control method thereof and computer system
CN118689800A
Method and system for ensuring data crash consistency
CN107329696A
Method and system for controlling SSD cache brushing-down speed in distributed storage system
CN111857589A
System-on-chip non-Cache data access method and device and electronic equipment
CN115794673A
Data writing method and device, graphic processing system, electronic component and electronic equipment
CN115794675A
