A memory sharing method and related device

By introducing shared memory nodes and address information recording mechanism in distributed systems, the problem of high memory maintenance cost in distributed systems is solved, and efficient memory sharing and stable application services are achieved.

CN115756879BActive Publication Date: 2025-10-10TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111032089.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-03
Publication Date
2025-10-10
Estimated Expiration
2041-09-03

AI Technical Summary

Technical Problem

Each node in a distributed system needs to be configured with a large amount of memory space to cache data objects, resulting in high maintenance costs.

Method used

By configuring shared memory nodes, application nodes do not need to cache data objects locally. They only need to reference data objects in shared memory nodes when needed, and record address information pairs during memory garbage collection to determine the objects to be updated to avoid reference exceptions and achieve memory sharing.

Benefits of technology

It reduces the memory maintenance cost of the distributed system and improves the system's memory utilization efficiency and service stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115756879B_ABST
    Figure CN115756879B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a memory sharing method and related device, the method is applied to a distributed system, the distributed system is configured with a shared memory node and a plurality of application nodes, and the distributed system can be applied to the field of maps. The shared memory node can store data objects through cloud technology, and the plurality of application nodes do not need to locally cache a large number of data objects, but only need to refer to the data objects cached in the shared memory node to provide corresponding application program services, such as reading through the cloud technology. When a remote object refers to a data object in the application node, address information pairs are recorded, when the shared memory node performs memory garbage collection, the remote object still referring to the data object is determined as an object to be updated through the address information pairs, the object to be updated is retained during the memory garbage collection, and abnormal reference to the object to be updated is avoided. Therefore, object sharing of the shared memory node has a basis for implementation, and the memory maintenance cost of the distributed system is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a memory sharing method and related devices. Background Art

[0002] Currently, many applications, such as e-commerce applications and big data applications, provide services to users through distributed systems.

[0003] Each node in this type of distributed system can be an application server, and data objects need to be frequently transferred between nodes to achieve data synchronization. In particular, each node can cache some data objects as temporary data in local memory using caching technology.

[0004] However, the current caching method requires each node to configure a large amount of memory space to cache these data objects. For distributed systems with a large amount of data object transmission, the memory configured for each node is massive, resulting in high distributed system memory maintenance costs. Summary of the Invention

[0005] In order to solve the above technical problems, the present application provides a memory sharing method and related devices to reduce the memory maintenance cost of the distributed system.

[0006] The embodiments of this application disclose the following technical solutions:

[0007] In one aspect, an embodiment of the present application provides a memory sharing method, which is applied to a distributed system, wherein the distributed system includes a shared memory node and multiple application nodes, and the data objects stored in the shared memory node are used to provide object sharing for the multiple application nodes. The method includes:

[0008] In response to a reference by a remote object in the application node to a data object in the shared memory node, recording an address information pair, the address information pair including a remote address of the remote object and a local address of the data object referenced by the remote object;

[0009] In response to a memory garbage collection operation on the shared memory node, a target address is determined from the remote address in the recorded address information pair, wherein the remote object corresponding to the target address still references the data object corresponding to the local address in the address information pair;

[0010] Determine the data object referenced by the target address as the object to be updated;

[0011] The memory garbage collection operation is performed on the shared memory node based on the object to be updated.

[0012] On the other hand, an embodiment of the present application provides a memory sharing device, which is applied to a distributed system, wherein the distributed system includes a shared memory node and multiple application nodes, and the data objects stored in the shared memory node are used to provide object sharing for the multiple application nodes. The device includes a recording unit, a determination unit, and a recovery unit:

[0013] The recording unit is configured to record an address information pair in response to a reference from a remote object in the application node to a data object in the shared memory node, the address information pair comprising a remote address of the remote object and a local address of the data object referenced by the remote object;

[0014] The determining unit is configured to determine, in response to a memory garbage collection operation on the shared memory node, a target address from the remote address in the recorded address information pair, wherein the remote object corresponding to the target address still references the data object corresponding to the local address in the address information pair;

[0015] The determining unit is further configured to determine the data object referenced by the target address as the object to be updated;

[0016] The recycling unit is configured to perform the memory garbage collection operation on the shared memory node based on the object to be updated.

[0017] On the other hand, an embodiment of the present application discloses a computer device, wherein the computer device includes a processor and a memory:

[0018] The memory is used to store program code and transmit the program code to the processor;

[0019] The processor is used to execute the memory sharing method described in the above aspects according to the instructions in the program code.

[0020] On the other hand, an embodiment of the present application discloses a computer-readable storage medium, which is used to store a computer program, and the computer program is used to execute the memory sharing method described in the above aspects.

[0021] As can be seen from the above technical solution, in addition to multiple application nodes, a distributed system also includes a shared memory node. The data objects stored in this shared memory node are used to provide object sharing to multiple application nodes. This eliminates the need for multiple application nodes to cache large numbers of data objects locally. Instead, they can simply reference the data objects cached in the shared memory node when needed to provide corresponding application services. To ensure that shared memory nodes can efficiently provide data object sharing, it is necessary to ensure that application nodes avoid abnormal references to their own data objects during memory garbage collection operations. Therefore, when a remote object in an application node references a data object in the shared memory node, this reference behavior is recorded using address information pairs. When the shared memory node needs to perform memory garbage collection, the recorded address information pairs are used to identify remote objects that are still referencing the data objects in the shared memory node. These remote objects are then identified as objects to be updated, and the objects to be updated are retained during memory garbage collection to avoid abnormal references to the objects to be updated. This provides a foundation for object sharing in shared memory nodes. Application nodes in a distributed system no longer need to allocate large amounts of memory and can still provide normal application services based on remote references to data objects in the shared memory node, reducing the memory maintenance costs of the distributed system. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0023] Figure 1 A schematic diagram of memory garbage collection for a shared memory node in a distributed system provided in an embodiment of the present application;

