Data sharing method and apparatus
The processor sets the physical address corresponding to the virtual address to realize data sharing among processes, solves the problem of high latency between processes, improves data sharing efficiency and concurrency, and simplifies processor operations.
Patent Information
- Application Number
- PCT/CN2024/136104
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-01-05
- Filing Date
- 2024-12-02
- Publication Date
- 2025-07-10
AI Technical Summary
There is a high latency for sharing data between processes, mainly because the data takes a long time to copy between physical addresses.
The processor sets the physical address corresponding to the virtual address, allowing processes other than the first process to directly access the shared virtual address, avoid copying of data between physical addresses, and use the heterogeneous architecture of volatile and nonvolatile memory to realize data sharing among processes.
Reduces the latency of sharing data between processes, improves the efficiency and concurrency of data sharing, simplifies processor operations, and reduces input/output stacks.
Smart Images

Figure CN2024136104_10072025_PF_FP_ABST
Abstract
Description
Data sharing method and device
[0001] This application claims priority to Chinese patent application number 202410029039.X, filed on January 5, 2024, entitled “Data Sharing Method and Device,” the entire contents of which are incorporated herein by reference. Technical Field
[0002] The present application relates to the field of storage technology, and in particular to a data sharing method and device. Background Art
[0003] In the field of storage technology, a process accesses data stored at a physical address by accessing the virtual address corresponding to the physical address. In addition, data can be shared between processes.
[0004] A process has a private virtual address, which can only be accessed by the process itself and cannot be accessed by other processes. If the first process wants to share the data stored at the physical address corresponding to the private virtual address with the second process, then the processor needs to copy the data stored at the physical address to the physical address corresponding to the shared virtual address. When the second process needs to access the data, it can access the shared virtual address. At this time, the processor can copy the data at the physical address corresponding to the shared virtual address to the physical address corresponding to the private virtual address of the second process. Afterwards, the second process can access the data stored at the physical address corresponding to the private virtual address by accessing the private virtual address of the second process, thereby sharing the data of the first process with the second process.
[0005] However, copying data between physical addresses takes a long time, resulting in higher latency when sharing data between processes. Summary of the Invention
[0006] This application provides a data sharing method and device that can solve the problem of high latency in sharing data between processes. The solution provided by this application is as follows:
[0007] In a first aspect, the present application provides a data sharing method, which is executed by a processor connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by instructions of the processor. In this method, after writing first data of a first process to a first physical address of the volatile memory, the processor sets the physical address corresponding to a shared virtual address to the first physical address. The first physical address is the physical address corresponding to a first private virtual address, which is accessible to the first process and prohibited from being accessed by processes other than the first process; the shared virtual address is accessible to any process.
[0008] In this way, other processes (such as the second process) other than the first process can access the data at the first physical address by accessing the shared virtual address, thereby enabling the first process to share data with other processes. It can be seen that the processor can share data between processes by setting the physical address corresponding to the virtual address, reducing the copying of shared data between processes, and thus reducing the latency of sharing data between processes.
[0009] Optionally, the processor can also move the first data out of the first physical address; and, when the first data exists in the second physical address of the non-volatile memory, the shared virtual address is locked to prevent the shared virtual address from being accessed by the process, and the physical address corresponding to the shared virtual address is changed from the first physical address to the second physical address, and then the shared virtual address is unlocked to allow the shared virtual address to be accessed by the process. For example, the processor can move the first data out of the first physical address based on whether the removal condition is met. The processor can determine whether the removal condition is met, and when the removal condition is met, it executes the operation of moving the first data out of the first physical address. When the removal condition is not met, it continues to determine whether the removal condition is met.
[0010] There are various ways to implement the removal condition.
[0011] For example, the removal conditions include: the capacity of the free storage space of the volatile memory is less than the capacity threshold. The free storage space of the volatile memory refers to the storage space in the volatile memory where no data is stored. When the capacity of the free storage space of the volatile memory is less than the capacity threshold, it is difficult for the volatile memory to support the storage of subsequent data. Therefore, the processor can move the data out of the volatile memory. After the data is moved out of the volatile memory, the storage space occupied by the data in the volatile memory is released, and the storage space becomes free storage space. In this way, the capacity of the free storage space of the volatile memory can be increased to support the storage of subsequent data.
[0012] For another example, the removal condition includes: within the target time period before the current moment, the number of processes accessing the shared virtual address is less than the number threshold. It can be seen that the processor can count the number of processes accessing the shared virtual address within the target time period before the current moment. When the number is less than the number threshold, it means that there are fewer processes accessing the shared virtual address, and the probability that the shared virtual address has been recently accessed is high. At this time, the first data on the first physical address corresponding to the shared virtual address can be removed. In this way, the capacity of the free storage space in the volatile memory can be increased, which is convenient for the storage of subsequent data. In addition, if within the target time period before the current moment, the number of processes accessing the shared virtual address is greater than or equal to the number threshold, it means that there are more processes accessing the shared virtual address recently, and the probability that the shared virtual address has been recently accessed is low. It is not currently appropriate to remove the data on the physical address corresponding to the shared virtual address to ensure normal access to the shared virtual address by the process.
[0013] For another example, the removal conditions include: the capacity of the free storage space of the volatile memory is less than a capacity threshold, and the number of processes accessing the shared virtual address in the target time period before the current moment is less than a number threshold.
[0014] It can be understood that the physical address corresponding to the virtual address is usually managed by the virtual memory subsystem, and in this application, the processor can also set the physical address corresponding to the virtual address. It can be seen that the virtual memory subsystem is exposed to the processor, and the processor can obtain the number of processes accessing the shared virtual address through the virtual memory subsystem. Therefore, this application supports the removal conditions including that the number of processes accessing the shared virtual address is less than the number threshold within the target time period before the current moment.
[0015] Optionally, the processor may further set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address based on an access request from the second process to the shared virtual address; the second private virtual address is accessible to the second process and is prohibited from being accessed by processes other than the second process. As can be seen from the above, the physical address corresponding to the second private virtual address is the same as the physical address corresponding to the shared virtual address, and the processor does not copy the data in the physical address corresponding to the shared virtual address to the physical address corresponding to the second private virtual address. Therefore, data copying is avoided, and delays in sharing data between processes caused by data copying are avoided.
[0016] In the present application, when the physical address corresponding to the shared virtual address is not the first physical address of the volatile memory, if the physical address corresponding to the shared virtual address is the second physical address of the non-volatile memory, then the processor can set the corresponding physical address for the second private virtual address of the second process without copying the data, so that the second process can access the data, the waiting time of the second process is shorter, and the delay of data sharing is reduced.
[0017] In addition, in the present application, if the processor changes the physical address corresponding to the shared virtual address to the physical address of the non-volatile memory after moving the data out of the volatile memory, then the complex processes in the related art can be avoided. Therefore, the processor performs fewer operations, which will further reduce the delay in sharing data between processes.
[0018] Furthermore, after the processor sets the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address according to the access request of the second process to the shared virtual address, the processor may also copy the first data in the second physical address to the third physical address of the volatile memory when the physical address corresponding to the shared virtual address is the second physical address; lock both the shared virtual address and the second private virtual address to prevent the shared virtual address and the second private virtual address from being accessed by the process; then change the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address; and finally unlock both the shared virtual address and the second private virtual address to allow the shared virtual address and the second private virtual address to be accessed by the process.
[0019] When the physical address corresponding to the shared virtual address is the physical address of the non-volatile memory (such as the second physical address mentioned above), considering that the access to the non-volatile memory is relatively slow, the processor can copy the first data in the second physical address to the third physical address of the volatile memory, and then change the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address. In this way, the second process can access the first data on the third physical address by accessing the second private virtual address. Moreover, since the third physical address is the physical address of the volatile memory, the second process can access the first data on the third physical address faster, which can further reduce the delay of sharing data between processes.
[0020] Optionally, the processor may copy the first data at the second physical address to the third physical address when setting the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address. Of course, copying the first data at the second physical address to the third physical address may also be performed after setting the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address, which is not limited in this application.
[0021] The above content describes the process of sharing data from the first process to the second process. Optionally, any process (such as the first process, the second process, or other processes) can also modify the data shared by the first process.
[0022] For example, the processor can lock the shared virtual address based on a data modification request for the shared virtual address to prevent the shared virtual address from being accessed by the process; the data modification request is used to request that the data at the physical address corresponding to the shared virtual address be modified to the second data at the fourth physical address of the volatile memory; thereafter, the processor can change the physical address corresponding to the shared virtual address to the fourth physical address, and unlock the shared virtual address to allow the shared virtual address to be accessed by the process. If a process (such as a second process) subsequently accesses the shared virtual address, the process will eventually access the modified second data instead of the original first data.
[0023] According to the above content, the processor only needs to change the physical address corresponding to the shared virtual address to complete the data modification. Since the time required to change the physical address corresponding to the shared virtual address is short, the shared virtual address is locked for a short time, which has little impact on the process accessing the shared virtual address.
[0024] Optionally, the processor in the present application can also perform a flush operation, for example, the processor can perform a flush operation when a flush condition is met. The flush condition can be that the cycle for executing the flush operation has arrived, or the capacity of the free storage space in the volatile memory is less than a threshold, etc. The flush operation may include: the processor first locks the shared virtual address to prevent the shared virtual address from being accessed by the process; then, the processor sets the physical address corresponding to the flush virtual address to the physical address corresponding to the shared virtual address, and then unlocks the shared virtual address to allow the shared virtual address to be accessed by the process; finally, the processor copies the data at the physical address corresponding to the flush virtual address to the fifth physical address of the non-volatile memory.
[0025] According to the above-mentioned dirty flushing operation, the way the processor flushes dirty is to first lock the shared virtual address, and then map the dirty flushing virtual address to the physical address corresponding to the shared virtual address (that is, the physical address corresponding to the dirty flushing virtual address is set to the physical address corresponding to the shared virtual address). Subsequently, the shared virtual address is unlocked, and the data on the physical address corresponding to the shared virtual address is copied to the non-volatile memory based on the dirty flushing virtual address. Since in the dirty flushing operation, the duration of the shared virtual address being locked is the duration of mapping the dirty flushing virtual address to the physical address corresponding to the shared virtual address, and the duration of mapping the dirty flushing virtual address to the physical address corresponding to the shared virtual address is shorter, the shared virtual address is locked for a shorter time. Therefore, the dirty flushing operation has less impact on the process accessing the shared virtual address.
[0026] In addition, during the dirty flush operation, if a process needs to modify the data at the physical address corresponding to the shared virtual address, the processor will change the physical address corresponding to the shared virtual address to the physical address where the new data is located. However, at this time, the physical address corresponding to the dirty flush virtual address is still the old physical address, so the processor still copies the data at the old physical address to the non-volatile memory.
[0027] Furthermore, when the processor copies the data at the physical address corresponding to the dirty virtual address to the fifth physical address of the non-volatile memory, it can directly copy the data to the fifth physical address. Alternatively, the processor can first copy the data at the physical address corresponding to the dirty virtual address to the log in the non-volatile memory; after successfully copying the data at the physical address corresponding to the dirty virtual address to the log, the processor copies the data on the log to the fifth physical address. In this way, it is ensured that the data copied by the processor to the fifth physical address is completely consistent with the data at the physical address corresponding to the dirty virtual address, or that the processor does not copy any data to the fifth physical address, thereby ensuring the atomicity of the data on the non-volatile memory.
[0028] In a second aspect, the present application provides a data sharing method, which is executed by a processor, the processor being connected to a volatile memory and a non-volatile memory, and the non-volatile memory being accessible by instructions of the processor; in this method, the processor will set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address according to an access request of the second process to the shared virtual address; the second private virtual address is allowed to be accessed by the second process, and is prohibited from being accessed by processes other than the second process, and the shared virtual address is allowed to be accessed by any process.
[0029] According to the above content, the physical address corresponding to the second private virtual address is the same as the physical address corresponding to the shared virtual address. The processor does not copy the data in the physical address corresponding to the shared virtual address to the physical address corresponding to the second private virtual address. Therefore, data copying is avoided, and the delay in sharing data between processes caused by data copying is avoided.
[0030] Optionally, before the processor sets the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address in response to the second process's access request to the shared virtual address, the method further includes: writing first data of the first process to a first physical address of the volatile memory, and setting the physical address corresponding to the shared virtual address to the first physical address. The first physical address is the physical address corresponding to the first private virtual address, the first private virtual address is accessible to the first process and is prohibited from being accessed by processes other than the first process; the shared virtual address is accessible to any process.
[0031] Optionally, the method also includes: the processor moves the first data out of the first physical address; when the first data exists in the second physical address of the non-volatile memory, locking the shared virtual address to prevent the shared virtual address from being accessed by the process; changing the physical address corresponding to the shared virtual address from the first physical address to the second physical address; unlocking the shared virtual address to allow the shared virtual address to be accessed by the process.
[0032] Optionally, the processor may move out the first data in the first physical address based on whether a removal condition is met; the removal condition includes at least one of the following conditions: the capacity of the free storage space of the volatile memory is less than a capacity threshold; and, within a target time period before the current moment, the number of processes accessing the shared virtual address is less than a quantity threshold.
[0033] Optionally, after setting the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address in accordance with the access request of the second process to the shared virtual address, the processor may also copy the first data in the second physical address to the third physical address of the volatile memory when the physical address corresponding to the shared virtual address is the second physical address; lock both the shared virtual address and the second private virtual address to prevent the shared virtual address and the second private virtual address from being accessed by the process; change the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address; and unlock both the shared virtual address and the second private virtual address to allow the shared virtual address and the second private virtual address to be accessed by the process.
[0034] Optionally, the processor may copy the first data in the second physical address to the third physical address when setting the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address.
[0035] Optionally, the method also includes: the processor locks the shared virtual address based on a data modification request for the shared virtual address to prevent the shared virtual address from being accessed by the process; the data modification request is used to request that the data at the physical address corresponding to the shared virtual address be modified to the second data at the fourth physical address of the volatile memory; thereafter, the processor changes the physical address corresponding to the shared virtual address to the fourth physical address, and unlocks the shared virtual address to allow the shared virtual address to be accessed by the process.
[0036] Optionally, the method also includes: the processor locks the shared virtual address to prevent the shared virtual address from being accessed by the process; the processor then sets the physical address corresponding to the dirty virtual address to the physical address corresponding to the shared virtual address, and unlocks the shared virtual address to allow the shared virtual address to be accessed by the process; finally, the processor copies the data at the physical address corresponding to the dirty virtual address to the fifth physical address of the non-volatile memory.
[0037] Optionally, when the processor copies the data at the physical address corresponding to the dirty flush virtual address to the fifth physical address of the non-volatile memory, it can copy the data at the physical address corresponding to the dirty flush virtual address to a log in the non-volatile memory; after successfully copying the data at the physical address corresponding to the dirty flush virtual address to the log, the processor can copy the data on the log to the fifth physical address.
[0038] In a third aspect, a data sharing device is provided, the data sharing device being a processor, the processor being connected to a volatile memory and a non-volatile memory, and the non-volatile memory being accessible by instructions from the processor; the data sharing device comprising: a write module and a first setting module. The write module is configured to write first data of a first process to a first physical address of the volatile memory; the first physical address is a physical address corresponding to a first private virtual address, the first private virtual address being accessible to the first process and prohibited from being accessed by processes other than the first process; and the first setting module is configured to set the physical address corresponding to a shared virtual address to the first physical address, the shared virtual address being accessible to any process.
[0039] Optionally, the data sharing device further includes: a removal module, a third locking module, a first change module, and a third unlocking module. The removal module is configured to remove the first data from the first physical address; the third locking module is configured to lock the shared virtual address when the first data exists in the second physical address of the non-volatile memory to prevent the shared virtual address from being accessed by a process; the first change module is configured to change the physical address corresponding to the shared virtual address from the first physical address to the second physical address; and the third unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process.
[0040] Optionally, the removal module is used to move the first data out of the first physical address based on whether a removal condition is met; the removal condition includes at least one of the following conditions: the capacity of the free storage space of the volatile memory is less than a capacity threshold; and, within a target time period before the current moment, the number of processes accessing the shared virtual address is less than a quantity threshold.
[0041] Optionally, the data sharing device further includes a second setting module configured to set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address based on an access request from the second process to the shared virtual address; the second private virtual address is accessible to the second process and is prohibited from being accessed by any process other than the second process.
[0042] Optionally, the data sharing device further includes: a second setting module, a first copy module, a fourth locking module, a second changing module, and a fourth unlocking module. The second setting module is configured to set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address according to an access request from the second process to the shared virtual address; the second private virtual address is allowed to be accessed by the second process and is prohibited from being accessed by processes other than the second process; the first copy module is configured to copy the first data in the second physical address to the third physical address of the volatile memory when the physical address corresponding to the shared virtual address is the second physical address; the fourth locking module is configured to lock both the shared virtual address and the second private virtual address to prevent the shared virtual address and the second private virtual address from being accessed by the process; the second changing module is configured to change both the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address; and the fourth unlocking module is configured to unlock both the shared virtual address and the second private virtual address to allow the shared virtual address and the second private virtual address to be accessed by the process.
[0043] Optionally, the first copy module is configured to: when the physical address corresponding to the second private virtual address is set as the physical address corresponding to the shared virtual address, copy the first data in the second physical address to the third physical address.
[0044] Optionally, the data sharing device further includes: a first locking module, a third changing module, and a first unlocking module. The first locking module is configured to lock the shared virtual address based on a data modification request for the shared virtual address to prevent the shared virtual address from being accessed by a process; the data modification request is configured to request that the data at the physical address corresponding to the shared virtual address be modified to second data at a fourth physical address of the volatile memory; the third changing module is configured to change the physical address corresponding to the shared virtual address to the fourth physical address; and the first unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process.
[0045] Optionally, the data sharing device further includes: a second locking module, a third setting module, a second unlocking module, and a second copying module. The second locking module is configured to lock the shared virtual address to prevent the shared virtual address from being accessed by a process; the third setting module is configured to set the physical address corresponding to the dirty virtual address to the physical address corresponding to the shared virtual address; the second unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process; and the second copying module is configured to copy the data at the physical address corresponding to the dirty virtual address to a fifth physical address of the non-volatile memory.
[0046] Optionally, the second copy module is used to: copy the data on the physical address corresponding to the dirty virtual address to the log in the non-volatile memory; after successfully copying the data on the physical address corresponding to the dirty virtual address to the log, copy the data on the log to the fifth physical address.
[0047] In a fourth aspect, the present application provides a data sharing device, which also belongs to a processor, is connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by instructions of the processor; the data sharing device includes: a second setting module. The second setting module is used to set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address based on an access request of a second process to the shared virtual address; the second private virtual address is accessible to the second process and prohibited from being accessed by processes other than the second process, and the shared virtual address is accessible to any process.
[0048] Optionally, the data sharing device further includes: a writing module and a first setting module. The writing module is configured to write first data of a first process into a first physical address of a volatile memory; the first physical address is a physical address corresponding to a first private virtual address, which is accessible to the first process but prohibited to any process other than the first process; and the first setting module is configured to set a physical address corresponding to a shared virtual address to the first physical address, which is accessible to any process.
[0049] Optionally, the data sharing device further includes: a removal module, a third locking module, a third unlocking module, and a first changing module. The removal module is configured to remove the first data from the first physical address; the third locking module is configured to lock the shared virtual address when the first data exists in the second physical address of the non-volatile memory to prevent the shared virtual address from being accessed by a process; the first changing module is configured to change the physical address corresponding to the shared virtual address from the first physical address to the second physical address; and the third unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process.
[0050] Optionally, the removal module is used to move the first data out of the first physical address based on whether a removal condition is met; the removal condition includes at least one of the following conditions: the capacity of the free storage space of the volatile memory is less than a capacity threshold; and, within a target time period before the current moment, the number of processes accessing the shared virtual address is less than a quantity threshold.
[0051] Optionally, the data sharing device further includes: a first copy module, a fourth locking module, a fourth unlocking module, and a second changing module. The first copy module is configured to copy the first data in the second physical address to the third physical address of the volatile memory when the physical address corresponding to the shared virtual address is the second physical address; the fourth locking module is configured to lock both the shared virtual address and the second private virtual address to prevent the shared virtual address and the second private virtual address from being accessed by a process; the second changing module is configured to change both the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address; and the fourth unlocking module is configured to unlock both the shared virtual address and the second private virtual address to allow the shared virtual address and the second private virtual address to be accessed by a process.
[0052] Optionally, the first copy module is configured to: when the physical address corresponding to the second private virtual address is set as the physical address corresponding to the shared virtual address, copy the first data in the second physical address to the third physical address.
[0053] Optionally, the data sharing device further includes: a first locking module, a third changing module, and a first unlocking module. The first locking module is configured to lock the shared virtual address based on a data modification request for the shared virtual address to prevent the shared virtual address from being accessed by a process; the data modification request is configured to request that the data at the physical address corresponding to the shared virtual address be modified to second data at a fourth physical address of the volatile memory; the third changing module is configured to change the physical address corresponding to the shared virtual address to the fourth physical address; and the first unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process.
[0054] Optionally, the data sharing device further includes: a second locking module, a third setting module, a second unlocking module, and a second copying module. The second locking module is configured to lock the shared virtual address to prevent the shared virtual address from being accessed by a process; the third setting module is configured to set the physical address corresponding to the dirty virtual address to the physical address corresponding to the shared virtual address; the second unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process; and the second copying module is configured to copy the data at the physical address corresponding to the dirty virtual address to a fifth physical address of the non-volatile memory.
[0055] Optionally, the second copy module is used to: copy the data on the physical address corresponding to the dirty virtual address to the log in the non-volatile memory; after successfully copying the data on the physical address corresponding to the dirty virtual address to the log, copy the data on the log to the fifth physical address.
[0056] In a fifth aspect, the present application provides a computer comprising: a processor, a volatile memory and a non-volatile memory, and the physical address of the non-volatile memory can be accessed by the instructions of the processor; the processor is used to execute the data sharing method described in any design of the first aspect or the second aspect.
[0057] In a sixth aspect, the present application provides a chip, which includes a programmable logic circuit and / or program instructions, and when the chip is running, is used to implement the data sharing method as described in any design of the first aspect or the second aspect.
[0058] In the seventh aspect, the present application provides a computer storage medium, which stores a computer program. When the computer program runs on a computer, it enables the computer to execute the data sharing method described in any one of the designs in the first aspect or the second aspect.
[0059] In an eighth aspect, the present application also provides a computer program product comprising instructions, which, when run on a computer, enables the computer to execute the data sharing method described in any one of the first aspect or the second aspect.
[0060] The effects of the second to eighth aspects mentioned above can refer to the effects of the corresponding designs in the first aspect mentioned above, and this application will not elaborate on them here. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] FIG1 is a schematic diagram of the structure of a computer provided in an embodiment of the present application;
[0062] FIG2 is a schematic diagram of a data copy process provided in an embodiment of the present application;
[0063] FIG3 is a flow chart of a data sharing method provided in an embodiment of the present application;
[0064] FIG4 is a schematic diagram of an example of a data sharing method provided in an embodiment of the present application;
[0065] FIG5 is a schematic diagram of another example of a data sharing method provided in an embodiment of the present application;
[0066] FIG6 is a schematic diagram of another example of a data sharing method provided in an embodiment of the present application;
[0067] FIG7 is a schematic diagram of another example of a data sharing method provided in an embodiment of the present application;
[0068] FIG8 is a schematic diagram of another example of a data sharing method provided in an embodiment of the present application;
[0069] FIG9 is a schematic diagram of a data sharing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0070] An embodiment of the present application provides a computer, as shown in FIG1 , comprising a processor 01 and memory. Furthermore, with the development of storage technology, memory has gradually adopted a heterogeneous architecture. In a heterogeneous architecture, the memory is divided into volatile memory 02 and non-volatile memory 03, and the processor 01 is connected to both the volatile memory 02 and the non-volatile memory 03.
[0071] Volatile memory can be read and written at any time. Volatile memory is typically used as a temporary storage medium (also known as a cache) for the operating system or other running processes. However, volatile memory cannot retain stored data when the power is turned off. To save data, it must be written from volatile memory to non-volatile memory. Non-volatile memory ensures that data is not lost when the power is turned off or the computer is suddenly or unexpectedly shut down.
[0072] Volatile memory can include dynamic random access memory (DRAM) and compute express link memory (CXL Memory). Non-volatile memory can include persistent memory (PM), 3D XPoint (3D XPoint), and CXL-based solid-state drives (SSDs).
[0073] Volatile memory typically features fast access times, data volatility, and small capacity, while non-volatile memory typically features slow access times, data non-volatility, and large capacity. For example, consider DRAM as the volatile memory and PM as the non-volatile memory. DRAM has a faster access speed, with a latency of approximately 80 to 140 nanoseconds. PM, on the other hand, has a slower access speed, with a latency of approximately 170 to 400 nanoseconds (or 3000 nanoseconds). Furthermore, PM has significantly lower bandwidth and concurrency than DRAM.
[0074] In addition, in the embodiments of the present application, the processor instructions can access not only volatile memory but also non-volatile memory. This heterogeneous architecture can be called a full memory architecture. The processor instructions can be load instructions or store instructions. The connection method between the non-volatile memory and the processor can be a computer express link (CXL) method, etc.
[0075] Furthermore, a process running on the processor can access data stored at a physical address by accessing the virtual address corresponding to the physical address. Furthermore, data can be shared between processes.
[0076] For example, a process has a private virtual address that can only be accessed by the process itself and cannot be accessed by other processes. For example, the private virtual address of the first process can only be accessed by the first process and cannot be accessed by the second process; the private virtual address of the second process can only be accessed by the second process and cannot be accessed by the first process. Therefore, if the first and second processes need to share data, they need to use a shared virtual address that can be accessed by any process.
[0077] The data generated by the first process during its operation will be stored at the physical address corresponding to the private virtual address of the first process. If the first process needs to share the data with the second process, the processor needs to copy the data to the physical address corresponding to the shared virtual address (which is different from the physical address corresponding to the private virtual address of the first process). When the second process accesses the data, it can access the shared virtual address. At this time, the processor can copy the data at the physical address corresponding to the shared virtual address to the physical address corresponding to the private virtual address of the second process. The second process can then access the data stored at the physical address corresponding to the private virtual address by accessing the private virtual address of the second process, thereby sharing the data of the first process with the second process.
[0078] As shown in Figure 2, the private virtual address 1.1 of the first process corresponds to physical address 2.1, the private virtual address 1.2 of the second process corresponds to physical address 2.2, and the shared virtual address 1.3 corresponds to physical address 2.3. Physical addresses 2.1, 2.2, and 2.3 are all physical addresses in volatile memory. Data generated by the first process during execution is stored at physical address 2.1. The processor then copies the data from physical address 2.1 to physical address 2.3. When the second process accesses shared virtual address 1.3, the processor can copy the data in physical address 2.3 to physical address 2.2. The second process can then access the data at private virtual address 1.2.
[0079] However, when sharing data between the first and second processes, data copying is required. For example, the processor needs to copy data from physical address 2.1 to physical address 2.3, and then from physical address 2.3 to physical address 2.2. This data copying takes a long time, resulting in a longer time between the time the first process generates data and the time the second process accesses that data. Consequently, data sharing between processes incurs a high latency.
[0080] When the capacity of the free storage space in the volatile memory is small, the processor will also move the data out of the volatile memory. In this way, when the second process accesses the shared virtual address, the processor may not be able to obtain the data from the physical address corresponding to the shared virtual address. At this time, the processor needs to search for the data in the non-volatile memory, and after finding the data, it will copy the data from the non-volatile memory to the physical address corresponding to the shared virtual address in the volatile memory, so that the subsequent processor can copy the data from the physical address corresponding to the shared virtual address to the physical address corresponding to the private virtual address of the second process. However, this process is relatively complicated, and the processor performs more operations, which will also increase the delay in sharing data between processes.
[0081] In addition, in the related art, when the flushing condition is met, the processor will also perform a flushing operation. The flushing condition can be that the cycle for executing the flushing operation has arrived, or the capacity of the free storage space in the volatile memory is less than a threshold, etc. The flushing operation may include: the processor locks the shared virtual address to prohibit the shared virtual address from being accessed by the process; then, the processor copies the data in the physical address corresponding to the shared virtual address to the non-volatile memory for backup; after copying the data in the physical address corresponding to the shared virtual address to the non-volatile memory, the processor unlocks the shared virtual address to allow the shared virtual address to be accessed by the process. Since the shared virtual address is locked during the execution of the flushing operation by the processor, the shared virtual address cannot be accessed by the process during this process, so it will affect the data shared between processes, resulting in a further increase in the delay in sharing data between processes.
[0082] Experiments show that among the delays in sharing data between processes, the delay caused by data transmission (copying data) accounts for more than 30% of the total delay, and the processor's software delay (the delay caused by more operations performed by the processor) accounts for more than 50% of the total delay.
[0083] In the above content, the physical address corresponding to the shared virtual address is taken as the physical address of the volatile memory as an example. Optionally, in the full memory architecture, the related technology can also set the physical address corresponding to the above shared virtual address to the address in the non-volatile memory. However, there is still the problem of data copying, so the latency of shared data is still high. In addition, since the access speed of volatile memory is relatively slow, it takes a long time to copy data to the physical address in the volatile memory, and to copy data from the physical address in the volatile memory to other physical addresses, which will further aggravate the latency of shared data.
[0084] An embodiment of the present application provides a data sharing method that can reduce the delay in sharing data between processes. The method is executed by the processor in Figure 1. The processor is connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by the instructions of the processor. It can be seen that the present application is applicable to memories using a heterogeneous architecture, and the heterogeneous architecture is a full memory architecture. The processor can call a data sharing process to execute the data sharing method provided in an embodiment of the present application. The data sharing process may include one or more processes. When the data sharing process includes multiple processes, different processes are used to perform different operations in the data sharing method.
[0085] For example, FIG3 is a flow chart of a data sharing method provided in an embodiment of the present application. As shown in FIG3 , the data sharing method includes:
[0086] S101. A processor writes first data of a first process into a first physical address of a volatile memory; the first physical address is a physical address corresponding to a first private virtual address of the first process.
[0087] During the execution of the first process, the processor may write first data of the first process into a first physical address corresponding to a first private virtual address of the first process, where the first physical address is a physical address of the volatile memory.
[0088] The first private virtual address is a virtual address private to the first process. The first private virtual address is allowed to be accessed by the first process, but is prohibited from being accessed by other processes except the first process.
[0089] In an embodiment of the present application, the first process and the subsequent second process may be processes of an application or other modules. The applications to which the first process and the second process belong may be the same or different, and this application does not limit this.
[0090] S102: The processor sets the physical address corresponding to the shared virtual address as a first physical address.
[0091] After writing the first data to the first physical address, the processor can map the shared virtual address to the first physical address, that is, set the physical address corresponding to the shared virtual address to the first physical address. The shared virtual address can be accessed by any process.
[0092] In this way, other processes (such as the second process) except the first process can access the data at the first physical address by accessing the shared virtual address, thereby enabling the first process to share data with other processes.
[0093] It can be seen that in S102, the physical address corresponding to the first private virtual address and the physical address corresponding to the shared virtual address are both the above-mentioned first physical address, and the processor does not copy the data in the first physical address to the physical address corresponding to the shared virtual address. Therefore, data copying is avoided, and the delay in sharing data between processes caused by data copying is avoided.
[0094] S103: The processor sets the physical address corresponding to the second private virtual address of the second process to the physical address corresponding to the shared virtual address according to the access request of the second process to the shared virtual address.
[0095] The second private virtual address is a virtual address private to the second process. The second private virtual address is allowed to be accessed by the second process, but is prohibited from being accessed by other processes except the second process.
[0096] When the second process needs to read the first data, it can initiate an access request to the shared virtual address. In this case, the processor can map the second private virtual address of the second process to the physical address corresponding to the shared virtual address. That is, the processor sets the physical address corresponding to the second private virtual address of the second process to the physical address corresponding to the shared virtual address. After setting the physical address corresponding to the second private virtual address of the second process, the second process can access the first data at the corresponding physical address by accessing the second private virtual address.
[0097] According to the above content, in S103, the physical address corresponding to the second private virtual address is the same as the physical address corresponding to the shared virtual address, and the processor does not copy the data in the physical address corresponding to the shared virtual address to the physical address corresponding to the second private virtual address. Therefore, data copying is avoided, and the delay in sharing data between processes caused by data copying is avoided.
[0098] It is understood that in the embodiment of the present application, the case where no data copy is performed in S102 and S103 is taken as an example. However, it is understood that it is also possible that no data copy is performed in S102 and data copy is performed in S103. Alternatively, data copy is performed in S102 and data copy is not performed in S103.
[0099] When data is copied in S102, the first physical address corresponding to the first private virtual address is different from the physical address corresponding to the shared virtual address. The processor needs to copy the first data at the first physical address corresponding to the first private virtual address to the physical address corresponding to the shared virtual address in S102.
[0100] When data is copied in S103, the physical address corresponding to the second private virtual address is different from the physical address corresponding to the shared virtual address. The processor needs to copy the first data at the physical address corresponding to the shared virtual address to the physical address corresponding to the second private virtual address in S103.
[0101] In summary, in the data sharing method provided in the embodiment of the present application, the processor can set the physical address corresponding to the shared virtual address to the first physical address after writing the first data of the first process to the first physical address of the volatile memory. In this way, it is convenient for other processes other than the first process (such as the second process) to access the data at the first physical address by accessing the shared virtual address, thereby enabling the first process to share data with other processes. It can be seen that the processor can realize data sharing between processes by setting the physical address corresponding to the virtual address, reduce the copying of shared data between processes, and therefore reduce the delay of sharing data between processes.
[0102] The sequence of steps in the method embodiments provided in the embodiments of the present application can be appropriately adjusted, and the steps can be increased or decreased accordingly according to the circumstances. Any technical personnel familiar with this technical field can easily think of different methods within the technical scope disclosed in this application, and they should all be covered within the scope of protection of this application, so they will not be repeated here.
[0103] The above content describes the process of sharing data from the first process to the second process. Optionally, any process (such as the first process, the second process, or other processes) can also modify the data shared by the first process.
[0104] For example, the processor can lock the shared virtual address based on a data modification request for the shared virtual address to prevent the shared virtual address from being accessed by the process. Assume that the data modification request is used to request that the data at the physical address corresponding to the shared virtual address be modified to the second data at the fourth physical address of the volatile memory. Then, the processor can then change the physical address corresponding to the shared virtual address to the fourth physical address. After changing the physical address corresponding to the shared virtual address to the fourth physical address, the processor can also unlock the shared virtual address to allow the shared virtual address to be accessed by the process. If a process (such as a second process) subsequently accesses the shared virtual address, the process will eventually access the modified second data instead of the original first data.
[0105] Furthermore, after the data at the physical address corresponding to the shared virtual address is changed from the first data to the second data, the processor can further lock the shared virtual address and change the physical address corresponding to the shared virtual address to the physical address where the other data is located in response to other data modification requests for the shared virtual address, and then unlock the shared virtual address. It can be seen that the processor can perform the above operations in response to multiple data modification requests in sequence, continuously modifying the data at the physical address corresponding to the shared virtual address.
[0106] According to the above content, the processor only needs to change the physical address corresponding to the shared virtual address to complete the data modification. Since the time required to change the physical address corresponding to the shared virtual address is short, the shared virtual address is locked for a short time, which has little impact on the process accessing the shared virtual address.
[0107] In related technologies, if the data at the physical address corresponding to a shared virtual address needs to be modified, the processor must first lock the shared virtual address. The processor then copies the second data at the fourth physical address to the physical address corresponding to the shared virtual address, thereby changing the data at the physical address corresponding to the shared virtual address from the first data to the second data. Finally, the processor unlocks the shared virtual address. However, this technology requires a long time to copy data, which results in a longer lock time for the shared virtual address, significantly impacting process access to the shared virtual address.
[0108] Optionally, the processor in the embodiment of the present application can also perform a flush operation. For example, the processor can perform a flush operation when a flush condition is met. The flush condition can be that the cycle for executing the flush operation has arrived, or the capacity of the free storage space in the volatile memory is less than a capacity threshold, etc. The flush operation may include: the processor first locks the shared virtual address to prevent the shared virtual address from being accessed by the process; then, the processor sets the physical address corresponding to the flush virtual address to the physical address corresponding to the shared virtual address, and then unlocks the shared virtual address to allow the shared virtual address to be accessed by the process; finally, the processor copies the data at the physical address corresponding to the flush virtual address to the fifth physical address of the non-volatile memory.
[0109] The aforementioned flush virtual address may be a private virtual address of a process that executes the flush operation in the processor, or may be another shared virtual address different from the aforementioned shared virtual address.
[0110] According to the above-mentioned dirty flushing operation, the way the processor flushes dirty is to first lock the shared virtual address, and then map the dirty flushing virtual address to the physical address corresponding to the shared virtual address (that is, the physical address corresponding to the dirty flushing virtual address is set to the physical address corresponding to the shared virtual address). Subsequently, the shared virtual address is unlocked, and the data on the physical address corresponding to the shared virtual address is copied to the non-volatile memory based on the dirty flushing virtual address. Since in the dirty flushing operation, the duration of the shared virtual address being locked is the duration of mapping the dirty flushing virtual address to the physical address corresponding to the shared virtual address, and the duration of mapping the dirty flushing virtual address to the physical address corresponding to the shared virtual address is shorter, the shared virtual address is locked for a shorter time. Therefore, the dirty flushing operation has less impact on the process accessing the shared virtual address.
[0111] In addition, during the dirty flush operation, if a process needs to modify the data at the physical address corresponding to the shared virtual address, the processor will change the physical address corresponding to the shared virtual address to the physical address where the new data is located. However, at this time, the physical address corresponding to the dirty flush virtual address is still the old physical address, so the processor still copies the data at the old physical address to the non-volatile memory.
[0112] For example, suppose a shared virtual address corresponds to physical address 1, and data 1 is stored at physical address 1. When a process accesses the shared virtual address, the data accessed is data 1. If the flush condition is met at this time, during the flush operation, the processor sets physical address 1 to the physical address corresponding to the flush virtual address and, based on this flush virtual address, copies data 1 at physical address 1 to non-volatile memory. During the flush operation, if a process needs to change the data associated with the shared virtual address from data 1 at physical address 1 to data 2 at physical address 2, the processor can change the physical address corresponding to the shared virtual address from physical address 1 to physical address 2. This way, subsequent processes accessing the shared virtual address will access data 2. However, the processor still copies data 1 to non-volatile memory instead of data 2. Later, if the flush condition is met again, the processor can copy data 2 to non-volatile memory using the same process as for copying data 1 to non-volatile memory.
[0113] It can be seen that during the dirty flushing operation, if the data associated with the shared virtual address is modified, two versions of the data associated with the shared virtual address will exist in the memory at the same time, and the processor will copy the old version of the data to the non-volatile memory, and the data accessed by the process when accessing the shared virtual address will be the new version of the data.
[0114] Furthermore, when the processor copies the data at the physical address corresponding to the dirty virtual address to the fifth physical address of the non-volatile memory, it can directly copy the data to the fifth physical address. Alternatively, the processor can first copy the data at the physical address corresponding to the dirty virtual address to the log in the non-volatile memory; after successfully copying the data at the physical address corresponding to the dirty virtual address to the log, the processor copies the data on the log to the fifth physical address. In this way, it is ensured that the data copied by the processor to the fifth physical address is completely consistent with the data at the physical address corresponding to the dirty virtual address, or that the processor does not copy any data to the fifth physical address, thereby ensuring the atomicity of the data on the non-volatile memory.
[0115] In an embodiment of the present application, the processor may further move data out of the free storage space to expand the capacity of the free storage space of the volatile memory.
[0116] For example, the processor can move the above-mentioned first data out of the first physical address. For example, the processor can move the first data out of the first physical address based on whether the removal condition is met. The processor can determine whether the removal condition is met, and when the removal condition is met, move the first data out of the first physical address. When the removal condition is not met, continue to determine whether the removal condition is met. After the data is moved out of the volatile memory, the storage space occupied by the data in the volatile memory is released, and the storage space becomes free storage space. In this way, the capacity of the free storage space of the volatile memory can be increased to support the storage of subsequent data.
[0117] There are various ways to implement the removal condition.
[0118] For example, the removal condition includes: the capacity of the free storage space of the volatile memory is less than the capacity threshold. The capacity threshold in the removal condition is different from the capacity threshold in the dirty flushing condition. For example, the capacity threshold in the removal condition is the first capacity threshold, and the capacity threshold in the dirty flushing condition is the second capacity threshold. The first capacity threshold may be less than the second capacity threshold. The free storage space of the volatile memory refers to the storage space in the volatile memory where no data is stored. When the capacity of the free storage space of the volatile memory is less than the capacity threshold, it is difficult for the volatile memory to support the storage of subsequent data. Therefore, the processor may remove the data in the volatile memory.
[0119] For another example, the removal condition includes: the number of processes accessing the shared virtual address within the target time period before the current moment is less than a threshold value. Thus, the processor can count the number of processes accessing the shared virtual address within the target time period before the current moment. When this number is less than the threshold value, it indicates that the number of processes accessing the shared virtual address is small, the data at the physical address corresponding to the shared virtual address is cold data, and the probability that the shared virtual address has been recently accessed is high. At this point, the first data at the first physical address corresponding to the shared virtual address can be removed.
[0120] In addition, if the number of processes accessing the shared virtual address during the target time period before the current time is greater than or equal to the threshold, this indicates that many processes have recently accessed the shared virtual address, the data at the physical address corresponding to the shared virtual address is hot data, and the probability of the shared virtual address being recently accessed is low. It is not currently appropriate to remove the data at the physical address corresponding to the shared virtual address to ensure normal access to the shared virtual address by the process.
[0121] For another example, the removal conditions include: the capacity of the free storage space of the volatile memory is less than a capacity threshold, and the number of processes accessing the shared virtual address in the target time period before the current moment is less than a number threshold.
[0122] It is understood that the physical address corresponding to a virtual address is usually managed by the virtual memory subsystem, but in the embodiments of the present application, the processor can also set the physical address corresponding to the virtual address. It can be seen that the virtual memory subsystem is exposed to the processor, and the processor can obtain the number of processes accessing the shared virtual address through the virtual memory subsystem. Therefore, the embodiments of the present application support removal conditions including the number of processes accessing the shared virtual address being less than a threshold value within a target time period before the current time.
[0123] Furthermore, after moving the first data from the first physical address, the processor may further determine whether the first data exists in the non-volatile memory. If the first data exists at the second physical address in the non-volatile memory, the processor may further perform subsequent operations to change the physical address corresponding to the shared virtual address from the first physical address to the second physical address.
[0124] For example, when the first data exists at the second physical address, the processor can lock the shared virtual address to prevent the shared virtual address from being accessed by the process; then, the processor changes the physical address corresponding to the shared virtual address from the first physical address to the second physical address; finally, the processor unlocks the shared virtual address to allow the shared virtual address to be accessed by the process.
[0125] It is understood that the first data at the second physical address in the volatile memory may be the first data copied at the second physical address by the processor during a flush operation; or the first data may have been pre-stored by the user at the second physical address in the volatile memory. In short, the embodiment of the present application does not limit the method by which the first data stored at the second physical address is obtained.
[0126] In addition, when the first data is not stored in the non-volatile memory, the processor does not need to change the physical address corresponding to the shared virtual address from the first physical address to the second physical address.
[0127] It is understandable that S103 in the above embodiment may occur before the processor changes the physical address corresponding to the shared virtual address from the first physical address to the second physical address, or may occur after the processor changes the physical address corresponding to the shared virtual address from the first physical address to the second physical address. When S103 occurs before the processor changes the physical address corresponding to the shared virtual address from the first physical address to the second physical address, the physical address corresponding to the shared virtual address is the first physical address of the volatile memory. When S103 occurs after the processor changes the physical address corresponding to the shared virtual address from the first physical address to the second physical address, the physical address corresponding to the shared virtual address is the second physical address of the non-volatile memory.
[0128] In related technologies, the physical address corresponding to the shared virtual address is the physical address of the volatile memory. After the processor moves the data from the physical address corresponding to the shared virtual address, if the process accesses the shared virtual address, the processor will find that the physical address corresponding to the shared virtual address does not hit the data. At this time, the processor needs to search for data in the non-volatile memory and copy the found data to the physical address corresponding to the shared virtual address. In this process, the process accessing the shared virtual address is in a waiting state, which will significantly increase the delay of data sharing. In addition, this process executed by the processor is relatively complex, and the processor performs more operations, which will also increase the delay of sharing data between processes.
[0129] However, in the embodiment of the present application, when the physical address corresponding to the shared virtual address is not the first physical address of the volatile memory, if the physical address corresponding to the shared virtual address is the second physical address of the non-volatile memory, then the processor can set the corresponding physical address for the second private virtual address of the second process without copying the data, so that the second process can access the data, the waiting time of the second process is shorter, and the delay of data sharing is reduced.
[0130] Furthermore, in the embodiment of the present application, after the processor moves the data out of the volatile memory, if the physical address corresponding to the shared virtual address is changed to the physical address of the non-volatile memory, then the complex processes in the related art can be avoided. As a result, the processor performs fewer operations, which further reduces the delay in sharing data between processes. In addition, because the operation of the processor in the embodiment of the present application is relatively simple, the input / output (I / O) stack related to the operation of the processor in the present application is relatively short.
[0131] Optionally, if the physical address corresponding to the shared virtual address in S103 is a physical address in the non-volatile memory, the processor may further perform the following operations to further reduce the latency of the shared data.
[0132] For example, when the physical address corresponding to the shared virtual address is the second physical address, the processor may copy the first data at the second physical address to the third physical address of the volatile memory. The processor then locks the shared virtual address to prevent the shared virtual address from being accessed by the process. The processor then changes the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address. Finally, the processor unlocks the shared virtual address to allow the shared virtual address to be accessed by the process.
[0133] When the physical address corresponding to the shared virtual address is the physical address of the non-volatile memory (such as the second physical address mentioned above), considering that the access to the non-volatile memory is relatively slow, the processor can copy the first data in the second physical address to the third physical address of the volatile memory, and then change the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address. In this way, the second process can access the first data on the third physical address by accessing the second private virtual address. Moreover, since the third physical address is the physical address of the volatile memory, the second process can access the first data on the third physical address faster, which can further reduce the delay of sharing data between processes.
[0134] Optionally, the processor may copy the first data in the second physical address to the third physical address of the volatile memory in parallel with S103. For example, when the processor sets the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address, the processor copies the first data in the second physical address to the third physical address. In this way, the copying of the first data can be completed as early as possible, further improving the efficiency of data sharing. Of course, the processor may also copy the first data in the second physical address to the third physical address of the volatile memory after S103, which is not limited in this embodiment of the present application.
[0135] Optionally, after copying the first data at the second physical address to the third physical address of the volatile memory, the processor may also move the first data at the second physical address out to increase the free storage space of the non-volatile memory. Of course, the processor may not move the first data at the second physical address out, and this embodiment of the application is not limited to this.
[0136] In the above content, data sharing between the first process and the second process through a shared virtual address is taken as an example. It can be understood that there can be multiple shared virtual addresses, and other processes can also share data through shared virtual addresses.
[0137] Before executing the method provided in the embodiment of the present application, the processor may also perform an initialization operation. The initialization operation may include: the processor first divides the shared virtual addresses to be used subsequently and creates relevant page tables for these shared virtual addresses. The virtual storage space composed of these shared virtual addresses can be called a flat cache (FLAC) virtual storage space.
[0138] It is worth noting that the processor has not set the physical addresses corresponding to these shared virtual addresses at this time, so the page table of the shared virtual address is not a complete page table. In the process of executing the method provided in the embodiment of the present application, when setting the corresponding physical address for the shared virtual address, the page table of the shared virtual address can be filled so that the page table points to the physical address corresponding to the shared virtual address.
[0139] When the processor sets the physical address corresponding to a virtual address (such as a shared virtual address), it can call the page attachment system to implement it.
[0140] In addition, when the processor executes the embodiments of the present application, the physical address corresponding to the shared virtual address may be set to a physical address in volatile memory or a physical address in non-volatile memory, but the process does not actually perceive these physical addresses. The process only needs to perceive the shared virtual address.
[0141] As can be seen from the foregoing description, the latency of sharing data between processes in the embodiments of the present application is low. Therefore, when multiple processes concurrently access a shared virtual address, the time it takes for each process to access the shared virtual address is relatively short. Therefore, the total time it takes for multiple processes to concurrently access the shared virtual address is also relatively short, enabling the embodiments of the present application to support a higher degree of concurrency. A process accessing a shared virtual address can be used to read or modify data at the physical address corresponding to the shared virtual address.
[0142] The method provided in the embodiment of the present application will be illustrated below with reference to Figures 4, 5, 6, 7 and 8.
[0143] As shown in Figure 4, assume that the private virtual address 1.1 of the first process corresponds to the physical address 2.1 in volatile memory. The processor can write the first process's data 1 to physical address 2.1. The processor then sets the physical address corresponding to the shared virtual address 3.1 to physical address 2.1. Afterwards, if the processor receives an access request from the second process for the shared virtual address 3.1, the processor can also set the physical address corresponding to the second process's private virtual address 4.1 to the physical address 2.1 corresponding to the shared virtual address 3.1 based on the access request. The second process can then access the data 1 at physical address 2.1 by accessing the private virtual address 4.1.
[0144] As shown in Figure 5, the processor can also move data 1 out of physical address 2.1. Assuming that data 1 is stored at physical address 5.1 of the non-volatile memory, the processor can also lock shared virtual address 3.1 to prevent shared virtual address 3.1 from being accessed by any process. Afterwards, the processor changes the physical address corresponding to shared virtual address 3.1 from physical address 2.1 to physical address 5.1. Finally, the processor can also unlock shared virtual address 3.1 to allow shared virtual address 3.1 to be accessed by any process. Afterwards, if a second process receives an access request to shared virtual address 3.1, the processor can also set the physical address corresponding to the second process's private virtual address 4.1 to physical address 5.1 corresponding to shared virtual address 3.1 based on the access request. Afterwards, the second process can access data 1 at physical address 5.1 by accessing private virtual address 4.1.
[0145] As shown in Figure 6, the processor can then copy data 1 at physical address 5.1 to physical address 2.2 of volatile memory. It can also lock both shared virtual address 3.1 and private virtual address 401 to prevent them from being accessed by other processes. It can also change the physical address corresponding to shared virtual address 3.1 and private virtual address 4.1 from physical address 5.1 to physical address 2.2. It can then unlock both shared virtual address 3.1 and private virtual address 401 to allow them to be accessed by other processes. The second process can then access data 1 at physical address 2.2 by accessing private virtual address 4.1.
[0146] The processor can also lock shared virtual address 3.1 based on a data modification request for shared virtual address 3.1 to prevent it from being accessed by any process. The data modification request is used to request that the data at the physical address corresponding to shared virtual address 3.1 be modified to data 2 at physical address 2.3 of volatile memory. As shown in Figure 7, assuming that this data modification request is received after Figure 6, the processor can change physical address 2.2 corresponding to shared virtual address 3.1 to physical address 2.3 of volatile memory. Finally, the processor unlocks shared virtual address 3.1 to allow access by any process.
[0147] The processor can also lock shared virtual address 3.1 to prevent shared virtual address 3.1 from being accessed by the process; and the processor sets the physical address corresponding to flush virtual address 3.2 to the physical address corresponding to shared virtual address 3.1. As shown in Figure 8, assuming that the flush operation is performed after Figure 7, the processor can set the physical address corresponding to flush virtual address 3.2 to physical address 2.3 corresponding to shared virtual address 3.1. The processor can then unlock shared virtual address 3.1 to allow shared virtual address 3.1 to be accessed by the process; the processor can also copy data 2 at physical address 2.3 corresponding to flush virtual address 3.2 to physical address 5.2 of the non-volatile memory.
[0148] Furthermore, the data shared using the method provided in the embodiment of the present application may be part of the data or all of the data of a process. Taking the example that the data shared using the method provided in the embodiment of the present application may be part of the data of a process, assuming that the data of the first process includes: data 1 and metadata of data 1, then data 1 can be shared using the method provided in the embodiment of the present application, while the metadata of data 1 is not shared using the method provided in the embodiment of the present application. For example, the processor can use a hashing method to allocate shared memory in volatile memory and shared memory in non-volatile memory for the metadata of data 1, and the metadata is stored in both shared memories. When the metadata needs to be shared to the second process, the processor obtains the metadata from the shared memory in the volatile memory and feeds it back to the second process.
[0149] Experiments have shown that, when compared with related technologies, the latency of sharing data between processes in the methods provided by the embodiments of this application is at least 10 times greater than that in the methods provided by the embodiments of this application. In scenarios where the total read / write volume is 64 gigabytes (GB) and each read / write volume is 2 mebibytes (MB), the efficiency of process read / write data in this application is over 200 times greater than that in related technologies.
[0150] Based on the data sharing method provided in the embodiment of the present application, the embodiment of the present application further provides a data sharing device. The data sharing device belongs to a processor. The processor is connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by instructions of the processor. As shown in Figure 9, the data sharing device includes:
[0151] The write module 901 is used to write the first data of the first process to the first physical address of the volatile memory; the first physical address is the physical address corresponding to the first private virtual address, and the first private virtual address is allowed to be accessed by the first process and is prohibited from being accessed by processes other than the first process; the operations performed by the write module 901 can refer to S101 in the aforementioned embodiment, and the embodiments of the present application will not be repeated here.
[0152] The first setting module 902 is used to set the physical address corresponding to the shared virtual address to the first physical address, and the shared virtual address is allowed to be accessed by any process. The operation performed by the first setting module 902 can refer to S102 in the above embodiment, and will not be repeated in this embodiment.
[0153] Optionally, the data sharing device further includes: a removal module, a third locking module, a first change module and a third unlocking module (all not shown in FIG9 ). The removal module is used to move the first data out of the first physical address; the third locking module is used to lock the shared virtual address when the first data exists in the second physical address of the non-volatile memory to prevent the shared virtual address from being accessed by the process; the first change module is used to change the physical address corresponding to the shared virtual address from the first physical address to the second physical address. The third unlocking module is used to unlock the shared virtual address to allow the shared virtual address to be accessed by the process. The operations performed by the removal module, the third locking module, the first change module and the third unlocking module can refer to the relevant descriptions in the aforementioned embodiments, and the embodiments of the present application will not be repeated here.
[0154] Optionally, the removal module is used to move the first data out of the first physical address based on whether a removal condition is met; the removal condition includes at least one of the following conditions: the capacity of the free storage space of the volatile memory is less than a capacity threshold; and, within a target time period before the current moment, the number of processes accessing the shared virtual address is less than a quantity threshold.
[0155] Optionally, the data sharing device further includes:
[0156] A second setting module (not shown in FIG9 ) is configured to set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address in response to an access request from the second process to the shared virtual address; the second private virtual address is accessible to the second process and is prohibited from being accessed by any process other than the second process. The operations performed by the second setting module may refer to S103 in the aforementioned embodiment and are not described in detail in this embodiment.
[0157] Optionally, the data sharing device further includes: a second setting module, a first copying module, a fourth locking module, a second changing module and a fourth unlocking module (all not shown in FIG. 9 ).
[0158] A second setting module is configured to set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address according to an access request from the second process to the shared virtual address; the second private virtual address is allowed to be accessed by the second process and is prohibited from being accessed by processes other than the second process; a first copy module is configured to copy the first data in the second physical address to the third physical address of the volatile memory when the physical address corresponding to the shared virtual address is the second physical address; a fourth locking module is configured to lock both the shared virtual address and the second private virtual address to prevent the shared virtual address and the second private virtual address from being accessed by the process; a second changing module is configured to change the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address; and a fourth unlocking module is configured to unlock both the shared virtual address and the second private virtual address to allow the shared virtual address and the second private virtual address to be accessed by the process. The operations performed by the second setting module, the first copy module, the fourth locking module, the second changing module, and the fourth unlocking module can refer to the relevant descriptions in the aforementioned embodiments, and the embodiments of this application will not be repeated here.
[0159] Optionally, the first copy module is configured to: when the physical address corresponding to the second private virtual address is set as the physical address corresponding to the shared virtual address, copy the first data in the second physical address to the third physical address.
[0160] Optionally, the data sharing device further includes:
[0161] a first locking module (not shown in FIG9 ), configured to lock the shared virtual address according to a data modification request for the shared virtual address, so as to prevent the shared virtual address from being accessed by any process; wherein the data modification request is used to request that data at a physical address corresponding to the shared virtual address be modified to second data at a fourth physical address of the volatile memory;
[0162] A third changing module (not shown in FIG9 ), configured to change the physical address corresponding to the shared virtual address to the fourth physical address;
[0163] The first unlocking module (not shown in FIG9 ) is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process.
[0164] The operations performed by the first locking module, the third changing module and the first unlocking module can refer to the introduction of the modification process of the data associated with the shared virtual address in the aforementioned embodiment, and will not be repeated here in the embodiment of the present application.
[0165] Optionally, the data sharing device further includes:
[0166] A second locking module (not shown in FIG9 ) is configured to lock the shared virtual address to prevent the shared virtual address from being accessed by any process;
[0167] A third setting module (not shown in FIG9 ) is configured to set the physical address corresponding to the dirty virtual address to the physical address corresponding to the shared virtual address;
[0168] a second unlocking module (not shown in FIG9 ), configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process;
[0169] The second copy module (not shown in FIG9 ) is configured to copy the data at the physical address corresponding to the dirty virtual address to the fifth physical address of the non-volatile memory.
[0170] The operations performed by the second locking module, the third setting module, the second unlocking module and the second copy module can refer to the introduction of the dirty operation in the aforementioned embodiment, and will not be repeated here in the embodiment of the present application.
[0171] Optionally, the second copy module is used to: copy the data on the physical address corresponding to the dirty virtual address to the log in the non-volatile memory; after successfully copying the data on the physical address corresponding to the dirty virtual address to the log, copy the data on the log to the fifth physical address.
[0172] An embodiment of the present application provides another data sharing device, which is also a processor. The processor is connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by instructions of the processor. The data sharing device includes:
[0173] The second setting module is used to set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address according to the access request of the second process to the shared virtual address; the second private virtual address is allowed to be accessed by the second process and is prohibited from being accessed by processes other than the second process, and the shared virtual address is allowed to be accessed by any process.
[0174] Optionally, the data sharing device further includes:
[0175] a writing module, configured to write first data of a first process into a first physical address of a volatile memory; the first physical address is a physical address corresponding to a first private virtual address, the first private virtual address is accessible to the first process and is prohibited from being accessed by processes other than the first process;
[0176] The first setting module is configured to set the physical address corresponding to the shared virtual address as the first physical address, wherein the shared virtual address is allowed to be accessed by any process.
[0177] Optionally, the data sharing device further includes: a removal module, a third locking module, a third unlocking module, and a first changing module. The removal module is configured to remove the first data from the first physical address; the third locking module is configured to lock the shared virtual address when the first data exists in the second physical address of the non-volatile memory to prevent the shared virtual address from being accessed by a process; the first changing module is configured to change the physical address corresponding to the shared virtual address from the first physical address to the second physical address; and the third unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process.
[0178] Optionally, the removal module is used to move the first data out of the first physical address based on whether a removal condition is met; the removal condition includes at least one of the following conditions: the capacity of the free storage space of the volatile memory is less than a capacity threshold; and, within a target time period before the current moment, the number of processes accessing the shared virtual address is less than a quantity threshold.
[0179] Optionally, the data sharing device further includes: a first copy module, a fourth locking module, a fourth unlocking module, and a second changing module. The first copy module is configured to copy the first data in the second physical address to the third physical address of the volatile memory when the physical address corresponding to the shared virtual address is the second physical address; the fourth locking module is configured to lock both the shared virtual address and the second private virtual address to prevent the shared virtual address and the second private virtual address from being accessed by a process; the second changing module is configured to change both the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address; and the fourth unlocking module is configured to unlock both the shared virtual address and the second private virtual address to allow the shared virtual address and the second private virtual address to be accessed by a process.
[0180] Optionally, the first copy module is configured to: when the physical address corresponding to the second private virtual address is set as the physical address corresponding to the shared virtual address, copy the first data in the second physical address to the third physical address.
[0181] Optionally, the data sharing device further includes: a first locking module, a third changing module, and a first unlocking module. The first locking module is configured to lock the shared virtual address based on a data modification request for the shared virtual address to prevent the shared virtual address from being accessed by a process; the data modification request is configured to request that the data at the physical address corresponding to the shared virtual address be modified to second data at a fourth physical address of the volatile memory; the third changing module is configured to change the physical address corresponding to the shared virtual address to the fourth physical address; and the first unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process.
[0182] Optionally, the data sharing device further includes: a second locking module, a third setting module, a second unlocking module, and a second copying module. The second locking module is configured to lock the shared virtual address to prevent the shared virtual address from being accessed by a process; the third setting module is configured to set the physical address corresponding to the dirty virtual address to the physical address corresponding to the shared virtual address; the second unlocking module is configured to unlock the shared virtual address to allow the shared virtual address to be accessed by a process; and the second copying module is configured to copy the data at the physical address corresponding to the dirty virtual address to a fifth physical address of the non-volatile memory.
[0183] Optionally, the second copy module is used to: copy the data on the physical address corresponding to the dirty virtual address to the log in the non-volatile memory; after successfully copying the data on the physical address corresponding to the dirty virtual address to the log, copy the data on the log to the fifth physical address.
[0184] An embodiment of the present application further provides a chip, which includes a programmable logic circuit and / or program instructions, and when the chip is running, is used to implement any data sharing method provided in the embodiment of the present application.
[0185] The embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions;
[0186] When the instructions are executed on a computer, the computer is enabled to execute any one of the data sharing methods provided in the embodiments of the present application.
[0187] The present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any one of the data sharing methods provided in the present application.
[0188] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product, which includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium, or a semiconductor medium (e.g., a solid-state hard disk).
[0189] In this application, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance. The term "at least one" refers to one or more, and "a plurality" refers to two or more, unless otherwise expressly defined.
[0190] The different types of embodiments, such as the method embodiments and device embodiments provided in the embodiments of this application, can refer to each other, and the embodiments of this application are not limited thereto. The order of the operations of the method embodiments provided in the embodiments of this application can be appropriately adjusted, and the operations can be increased or decreased accordingly according to the circumstances. Any person skilled in the art who can easily think of a method of variation within the technical scope disclosed in this application should be included in the scope of protection of this application, and therefore will not be described in detail.
[0191] In the corresponding embodiments provided in this application, it should be understood that the disclosed devices, etc. can be implemented through other structural methods. For example, the device embodiments described above are merely illustrative. For example, the division of modules is only a logical function division. In actual implementation, there may be other division methods, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or module, which can be electrical or other forms.
[0192] Units described as separate components may or may not be physically separate, and components described as units may or may not be physical units, and may be located in one place or distributed across multiple devices. Some or all of these units may be selected to achieve the purpose of this embodiment based on actual needs.
[0193] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.
Claims
1. A data sharing method, characterized in that, The method is executed by a processor, which is connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by the instructions of the processor; the method includes: Writing first data of a first process to a first physical address of the volatile memory; the first physical address is a physical address corresponding to a first private virtual address, and the first private virtual address is allowed to be accessed by the first process and prohibited from being accessed by processes other than the first process; Setting the physical address corresponding to a shared virtual address to the first physical address, and the shared virtual address is allowed to be accessed by any process.
2. The method according to claim 1, wherein The method further includes: Moving the first data out of the first physical address; When the first data exists in a second physical address of the non-volatile memory, locking the shared virtual address to prevent the shared virtual address from being accessed by a process; Changing the physical address corresponding to the shared virtual address from the first physical address to the second physical address; Unlocking the shared virtual address to allow the shared virtual address to be accessed by a process.
3. The method according to claim 2, wherein Moving the first data out of the first physical address includes: Moving the first data out of the first physical address according to the satisfaction of a moving-out condition; The moving-out condition includes at least one of the following conditions: The capacity of the free storage space of the volatile memory is less than a capacity threshold; And, within a target time period before the current moment, the number of processes accessing the shared virtual address is less than a number threshold.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: According to an access request of a second process to the shared virtual address, setting the physical address corresponding to a second private virtual address to the physical address corresponding to the shared virtual address; the second private virtual address is allowed to be accessed by the second process and prohibited from being accessed by processes other than the second process.
5. The method according to claim 2 or 3, characterized in that, The method further includes: According to an access request of a second process to the shared virtual address, setting the physical address corresponding to a second private virtual address to the physical address corresponding to the shared virtual address; the second private virtual address is allowed to be accessed by the second process and prohibited from being accessed by processes other than the second process; When the physical address corresponding to the shared virtual address is the second physical address, copying the first data in the second physical address to a third physical address of the volatile memory; Locking both the shared virtual address and the second private virtual address to prevent the shared virtual address and the second private virtual address from being accessed by a process; Changing both the physical address corresponding to the shared virtual address and the physical address corresponding to the second private virtual address from the second physical address to the third physical address; Unlocking both the shared virtual address and the second private virtual address to allow the shared virtual address and the second private virtual address to be accessed by a process.
6. The method according to claim 5, wherein Copying the first data in the second physical address to a third physical address of the volatile memory includes: When setting the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address, copy the first data in the second physical address to the third physical address.
7. The method according to any one of claims 1 to 6, characterized in that, The method further includes: Lock the shared virtual address according to a data modification request for the shared virtual address to prevent the shared virtual address from being accessed by a process; the data modification request is used to request modifying the data on the physical address corresponding to the shared virtual address to the second data on the fourth physical address of the volatile memory; Change the physical address corresponding to the shared virtual address to the fourth physical address; Unlock the shared virtual address to allow the shared virtual address to be accessed by a process.
8. The method according to any one of claims 1 to 7, characterized in that, The method further includes: Lock the shared virtual address to prevent the shared virtual address from being accessed by a process; Set the physical address corresponding to the dirty virtual address to the physical address corresponding to the shared virtual address; Unlock the shared virtual address to allow the shared virtual address to be accessed by a process; Copy the data on the physical address corresponding to the dirty virtual address to the fifth physical address of the non-volatile memory.
9. The method according to claim 8, characterized in that Copying the data on the physical address corresponding to the dirty virtual address to the fifth physical address of the non-volatile memory includes: Copy the data on the physical address corresponding to the dirty virtual address to the log in the non-volatile memory; After successfully copying the data on the physical address corresponding to the dirty virtual address to the log, copy the data on the log to the fifth physical address.
10. A data sharing method, characterized in that, The method is executed by a processor, the processor is connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by the instructions of the processor; the method includes: According to an access request of a second process to a shared virtual address, set the physical address corresponding to the second private virtual address to the physical address corresponding to the shared virtual address; the second private virtual address is allowed to be accessed by the second process and prohibited from being accessed by processes other than the second process, and the shared virtual address is allowed to be accessed by any process.
11. A data sharing device, characterized in that, The data sharing device belongs to the processor, the processor is connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by the instructions of the processor; The data sharing device includes: A writing module, configured to write the first data of the first process to the first physical address of the volatile memory; the first physical address is the physical address corresponding to the first private virtual address, and the first private virtual address is allowed to be accessed by the first process and prohibited from being accessed by processes other than the first process; A first setting module, configured to set the physical address corresponding to the shared virtual address to the first physical address, and the shared virtual address is allowed to be accessed by any process.
12. A data sharing device, characterized in that, The data sharing device belongs to the processor, the processor is connected to a volatile memory and a non-volatile memory, and the non-volatile memory can be accessed by the instructions of the processor; The data sharing device includes: A first setting module, configured to set the physical address corresponding to a second private virtual address as the physical address corresponding to the shared virtual address according to an access request of a second process to the shared virtual address; the second private virtual address is allowed to be accessed by the second process and prohibited from being accessed by processes other than the second process, and the shared virtual address is allowed to be accessed by any process.
13. A computer, characterized in that, Comprising: A processor, a volatile memory, and a non-volatile memory, and the physical address of the non-volatile memory can be accessed by an instruction of the processor; The processor is configured to execute the data sharing method according to any one of claims 1 to 10.
14. A chip, characterized in that, The chip includes programmable logic circuits and / or program instructions, which are configured to implement the data sharing method according to any one of claims 1 to 10 when the chip runs.
15. A computer storage medium, characterized in that, A computer program is stored in the storage medium, and when the computer program runs on a computer, the computer is caused to execute the data sharing method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Communicating method and system between user mode and kernel
CN105677493A
Shared memory processing method and device, computer equipment and storage medium
CN116302598A
Data communication method and device, processing system, electronic equipment and storage medium
CN116755902A
Inter-process data sharing method and device and electronic equipment
CN117009109A
Inter-process data sharing method and device and electronic equipment
CN117033028A