Data reading and writing method and apparatus
By setting a preset rewrite count mechanism for the cache proxy in a multi-core system, the cache proxy directly receives data and exclusive status when the count is reached, solving the exclusive status delay problem, improving data writing efficiency and ensuring data consistency.
Patent Information
- Application Number
- PCT/CN2024/136426
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-03-25
- Filing Date
- 2024-12-03
- Publication Date
- 2025-10-02
AI Technical Summary
In the existing technology, the latency for a multi-core system to obtain an exclusive state when writing shared data is long, which affects the efficiency of writing shared data. The state speculation strategy cannot effectively reduce the latency in the sharing scenario.
By setting a preset number of times in the cache proxy, when the number of consecutive rewrites of the data corresponding to the target address reaches the preset number, the cache proxy directly receives the data and the exclusive state without obtaining the exclusive state again, thereby achieving direct data rewrite.
This reduces the latency of acquiring exclusive status, improves the efficiency of writing data, and ensures data consistency across multiple cache agents.
Smart Images

Figure CN2024136426_02102025_PF_FP_ABST
Abstract
Description
Data reading and writing method and device
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on March 25, 2024, with application number 202410350489.9 and application name “A Data Reading and Writing Method and Device”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of communication technology, and in particular to a data reading and writing method and device. Background Art
[0003] To ensure atomic correctness when reading and writing shared data by multiple cores, the shared data must be stored in a critical region of the memory. This critical region is a memory region protected by a lock mechanism. Only cores with access rights can read and write shared data within the critical region. When the first core with access rights among multiple cores reads or writes shared data, the first core sends a read request to the memory to obtain the shared data and the shared status. The read request includes the storage address of the shared data. The memory sends the shared data and the shared status to the first core. The shared status indicates that the shared data is valid for at least two cores. After reading the shared data, the first core calculates the shared data and obtains the result. The first core then sends a write request to the memory to obtain the exclusive status. The write request includes the storage address of the shared data. The memory sends the shared data and the exclusive status to the first core. The exclusive status indicates that the shared data is valid only for one core. After obtaining the exclusive status, the first core writes the result to the address. Because the exclusive status must be obtained before writing shared data, the latency of obtaining the exclusive status reduces the efficiency of writing shared data. Therefore, how to reduce the latency of obtaining exclusive status and improve the efficiency of writing shared data has become an urgent problem that needs to be solved.
[0004] Currently, a state speculation strategy is used to reduce the latency of acquiring exclusive status. Specifically, the first core sends a read request to the home agent (HA), which includes the storage address of the shared data. The HA determines whether the shared data is valid in other cores. Valid states include shared, exclusive, and overwritten. If the shared data is valid in other cores, the shared data and shared status are sent to the first core. The scenario where the shared data is valid in other cores is called a shared scenario. If the shared data is invalid in other cores, the shared data and exclusive status are sent to the first core. That is, the first core directly receives the exclusive status after sending the read request. When writing the operation results of the shared data, there is no need to obtain the exclusive status, which reduces the latency of acquiring the exclusive status.
[0005] However, the state speculation strategy cannot reduce the latency of obtaining exclusive state in a shared scenario. Summary of the Invention
[0006] The present application provides a data reading and writing method and device for reducing the latency of acquiring an exclusive state and improving the efficiency of writing data.
[0007] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0008] In a first aspect, a data reading and writing method is provided, which is applied to a storage system including multiple cache agents and a local agent HA, wherein the HA manages the multiple cache agents, and the multiple cache agents are used to manage multiple caches. The method includes: a first cache agent sends a read request to the HA, the read request is used to obtain data corresponding to a target address and a sharing status, and the first cache agent is a cache agent with access rights among the multiple cache agents; when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first cache agent receives first status information, the first status information is used to indicate first data and an exclusive status, the first data being data corresponding to the target address in a second cache agent that accesses the target address before the first cache agent; and the first cache agent rewrites the first data in the first cache agent into the second data.
[0009] In the above technical solution, the first cache agent with access rights among multiple cache agents sends a read request to the HA to obtain the data corresponding to the target address and the shared status. When the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first cache agent receives the first data and the exclusive status. The first data is the data corresponding to the target address in the second cache agent that accessed the target address before the first cache agent. When the first cache agent rewrites the first data, it no longer needs to obtain the exclusive status, thereby reducing the delay in obtaining the exclusive status and improving the efficiency of writing data.
[0010] In a possible implementation of the first aspect, the method further includes: the second cache agent receives first indication information sent by the HA, the first indication information being used to indicate whether a third cache agent that accessed the target address before the second cache agent rewrites the data corresponding to the target address; when the second cache agent determines that both the third cache agent and the second cache agent rewrite the data corresponding to the target address, the second cache agent sends first status information to the first cache agent. In the above possible implementation, when the second cache agent determines that both the third cache agent and the second cache agent rewrite the data corresponding to the target address, that is, when the data corresponding to the target address is rewritten twice in a row, the second cache agent sends the first status information to the first cache agent, that is, the second cache agent performs a status upgrade and directly sends the exclusive status and the first data to the first cache agent. After receiving the first status information, the first cache agent can directly rewrite the first data without obtaining the exclusive status, thereby reducing the latency in obtaining the exclusive status and improving the efficiency of writing data.
[0011] In a possible implementation of the first aspect, the method further includes: the second cache agent sending second state information to the HA, the second state information including the first data and the overwritten state, and updating the state of the first data in the second cache agent from the overwritten state to the invalid state. In this possible implementation, the consistency of the data corresponding to the target address is ensured across multiple cache agents.
[0012] In one possible implementation of the first aspect, the first indication information is sent by the HA when determining that the data corresponding to the target address is in a valid state in the second cache agent, where the valid state includes a shared state, an exclusive state, or an overwrite state. In this possible implementation, the HA determines that the data corresponding to the target address is in a valid state in the second cache agent, thereby resolving the latency issue of obtaining an exclusive state in a shared scenario and improving data writing efficiency.
[0013] In a possible implementation of the first aspect, the first cache agent receives the first status information, including: when the HA determines that the number of consecutive rewrites of data corresponding to the target address has reached a preset number, the first cache agent receives the first status information sent by the HA. In this possible implementation, the first cache agent receives the first status information sent by the HA, i.e., the HA performs a status upgrade, and the HA directly sends the exclusive status and the first data to the first cache agent. After receiving the first status information, the first cache agent can directly rewrite the first data without retrieving the exclusive status, thereby reducing the latency of obtaining the exclusive status, improving data writing efficiency, and increasing the selectivity of the solution.
[0014] In a possible implementation of the first aspect, the method further includes: the second cache agent receiving second indication information sent by the HA, the second indication information being used to instruct: sending second status information to the HA, the second status information including the first data and the rewrite status, and information indicating whether the second cache agent rewrites the data corresponding to the target address; and the second cache agent responding to the second indication information. In the above possible implementation, the HA obtains the second status information, ensuring that the data corresponding to the target address sent by the HA to the first cache agent is the latest data, and ensuring the consistency of the target data across multiple cache agents.
[0015] In one possible implementation of the first aspect, the second indication information is sent by the HA when determining that the data corresponding to the target address is in a valid state in the second cache agent, where the valid state includes a shared state, an exclusive state, or an overwrite state. In this possible implementation, the HA determines that the data corresponding to the target address is in a valid state in the second cache agent, thereby resolving the latency issue of obtaining the exclusive state in a shared scenario and improving data writing efficiency.
[0016] In a possible implementation of the first aspect, the method further includes: the second cache agent receiving third indication information sent by the HA, the third indication information being used to instruct the second cache agent to update the state of the first data in the second cache agent from an overwritten state to an invalid state; and the second cache agent responding to the third indication information. In the above possible implementation, the consistency of the target first corresponding data in multiple cache agents is ensured.
[0017] In a possible implementation of the first aspect, the method further includes: when the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, the first cache agent receives third status information sent by the second cache agent, the third status information is used to indicate the first data and the shared status; the first cache agent sends a write request to the HA based on the third status information, the write request is used to obtain the data corresponding to the target address and the exclusive status; the first cache agent receives the first status information sent by the HA.
[0018] In a possible implementation of the first aspect, the method further includes: when the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, the first cache agent receives third status information sent by the HA, where the third status information is used to indicate the first data and the shared status; the first cache agent sends a write request to the HA based on the third status information, where the write request is used to obtain the data corresponding to the target address and the exclusive status; and the first cache agent receives the first status information sent by the HA.
[0019] In a second aspect, a data reading and writing method is provided, which is applied to a storage system including multiple cache agents and a local agent HA, wherein the HA manages the multiple cache agents, and the multiple cache agents are used to manage multiple caches. The method includes: the HA receives a read request sent by a first cache agent, the read request is used to obtain data and a sharing status corresponding to a target address, and the first cache agent is a cache agent with access rights among the multiple cache agents; the HA sends relevant information for sending first status information to the second cache agent, and the first status information is sent when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number. The first status information is used to indicate first data and an exclusive status, and the first data is the data corresponding to the target address in the second cache agent that accesses the target address before the first cache agent.
[0020] In the above technical solution, after the HA receives the read request sent by the first cache agent, it sends relevant information for sending the first data and the exclusive status to the second cache agent, so that the first cache agent receives the first data and the exclusive status when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number. When the first cache agent rewrites the first data, it no longer needs to obtain the exclusive status, thereby reducing the delay in obtaining the exclusive status and improving the efficiency of writing data.
[0021] In a possible implementation of the second aspect, the relevant information includes first indication information, and the HA sending the relevant information to the second cache agent includes: the HA sending the first indication information to the second cache agent, the first indication information being used to indicate whether a third cache agent that accessed the target address before the second cache agent rewrites the data corresponding to the target address; the first status information is sent by the second cache agent when it determines that both the third cache agent and the second cache agent rewrite the data corresponding to the target address. In the above possible implementation, the first data and the exclusive status are sent by the second cache agent when it determines that both the third cache agent and the second cache agent rewrite the data corresponding to the target address, that is, the second cache agent upgrades its status according to the first indication information. After the first cache agent receives the first data and the exclusive status, it can rewrite the data without obtaining the exclusive status, thereby reducing the latency in obtaining the exclusive status and improving the efficiency of writing data.
[0022] In a possible implementation of the second aspect, the method further includes: the HA receiving second state information sent by the second cache agent, the second state information including the first data and the overwrite state, and updating the state of the first data in the HA from an exclusive state to an overwrite state. In this possible implementation, consistency of the data corresponding to the target address is ensured across multiple cache agents.
[0023] In one possible implementation of the second aspect, the first indication information is sent by the HA when determining that the data corresponding to the target address is in a valid state in the second cache agent. The valid state includes a shared state, an exclusive state, or an overwritten state. This possible implementation solves the problem of latency in obtaining the exclusive state in a shared scenario and improves data writing efficiency.
[0024] In a possible implementation of the second aspect, the relevant information further includes second indication information, and the HA sends the relevant information to the second cache agent, including: the HA sending the second indication information to the second cache agent, the second indication information being used to indicate: sending second status information to the HA, the second status information including first data and an overwrite status, and information indicating whether the second cache agent overwrites the data corresponding to the target address; the HA receiving the second status information sent by the second cache agent and the information indicating whether the second cache agent overwrites the data corresponding to the target address, and updating the status of the first data in the second cache agent from an exclusive status to an overwrite status; and when the HA determines that the number of consecutive overwrites of the data corresponding to the target address reaches a preset number, the HA sends the first status information to the first cache agent. In the above possible implementation, the first data and the exclusive status are sent by the HA when it determines that both the third cache agent and the second cache agent have overwritten the data corresponding to the target address, i.e., the HA performs a status upgrade based on the second indication information. After the first cache agent receives the first data and the exclusive status, it can overwrite the data without retrieving the exclusive status, thereby reducing the latency in obtaining the exclusive status, improving data writing efficiency, and increasing the selectivity of the solution.
[0025] In one possible implementation of the second aspect, the second indication information is sent by the HA when determining that the status of the first data in the second cache agent is valid, where the valid status includes a shared status, an exclusive status, or an overwritten status. This possible implementation solves the issue of latency in obtaining the exclusive status in a shared scenario and improves data writing efficiency.
[0026] In a possible implementation of the second aspect, the method further includes: the HA sending third indication information to the second cache agent, the third indication information being used to instruct the second cache agent to update the state of the first data in the second cache agent from an overwritten state to an invalid state. In this possible implementation, the consistency of the data corresponding to the target address in multiple cache agents is ensured.
[0027] In a possible implementation of the second aspect, the method further includes: when the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, the HA receives a write request sent by the first cache agent, the write request is used to obtain the data corresponding to the target address and the exclusive status, the write request is sent by the first cache agent after receiving the third status information sent by the second cache agent, the third status information is used to indicate the first data and the shared status; the HA sends the first status information to the first cache agent.
[0028] In a possible implementation of the second aspect, the method further includes: when the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, the HA sends third status information to the first cache agent, where the third status information is used to indicate the first data and the shared status; the HA receives a write request sent by the first cache agent, where the write request is used to obtain the data corresponding to the target address and the exclusive status; and the HA sends the first status information to the first cache agent.
[0029] According to a third aspect, a data reading and writing device is provided, which is applied to a storage system including multiple cache agents and a local agent HA, wherein the HA manages the multiple cache agents, and the multiple cache agents are used to manage multiple caches. The device includes: a first sending unit, which is used to send a read request to the HA, and the read request is used to obtain data corresponding to the target address and the sharing status. The first sending unit is a sending unit in the first cache agent with access rights among the multiple cache agents; a first receiving unit, which is used to receive first status information when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, and the first status information is used to indicate first data and an exclusive status. The first data is data corresponding to the target address in the second cache agent that accesses the target address before the first cache agent; and a first rewriting unit, which is used to rewrite the first data in the first cache agent into the second data.
[0030] In a possible implementation of the third aspect, the device also includes: a second receiving unit, configured to receive first indication information sent by the HA, where the first indication information is used to indicate whether a third cache agent that accesses the target address before the second cache agent rewrites data corresponding to the target address; and a second sending unit, configured to send first status information to the first cache agent when it is determined that both the third cache agent and the second cache agent rewrite the data corresponding to the target address.
[0031] In a possible implementation of the third aspect, the device also includes: a first update unit, a second sending unit, further used to send second status information to the HA, the second status information including the first data and the rewrite status; the first update unit, used to update the status of the first data in the second cache agent from the rewrite status to the invalid status.
[0032] In a possible implementation of the third aspect, the first indication information is sent by the HA when determining that the data corresponding to the target address is in a valid state in the second cache agent, where the valid state includes a shared state, an exclusive state, or an overwritten state.
[0033] In a possible implementation of the third aspect, the first receiving unit is further configured to: when the HA determines that the number of consecutive rewrites of data corresponding to the target address reaches a preset number, receive the first status information sent by the HA.
[0034] In a possible implementation of the third aspect, the second receiving unit is used to receive second indication information sent by the HA, where the second indication information is used to indicate: sending second status information to the HA, where the second status information includes the first data and the rewrite status, and information about whether the second cache agent rewrites the data corresponding to the target address; and the second sending unit is further used to send the second status information to the HA.
[0035] In a possible implementation of the third aspect, the second indication information is sent by the HA when determining that the state corresponding to the target address in the second cache agent is a valid state, where the valid state includes a shared state, an exclusive state, or an overwritten state.
[0036] In a possible implementation of the third aspect, the second receiving unit is further used to receive third indication information sent by the HA, where the third indication information is used to indicate that the state of the first data in the second cache agent is updated from the overwritten state to the invalid state; and the first updating unit is further used to update the state of the first data in the second cache agent from the overwritten state to the invalid state.
[0037] In a possible implementation of the third aspect, the first receiving unit is further used to receive third status information sent by the second cache agent when the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, and the third status information is used to indicate the first data and the shared status; the first sending unit is further used to send a write request to the HA according to the third status information, and the write request is used to obtain the data corresponding to the target address and the exclusive status; the first receiving unit is further used to receive the first status information sent by the HA.
[0038] In a possible implementation of the third aspect, the first receiving unit is further used to receive third status information sent by the HA when the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, and the third status information is used to indicate the first data and the shared status; the first sending unit is further used to send a write request to the HA according to the third status information, and the write request is used to obtain the data corresponding to the target address and the exclusive status; the first receiving unit is also used to receive the first status information sent by the HA.
[0039] In a fourth aspect, a data reading and writing device is provided, which is applied to a storage system including multiple cache agents and a local agent HA, wherein the HA manages the multiple cache agents, and the multiple cache agents are used to manage multiple caches. The device includes: a third receiving unit, used to receive a read request sent by a first cache agent, the read request is used to obtain data corresponding to a target address and a sharing status, and the first cache agent is a cache agent with access rights among the multiple cache agents; a third sending unit, used to send relevant information for sending first status information to the second cache agent, and the first status information is sent when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, and the first status information is used to indicate first data and an exclusive status, and the first data is the data corresponding to the target address in the second cache agent that accesses the target address before the first cache agent.
[0040] In a possible implementation of the fourth aspect, the relevant information includes first indication information, and the third sending unit is further specifically used to: send the first indication information to the second cache agent, where the first indication information is used to indicate: whether a third cache agent that accesses the target address before the second cache agent rewrites data corresponding to the target address; the first status information is sent by the second cache agent when it determines that both the third cache agent and the second cache agent rewrite the data corresponding to the target address.
[0041] In a possible implementation of the fourth aspect, the third receiving unit is further used to receive second status information sent by the second cache agent, where the second status information includes the first data and the rewrite status; and the second updating unit is used to update the status of the first data in the HA from the exclusive status to the rewrite status.
[0042] In a possible implementation of the fourth aspect, the first indication information is sent by the third sending unit when it is determined that the status of the data corresponding to the target address in the second cache agent is a valid state, where the valid state includes a shared state, an exclusive state, or an overwritten state.
[0043] In a possible implementation of the fourth aspect, the relevant information also includes second indication information, and the third sending unit is further used to send the second indication information to the second cache agent, where the second indication information is used to indicate: sending second status information to the HA, the second status information including the first data and the rewrite status, and information on whether the second cache agent rewrites the data corresponding to the target address; the third receiving unit is further used to receive the second status information sent by the second cache agent, and information on whether the second cache agent rewrites the data corresponding to the target address; the second updating unit is further used to update the status of the first data in the second cache agent from an exclusive status to a rewrite status; and the third sending unit is further used to send the first status information to the first cache agent when it is determined that the number of consecutive rewrites of the data corresponding to the target address reaches a preset number.
[0044] In a possible implementation of the fourth aspect, the second indication information is sent by the HA when determining that the data corresponding to the target address is in a valid state in the second cache agent, where the valid state includes a shared state, an exclusive state, or an overwritten state.
[0045] In a possible implementation of the fourth aspect, the third sending unit is further configured to send third indication information to the second cache agent, where the third indication information is configured to instruct to update the state of the first data in the second cache agent from an overwritten state to an invalid state.
[0046] In a possible implementation of the fourth aspect, the third receiving unit is further used to receive a write request sent by the first cache agent when the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, the write request being used to obtain the data corresponding to the target address and the exclusive status, and the write request being sent by the first cache agent after receiving third status information sent by the second cache agent, the third status information being used to indicate the first data and the shared status; the third sending unit is further used to send the first status information to the first cache agent after the third receiving unit receives the write request.
[0047] In a possible implementation of the fourth aspect, the third sending unit is further used to send third status information to the first cache agent when the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, and the third status information is used to indicate the first data and the shared status; the third receiving unit is further used to receive a write request sent by the first cache agent, and the write request is used to obtain the data corresponding to the target address and the exclusive status; the third sending unit is further used to send the first status information to the first cache agent after the third receiving unit receives the write request.
[0048] In a fifth aspect, an electronic device is provided, which includes a memory and a processor, the processor includes a storage system, the storage system includes multiple cache agents and a local agent HA, the HA is used to execute the data reading and writing method provided by the above-mentioned first aspect or any possible implementation of the first aspect, the multiple cache agents are used to execute the data reading and writing method provided by the above-mentioned second aspect or any possible implementation of the second aspect, and the memory is used to store data.
[0049] In another aspect of the present application, a computer-readable storage medium is provided, in which a computer program or instruction is stored. When the computer program or instruction is executed, the data reading and writing device implements the data reading and writing method provided by the first aspect or any possible implementation of the first aspect.
[0050] In another aspect of the present application, a computer-readable storage medium is provided, in which a computer program or instruction is stored. When the computer program or instruction is executed, the data reading and writing device implements the data reading and writing method provided by the second aspect or any possible implementation of the second aspect.
[0051] In another aspect of the present application, a computer program product is provided, which includes: a computer program (also referred to as code, or instructions), which, when executed, enables a data reading and writing device to execute a data reading and writing method as provided in the first aspect or any possible implementation of the first aspect.
[0052] In another aspect of the present application, a computer program product is provided, which includes: a computer program (also referred to as code, or instructions), which, when executed, enables a data reading and writing device to execute a data reading and writing method as provided in the second aspect or any possible implementation of the second aspect.
[0053] It can be understood that the beneficial effects that can be achieved by any of the data reading and writing devices, computer-readable storage media and computer program products provided above can correspond to the beneficial effects of the data reading and writing methods provided above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] FIG1 is a schematic diagram of the structure of a storage system provided in an embodiment of the present application;
[0055] FIG2 is a schematic diagram of the structure of another storage system provided in an embodiment of the present application;
[0056] FIG3 is a schematic structural diagram of an electronic device provided in an embodiment of the present application;
[0057] FIG4 is a flow chart of a data reading and writing method provided in an embodiment of the present application;
[0058] FIG5 is a flow chart of another data reading and writing method provided in an embodiment of the present application;
[0059] FIG6 is a flow chart of another data reading and writing method provided in an embodiment of the present application;
[0060] FIG7 is a flow chart of another data reading and writing method provided in an embodiment of the present application;
[0061] FIG8 is a flowchart of another data reading and writing method provided in an embodiment of the present application;
[0062] FIG9 is a flowchart of another data reading and writing method provided in an embodiment of the present application;
[0063] FIG10 is a schematic structural diagram of a data reading and writing device provided in an embodiment of the present application;
[0064] FIG11 is a schematic structural diagram of another data reading and writing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0065] In this application, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the relationship between associated objects, indicating that three relationships can exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, or B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, "at least one of a, b, or c" can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple. In addition, the embodiments of this application use words such as "first" and "second" to distinguish between identical or similar items with substantially the same function and effect. For example, the first threshold and the second threshold are merely to distinguish different thresholds and do not define their order of precedence. Those skilled in the art will understand that words such as "first" and "second" do not define the quantity or execution order.
[0066] It should be noted that, in this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described in this application as "exemplary" or "for example" should not be construed 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.
[0067] Before introducing the embodiments of the present application, the relevant knowledge involved in the present application is first explained.
[0068] To ensure atomic correctness when reading and writing shared data across multiple cores (also known as processing cores, kernels, or processor cores), shared data must be stored within a critical region of memory. This critical region is a memory area protected by a lock mechanism. Only cores with access rights can read and write shared data within the critical region. The following briefly describes the process of obtaining access rights to a critical region.
[0069] For the first core among multiple cores, the first core sends an access request to the memory for accessing the target address. The access request includes the target address, which is the storage address in the critical region. The memory receives the access request. If the lock variable of the critical region is 0, the memory sends a first indication message to the first core. The first indication message indicates that the first core has access rights to the critical region, and the lock variable 0 indicates that no other core is accessing the critical region. If the lock variable of the critical region is 1, the memory sends a second indication message to the first core. The second indication message indicates that other cores are accessing the critical region and the first core cannot access the critical region. The lock variable 1 indicates that a core is accessing the critical region. Therefore, each core needs to obtain access rights to the critical region before reading and writing shared data in the critical region. Only cores with access rights can read and write shared data in the critical region.
[0070] In one possible embodiment, when a core with access rights to a critical region reads or writes shared data, it first obtains the shared data and shared status through a read request, then obtains the exclusive status through a write request. Only after obtaining the exclusive status can the shared data be rewritten. The latency in obtaining the exclusive status reduces the efficiency of writing shared data. Therefore, how to reduce the latency in obtaining the exclusive status and improve the efficiency of writing shared data has become an urgent problem. Currently, state speculation strategies are used to reduce the latency in obtaining the exclusive status. However, these strategies cannot reduce the latency in obtaining the exclusive status in shared scenarios.
[0071] Based on this, an embodiment of the present application provides a data reading and writing method, which is applied to a storage system including multiple cache agents (CA) and a home agent (HA). The data reading and writing method includes: a first cache agent with access rights among the multiple cache agents obtains the data and sharing status corresponding to the target address through a read request. When the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, for example, when the data corresponding to the target address is overwritten twice in succession, the first cache agent receives first status information. The first status information includes the data corresponding to the target address and an exclusive status. That is, when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first cache agent directly receives the data corresponding to the target address and the exclusive status. When the first cache agent rewrites the data corresponding to the target address, it no longer needs to obtain the exclusive status, thereby reducing the delay in obtaining the exclusive status and improving the efficiency of writing data.
[0072] The data reading and writing method provided in the embodiment of the present application can be applied to a storage system. The structure of the storage system is described below with reference to FIG1 .
[0073] FIG1 is a schematic diagram of the structure of a storage system provided in an embodiment of the present application, which includes multiple cache proxies and a local proxy HA. The storage system can also be called a consistency hierarchy management system. For example, the multiple cache proxies may include four cache proxies, and their identification information may be represented as CA0 to CA3, respectively. The identification information corresponding to each cache proxies is used to uniquely indicate the cache proxies. FIG1 takes the example of multiple cache proxies including four cache proxies. FIG1 only shows part of the information in each cache proxies and HA.
[0074] Each of the multiple cache agents can be used to manage multiple caches. In a first possible embodiment, each of the multiple cache agents can be used to manage a first-level cache L1. Each cache agent corresponds to a core in a multi-core processor. Each core includes a first-level cache L1 and a third-level cache L3. Each core does not include a second-level cache L2. L1 is a dedicated cache for each core, while L3 is a shared cache for multiple cores. Multiple cache agents correspond to multiple cores, and multiple cache agents are used to manage multiple L1s. In a second possible embodiment, each of the multiple cache agents can be used to manage an L2. Each cache agent corresponds to a core in a multi-core processor. In this case, each core includes an L1, L2, and L3. L1 and L2 are dedicated caches for each core, while L3 is a shared cache for multiple cores. Multiple cache agents correspond to multiple cores, and multiple cache agents are used to manage multiple L2s. In a third possible embodiment, each of the multiple cache agents can be used to manage an L3. Each cache agent corresponds to multiple cores. L3 is a shared cache for multiple cores, and multiple cache agents are used to manage multiple L3s.
[0075] In one possible embodiment, for each of the multiple cache proxies, the cache managed by the cache proxies stores a target address, data corresponding to the target address, a status of the data corresponding to the target address, and information indicating whether the cache proxies have overwritten the data corresponding to the target address. The status of the data corresponding to the target address may include a shared (S) state, an exclusive (E) state, an invalid (I) state, a modified (M) state, and a valid state. For example, each of the multiple cache proxies has a corresponding CA directory, which stores the target address, data corresponding to the target address, a status of the data corresponding to the target address, and information indicating whether the cache proxies have overwritten the data corresponding to the target address.
[0076] The shared state indicates that the data corresponding to the target address is valid in the caches managed by at least two cache agents, that is, the data corresponding to the target address is stored in the caches managed by at least two cache agents, and both are valid; the E state indicates that the data corresponding to the target address is valid only in the cache managed by one cache agent, that is, only one cache agent among multiple cache agents stores the data corresponding to the target address, and it is valid; the I state indicates that the data corresponding to the target address is invalid in multiple cache agents, that is, the data corresponding to the target address stored in multiple caches managed by multiple cache agents is invalid data or the data corresponding to the target address is not stored in multiple caches; the M state indicates that the data corresponding to the target address is overwritten; the valid state indicates that the state of the data corresponding to the target address is any one of the S state, E state or M state. For example, in FIG1 , the state of the data corresponding to the target address in CA0, CA1 and CA3 is I state, and the state in CA2 is M state as an example.
[0077] In one possible embodiment, each cache agent is further configured to write the target address, the data corresponding to the target address, the status of the data corresponding to the target address, and an indication of whether the cache agent rewrites the data corresponding to the target address into the CA directory corresponding to the cache agent, for example, CA0 corresponds to the CA0 directory, CA1 corresponds to the CA1 directory, CA2 corresponds to the CA2 directory, and CA3 corresponds to the CA3 directory. Each cache agent is further configured to update the data corresponding to the target address, the status of the data corresponding to the target address, and an indication of whether the cache agent rewrites the data corresponding to the target address in the CA directory. Each cache agent is further configured to send a read request and a write request to the HA. The read request is used to read the data corresponding to the target address. The size of the data corresponding to the target address is the cache line (CL) size. For example, the cache line size can be 64 bytes.
[0078] The HA can be used to manage multiple cache agents. In a first possible embodiment, when multiple cache agents manage multiple L1 or L2 nodes, the HA is an L3 node. In a second possible embodiment, when multiple cache agents manage multiple L3 nodes, the HA manages multiple L3 nodes. The HA stores information such as the target address, the data corresponding to the target address, the status of the data corresponding to the target address in each of the multiple cache agents managed by the HA, and whether the multiple cache agents have rewritten the data corresponding to the target address. For example, the HA includes an HA directory, which stores all of the above information. In Figure 1, the data corresponding to the target address is represented by CL.
[0079] Exemplarily, the HA records the status of the CL in multiple cache agents in binary form. For example, each binary number in 0010 represents the status of the CL in the corresponding cache agent. The first 0 in 0010 indicates that the status of the CL in CA0 is I, the second 0 indicates that the status of the CL in CA1 is I, 1 indicates that the status of the CL in CA2 is valid, and the third 0 indicates that the status of the CL in CA3 is I. Since the CL is valid in only one cache agent, the status of the CL in multiple cache agents is exclusive. Optionally, 0000 indicates that the status of the CL in multiple cache agents is invalid; if the status of the CL in at least two cache agents is valid, the status of the CL in multiple cache agents is shared.
[0080] In one possible embodiment, as shown in FIG2 , each of the multiple cache agents sends a read request to the HA to obtain the data corresponding to the target address. After receiving the read request, the HA queries the HA directory to determine whether the data corresponding to the target address is valid in the HA or another cache agent. If the data corresponding to the target address is invalid in both the HA and other cache agents, the HA reads the data corresponding to the target address from the memory. If the data corresponding to the target address is valid in the HA or other cache agent, the HA or other cache agent sends the data corresponding to the target address. For example, the memory may include double data rate synchronous dynamic random access memory (DDR SDRAM), or DDR for short.
[0081] The above storage system can be applied to an electronic device, for example, a processor of the electronic device. The electronic device can be used as a terminal device or a server. Optionally, the electronic device includes but is not limited to: mobile phones, tablet computers, laptops, desktop computers, PDAs, ultra-mobile personal computers (umPCs), mobile internet devices (MIDs), netbooks, camcorders, cameras, wearable devices (such as smart watches and smart bracelets, etc.), vehicle-mounted equipment (such as cars, bicycles, electric vehicles, airplanes, ships, trains, high-speed railways, etc.), virtual reality (VR) equipment, augmented reality (AR) equipment, wireless terminals in industrial control, smart home devices (such as refrigerators, televisions, air conditioners, electric meters, etc.), intelligent robots, workshop equipment, wireless terminals in self-driving, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, or wireless terminals in smart homes, flying equipment (such as intelligent robots, hot air balloons, drones, airplanes), etc.
[0082] The structure of the electronic device is described below with reference to FIG3 .
[0083] 3 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device 30 may include: a processor 310, a bus 320, a memory 330, and a communication interface 340. The processor 310, the memory 330, and the communication interface 340 are connected via the bus 320.
[0084] It should be understood that in this embodiment, the processor 310 may be a CPU, but may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0085] The processor 310 may also be a graphics processing unit (GPU), a neural network processing unit (NPU), a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the program of the present application. In the embodiment of the present application, the processor 310 may include a storage system. The processor 310 is a multi-core processor. For example, the processor 310 may include 4 cores or 8 cores.
[0086] The communication interface 340 is used to implement communication between the electronic device 30 and an external device or component.
[0087] Bus 320 may include a path for transmitting information between the aforementioned components (e.g., processor 310 and memory 330). In addition to a data bus, bus 320 may also include a power bus, a control bus, and a status signal bus. However, for clarity, various buses are labeled as bus 320 in the figure. Bus 320 may be a Peripheral Component Interconnect Express (PCIe) bus, an Extended Industry Standard Architecture (EISA) bus, a unified bus (Ubus or UB), a Compute Express Link (CXL), a Cache Coherent Interconnect for Accelerators (CCIX), etc.
[0088] It is worth noting that Figure 3 only takes the electronic device 30 including 1 processor 310 and 1 memory 330 as an example. Here, the processor 310 and the memory 330 are respectively used to indicate a type of device or equipment. In a specific embodiment, the number of each type of device or equipment can be determined according to business requirements.
[0089] Memory 330 may be a volatile memory pool or a non-volatile memory pool, or may include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM, synchronous dynamic RAM, DDR, enhanced synchronous dynamic RAM (ESDRAM), synchronized dynamic RAM (SLDRAM), and direct RAM bus RAM (DR RAM).
[0090] FIG4 is a flow chart of a data reading and writing method provided in an embodiment of the present application, which can be applied to the storage system provided above, wherein the storage system includes multiple cache agents and HA. The method includes the following steps.
[0091] S401: A first cache agent sends a read request to the HA. The read request is used to obtain data and sharing status corresponding to a target address. The first cache agent is a cache agent with access rights among multiple cache agents.
[0092] The first cache agent is a cache agent with access rights among the multiple cache agents, that is, the first cache agent is a cache agent with access rights to a critical region among the multiple cache agents. The critical region is a storage region protected by a lock mechanism among the multiple storage regions included in the memory. The target address is a storage address within the critical region. Data stored in the critical region can be read and written by multiple cache agents (i.e., multiple cores). In the following embodiments, it is assumed that each cache agent obtains access rights before sending a read or write request to the HA.
[0093] In addition, a read request includes a target address. The shared state is the status of the data corresponding to the target address in multiple cache agents. The shared state indicates that the data corresponding to the target address is valid in at least two cache agents. In other words, the CA directories corresponding to at least two of the multiple cache agents store the data corresponding to the target address, and the data corresponding to the target address is valid. The shared state is also called the S state.
[0094] Optionally, the size of the data corresponding to the target address is a cache line (CL) size, for example, a cache line size may be 64 bytes. Each cache agent in the plurality of cache agents reads and writes data in units of a cache line each time.
[0095] S402: The HA receives a read request sent by the first cache agent.
[0096] S403: The HA sends, to the second cache agent, information related to sending first status information. The first status information is sent when the number of consecutive rewrites of data corresponding to the target address reaches a preset number. The first status information is used to indicate first data and an exclusive state. The first data is data corresponding to the target address in the second cache agent that accessed the target address before the first cache agent.
[0097] The exclusive state refers to the state in which the data corresponding to the target address is stored in multiple caches. This means that the data corresponding to the target address is valid only in one cache. This means that only the CA directory corresponding to one cache stores the data corresponding to the target address, and the data corresponding to the target address is valid. The exclusive state is also called the E state.
[0098] In addition, the preset number of times is a pre-set number of times, and the preset number of times can be greater than or equal to 2. For example, the preset number of times can be 2 or 3. This application does not make specific restrictions on this. The specific value is set according to actual needs or the experience of relevant staff. In the embodiment of this application, the preset number of times is 2 as an example.
[0099] In a possible embodiment, the relevant information includes first indication information. For example, as shown in FIG5 , step S403 includes:
[0100] S403a: The HA sends first indication information to the second cache agent, where the first indication information is used to indicate whether a third cache agent that accesses the target address before the second cache agent rewrites data corresponding to the target address.
[0101] In one possible implementation, the first indication information may be snoopS, and the first indication information includes first rewrite information in the HA directory. The first rewrite information is used to instruct a third cache agent that accesses the target address before the second cache agent whether to rewrite data corresponding to the target address. The first indication information is further used to instruct the second cache agent to send the data corresponding to the target address and the sharing status to the first cache agent.
[0102] The first indication information is sent by the HA when it determines that the data corresponding to the target address is in a valid state in the second cache agent. A valid state includes a shared state, an exclusive state, or an overwritten state. Specifically, the HA queries the HA directory. If the data corresponding to the target address is in a valid state in the second cache agent, the HA sends the first indication information to the second cache agent. If the data corresponding to the target address is in an invalid state in the second cache agent, the HA sends a request to the memory to obtain the data corresponding to the target address.
[0103] Furthermore, the method provided in the embodiment of the present application also includes:
[0104] S501: The second cache agent receives first indication information sent by the HA.
[0105] S502a: When the second cache agent determines that both the third cache agent and the second cache agent rewrite the data corresponding to the target address, the second cache agent sends first status information to the first cache agent.
[0106] Specifically, when the second cache agent determines, based on the first rewrite information and the second rewrite information stored in the CA2 directory, that both the third cache agent and the second cache agent rewrite the data corresponding to the target address, the second cache agent sends first status information to the first cache agent, and the second rewrite information is used to indicate whether the second cache agent rewrites the data corresponding to the target address.
[0107] Further, please continue to refer to FIG4 , the method provided in the embodiment of the present application also includes:
[0108] S404: When the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first cache agent receives first status information.
[0109] S405: The first cache agent rewrites the first data in the first cache agent into the second data.
[0110] Specifically, the first cache agent rewrites the first data corresponding to the target address in the CA1 directory into the second data, and updates the state information of the first data in the CA1 directory from the exclusive state to the rewritten state.
[0111] In a possible embodiment, referring to FIG. 5 , step S404 includes:
[0112] S404a: When the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first cache receives the first status information sent by the second cache agent.
[0113] Furthermore, the method provided in the embodiment of the present application also includes:
[0114] S503: The second cache agent sends second status information to the HA, where the second status information includes the first data and the rewrite status.
[0115] S504: The second cache agent updates the state of the first data in the second cache agent from the overwritten state to the invalid state.
[0116] S505: The HA receives the second status information sent by the second cache agent.
[0117] S506: The HA updates the data corresponding to the target address in the HA to the first data, and updates the state of the first data in the HA from the exclusive state to the rewrite state.
[0118] Specifically, the HA updates the data corresponding to the target address stored in the HA directory to the first data, and updates the state of the first data in the HA directory in the second cache agent from an exclusive state to an overwritten state.
[0119] In a possible embodiment, as exemplarily shown in FIG6 , after step S501, the method provided in the embodiment of the present application further includes:
[0120] S502b: When the second cache agent determines that the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, the second cache agent sends third status information to the first cache agent, where the third status information is used to indicate the first data and the sharing status.
[0121] The fact that the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number indicates that the second cache agent has not rewritten the data corresponding to the target address, or that a third cache agent that accessed the target address before the second cache agent has not rewritten the data corresponding to the target address, or that both the second cache agent and the third cache agent have rewritten the data corresponding to the target address. In other words, the number of consecutive rewrites of the data corresponding to the target address is less than two.
[0122] Furthermore, the second cache agent updates the state of the first data in the CA2 directory to a shared state.
[0123] S601: The first cache agent receives third status information sent by the second cache agent.
[0124] S602: The first cache agent sends a write request to the HA according to the third state information, where the write request is used to obtain data corresponding to the target address and an exclusive state.
[0125] S603: The HA receives the write request sent by the first cache agent.
[0126] Furthermore, the HA sends third indication information to the second cache agent, where the third indication information is used to instruct the second cache agent to send the first data and the second rewrite information to the HA, and update the status of the first data in the CA2 directory to an invalid state.
[0127] S604: The HA sends first status information to the first cache agent.
[0128] S605: After receiving the first state information, the first cache proxy executes step S405.
[0129] In this embodiment, after the first cache agent sends a read request, the second cache agent determines whether to upgrade the status, that is, the second cache agent determines whether to send the first data and the exclusive status directly to the first cache agent, saving one interaction between the cache agent and the HA, further reducing the delay in obtaining the exclusive status, and improving the efficiency of the first cache agent in rewriting data.
[0130] In another possible embodiment, the relevant information includes second indication information. For example, as shown in FIG7 , step S403 includes:
[0131] S403b: The HA sends second indication information to the second cache agent, where the second indication information is used to instruct: to send second status information to the HA, where the second status information includes the first data and the rewrite status, and the second rewrite information.
[0132] The second indication information is sent by the HA when it is determined that the state of the data corresponding to the target address in the second cache agent is valid.
[0133] S701: The second cache agent receives the second indication information, and sends the first data and the rewrite status, as well as the second rewrite information to the HA.
[0134] S702: The HA receives the second state information and the second rewrite information sent by the second cache agent, and updates the state of the first data in the second cache agent from the exclusive state to the rewrite state.
[0135] Specifically, the HA updates the data corresponding to the target address in the HA directory to the first data, and updates the state of the first data in the HA directory in the second cache agent from an exclusive state to an overwritten state.
[0136] S703a: When the HA determines that the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the HA sends first status information to the first cache agent.
[0137] Specifically, when the HA determines, based on the first rewrite information and the second rewrite information, that the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the HA sends the first status information to the first cache agent.
[0138] S704: The HA sends third indication information to the second cache agent, where the third indication information is used to instruct the state of the first data in the second cache agent to be updated from the overwritten state to the invalid state.
[0139] S705: The second cache agent receives the third indication information sent by the HA, and updates the state of the first data in the second cache agent from the overwritten state to the invalid state.
[0140] Specifically, the second cache agent updates the state of the first data in the CA2 directory from the overwritten state to the invalid state.
[0141] Further, please continue to refer to FIG. 7 , step S404 includes:
[0142] S404b: When the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first cache receives the first status information sent by the HA.
[0143] Furthermore, after receiving the first status information, the first cache executes step S405.
[0144] In a possible embodiment, referring to FIG. 8 , after step S702 , the method provided in the embodiment of the present application further includes:
[0145] S703b: When the HA determines that the number of consecutive rewrites of the data corresponding to the target address does not reach a preset number, the HA sends third status information to the first cache agent.
[0146] S801: The first cache agent receives third state information sent by the HA.
[0147] Furthermore, after the first cache proxy executes the above step S602 and the HA executes the above steps S603 and S604, the first cache proxy executes the above steps S605 and S405.
[0148] S802: The HA sends fourth indication information to the second cache agent, where the fourth indication information is used to instruct the first data to be updated to an invalid state in the second cache agent.
[0149] S803: The second cache agent receives the fourth indication information, and updates the state of the first data in the second cache agent to an invalid state.
[0150] In this embodiment, after HA receives the return information from the second cache agent based on the second indication information, it is confirmed that the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, and HA decides to upgrade the status, that is, HA sends the first status information to the first cache agent. The first cache agent directly receives the exclusive status after sending the read request. When writing data, there is no need to obtain the exclusive status. While reducing the delay in obtaining the exclusive status, the selectivity of the solution is increased.
[0151] In one possible embodiment, assuming that a third cache agent and a second cache agent that access the target address before the first cache agent both rewrite the data corresponding to the target address, and that each cache agent determines the number of consecutive rewrites of the data corresponding to the target address. Prior to step S401, the method provided in this embodiment of the present application further includes:
[0152] The third cache agent sends a read request to the HA to obtain the data and shared status corresponding to the target address; assuming that no other cache agent reads or writes the data corresponding to the target address before the third cache agent, the HA sends the third data and shared status to the third cache agent, and records the status of the third data in the third cache in the HA directory as shared status; the third cache agent receives the third data and records the status of the third data (shared status) in the CA3 directory, and the third cache agent sends a request to the HA to obtain the exclusive status; the HA sends the third data and exclusive status to the third cache agent, and updates the status of the third data from shared status to exclusive status in the HA directory; the third cache agent rewrites the third data in the third cache agent to fourth data, and updates the shared status in the CA3 directory to rewritten status.
[0153] Furthermore, the method provided in the embodiment of the present application also includes:
[0154] The second cache agent sends a read request to the HA to obtain the data and sharing status corresponding to the target address; the HA queries the HA directory to determine that the data corresponding to the target address is in an exclusive state (i.e., a valid state) in the third cache agent, and the HA sends a first indication message to the third cache agent. Since the third cache agent is the first cache agent to access the target address, no cache agent has rewritten the data corresponding to the target address before the third cache agent, and the first rewrite information in the first indication message indicates that the number of consecutive rewrites of the target address is 0; the third cache agent receives the first indication message and determines that the number of consecutive rewrites of the data corresponding to the target address has not reached a preset number, and the third cache agent sends the fourth data and sharing status to the second cache agent, updates the status of the fourth data in the CA3 directory from the rewrite status to the shared status, and sends the fourth data and rewrite status to the HA; the HA receives the fourth data and rewrite status, updates the data corresponding to the target address in the HA directory from the third data to the fourth data, and updates the status of the fourth data in the HA directory in the third cache agent from the exclusive state to the rewrite state. The second cache agent sends a request to the HA for an exclusive state based on the fourth data and the shared state. The HA sends the fourth data and the exclusive state to the second cache agent, and sends an instruction to update the overwrite state in the CA3 directory to an invalid state to the third cache agent. The second cache agent receives the fourth data and the exclusive state, rewrites the fourth data in the CA2 directory to the first data, and updates the state information of the first data in the CA2 directory from the shared state to the overwrite state. The third cache agent receives the instruction to update the overwrite state in the CA3 directory to an invalid state, and updates the overwrite state in the CA3 directory to an invalid state.
[0155] In another possible embodiment, illustratively, as shown in FIG9 , after step S402 , the method provided in the embodiment of the present application includes:
[0156] S901: When the number of consecutive rewrites of data corresponding to the target address reaches a preset number and satisfies a first threshold, the HA sends fifth indication information to the second cache agent, where the fifth indication information is used to instruct the first status information to be sent to the first cache agent.
[0157] Among them, the first threshold is greater than the preset number of times, and its specific value can be set according to actual needs and is not specifically limited in the embodiment of the present application.
[0158] In one possible implementation, historical information about the number of times the data corresponding to the target address has been continuously rewritten reaching a preset number of times can be recorded. For example, the number of times the data corresponding to the target address has been continuously rewritten reaching a preset number of times can be recorded in a historical information table. If the number of times the data corresponding to the target address has been continuously rewritten reaches a preset number of times, the number of times the data corresponding to the target address has been continuously rewritten meeting a first threshold, indicating that the data corresponding to the target address will likely be rewritten again the next time it is accessed. In this embodiment, the state of the target address that meets the first threshold is directly upgraded, that is, the data corresponding to the target address and the exclusive state are directly sent to the first cache agent, further reducing the latency in obtaining the exclusive state and improving the efficiency of writing data.
[0159] Furthermore, the first cache proxy executes the above steps S605 and S405.
[0160] An embodiment of the present application provides a data reading and writing method. After a first cache agent with access rights among multiple cache agents sends a read request to the HA to obtain data corresponding to a target address and a shared status, when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first cache agent directly receives the data corresponding to the target address and the exclusive status, that is, performs a status upgrade. When the first cache agent rewrites the data corresponding to the target address, it no longer needs to obtain the exclusive status, thereby reducing the delay in obtaining the exclusive status and improving the efficiency of writing data.
[0161] The present application also provides a data reading and writing device. For example, as shown in FIG10 , the data reading and writing device may include a first sending unit 101, a first receiving unit 102, and a first rewriting unit 103. The first sending unit 101 may be used to execute steps S401 and S602 in the above method embodiment, and / or other steps described herein; the first receiving unit 102 may be used to execute steps S404 (including steps S404a and S404b), S502a, S502b, S605, and S801 in the above method embodiment, and / or other steps described herein; and the first rewriting unit 103 may be used to execute step S405 in the above method embodiment.
[0162] Optionally, the data reading and writing device may further include a second receiving unit 104, a second sending unit 105, and a first updating unit 106. The second receiving unit 104 may be configured to execute step S501, relevant steps in step S701, relevant steps in step S705, and relevant steps in step S803 in the above-described method embodiment, and / or other steps described herein; the second sending unit 105 may be configured to execute step S502a, step S502b, step S503, and relevant steps in step S701 in the above-described method embodiment, and / or other steps described herein; and the first updating unit 106 may be configured to update the state of the first data in the second cache agent from an overwritten state to an invalid state.
[0163] The present application also provides another data reading and writing device. For example, as shown in FIG11 , the data reading and writing device may include a third receiving unit 110 and a third sending unit 111. The third receiving unit 110 may be used to execute the relevant information in step S402, step S505, step S603, and step S702 in the above method embodiment, and / or other steps described herein; the third sending unit 111 may be used to execute step S403 (including step S403a and step S403b), step S604, step S703a, step S703b, step S704, step S802, step S901 in the above method embodiment, and / or other steps described herein.
[0164] Optionally, the data reading and writing device may further include a second updating unit 112. The second updating unit 112 may be used to update the state of the first data in the HA from an exclusive state to a rewritten state.
[0165] It can be understood that all relevant contents of each step involved in the above method embodiment can be referred to the embodiment of the data reading and writing device, and the embodiment of the present application will not be repeated here.
[0166] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules or units is merely a logical functional division. In actual implementation, other division methods may be used, such as combining or integrating multiple units or components into another device, or ignoring or not implementing certain features.
[0167] The units described as separate components may or may not be physically separate, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple places. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0168] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. The readable storage medium may include: a USB flash drive, a mobile hard drive, a read-only memory, a random access memory, a magnetic disk, or an optical disk, etc., which can store program code. Based on this understanding, the technical solution of the embodiment of the present application, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product.
[0169] An embodiment of the present application further provides an electronic device, comprising a memory and a processor, the processor comprising a storage system, the storage system comprising multiple cache proxies and a local proxy (HA), and the memory for storing data. The electronic device may be the electronic device shown in FIG3 . A description of the electronic device is provided in FIG3 and is not further detailed here.
[0170] In another embodiment of the present application, a readable storage medium is provided, which stores computer-executable instructions. When a data reading and writing device runs the computer-executable instructions, the data reading and writing device executes the steps in the above method embodiment.
[0171] In another embodiment of the present application, a computer program product is also provided, which includes computer instructions, which are stored in a readable storage medium; at least one processor of the device can read the computer instructions from the readable storage medium, and at least one processor executes the computer instructions so that the data reading and writing device performs the steps in the above method embodiment.
[0172] 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 data reading and writing method, characterized in that: Applied to a storage system including multiple cache proxies and a local proxy HA, the HA managing the multiple cache proxies, the multiple cache proxies being used to manage multiple caches, the method comprising: A first cache agent sends a read request to the HA, wherein the read request is used to obtain data and a sharing status corresponding to a target address, and the first cache agent is a cache agent with access rights among the multiple cache agents; When the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first cache agent receives first status information, where the first status information is used to indicate first data and an exclusive state, where the first data is data corresponding to the target address in a second cache agent that accessed the target address before the first cache agent. The first cache agent rewrites the first data in the first cache agent into second data.
2. The method according to claim 1, characterized in that The method further comprises: The second cache agent receives first indication information sent by the HA, where the first indication information is used to indicate whether a third cache agent that accesses the target address before the second cache agent rewrites data corresponding to the target address; When the second cache agent determines that both the third cache agent and the second cache agent rewrite the data corresponding to the target address, the second cache agent sends the first status information to the first cache agent.
3. The method according to claim 2, characterized in that The method further comprises: The second cache agent sends second status information to the HA, where the second status information includes the first data and the rewrite status, and updates the status of the first data in the second cache agent from the rewrite status to the invalid status.
4. The method according to claim 2 or 3, characterized in that The first indication information is sent by the HA when determining that the state of the data corresponding to the target address in the second cache agent is valid, and the valid state includes the shared state, the exclusive state, or the overwritten state.
5. The method according to claim 1, wherein The first cache agent receives first status information, including: When the HA determines that the number of consecutive rewrites of the data corresponding to the target address reaches the preset number, the first cache agent receives the first status information sent by the HA.
6. The method according to claim 5, characterized in that The method further comprises: The second cache agent receives second indication information sent by the HA, where the second indication information is used to instruct: sending second status information to the HA, where the second status information includes the first data and a rewrite status, and information indicating whether the second cache agent rewrites data corresponding to the target address; The second cache agent responds to the second indication information.
7. The method according to claim 6, characterized in that The second indication information is sent by the HA when determining that the state of the data corresponding to the target address in the second cache agent is valid, and the valid state includes the shared state, the exclusive state, or the overwritten state.
8. The method according to any one of claims 5 to 7, characterized in that: The method further comprises: The second cache agent receives third indication information sent by the HA, where the third indication information is used to instruct to update the state of the first data in the second cache agent from the overwritten state to the invalid state; The second cache agent responds to the third indication information.
9. The method according to any one of claims 1 to 4, characterized in that The method further comprises: When the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number, the first cache agent receives third status information sent by the second cache agent, where the third status information is used to indicate the first data and the sharing status; The first cache agent sends a write request to the HA according to the third state information, where the write request is used to obtain data corresponding to the target address and the exclusive state; The first cache agent receives the first status information sent by the HA.
10. The method according to claim 1, characterized in that The method further comprises: When the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number, the first cache agent receives third status information sent by the HA, where the third status information is used to indicate the first data and the sharing status; The first cache agent sends a write request to the HA according to the third state information, where the write request is used to obtain data corresponding to the target address and the exclusive state; The first cache agent receives the first status information sent by the HA.
11. A data reading and writing method, characterized in that: Applied to a storage system including multiple cache proxies and a local proxy HA, the HA managing the multiple cache proxies, the multiple cache proxies being used to manage multiple caches, the method comprising: The HA receives a read request sent by a first cache agent, the read request being used to obtain data and a sharing status corresponding to a target address, the first cache agent being a cache agent having access rights among the multiple cache agents; The HA sends relevant information for sending first status information to the second cache agent. The first status information is sent when the number of consecutive rewrites of data corresponding to the target address reaches a preset number. The first status information is used to indicate first data and an exclusive state. The first data is the data corresponding to the target address in the second cache agent that accesses the target address before the first cache agent.
12. The method according to claim 11, characterized in that The relevant information includes first indication information, and the HA sending the relevant information to the second cache agent includes: The HA sends the first indication information to the second cache agent, where the first indication information is used to indicate whether a third cache agent that accesses the target address before the second cache agent rewrites data corresponding to the target address; The first status information is sent by the second cache agent when it is determined that both the third cache agent and the second cache agent rewrite the data corresponding to the target address.
13. The method according to claim 12, characterized in that The method further comprises: The HA receives second state information sent by the second cache agent, where the second state information includes first data and a rewrite state, and updates the state of the first data in the HA from the exclusive state to the rewrite state.
14. The method according to claim 12 or 13, characterized in that The first indication information is sent by the HA when determining that the state of the data corresponding to the target address in the second cache agent is valid, and the valid state includes the shared state, the exclusive state, or the overwritten state.
15. The method according to claim 11, characterized in that The relevant information further includes second indication information, and the HA sends the relevant information to the second cache agent, including: The HA sends the second indication information to the second cache agent, where the second indication information is used to instruct: sending second status information to the HA, where the second status information includes the first data and the rewrite status, and information about whether the second cache agent rewrites the data corresponding to the target address; The HA receives the second state information sent by the second cache agent and information indicating whether the second cache agent rewrites the data corresponding to the target address, and updates the state of the first data in the second cache agent from the exclusive state to the rewritten state; When the HA determines that the number of consecutive rewrites of the data corresponding to the target address reaches the preset number, the HA sends the first status information to the first cache agent.
16. The method according to claim 15, characterized in that The second indication information is sent by the HA when determining that the state of the first data in the second cache agent is a valid state, where the valid state includes the shared state, the exclusive state, or the overwritten state.
17. The method according to claim 15 or 16, characterized in that The method further comprises: The HA sends third indication information to the second cache agent, where the third indication information is used to instruct to update the state of the first data in the second cache agent from the overwritten state to the invalid state.
18. The method according to any one of claims 11 to 14, characterized in that: The method further comprises: When the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number, the HA receives a write request sent by the first cache agent, the write request being used to obtain the data corresponding to the target address and the exclusive state, the write request being sent by the first cache agent after receiving third state information sent by the second cache agent, the third state information being used to indicate the first data and the shared state; The HA sends the first status information to the first cache agent.
19. The method according to claim 11, wherein The method further comprises: When the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number, the HA sends third status information to the first cache agent, where the third status information is used to indicate the first data and the sharing status; The HA receives a write request sent by the first cache agent, where the write request is used to obtain data corresponding to the target address and the exclusive state; The HA sends the first status information to the first cache agent.
20. A data reading and writing device, characterized in that: Applicable to a storage system including multiple cache proxies and a local proxy HA, wherein the HA manages the multiple cache proxies, and the multiple cache proxies are used to manage multiple caches, the apparatus comprises: a first sending unit, configured to send a read request to the HA, wherein the read request is used to obtain data and a sharing status corresponding to a target address, the first sending unit being a sending unit in a first cache agent having access rights among the multiple cache agents; a first receiving unit, configured to receive first status information when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, the first status information being used to indicate first data and an exclusive state, the first data being data corresponding to the target address in a second cache agent that accessed the target address before the first cache agent; The first rewriting unit is configured to rewrite the first data in the first cache agent into second data.
21. The device according to claim 20, characterized in that The device further comprises: a second receiving unit, configured to receive first indication information sent by the HA, where the first indication information is used to indicate whether a third cache agent that accesses the target address before the second cache agent rewrites data corresponding to the target address; The second sending unit is configured to send the first state information to the first cache agent when it is determined that both the third cache agent and the second cache agent rewrite the data corresponding to the target address.
22. The device according to claim 21, characterized in that The device further includes: a first updating unit, The second sending unit is further configured to send second status information to the HA, where the second status information includes the first data and the rewrite status; The first updating unit is configured to update the state of the first data in the second cache agent from the overwritten state to an invalid state.
23. The device according to claim 21 or 22, characterized in that The first indication information is sent by the HA when determining that the state of the data corresponding to the target address in the second cache agent is valid, and the valid state includes the shared state, the exclusive state, or the overwritten state.
24. The device according to claim 20, characterized in that The first receiving unit is further configured to: When the HA determines that the number of consecutive rewrites of the data corresponding to the target address reaches the preset number, the first state information sent by the HA is received.
25. The device according to claim 24, characterized in that a second receiving unit, configured to receive second indication information sent by the HA, the second indication information being used to instruct: sending second status information to the HA, the second status information including the first data and the rewrite status, and information indicating whether the second cache agent rewrites the data corresponding to the target address; The second sending unit is further configured to send second status information to the HA.
26. The device according to claim 25, characterized in that The second indication information is sent by the HA when determining that the state corresponding to the target address in the second cache agent is a valid state, where the valid state includes the shared state, the exclusive state, or the overwritten state.
27. The device according to any one of claims 24 to 26, characterized in that The second receiving unit is further configured to receive third indication information sent by the HA, where the third indication information is configured to indicate that the state of the first data in the second cache agent is updated from the overwritten state to the invalid state; The first updating unit is further configured to update the state of the first data in the second cache agent from the overwritten state to an invalid state.
28. The device according to any one of claims 20 to 23, characterized in that The first receiving unit is further configured to receive third status information sent by the second cache agent when the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number, the third status information being used to indicate the first data and the sharing status; The first sending unit is further configured to send a write request to the HA according to the third state information, wherein the write request is used to obtain data corresponding to the target address and the exclusive state; The first receiving unit is further configured to receive the first status information sent by the HA.
29. The device according to claim 20, characterized in that The first receiving unit is further configured to receive third status information sent by the HA when the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number, the third status information being used to indicate the first data and the sharing status; The first sending unit is further configured to send a write request to the HA according to the third state information, wherein the write request is used to obtain data corresponding to the target address and the exclusive state; The first receiving unit is further configured to receive the first status information sent by the HA.
30. A data reading and writing device, characterized in that: Applicable to a storage system including multiple cache proxies and a local proxy HA, wherein the HA manages the multiple cache proxies, and the multiple cache proxies are used to manage multiple caches, the apparatus comprises: a third receiving unit, configured to receive a read request sent by a first cache agent, the read request being used to obtain data and a sharing status corresponding to a target address, the first cache agent being a cache agent with access rights among the multiple cache agents; a third sending unit, configured to send, to the second cache agent, relevant information for sending first status information, where the first status information is sent when the number of consecutive rewrites of the data corresponding to the target address reaches a preset number, and the first status information is used to indicate first data and an exclusive state, where the first data is data corresponding to the target address in the second cache agent that accessed the target address before the first cache agent.
31. The device according to claim 30, characterized in that The relevant information includes first indication information, and the third sending unit is further configured to: Sending the first indication information to the second cache agent, where the first indication information is used to indicate whether a third cache agent that accesses the target address before the second cache agent rewrites data corresponding to the target address; The first status information is sent by the second cache agent when it is determined that both the third cache agent and the second cache agent rewrite the data corresponding to the target address.
32. The device according to claim 31, characterized in that The third receiving unit is further configured to receive second status information sent by the second cache agent, where the second status information includes the first data and a rewrite status; The second updating unit is configured to update the state of the first data in the HA from the exclusive state to the overwritten state.
33. The device according to claim 31 or 32, characterized in that The first indication information is sent by the third sending unit when determining that the state of the data corresponding to the target address in the second cache agent is a valid state, where the valid state includes the shared state, the exclusive state, or the overwritten state.
34. The device according to claim 30, characterized in that The relevant information also includes second indication information, The third sending unit is further configured to send the second indication information to the second cache agent, where the second indication information is used to instruct: sending second status information to the HA, where the second status information includes the first data and a rewrite status, and information indicating whether the second cache agent rewrites the data corresponding to the target address; The third receiving unit is further configured to receive the second status information sent by the second cache agent, and information indicating whether the second cache agent rewrites the data corresponding to the target address; The second updating unit is further configured to update the state of the first data in the second cache agent from the exclusive state to the overwritten state; The third sending unit is further configured to send the first status information to the first cache agent when it is determined that the number of consecutive rewrites of the data corresponding to the target address reaches the preset number.
35. The device according to claim 34, characterized in that The second indication information is sent by the HA when determining that the state of the data corresponding to the target address in the second cache agent is valid, and the valid state includes the shared state, the exclusive state, or the overwritten state.
36. The device according to claim 34 or 35, characterized in that The third sending unit is further configured to send third indication information to the second cache agent, where the third indication information is configured to instruct the state of the first data in the second cache agent to be updated from the overwritten state to the invalid state.
37. The device according to any one of claims 30 to 33, characterized in that The third receiving unit is further configured to receive a write request sent by the first cache agent when the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number, the write request being used to obtain the data corresponding to the target address and the exclusive state, the write request being sent by the first cache agent after receiving third state information sent by the second cache agent, the third state information being used to indicate the first data and the shared state; The third sending unit is further configured to send the first status information to the first cache agent after the third receiving unit receives the write request.
38. The device according to claim 30, characterized in that The third sending unit is further configured to send third status information to the first cache agent when the number of consecutive rewrites of the data corresponding to the target address does not reach the preset number, the third status information being used to indicate the first data and the sharing status; The third receiving unit is further configured to receive a write request sent by the first cache agent, wherein the write request is used to obtain data corresponding to the target address and the exclusive state; The third sending unit is further configured to send the first status information to the first cache agent after the third receiving unit receives the write request.
39. An electronic device, characterized in that: The electronic device includes a memory and a processor, the processor includes a storage system, the storage system includes multiple cache agents and a local agent HA, the HA is used to execute the data reading and writing method as described in any one of claims 11-19, the multiple cache agents are used to execute the data reading and writing method as described in any one of claims 1-10, and the memory is used to store data.
40. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions. When the computer instructions are executed on the data reading and writing device, the data reading and writing device executes the data reading and writing method according to any one of claims 1 to 10, or the data reading and writing method according to any one of claims 11 to 19.
41. A computer program product comprising instructions, characterized in that The computer program product includes: a computer program, which, when executed, enables a data reading and writing device to execute the data reading and writing method according to any one of claims 1 to 10, or the data reading and writing method according to any one of claims 11 to 19.
Citation Information
Patent Citations
Data reading method, device, and multi-core processor
CN113168400A
Cache data consistency method and device, host agent and multi-core processor
CN116069507A
Access request processing method, multi-core processor system, chip and electronic equipment
CN116126517A
Memory control device, cache coherence system and cache coherence method
CN116414563A
Hybrid directory and snoopy-based coherency to reduce directory update overhead in two-level memory
US20200356482A1