[0024] Figure 2 A flow chart of a memory sharing method provided in an embodiment of the present application;

[0025] Figure 3 A schematic diagram of memory sharing in a distributed system based on Java applications provided in an embodiment of the present application;

[0026] Figure 4 A remote marking flow chart for determining an object to be updated provided in an embodiment of the present application;

[0027] Figure 5 A memory garbage collection flow chart provided in an embodiment of the present application;

[0028] Figure 6A device structure diagram of a memory sharing device provided for an embodiment of the present application;

[0029] Figure 7 A structure diagram of a terminal device provided for an embodiment of the present application;

[0030] Figure 8 A structure diagram of a server provided for an embodiment of the present application. DETAILED DESCRIPTION

[0031] The embodiments of the present application are described below in conjunction with the accompanying drawings.

[0032] In the related art, in order for each node of a distributed system to be able to cache data objects as temporary data, a sufficient amount of memory space needs to be respectively configured, and the maintenance cost is very high.

[0033] Therefore, an embodiment of the present application provides a memory sharing method, through a shared memory manner, an application node in a distributed system no longer needs to configure a large amount of memory and can provide normal application program services based on remote reference to data objects in a shared memory node, thereby reducing the memory maintenance cost of the distributed system.

[0034] The memory sharing method provided by the present application can be implemented by a computer device, which can be a terminal device, a server, etc. The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal can be a mobile phone, a computer, a smart voice interaction device, a smart home appliance, a vehicle-mounted terminal, etc., but is not limited thereto. The terminal and the server can be directly or indirectly connected through wired or wireless communication, which is not limited by the present application.

[0035] The memory sharing method can be applied to the cloud storage function in the cloud technology field. Cloud storage is a new concept extended and developed on the basis of the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as a storage system) is a storage system that cooperatively works together to provide data storage and business access functions to the outside by collecting a large number of various types of storage devices (storage nodes) in the network through cluster applications, grid technology, and distributed storage file systems, etc.

[0036] Currently, storage systems utilize a method for creating logical volumes. When creating a logical volume, physical storage space is allocated for each logical volume. This physical storage space may consist of disks on a specific storage device or several storage devices. When a client stores data on a logical volume, it stores the data on a file system. The file system divides the data into multiple parts, each of which is an object. An object contains not only the data but also additional information such as the data identifier (ID) of the data entity. The file system writes each object to the physical storage space of the logical volume and records the storage location information of each object. Therefore, when a client requests access to data, the file system can provide access to the data based on the storage location information of each object.

[0037] The storage system allocates physical storage space to logical volumes by pre-dividing the physical storage space into stripes based on the estimated capacity of the objects to be stored in the logical volume (this estimate often has a large margin relative to the actual capacity of the objects to be stored) and the Redundant Array of Independent Disks (RAID) groupings. A logical volume can be understood as a stripe, thereby allocating physical storage space to the logical volume.

[0038] For example, the shared memory nodes of the distributed system in the embodiments of the present application can store data objects via cloud storage. Furthermore, the application nodes in the distributed system can also store remote objects via cloud storage. It should be noted that the distributed system provided by the embodiments of the present application can be applied to the map field. The data objects in the shared storage nodes can be map-related data objects, thereby providing memory sharing for other application nodes in the map field.

[0039] like Figure 1 The distributed system shown includes a shared memory node, as well as application node 1, application node 2, and application node 3. In this embodiment, the aforementioned computer device is server 100, which serves as a hardware implementation of a shared memory node and stores data objects a, b, c, and d for providing object sharing to application nodes 1, 2, and 3. As a result, application nodes 1, 2, and 3 no longer need to use their own memory space to store data objects a, b, c, and d. Instead, they can provide corresponding application services by simply referencing the data objects cached in the shared memory node when needed, saving memory overhead. Application nodes 1-3 are servers that provide corresponding application services to terminal devices. Terminal devices can obtain services provided by applications by accessing application nodes 1-3 in the distributed system.

[0040] In order to make the shared memory node provide data object sharing efficiently, it is necessary to ensure that the application node avoids abnormal references to its own data objects during memory garbage collection operations. The server 100 records the reference behavior of the remote object in the application node to the data object of the shared memory node through the address information pair. For example, before performing memory garbage collection (GC), Figure 1 The scenario shown records two address information pairs, namely address information pair 1: <remote address of remote object in application node 1, local address of data object a>, and address information pair 2: <remote address of remote object in application node 3, local address of data object d>.

[0041] When a shared memory node needs to perform memory garbage collection, server 100 determines whether the remote object in application node 1 still references data object a through recorded address information pair 1, and determines whether the remote object in application node 3 still references data object d through address information pair 2. If it is determined that only the remote object in application node 3 still references data object d, and the remote object in application node 1 no longer exists (for example, it has gone offline), the remote address in address information pair 2 is determined as the target address, and data object d identified by the local address in address information pair 2 is determined as the object to be updated.

[0042] When performing memory garbage collection, retain the objects to be updated to avoid exceptions in the reference to the updated objects. For example, Figure 1 In the scenario shown, after memory garbage collection is performed on the shared memory node, the only data object stored in the shared memory node is data object d. The originally stored data objects a, b, and c are cleared from the shared memory through the memory garbage collection operation, thereby reclaiming memory resources for the shared memory node.

[0043] This provides a basis for object sharing in shared memory nodes. Application nodes in distributed systems no longer need to be configured with large amounts of memory and can provide normal application services based on remote references to data objects in shared memory nodes, reducing the memory maintenance cost of distributed systems.

[0044] Next, we will still use the server as the aforementioned computer device for explanation. Figure 2 A flow chart of a memory sharing method provided in an embodiment of the present application is provided. The method is applied to a distributed system including a shared memory node and multiple application nodes, such as Figure 1 The distributed system diagram is shown in FIG.

[0045] In some related technologies, cache technology is applied in Java applications, such as LinkedHashMap, ConcurrentHashMap provided in Java standard library, and various third-party LRU Cache implementations (such as guava Cache and caffeine cache familiar to Java programmers), and the contents stored in these caches are usually from some KV storage (such as HBase) or database (such as MySQL). For example, for e-commerce applications, popular users and popular commodities are often preloaded from the database into the cache of each distributed application. These applications use the same cache for most of the content, resulting in a lot of memory waste.

[0046] It needs to be explained that the shared memory node in the distributed system can provide object sharing for multiple application nodes based on the saved data objects, so that the shared memory node and the multiple application nodes constitute a memory sharing system, so that the multiple application nodes do not need to cache a large amount of data objects locally, but only need to reference the data objects cached in the shared memory node when needed to provide corresponding application program services. The application node is a server node that provides the corresponding application program service for the terminal device, and the terminal device can access the application node to obtain the service provided by the application program.

[0047] In a distributed system, there can be one or more such memory sharing systems, and the shared memory nodes in different memory sharing systems are different, and the application nodes can be different, or partially or completely the same. For ease of illustration, the embodiments hereinafter mainly take one shared memory system (one shared memory node and multiple application nodes) in a distributed system as an example for illustration.

[0048] The method comprises:

[0049] S201: In response to the reference of the data object in the shared memory node by the remote object in the application node, recording the address information pair.

[0050] In order to enable the shared memory node to efficiently provide sharing of data objects, the server needs to ensure that the reference of the application node to its own data object does not appear abnormal during the memory garbage collection operation.

[0051] Therefore, the server can record the reference behavior of the application node to the data object in the shared memory node by means of address information pair, and the address information pair comprises the remote address of the remote object and the local address of the data object referenced by the remote object.

[0052] When a remote object in an application node references a data object in a shared memory node, the address information pair can be in the form of<remote_address,local_address> , where remote_address is the address of the remote object and local_address is the address of the data object.

[0053] Both the remote objects in the application node and the data objects in the shared memory node represent data in the application. For example, this could be the price of a product in an e-commerce application, or a user's nickname. When an application node needs to provide a terminal device with a product price, it can reference the data object in the shared memory node containing the product price parameters through its remote object.

[0054] Some related technologies use Remote Procedure Calls (RPCs) to reference data objects. This reference method requires the sender (e.g., a shared memory node) to serialize the data object into a byte array before transmission. After transmitting the data object over the network to the destination (e.g., an application node), the destination node deserializes the byte array into the data object before use. This entire transmission process consumes significant processing resources and incurs high network overhead.

[0055] To this end, the present invention introduces Remote Direct Memory Access (RDMA) technology, which supports memory sharing in distributed systems. This technology allows direct access to memory on a remote host, bypassing the remote operating system, saving CPU resources and reducing network communication latency.

[0056] In a possible implementation, multiple application nodes reference the data object in the shared memory node through remote memory direct access.

[0057] like Figure 3 The diagram shows a distributed system based on Java applications, where the Java heap memory service serves as a shared memory node, and Java applications 1-3 serve as multiple application nodes that access the object sharing functionality provided by the Java heap memory service. The Java applications may be map applications.

[0058] Among them, the heap memory stores newly created data objects and is a memory area with continuous virtual addresses. Object allocation and memory recycling are managed by GC. The Java heap memory service mainly provides heap memory sharing services. Java applications, as application nodes, directly access data objects in the shared heap memory through the RDMA network. Java applications, like general Java applications, have their own heap memory space. In addition, they can access objects in remote heap memory services through RDMA. The types of referenced data objects are some data structures provided by the Java heap memory service. The RDMA network can be a series of verbs based on the existing Infiniband network. The library written in a series of C codes it provides is abstracted and encapsulated as system calls for accessing remote virtual addresses (mainly providing RDMA_PUT and RDMA_GET). Both Java applications and Java heap memory services can operate the addresses of remote processes through RDMA_PUT and RDMA_GET.

[0059] In addition, the Java heap memory service does not interfere with Java applications. In actual use, a Java application can dynamically expand or shrink its own heap space without affecting other Java applications.

[0060] Before a Java application can use the shared heap memory data object sharing service, it must register with the Java heap memory service during initialization. After registration, the Java application and the Java heap memory service can identify each other's addresses. After the Java application exits, the GC algorithm in the Java heap memory service detects the exit and updates the registered remote objects. The exited Java application will no longer be accessed.

[0061] It should be noted that the embodiments of the present application do not limit whether the application nodes in a distributed system belong to the same application. When multiple applications have data objects that can be shared, the application nodes of the multiple applications can be deployed in a distributed system, and the same shared memory node can be used to provide data object sharing services for the application nodes of different applications.

[0062] Since the memory space of the shared memory node is used as shared memory for multiple application nodes, in order to improve sharing efficiency, the server will specifically determine which data objects need to be stored in the shared memory node.

[0063] In a possible implementation manner, any data object stored in the shared memory node is a data object required by at least two application nodes among the multiple application nodes.

[0064] The server determines whether a data object needs to be referenced by at least two application nodes. If so, it determines whether the data object can be stored in the shared memory node. This effectively controls the scale of data objects stored in the shared memory node, eliminating the need to store all data objects in the entire distributed system in the shared memory node. This reduces the waiting time for subsequent shared memory nodes to perform memory garbage collection, and improves the service stability of each application node in the distributed system.

[0065] S202: In response to a memory garbage collection operation on the shared memory node, determine a target address from a remote address in the recorded address information pair.

[0066] S203: Determine the data object referenced by the target address as the object to be updated.

[0067] Since each application node's reference to a data object is recorded through an address information pair, when a memory garbage collection operation is triggered, the server can determine the "live objects" in the shared memory node based on the previously recorded address information pairs, that is, the data objects that are still referenced by remote objects.

[0068] Therefore, it is necessary to first determine whether the remote object still references the data object identified in the address information pair, and based on this, determine the target address from the remote address identified by the address information pair. The remote object corresponding to the target address still references the data object corresponding to the local address in the address information pair.

[0069] In a possible implementation, for S202, the following steps are included, specifically in combination with Figure 4 Also explain:

[0070] S2021: In response to a memory garbage collection operation on the shared memory node, determine the remote address in the recorded address information pair as the address to be identified.

[0071] like Figure 4 As shown, in response to the memory garbage collection operation on the shared memory node, remote marking starts. Of course, remote marking can also be started before the memory garbage collection operation.

[0072] After the remote marking starts, the address information recorded at this time needs to be identified, and the remote address therein is determined as the address to be identified and can be added to the remote object collection.

[0073] S2022: Scan the remote object corresponding to the address to be identified.

[0074] like Figure 4As shown, for the determined remote object set, the address to be identified is extracted from the set and a remote object scan is performed. By scanning the remote objects, it is determined whether the remote object corresponding to the address to be identified still exists, for example, whether it has been offline or is still online. If the remote object does not exist, S2024 can be directly executed to determine that the address to be identified is a non-target address. If the remote object exists, it can be further determined whether the remote object has changed its reference relationship to the data object corresponding to the local address in the address information pair.

[0075] If it is determined that the remote object corresponding to the address to be identified exists, and the reference relationship to the data object corresponding to the local address in the address information pair is not changed, execute S2023;

[0076] If it is determined that the remote object corresponding to the address to be identified does not exist, or the reference relationship of the data object corresponding to the local address in the address information pair is changed, S2024 is executed.

[0077] S2023: Mark the address to be identified as the target address.

[0078] If the address to be identified is the target address, the data object referenced by the target address can be identified as an object to be updated, that is, marked as a live object. The object to be updated can also be added to the waiting update queue for subsequent memory garbage collection operations.

[0079] S2024: Mark the address to be identified as a non-target address, and the data object corresponding to the local address in the address information pair where the non-target address is located belongs to memory garbage that can be cleared by the memory garbage collection operation.

[0080] In addition, the determined target address and non-target address may be deleted from the remote object collection, and the cycle may be continued until the remote object collection is empty, thereby determining the end of the remote tag.

[0081] Remote marking is equivalent to determining the objects to be updated that need to be retained during memory garbage collection from the data objects in the shared memory node, thereby avoiding the incorrect release of objects to be updated during memory garbage collection, which may cause exceptions in ongoing object references.

[0082] In one possible implementation, the recorded address information pairs for which the target address has not been determined are deleted. Since the remote address in an address information pair is not determined as the target address, it is equivalent to the data object corresponding to the local address in the address information pair not being referenced by the remote object, thus being an invalid address information pair. Therefore, the address information pair can be no longer maintained and deleted. This reduces the number of address information pairs maintained by the system and the number of address information pairs that need to be processed during the next memory garbage collection.

[0083] S204: Perform the memory garbage collection operation on the shared memory node based on the object to be updated.

[0084] Memory garbage collection frees all data objects in a shared memory node, except for the objects to be updated. This frees up memory space, allowing the server to continue providing object sharing services to application nodes.

[0085] The embodiments of the present application provide multiple ways to retain objects to be updated during memory garbage collection. With respect to S204 , two of the ways will be mainly described below.

[0086] The first possible way: copy to a new address

[0087] In this approach, the object to be updated is stored at a first local address in the heap memory space of the shared memory node. During memory garbage collection, the first local address in the address information pair containing the target address is updated to the second local address, generating an updated address information pair. This updated address information pair is then sent to the application node corresponding to the target address.

[0088] In other words, the determined objects to be updated can be uniformly copied to a continuous storage space. This not only preserves the objects to be updated, but also makes the remaining memory space of the shared memory node more continuous after memory garbage collection, which is convenient for subsequent storage of newly created data objects and improves the sharing efficiency of data objects in memory.

[0089] However, in this way, the storage address of the object to be updated will change after memory garbage collection, for example, from the first local address to the second local address. In order for the remote object (corresponding to the target address) that is referencing the object to be updated originally at the first local address to continue to reference the object to be updated normally after memory garbage collection, the remote object needs to be informed of the new address of the object to be updated.

[0090] To this end, based on the storage address of the object to be updated being updated from the first local address to the second local address, the address information pair corresponding to the object to be updated and the remote object can be updated, with the original first local address in the address information pair being updated to the second local address. The updated address information pair can then be sent to the target address so that the application node that has the remote object is aware that the address of the object to be updated has changed.

[0091] Furthermore, in order to improve the reference efficiency after memory garbage collection, and because there is a certain time difference between determining the object to be updated and performing memory garbage collection, it is possible to verify whether the remote object corresponding to the target address exists and that the original reference relationship has not changed before sending the updated address information pair to the application node corresponding to the target address.

[0092] Therefore, in a possible implementation, the method further includes:

[0093] Scanning the remote object corresponding to the target address;

[0094] If it is determined that the remote object corresponding to the target address exists and the reference relationship to the data object corresponding to the local address in the address information pair is not changed, the operation of sending the updated address information pair to the application node corresponding to the target address is performed.

[0095] Next, combine Figure 5 Memory garbage collection is an update of the memory of the shared memory node. After the update starts, you can get the following information: Figure 4 A waiting update queue is determined to include objects to be updated. Objects to be updated are obtained from the waiting update queue and copied so that they are uniformly stored in a continuous storage space. After copying, it is necessary to further determine whether a remote object referencing the object to be updated exists and whether the reference relationship has changed. If it is determined that the remote object corresponding to the address to be identified exists and the reference relationship to the data object corresponding to the local address in the address information pair has not changed, an updated address information pair may be sent to the remote object to update the reference relationship maintained by the application node where the remote object resides.

[0096] The second method: keep the original address

[0097] That is, the heap memory space of the shared memory node is cleared of all data objects except the object to be updated. After the clearing, the object to be updated is still stored in the shared memory node based on the original address. For example, before garbage collection, the object to be updated is stored at the first local address in the heap memory space of the shared memory node. After garbage collection, the object to be updated is still stored at the first local address in the heap memory space of the shared memory node.

[0098] The advantage of this approach is that the address of the object to be updated remains unchanged before and after memory garbage collection, so there is no need to notify the remote object that references the object to be updated, nor is there any need to further verify whether the remote object exists and the reference relationship has not changed, thereby reducing data interaction between systems and improving the utilization of system resources.

[0099] As can be seen, in addition to multiple application nodes, a distributed system also includes shared memory nodes. The data objects stored in these shared memory nodes are used to provide object sharing to multiple application nodes. This eliminates the need for application nodes to cache large numbers of data objects locally. Instead, they can simply reference the data objects cached in the shared memory nodes when needed to provide corresponding application services. To ensure efficient data object sharing in shared memory nodes, it is necessary to prevent application nodes from encountering anomalies in their own data objects during garbage collection. Therefore, when a remote object in an application node references a data object in the shared memory node, this reference is recorded using address information. When garbage collection is required, the recorded address information is used to identify remote objects still referencing the data object in the shared memory node. These remote objects are then identified as objects to be updated, and the objects to be updated are retained during garbage collection to avoid anomalies in the referenced objects. This provides a foundation for object sharing in shared memory nodes. Application nodes in a distributed system no longer need to allocate large amounts of memory and can still provide normal application services based on remote references to data objects in the shared memory nodes, reducing the memory maintenance costs of the distributed system.

[0100] In addition to shared memory nodes requiring memory garbage collection, in some scenarios, application nodes also need to perform memory garbage collection on their own maintained memory.

[0101] In a possible implementation, the method further includes:

[0102] In response to a memory garbage collection operation on the application node, determining a remote object in the application node that is referencing a data object in the shared memory node as an object to be retained;

[0103] Clear the remote objects in the application node except the object to be retained.

[0104] That is, when an application node needs to perform memory garbage collection, if a remote object is referencing a data object in the shared memory node, the remote object must be retained during the garbage collection to ensure continued reference after the garbage collection. Furthermore, the remote object can be pinned to its original storage address, so that the remote object always uses the same address. Since Java applications rarely reference remote objects, pinning the addresses of these remote objects does not affect GC on the Java application side.

[0105] Figure 6This is a device structure diagram of a memory sharing device provided in an embodiment of the present application. The memory sharing device 600 is applied to a distributed system. The distributed system includes a shared memory node and multiple application nodes. The data objects stored in the shared memory node are used to provide object sharing for the multiple application nodes. The memory sharing device 600 includes a recording unit 601, a determination unit 602, and a recovery unit 603:

[0106] The recording unit 601 is configured to record an address information pair in response to a reference from a remote object in the application node to a data object in the shared memory node, the address information pair including a remote address of the remote object and a local address of the data object referenced by the remote object;

[0107] The determining unit 602 is configured to determine, in response to a memory garbage collection operation on the shared memory node, a target address from the remote address in the recorded address information pair, wherein the remote object corresponding to the target address still references the data object corresponding to the local address in the address information pair;

[0108] The determining unit 602 is further configured to determine the data object referenced by the target address as the object to be updated;

[0109] The recycling unit 603 is configured to perform the memory garbage collection operation on the shared memory node based on the object to be updated.

[0110] In a possible implementation manner, the determining unit is further configured to:

[0111] In response to a memory garbage collection operation on the shared memory node, determining a remote address in the recorded address information pair as an address to be identified;

[0112] Scanning the remote object corresponding to the address to be identified;

[0113] If it is determined that the remote object corresponding to the address to be identified exists and the reference relationship to the data object corresponding to the local address in the address information pair is not changed, the address to be identified is marked as the target address;

[0114] If it is determined that the remote object corresponding to the address to be identified does not exist, or the reference relationship of the data object corresponding to the local address in the address information pair is changed, the address to be identified is marked as a non-target address, and the data object corresponding to the local address in the address information pair where the non-target address is located belongs to memory garbage that can be cleaned up by the memory garbage collection operation.

[0115] In a possible implementation, the object to be updated is stored at a first local address in the heap memory space of the shared memory node, and the recycling unit is further configured to:

[0116] Clearing the data object in the heap memory space, and re-saving the object to be updated to a second local address in the heap memory space;

[0117] Updating the first local address in the address information pair where the target address is located to the second local address to obtain an updated address information pair;

[0118] Send the updated address information pair to the application node corresponding to the target address.

[0119] In a possible implementation, the device further includes a scanning unit:

[0120] The scanning unit is used to scan the remote object corresponding to the target address;

[0121] If the scanning unit determines that the remote object corresponding to the address to be identified exists and the reference relationship to the data object corresponding to the local address in the address information pair has not changed, the recycling unit is triggered to execute the operation of sending the updated address information pair to the application node corresponding to the target address.

[0122] In a possible implementation, the recovery unit is further configured to:

[0123] Clear the heap memory space of the shared memory node of the data objects except the object to be updated.

[0124] In a possible implementation, the apparatus further includes an identification unit, where the identification unit is configured to:

[0125] In response to a memory garbage collection operation on the application node, determining a remote object in the application node that is referencing a data object in the shared memory node as an object to be retained;

[0126] Clear the remote objects in the application node except the object to be retained.

[0127] In a possible implementation manner, any one data object stored in the shared memory node is a data object required by at least two application nodes among the multiple application nodes.

[0128] In a possible implementation, the multiple application nodes correspond to different application programs.

[0129] In a possible implementation, the multiple application nodes reference the data objects in the shared memory node through remote memory direct access.

[0130] In a possible implementation, the apparatus further includes a deleting unit configured to delete, from the recorded address information pairs, the address information pairs for which the target address has not been determined.

[0131] The embodiment of the present application further provides a computer device, which is the computer device described above and may include a terminal device or a server, and the aforementioned memory sharing device may be configured in the computer device. The computer device is described below with reference to the accompanying drawings.

[0132] If the computer device is a terminal device, see Figure 7 As shown, the embodiment of the present application provides a terminal device, taking a mobile phone as an example:

[0133] Figure 7 The block diagram shows a partial structure of a mobile phone related to the terminal device provided in the embodiment of the present application. Figure 7 The mobile phone includes components such as a radio frequency (RF) circuit 1410, a memory 1420, an input unit 1430, a display unit 1440, a sensor 1450, an audio circuit 1460, a wireless fidelity (WiFi) module 1470, a processor 1480, and a power supply 1490. It will be understood by those skilled in the art that Figure 7 The mobile phone structure shown in the figure does not constitute a limitation to the mobile phone, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0134] The following combination Figure 7 A detailed introduction to the various components of a mobile phone:

[0135] The RF circuit 1410 can be used to receive and send signals during information transmission or calls. In particular, after receiving downlink information from the base station, it is sent to the processor 1480 for processing. In addition, the designed uplink data is sent to the base station. Generally, the RF circuit 1410 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (LNA), a duplexer, etc. In addition, the RF circuit 1410 can also communicate with the network and other devices through wireless communication. The above-mentioned wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0136] Memory 1420 can be used to store software programs and modules. Processor 1480 executes the various functional applications and data processing of the mobile phone by running the software programs and modules stored in memory 1420. Memory 1420 may mainly include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function (such as a sound playback function, an image playback function, etc.); the data storage area may store data created based on the use of the mobile phone (such as audio data, a phone book, etc.). In addition, memory 1420 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0137] The input unit 1430 can be used to receive input digital or character information, and to generate key signal input related to the user settings and function control of the mobile phone. Specifically, the input unit 1430 may include a touch panel 1431 and other input devices 1432. The touch panel 1431, also known as a touch screen, can collect user touch operations on or near it (such as operations performed by the user using a finger, stylus, or any other suitable object or accessory on or near the touch panel 1431) and drive the corresponding connection device according to a pre-set program. Optionally, the touch panel 1431 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch direction and detects the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device and converts it into touch point coordinates, which are then sent to the processor 1480. It can also receive commands sent by the processor 1480 and execute them. In addition, the touch panel 1431 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 1431, the input unit 1430 may further include other input devices 1432. Specifically, the other input devices 1432 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, power keys, etc.), a trackball, a mouse, and a joystick.

[0138] The display unit 1440 can be used to display information input by the user or information provided to the user and various menus of the mobile phone. The display unit 1440 may include a display panel 1441. Optionally, the display panel 1441 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. Further, the touch panel 1431 may cover the display panel 1441. When the touch panel 1431 detects a touch operation on or near it, it is transmitted to the processor 1480 to determine the type of touch event. Subsequently, the processor 1480 provides corresponding visual output on the display panel 1441 according to the type of touch event. Although in Figure 7 In the embodiment, the touch panel 1431 and the display panel 1441 are used as two independent components to realize the input and output functions of the mobile phone, but in some embodiments, the touch panel 1431 and the display panel 1441 can be integrated to realize the input and output functions of the mobile phone.

[0139] The mobile phone may also include at least one sensor 1450, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 1441 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 1441 and / or the backlight when the mobile phone is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that the mobile phone can also be configured with, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be described here.

[0140] Audio circuit 1460, speaker 1461, and microphone 1462 provide an audio interface between the user and the phone. Audio circuit 1460 converts received audio data into electrical signals and transmits them to speaker 1461, which then converts them into sound signals for output. Microphone 1462, on the other hand, converts collected sound signals into electrical signals, which are then received by audio circuit 1460 and converted into audio data. The audio data is then processed by processor 1480 and transmitted to, for example, another phone via RF circuit 1410, or stored in memory 1420 for further processing.

[0141] WiFi is a short-range wireless transmission technology. Mobile phones can help users send and receive emails, browse the web, and access streaming media through the WiFi module 1470. It provides users with wireless broadband Internet access. Figure 7 A WiFi module 1470 is shown, but it is understandable that it is not an essential component of the mobile phone and can be omitted as needed without changing the essence of the invention.

[0142] Processor 1480 is the control center of the phone, connecting all parts of the phone using various interfaces and circuits. By running or executing software programs and / or modules stored in memory 1420 and accessing data stored in memory 1420, it performs various phone functions and processes data, thereby providing overall monitoring of the phone. Optionally, processor 1480 may include one or more processing units; preferably, processor 1480 may integrate an application processor and a modem processor, with the application processor primarily handling the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 1480.

[0143] The mobile phone also includes a power supply 1490 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 1480 through a power management system, thereby managing charging, discharging, and power consumption through the power management system.

[0144] Although not shown, the mobile phone may also include a camera, a Bluetooth module, etc., which will not be described in detail here.

[0145] In this embodiment, the terminal device can be applied to a distributed system, which includes a shared memory node and multiple application nodes. The data objects stored in the shared memory node are used to provide object sharing for the multiple application nodes. The processor 1480 included therein further has the following functions:

[0146] In response to a reference by a remote object in the application node to a data object in the shared memory node, recording an address information pair, the address information pair including a remote address of the remote object and a local address of the data object referenced by the remote object;

[0147] In response to a memory garbage collection operation on the shared memory node, a target address is determined from the remote address in the recorded address information pair, wherein the remote object corresponding to the target address still references the data object corresponding to the local address in the address information pair;

[0148] Determine the data object referenced by the target address as the object to be updated;

[0149] The memory garbage collection operation is performed on the shared memory node based on the object to be updated. If the computer device is a server, the embodiment of the present application also provides a server, see Figure 8 As shown, Figure 8 The structural diagram of the server 1500 provided in the embodiment of the present application, the server 1500 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPUs) 1522 (for example, one or more processors) and a memory 1532, and one or more storage media 1530 (for example, one or more mass storage devices) for storing application programs 1542 or data 1544. Among them, the memory 1532 and the storage medium 1530 can be temporary storage or permanent storage. The program stored in the storage medium 1530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1522 can be configured to communicate with the storage medium 1530 to execute a series of instruction operations in the storage medium 1530 on the server 1500.

[0150] The server 1500 may also include one or more power supplies 1526, one or more wired or wireless network interfaces 1550, one or more input and output interfaces 1558, and / or one or more operating systems 1541, such as Windows Server 2003. TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM etc.

[0151] The steps performed by the server in the above embodiment can be based on Figure 8 The server structure shown.

[0152] In addition, an embodiment of the present application further provides a storage medium, which is used to store a computer program, and the computer program is used to execute the method provided by the above embodiment.

[0153] An embodiment of the present application also provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the method provided in the above embodiment.

[0154] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the above-mentioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the above-mentioned storage medium can be at least one of the following media: read-only memory (English: Read-only Memory, abbreviated: ROM), RAM, magnetic disk or optical disk, etc., various media that can store program codes.

[0155] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments. The device and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. A person of ordinary skill in the art can understand and implement it without expending creative work.

[0156] The above is merely one specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application 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 memory sharing method, characterized in that: The method is applied to a distributed system, the distributed system including a shared memory node and multiple application nodes, the data objects stored in the shared memory node are used to provide object sharing for the multiple application nodes, and the method includes: In response to a reference by a remote object in the application node to a data object in the shared memory node, recording an address information pair, the address information pair including a remote address of the remote object and a local address of the data object referenced by the remote object; In response to a memory garbage collection operation on the shared memory node, the remote address in the recorded address information pair is determined as the address to be identified; the remote object corresponding to the address to be identified is scanned; if it is determined that the remote object corresponding to the address to be identified exists and the reference relationship to the data object corresponding to the local address in the address information pair has not changed, the address to be identified is marked as the target address, and the remote object corresponding to the target address still references the data object corresponding to the local address in the address information pair; Determine the data object referenced by the target address as the object to be updated; The memory garbage collection operation is performed on the shared memory node based on the object to be updated.

2. The method according to claim 1, characterized in that After scanning the remote object corresponding to the address to be identified, the method further includes: If it is determined that the remote object corresponding to the address to be identified does not exist, or the reference relationship of the data object corresponding to the local address in the address information pair is changed, the address to be identified is marked as a non-target address, and the data object corresponding to the local address in the address information pair where the non-target address is located belongs to memory garbage that can be cleaned up by the memory garbage collection operation.

3. The method according to claim 1, characterized in that The object to be updated is stored at a first local address in the heap memory space of the shared memory node, and performing the memory garbage collection operation on the shared memory node based on the object to be updated includes: Clearing the data object in the heap memory space, and re-saving the object to be updated to a second local address in the heap memory space; Updating the first local address in the address information pair where the target address is located to the second local address to obtain an updated address information pair; Send the updated address information pair to the application node corresponding to the target address.

4. The method according to claim 3, characterized in that The method further comprises: Scanning the remote object corresponding to the target address; If it is determined that the remote object corresponding to the address to be identified exists and the reference relationship to the data object corresponding to the local address in the address information pair is not changed, the operation of sending the updated address information pair to the application node corresponding to the target address is performed.

5. The method according to claim 1, wherein The performing the memory garbage collection operation on the shared memory node based on the object to be updated includes: Clear the heap memory space of the shared memory node of the data objects except the object to be updated.

6. The method according to claim 1, characterized in that The method further comprises: In response to a memory garbage collection operation on the application node, determining a remote object in the application node that is referencing a data object in the shared memory node as an object to be retained; Clear the remote objects in the application node except the object to be retained.

7. The method according to any one of claims 1 to 6, characterized in that Any data object stored in the shared memory node is a data object required by at least two application nodes among the multiple application nodes.

8. The method according to any one of claims 1 to 6, characterized in that: The multiple application nodes correspond to different application programs.

9. The method according to any one of claims 1 to 6, characterized in that: The multiple application nodes reference the data objects in the shared memory node through remote memory direct access.

10. The method according to any one of claims 1 to 6, characterized in that: After determining the target address from the remote address in the recorded address information pair, the method further includes: The address information pairs for which the target address has not been determined are deleted from the recorded address information pairs.

11. A memory sharing device, characterized in that: The device is applied to a distributed system, the distributed system including a shared memory node and multiple application nodes, the data objects stored in the shared memory node are used to provide object sharing for the multiple application nodes, and the device includes a recording unit, a determination unit, and a recovery unit: The recording unit is configured to record an address information pair in response to a reference from a remote object in the application node to a data object in the shared memory node, the address information pair comprising a remote address of the remote object and a local address of the data object referenced by the remote object; The determining unit is configured to, in response to a memory garbage collection operation on the shared memory node, determine the remote address in the recorded address information pair as the address to be identified; scan the remote object corresponding to the address to be identified; if it is determined that the remote object corresponding to the address to be identified exists and the reference relationship to the data object corresponding to the local address in the address information pair has not been changed, mark the address to be identified as the target address, and the remote object corresponding to the target address still references the data object corresponding to the local address in the address information pair; The determining unit is further configured to determine the data object referenced by the target address as the object to be updated; The recycling unit is configured to perform the memory garbage collection operation on the shared memory node based on the object to be updated.

12. The device according to claim 11, characterized in that The determining unit is further configured to: If it is determined that the remote object corresponding to the address to be identified does not exist, or the reference relationship of the data object corresponding to the local address in the address information pair is changed, the address to be identified is marked as a non-target address, and the data object corresponding to the local address in the address information pair where the non-target address is located belongs to memory garbage that can be cleaned up by the memory garbage collection operation.

13. The device according to claim 11, characterized in that The object to be updated is stored at a first local address in the heap memory space of the shared memory node, and the recycling unit is further configured to: Clearing the data object in the heap memory space, and re-saving the object to be updated to a second local address in the heap memory space; Updating the first local address in the address information pair where the target address is located to the second local address to obtain an updated address information pair; Send the updated address information pair to the application node corresponding to the target address.

14. A computer device, characterized in that: The computer device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the memory sharing method according to any one of claims 1 to 10 according to instructions in the program code.

15. A computer-readable storage medium, characterized in that The computer-readable storage medium is used to store a computer program, and the computer program is used to execute the memory sharing method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Memory garbage collection method and apparatus

    CN106201904A

  • Data cache system, method and computer terminal for java platform

    CN109101554A