Memory resource management method and device, storage medium and electronic equipment

By setting the same memory space between the server and the client, and updating the number of references of the memory resource using the target interface, the problem of inefficient memory resource management is solved, and the secure and efficient management of memory resources is achieved.

CN119537003APending Publication Date: 2025-02-28ZHEJIANG DAHUA TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411587234.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-07
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

In the prior art, memory resources are managed in low efficiency, resulting in abnormal process exit and abnormal memory resources release.

Method used

By deploying the target process on the server side and setting the same memory space between the client and the server side, the number of references to the memory resource is updated using the target interface. The specific steps include: responding to the target process startup and initializing the target interface; responding to the message sent by the first process, increasing or decreasing the number of target references through the target interface; releasing the target memory resource when the target references meet the preset conditions.

Benefits of technology

It realizes safe and reliable access to memory resources between processes, avoids unnecessary resource retention or early release, and improves the utilization rate and management efficiency of memory resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 00000000_0000_ABST
    Figure 00000000_0000_ABST
Patent Text Reader

Abstract

The invention discloses a memory resource management method and device, a storage medium and electronic equipment. The method comprises the steps that in response to starting of a target process, a target interface of the target process is initialized; in response to the received first message sent by the first process, the target reference frequency is increased by a preset value through the target interface, the first process is deployed on the client, the client and the server are set to use the same memory space, and the target reference frequency represents the reference frequency of the target memory resource; the first message is used for indicating that target memory resources need to be used; in response to the received second message, reducing the target reference frequency by a preset value through the target interface, the second message being used for indicating that the target memory resource is used up; and releasing the target memory resource under the condition that the target reference frequency meets a preset condition. The technical problem that the management efficiency of memory resources is low is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and in particular to a method and device for managing memory resources, a storage medium, and an electronic device. Background Art

[0002] In the related art, users can independently develop applications based on the user software development kit (SDK) provided by the operating system developer, and install the applications on the terminal device. Then, the user can send business requests to the service process through the SDK on the terminal device to complete the execution of related business. In this process, since there is a need for multiple processes to access memory resources during the business execution process, there is often a phenomenon of abnormal process exit and abnormal release of memory resources. Therefore, there is a technical problem of low memory resource management efficiency in the related art.

[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0004] The embodiments of the present application provide a method and device for managing memory resources, a storage medium, and an electronic device, so as to at least solve the technical problem of low management efficiency of memory resources.

[0005] According to one aspect of an embodiment of the present application, a method for managing memory resources is provided, comprising: in response to a target process being started, initializing a target interface of the target process, wherein the target process is deployed on a server, and the target interface is used to update the number of references of a memory resource from the server; in response to receiving a first message sent by a first process, increasing the target number of references by a preset value through the target interface, wherein the first process is deployed on a client, and the client and the server are configured to use the same memory space, the target number of references indicates the number of times the target memory resource is referenced, and the first message is used to indicate that the target memory resource needs to be used; in response to receiving a second message, reducing the target number of references by the preset value through the target interface, wherein the second message is used to indicate that the target memory resource has been used up; and releasing the target memory resource when the target number of references meets a preset condition.

[0006] According to another aspect of an embodiment of the present application, a memory resource management device is also provided, including: a startup module, used to initialize a target interface of the target process in response to the startup of the target process, wherein the target process is deployed on a server, and the target interface is used to update the number of references of the memory resource from the server; a first update module, used to increase the target reference number by a preset value through the target interface in response to receiving a first message sent by the first process, wherein the first process is deployed on a client, and the client and the server are set to use the same memory space, the target reference number indicates the number of times the target memory resource is referenced, and the first message is used to indicate that the target memory resource needs to be used; a second update module, used to reduce the target reference number by the preset value through the target interface in response to receiving a second message, wherein the second message is used to indicate that the target memory resource has been used up; a release module, used to release the target memory resource when the target reference number meets a preset condition.

[0007] Optionally, the device is used to increase the target reference count by a preset value through the target interface in response to receiving a first message sent by a first process in the following manner: in response to receiving the first message, collecting the target memory resources from the memory space; increasing the target reference count by a preset value through the target interface, and sending the target memory resources to the first process.

[0008] Optionally, the device is used to increase the target reference count by a preset value through the target interface in response to receiving a first message sent by a first process in the following manner, including at least one of the following: when the first message indicates that the first process requests to obtain the target memory resource, increasing the target reference count by the preset value through the target interface; when the first message indicates that the first process requests to execute a target business based on the target memory resource, asynchronously executing the target business through the target process and increasing the target reference count by the preset value through the target interface, wherein when the first process requests to execute the target business based on the target memory resource, the first process increases the target reference count by the preset value through the first interface, and the first interface is used to update the reference count of the memory resource from the client deployed by the first process.

[0009] Optionally, the device is used to reduce the target reference count by the preset value through the target interface in response to receiving a second message in the following manner: when the second message indicates that the first process requests to release the target memory resources, the target reference count is reduced by the preset value through the target interface, wherein when the first process requests to release the target memory resources, the first process reduces the target reference count by the preset value through the first interface; when the second message indicates that the target business execution is completed, the target reference count is reduced by the preset value through the target interface.

[0010] Optionally, the device is used to release the target memory resource when the target reference count meets a preset condition in the following manner: periodically querying the reference count corresponding to each memory resource in the memory space through a thread; determining the memory resources whose reference counts meet the preset condition as memory resources to be released, and releasing the memory resources to be released by calling a preset callback function.

[0011] Optionally, the device is also used for: in response to receiving a first message sent by a first process, after increasing the target reference count by a preset value through the target interface, in response to receiving a third message sent by the first process, reducing the target reference count by the preset value through the target interface, wherein the third message is used to indicate that an abnormality exists in the first process, when the first process requests to execute the target business based on the target memory resource, the first process increases the target reference count by the preset value through the first interface, when an abnormality exists in the first process, the first process clears the reference sub-count to zero through the first interface, the target reference count includes the reference sub-count, and the reference sub-count indicates the number of times the target memory resource is referenced by the first process, and the first interface is used to update the reference count of the memory resource from the client deployed by the first process.

[0012] Optionally, the device is also used for: in response to receiving a first message sent by the first process, after increasing the target reference count by a preset value through the target interface, in response to receiving a fourth message sent by the first process, reducing the target reference count by the preset value through the target interface, wherein the fourth message is used to indicate that the first process has sent the physical address corresponding to the target memory resource to the second process, and there is an exception in the first process, and when the second process requests to execute the target business based on the target memory resource, the second process increases the target reference count by the preset value through the second interface; when the second process requests to release the target memory resource, the second process reduces the target reference count by the preset value through the second interface, and the second interface is used to update the reference count of the memory resource from the client deployed by the second process.

[0013] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned memory resource management method when running.

[0014] According to another aspect of the embodiments of the present application, a computer program product or a computer program is provided, the computer program product or the computer program includes a computer instruction, and the computer instruction is stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the above memory resource management method.

[0015] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the memory resource management method through the computer program.

[0016] In an embodiment of the present application, in response to the start of a target process, a target interface of the target process is initialized, wherein the target process is deployed on a server, and the target interface is used to update the number of references of a memory resource from the server; in response to receiving a first message sent by a first process, the target number of references is increased by a preset value through the target interface, wherein the first process is deployed on a client, and the client and the server are set to use the same memory space, the target number of references indicates the number of times the target memory resource is referenced, and the first message is used to indicate that the target memory resource needs to be used; in response to receiving a second message, the target number of references is reduced by a preset value through the target interface, wherein the second message is used to indicate that the target memory resource has been used up; when the target number of references meets a preset condition, the target memory resource is released, and the use of the target memory resource by the process is determined in real time through the target number of references, ensuring that operations such as access and release of memory resources can be performed safely and reliably between processes, and unnecessary resource retention or early release is avoided through accurate reference counting, thereby achieving the technical effect of improving the utilization rate and management efficiency of memory resources, and further solving the technical problem of low management efficiency of memory resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0018] Figure 1 is a schematic diagram of an application environment of an optional memory resource management method according to an embodiment of the present application;

[0019] Figure 2 is a flowchart of an optional memory resource management method according to an embodiment of the present application;

[0020] Figure 3 is a schematic diagram of an optional memory resource management method according to an embodiment of the present application;

[0021] Figure 4 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application;

[0022] Figure 5 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application;

[0023] Figure 6 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application;

[0024] Figure 7 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application;

[0025] Figure 8 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application;

[0026] Fig. 9 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application;

[0027] Fig.10 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application;

[0028] Fig.11 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application;

[0029] Fig.12 is a schematic structural diagram of an optional memory resource management device according to an embodiment of the present application;

[0030] Fig.13 is a schematic diagram of the structure of an optional memory resource management product according to an embodiment of the present application;

[0031] Fig.14 It is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0032] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0033] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0034] The present application is described below in conjunction with embodiments:

[0035] According to one aspect of an embodiment of the present application, a method for managing memory resources is provided. Optionally, in this embodiment, the method for managing memory resources can be applied to Figure 1 In the hardware environment composed of the server 101 and the terminal device 103 shown in FIG. Figure 1 As shown, the server 101 is connected to the terminal 103 via a network, and can be used to provide services for the terminal device or the application installed on the terminal device. The application 107 can be a video application, an instant messaging application, a browser application, an educational application, a game application, etc. A database 105 may be set up on the server or independently of the server to provide data storage services for the server 101, for example, a game data storage server. The above-mentioned network may include, but is not limited to, a wired network and a wireless network, wherein the wired network includes, a local area network, a metropolitan area network and a wide area network; the wireless network includes, Bluetooth, WIFI and other networks that implement wireless communication; the terminal device 103 may be a terminal configured with an application, and may include, but is not limited to, at least one of the following: a mobile phone (such as an Android phone, an iOS phone, etc.), a laptop computer, a tablet computer, a PDA, a MID (Mobile Internet Devices), a PAD, a desktop computer, a smart TV, an intelligent voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, a virtual reality (VR) terminal, an augmented reality (AR) terminal, a mixed reality (MR) terminal and other computer devices; the above-mentioned server may be a single server, a server cluster consisting of multiple servers, or a cloud server.

[0036] Combination Figure 1 As shown, the above-mentioned memory resource management method can be executed by an electronic device, which can be a terminal device or a server. The above-mentioned memory resource management method can be implemented by the terminal device or the server separately, or by the terminal device and the server together.

[0037] The above is only an example and is not specifically limited in this embodiment.

[0038] Optionally, as an optional implementation, as Figure 2 As shown, the above memory resource management method includes:

[0039] S202, in response to the target process being started, initializing a target interface of the target process, wherein the target process is deployed on a server, and the target interface is used to update the number of references of a memory resource from the server;

[0040] Optionally, in an embodiment of the present application, the target process may be initiated by a server, and the target interface may include but is not limited to device input / output interfaces of various operating systems. For example, in a Unix / Linux operating system, the target interface may be an "input / output control", referred to as an ioctl interface.

[0041] Exemplarily, a user can deploy a server and a client on a terminal device. Both can be deployed on the same terminal device or on different terminal devices. For example, a user can deploy both a server application and a client application on his or her personal computer, or deploy a client application on a personal computer while deploying the server application on a remote server.

[0042] In an exemplary embodiment, taking the server and client of an application deployed on the same terminal device as an example, the above-mentioned target process can be the client process. Then, the target process executes the service by calling the SDK interface. The SDK is used to program and generate applications. The SDK interface sends the service request to the server internally. The server parses the request content and sends the corresponding service requested by the client to each service for execution.

[0043] Specifically, Figure 3 is a schematic diagram of an optional memory resource management method according to an embodiment of the present application. Assume that the technical architecture designed in the embodiment of the present application is as follows Figure 3 As shown, it includes the reference counting information record of the application state adaptation layer and the kernel state:

[0044] S1, kernel state: provides an independent reference counting driver, which records the number of references to all memory resource addresses and the number of resource references by each process;

[0045] S2, application state: The client and the server complete the implementation of the adaptation layer respectively. Both ends call the ioctl interface (the above-mentioned target interface) through their respective adaptation layers to enable the kernel's reference counting driver to complete the addition of physical addresses that need to be supervised, increase / decrease the number of references corresponding to the physical addresses, and save the physical addresses with reference counts of 0.

[0046] Furthermore, the target interface can be used to determine the number of references to memory resources that need to be updated, ensuring that when both the client and the server have used up all the memory resources, the reference count can be correctly reduced to avoid problems such as memory leaks.

[0047] S204, in response to receiving a first message sent by a first process, increasing a target reference count by a preset value through a target interface, wherein the first process is deployed on a client, the client and the server are configured to use the same memory space, the target reference count indicates the number of times the target memory resource is referenced, and the first message is used to indicate that the target memory resource needs to be used;

[0048] Optionally, in an embodiment of the present application, the above-mentioned first process can be understood as any process or application on the client, for example, it can be a user application, an operating system process, or any software module running on the client that needs to access shared memory resources. The above-mentioned first message refers to a signal or request sent by the first process to indicate that it needs to access or use the target memory resources on the server. The first message can be sent through a certain communication protocol or interface, such as through a remote procedure call (RPC), a shared memory interface, or a network socket, etc. The above-mentioned target reference count refers to the number of times the target memory resource is referenced or accessed by the client or other server processes. Based on the target reference count, it can be determined in time when the resources need to be released, or how to schedule when there is resource competition. The above-mentioned preset value can be flexibly set manually, and the present application does not impose any restrictions on this.

[0049] Exemplarily, when the first message is received, the target reference count at the target interface is increased by the value to reflect the increase in references or usage of the target memory resource. The preset value can be 1 or other values, depending on the needs of the system designer. For example, if more precise tracking of resource usage is required, a preset value of 1 can be selected; if the frequency of counting operations needs to be reduced, a larger preset value may be selected.

[0050] In an exemplary embodiment, the client needs to access the same memory resource deployed on the server. When a process (first process) on the client sends a request (first message) to access this resource, the target interface on the server will receive the request and increase the target reference count by a preset value (for example, 1) to accurately track the total number of times the resource is referenced.

[0051] S206, in response to receiving the second message, reducing the target reference count by a preset value through the target interface, wherein the second message is used to indicate that the target memory resource has been used up;

[0052] Optionally, in an embodiment of the present application, the above-mentioned second message refers to a signal or request sent by the first process and other processes that can communicate with the first process, which is used to indicate that the target memory resources have been used up and the number of target references can be reduced by a preset value. The first message can be sent through a certain communication protocol or interface, such as through a remote procedure call (RPC), a shared memory interface, or a network socket.

[0053] Exemplarily, when a process on the server side in the application state no longer needs to use the target memory resources, a second message (for example, a signal to release or abandon memory) is sent to the memory management module in the memory state through the target interface. The second message may include but is not limited to an identifier of the target memory resource and a command to reduce the number of references.

[0054] Then, after receiving the second message, the memory management module will find the target memory resource corresponding to the identifier, and then reduce the reference count of the resource by a preset value, which can be set to 1 because each program or process that no longer needs the resource will send a message to reduce the reference count once.

[0055] S208, when the target reference count meets a preset condition, releasing the target memory resource.

[0056] Exemplarily, when the target reference count is reduced to zero (or reaches a certain threshold, such as when the target reference count is -1, the target memory resource can be released), the memory management module will release the resource from the available memory pool so that other programs or processes can use it again.

[0057] In an exemplary embodiment, the embodiment of the present application can be applied to a multi-process memory resource reuse management business scenario. Specifically, Figure 4 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application, such as Figure 4 As shown, assuming that the target reference count of DATA_A is initially 0, including but not limited to:

[0058] S402, the client sends a first message to the server to obtain the memory DATA_A (the above-mentioned target memory resource) storing business data from the server;

[0059] S404, after receiving the request, the server first collects data. After the collection is completed, the target reference count of DATA_A is increased by 1 (preset value), and then DATA_A is returned to the client. At this time, the target reference count is 1;

[0060] S404, after the client obtains DATA_A, the target reference count of DATA_A data is increased by 1, and the target reference count is now 2 (corresponding to Figure 3 Step 1 shown);

[0061] S406, the client obtains and parses the service B execution request initiated by the server (corresponding to Figure 3 In step 2 shown in FIG. 1 , it is determined that DATA_A needs to be used. Therefore, before asynchronously executing service B, the reference count of DATA_A is increased by 1. At this time, the target reference count is 3 (corresponding to Figure 3 step2-1) shown;

[0062] S408, in response to the completion of the execution of service B, the server reduces the target reference count of DATA_A by 1. At this time, the target reference count is 1 (corresponding to Figure 3 step2-2 shown);

[0063] S410, the client sends a second message to the server, indicating that the service B is successfully executed, and requests to reduce the target reference count of the DATA_A data by 1. At this time, the target reference count is 2;

[0064] S412, the client determines that the execution of service B is completed and DATA_A is no longer needed, and the target reference count of DATA_A is reduced by 1 again. At this time, the target reference count is 0 (corresponding to Figure 3 Step 3 shown);

[0065] Furthermore, the reference count management module thread loop checks the memory address whose target reference count is 0. At this time, the target reference count of DATA_A is 0, and the target interface corresponding to DATA_A is called to complete the memory release.

[0066] Through the embodiment of the present application, in response to the start of the target process, the target interface of the target process is initialized, wherein the target process is deployed on the server side, and the target interface is used to update the number of references of the memory resource from the server side; in response to receiving the first message sent by the first process, the target reference number is increased by a preset value through the target interface, wherein the first process is deployed on the client, the client and the server are set to use the same memory space, the target reference number indicates the number of times the target memory resource is referenced, and the first message is used to indicate that the target memory resource needs to be used; in response to receiving the second message, the target reference number is reduced by a preset value through the target interface, wherein the second message is used to indicate that the target memory resource has been used up; when the target reference number meets the preset condition, the target memory resource is released, and the process's use of the target memory resource is determined in real time through the target reference number, ensuring that the memory resource can be safely and reliably accessed and released between processes, and through accurate reference counting, unnecessary resource retention or early release is avoided, thereby achieving the technical effect of improving the utilization rate and management efficiency of memory resources, and further solving the technical problem of low management efficiency of memory resources.

[0067] As an optional scheme, in response to receiving the first message sent by the first process, the target reference count is increased by a preset value through the target interface, including: in response to receiving the first message, collecting the target memory resources from the memory space; increasing the target reference count by a preset value through the target interface, and sending the target memory resources to the first process.

[0068] Optionally, in an embodiment of the present application, the above-mentioned memory space may include but is not limited to a shared memory pool, etc., and may include but is not limited to being used to store the above-mentioned target memory resources, etc.

[0069] In an exemplary embodiment, for example, when a first process requests access to a specific target memory resource, the system checks whether the target memory resource exists in the shared memory pool. If so, the system increases the reference count of the target memory resource through a specific target interface (for example, the ioctl interface in a Unix system) to ensure that the target memory resource is not accidentally released when shared among multiple processes, and sends the target memory resource to the first process for use, thereby effectively reducing duplicate loading of resources and improving the system's resource utilization efficiency and communication speed between processes.

[0070] Through the embodiments of the present application, an efficient and secure memory resource sharing mechanism is implemented.

[0071] As an optional scheme, the above-mentioned response to receiving the first message sent by the first process, increasing the target reference count by the preset value through the above-mentioned target interface, includes at least one of the following: when the above-mentioned first message indicates that the above-mentioned first process requests to obtain the above-mentioned target memory resources, increasing the above-mentioned target reference count by the above-mentioned preset value through the above-mentioned target interface; when the above-mentioned first message indicates that the above-mentioned first process requests to execute the target business based on the above-mentioned target memory resources, asynchronously implementing the execution of the above-mentioned target business through the above-mentioned target process and increasing the above-mentioned target reference count by the above-mentioned preset value through the above-mentioned target interface, wherein when the above-mentioned first process requests to execute the above-mentioned target business based on the above-mentioned target memory resources, the above-mentioned first process increases the above-mentioned target reference count by the above-mentioned preset value through the first interface, and the above-mentioned first interface is used to update the reference count of memory resources from the client deployed by the above-mentioned first process.

[0072] Optionally, in an embodiment of the present application, the above-mentioned target business may include but is not limited to data addition, deletion, query and modification, and the above-mentioned target business, updating of reference counts and acquisition of target memory resources may all be executed asynchronously, and the present application does not impose any limitation on this.

[0073] In an exemplary embodiment, if the first message indicates that the first process requests to obtain the target memory resources, the target reference count can be increased directly through the target interface to ensure the accuracy of the resource usage status. In other words, before executing the target business, the target reference count is increased by a preset value based on the target resource usage request, thereby avoiding resource conflicts and data inconsistency problems.

[0074] In another exemplary embodiment, the first process may request to execute the target business based on the target memory resources. In order to improve the response speed and efficiency of the system, these two operations may be performed asynchronously, that is, the business execution and the update of the reference count may be performed in parallel without blocking each other.

[0075] Through the embodiments of the present application, in the above two different application scenarios, the number of target references can be increased according to the actual calling situation of the target memory resources. By reasonably designing the interface and message processing flow, problems such as resource contention, deadlock and data competition can be effectively avoided, thereby improving the management performance and stability of memory resources.

[0076] As an optional scheme, in response to receiving the second message, reducing the target reference count by the preset value through the target interface, including: when the second message indicates that the first process requests to release the target memory resources, reducing the target reference count by the preset value through the target interface, wherein when the first process requests to release the target memory resources, the first process reduces the target reference count by the preset value through the first interface; when the second message indicates that the target business execution is completed, reducing the target reference count by the preset value through the target interface.

[0077] In an exemplary embodiment, assume that the target memory resource is shared by processes A, B, and C, and they are all using this resource. At this time, the target reference count may be 3 (each process holds a reference). When process A completes the use of the target memory resource, it will send a request (equivalent to the second message) to the operating system, indicating that it wants to release the resource. After receiving the release request from process A, the operating system will check the target reference count. If the target reference count is 3 at this time, after confirming the request of process A, the operating system will reduce the target reference count by a preset value of 1 through the target interface (the interface here can be understood as a certain mechanism or function within the operating system), indicating that process A no longer uses this resource.

[0078] Furthermore, the target reference count decreases to 2, indicating that processes B and C are still using this resource. If process B subsequently requests to release this resource, the reference count will decrease by 1 again to 1, indicating that only process C is now using this resource. Once processes A, B, and C have all released their use of the target memory resources, the target reference count will decrease to 0, indicating that the operating system can safely reclaim or reallocate the target memory resources.

[0079] It should be noted that, in an embodiment of the present application, the above-mentioned second message may include but is not limited to being used to indicate that the execution of the target business is completed and the target reference count needs to be reduced, and may also be used to indicate the release of target memory resources. Correspondingly, the target reference count is 0 at this time. In other words, in an embodiment of the present application, even if the client initiates a second message, indicating that the execution of the target business is completed, the target reference count can be subtracted from the preset value. However, the target reference count is not necessarily 0 at this time. Then, the client may initiate a second message to the server again, and the server parses the second message. At this time, the second message no longer indicates that the execution of the target business is completed, but requests the release of the target memory resources.

[0080] Based on this, an efficient and flexible resource management mechanism is implemented. Specifically, this mechanism allows the client to notify the server to reduce the number of target references after the business execution is completed, so as to release the resources that are no longer needed in time and avoid resource waste. In addition, it also supports the client to directly request the release of target memory resources under specific circumstances, even if the target reference count is not 0, which further enhances the flexibility and response speed of resource management and ensures the optimization of system performance and resource utilization.

[0081] Through the embodiments of the present application, in the above two different application scenarios, the number of target references can be reduced according to the actual calling situation of the target memory resources, ensuring that when all processes that reference the memory resources have completed their use and request release, the memory resources can be correctly recycled, avoiding memory leaks or improper release of resources, thereby improving the resource management efficiency and reliability of the system.

[0082] As an optional solution, the above-mentioned target memory resource is released when the above-mentioned target reference count meets the preset conditions, including: periodically querying the reference count corresponding to each memory resource in the above-mentioned memory space through a thread; determining the memory resources whose reference counts meet the above-mentioned preset conditions as memory resources to be released, and releasing the above-mentioned memory resources to be released by calling a preset callback function.

[0083] Optionally, in an embodiment of the present application, the cycle of querying the number of references corresponding to each memory resource in the above-mentioned memory space through the thread can be flexibly set, and the present application does not limit this. The above-mentioned memory resources to be released can be understood as memory resources whose reference counts meet preset conditions, for example, the reference count is 0 or the reference count is less than or equal to a preset value, etc. The above-mentioned preset callback function refers to a pre-defined function for processing the memory resources to be released. The preset callback function can perform operations related to releasing memory, including but not limited to removing the memory resource from the memory space, returning it to the operating system, or performing other tasks related to resource management, etc.

[0084] For example, in C++, the preset callback function can be defined as a function pointer or use a smart pointer (such as the reset method of std::shared_ptr) to automatically manage memory. When the reference count reaches 0, the smart pointer will automatically call the function to release the memory. In Java, similar concepts can be implemented through the finalize method or garbage collection mechanism.

[0085] In an exemplary embodiment, when a target memory resource is created, its reference counter is initialized to 1, and each time the target memory resource is referenced by another part of the program, the reference counter increases. Similarly, when a reference no longer uses the target memory resource, the reference counter decreases, and a condition is preset in the operating system, such as "when the reference counter is 0, the resource can be released."

[0086] Furthermore, the periodic thread query in the embodiments of the present application may include but is not limited to: the operating system sets a background thread, for example, once every 5 minutes, to check the reference counters of all memory resources. The thread will traverse the entire memory space to check the status of each memory resource. During the query process, the thread reads the reference counter of each memory resource in turn. For example, there are three memory resources A, B, and C, and their reference counters are 3, 0, and 2, respectively. When the thread finds that the reference counter of resource B is 0, it means that resource B is not currently referenced by any part of the program, and the preset release condition is met. Then, the thread will call the preset callback function to release resource B.

[0087] Through the embodiments of the present application, it is possible to dynamically track and manage the usage of memory resources, and release memory resources that are no longer needed when appropriate, thereby achieving the technical effect of avoiding memory leaks while maintaining efficient and stable operation of the operating system.

[0088] As an optional solution, after increasing the target reference count by a preset value through the target interface in response to receiving the first message sent by the first process, the method further includes:

[0089] In response to receiving a third message sent by the first process, the target reference count is reduced by the preset value through the target interface, wherein the third message is used to indicate that an exception exists in the first process. When the first process requests to execute the target business based on the target memory resource, the first process increases the target reference count by the preset value through the first interface. When an exception exists in the first process, the first process clears the reference sub-count to zero through the first interface. The target reference count includes the reference sub-count, which indicates the number of times the target memory resource is referenced by the first process. The first interface is used to update the reference count of the memory resource from the client deployed by the first process.

[0090] Optionally, in an embodiment of the present application, the above-mentioned first message, second message, and third message may be displayed including but not limited to text, voice, video, image, etc. The above-mentioned third message refers to an abnormality in the first process on the client. At this time, the first process is using the target memory resources, which will cause memory leaks and other problems.

[0091] Furthermore, in order to prevent the above-mentioned memory leakage and other problems, the embodiment of the present application proposes to clear the reference sub-count (the number of times the first process references the target memory resource) to zero, indicating that the target memory is no longer used or referenced by the first process. Thus, the operating system will determine whether the target memory resource can be used by other processes based on the reduced reference count. If the reference count is 0, it means that the target memory resource is available and can be referenced by other processes, thereby achieving the technical effect of effectively avoiding memory leaks and improving memory utilization.

[0092] Exemplarily, the abnormality of the above-mentioned first process may include but is not limited to memory access errors: such as access to illegal addresses and segmentation faults, which are usually caused by the program trying to access a memory area that it does not have permission to access; I / O errors: when performing file operations, network communications or other input and output operations, if the file does not exist, insufficient permissions, device failure, etc., I / O abnormalities may occur; system call failure: if system calls such as opening files, creating processes, loading libraries, etc. fail for various reasons, process abnormalities may also occur; signal processing: if the signals sent to the process by the operating system are not handled properly, process abnormalities may also occur, such as SIGSEGV, SIGFPE, etc.; resource exhaustion: if the process consumes too much CPU time, memory, open file descriptors, etc., resulting in system resource exhaustion, process abnormalities may also occur; configuration errors: such as network configuration, system configuration, environment variables, etc.

[0093] In an exemplary embodiment, Figure 5 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application, such as Figure 5 As shown, after the client obtains data DATA_A, before sending a request to execute business B (target business) to the server, it needs to add 1 to the target reference count of DATA_A. After the target reference count is added, the client exits abnormally (corresponding to the first process exception mentioned above). In this scenario, the server first detects that the client connection is disconnected, and will reduce the reference count of the corresponding resource DATA_A by 1; because when the client initializes the reference management module, it first obtains the file descriptor of the reference count management driver through the open function. After the client exits abnormally, the Linux kernel will call the driver's release callback function, and the driver obtains the current abnormal exit process ID, and obtains the reference count of DATA_A through the process ID. Finally, the total target reference count corresponding to DATA_A is subtracted from the number of references by the client process (the above-mentioned sub-reference count), that is, the number is subtracted by 1, and the server thread loop checks that the reference count of this resource is 0, triggering the resource release callback function.

[0094] As an optional scheme, after increasing the target reference count by the preset value through the target interface in response to receiving the first message sent by the first process, the method further includes: reducing the target reference count by the preset value through the target interface in response to receiving the fourth message sent by the first process, wherein the fourth message is used to indicate that the first process has sent the physical address corresponding to the target memory resource to the second process, and there is an abnormality in the first process, and when the second process requests to execute the target business based on the target memory resource, the second process increases the target reference count by the preset value through the second interface; when the second process requests to release the target memory resource, the second process reduces the target reference count by the preset value through the second interface, and the second interface is used to update the reference count of the memory resource from the client deployed by the second process.

[0095] Optionally, in an embodiment of the present application, the fourth message may include but is not limited to being displayed in text, voice, video, image, etc. The fourth message refers to the situation where the first process has sent the physical address corresponding to the target memory resource to the second process, and an exception has occurred in the first process. The second process is different from the first process. The second process is used to request to execute the target business based on the target memory resources, and the first process is used to request to obtain the target memory resources.

[0096] In an exemplary embodiment, Figure 6 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application, such as Figure 6 As shown:

[0097] S1, after the P_B process (first process) obtains the memory resource DATA_A, the server adds monitoring of the number of references to DATA_A, the total number of references is 1, and the P_B process then sends the physical address corresponding to the data to the P_A process (second process);

[0098] S2, after the P_A process receives the physical address, it needs to use the SDK interface to complete the memory mapping operation. After the memory mapping, the reference count of DATA_A will be increased by 1, and the number of references will become 2;

[0099] S3, if P_B ​​exits abnormally at this time, after the server receives the exception, the reference count of DATA_A decreases by 1, and the number of references becomes 1;

[0100] S4, after the P_A process finishes using DATA_A, it demaps it, and the reference count of DATA_A decreases by 1, and the total number of references becomes 0. After the server thread finds that the number of references to DATA_A is 0, it calls the corresponding release interface.

[0101] It should be noted that the demapping here refers to the P_A process releasing the access to the shared memory segment DATA_A through the interface provided by the SDK or system call (such as munmap(), etc., and the implementation function is different in different operating systems), so that DATA_A becomes invisible in the address space of the P_A process, and at the same time notifies the server (or system) that its reference to DATA_A is no longer needed, thereby allowing the server thread to query and determine whether DATA_A can be safely released. In addition, after demapping, the physical memory of DATA_A will not be reclaimed by the operating system immediately. After all processes have unmapped the memory segment and no other process or service holds a reference to the memory segment, that is, after the last reference is released, the server can safely call the release interface to truly return the DATA_A physical memory to the operating system for use by other applications, ensuring the consistency and security of shared data between processes.

[0102] Through the embodiments of the present application, memory leaks can be effectively avoided, memory utilization can be improved, and the technical effect of improving the correct release and reuse rate of memory in a multi-process or multi-threaded environment can be achieved.

[0103] In an exemplary embodiment, the memory resource management method proposed in the present application can be applied to a multi-process memory resource reuse management business scenario. Specifically, in the related technology, Figure 7 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application, such as Figure 7 As shown, the terminal device allows users to install their own applications (APP). Users can write their own APP based on the user software development kit (SDK) provided by the operating system (OS) developer. After installing the APP on the terminal device, they can send business requests to the service process through the SDK to complete the execution of related business.

[0104] Specifically, Figure 8 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application, wherein the client and server memory resource business interaction is as follows Figure 8 As shown, the terminal device has a client and a server. The client process executes the business by calling the SDK interface. The SDK interface sends the business request to the Service management module internally. The Service management module sends the business to each service for execution according to the specific request content. Therefore, in the embodiment of the present application, a unified reference counting module is introduced to perform reference counting on the memory that needs to be monitored. The memory data will be released only when all users release the reference to the memory to ensure that the business of the client and the server can be executed normally.

[0105] Exemplarily, in the embodiment of the present application, a reference counting management solution architecture can be designed, which is divided into two parts, namely, the application state adaptation layer and the kernel state reference counting information recording: (1) Kernel state: provide an independent reference counting driver, which records the number of references of all memory resource addresses and the number of times each process references the resource; Application state (2): the client and the server respectively complete the implementation of the adaptation layer, and both ends call the ioctl interface (input and output control interface) through their respective adaptation layers to enable the kernel reference counting driver to complete the addition of physical addresses that need to be supervised, increase / decrease the number of references corresponding to the physical address, and save the physical address with a reference count of 0;

[0106] On the one hand, in the embodiments of the present application, Fig.11 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application, such as Fig.11 As shown, the referenced counting management module design scheme may include but is not limited to setting up the client and server in the application state, both ends implementing the adaptation layer with the kernel reference counting management module, and completing the reference counting statistics of the memory address and the number of references between each process in the kernel state.

[0107] S1, in the client adaptation layer of the application state, the adaptation layer mainly supports reference count increase and decrease:

[0108] S1-1, reference count increase: through the ioctl interface, the kernel reference count management driver module increases the reference count of the corresponding memory resource by 1;

[0109] S1-2, reference count reduction: through the ioctl interface, the kernel reference count management driver module reduces the reference count of the corresponding memory resource by 1;

[0110] S2, the server-side adaptation layer in the application state needs to support the increase and decrease of reference counts, add memory resources that need to be monitored, and start the memory resources that should be released when the thread loop is started:

[0111] S2-1, start the thread loop to release the memory resources: when initializing the application state server reference count management adaptation layer, start the thread loop to obtain the resource memory address of the reference count management module as 0 and the corresponding resource release callback function pointer from the kernel through the ioctl interface, and then call the corresponding resource release callback function;

[0112] S2-2, add memory resources that need to be monitored: the resource producer adds the provided memory resources to the reference counting management module to complete resource usage detection. The producer needs to provide the memory address and release function pointer corresponding to the required resources. The adaptation layer adds these two pieces of information to the kernel driver through the ioctl interface;

[0113] S2-3, increase the reference count: through the ioctl interface, the kernel reference count management driver module increases the reference count of the corresponding memory resource by 1;

[0114] S2-4, reduce the reference count: through the ioctl interface, the kernel reference count management driver module reduces the reference count of the corresponding memory resource by 1.

[0115] On the other hand, in the embodiment of the present application, the referenced counting management module design scheme may include but is not limited to supporting the application state to complete the addition of resources to be monitored through the ioctl interface in the kernel state, the increase and decrease of resource reference counts, and support for obtaining resource addresses with reference counts of 0, including but not limited to:

[0116] S1, add resources to be monitored: record the address information to be monitored, initialize the number of references to 1, then record the current process PID and initialize the number of times the current process references the resource to 1;

[0117] S2, increase the reference count: first check whether the address exists. If not, return with an error. If it exists, add 1 to the reference count and add 1 to the number of times the current process references the resource.

[0118] S3, reference count reduction: first check whether the address exists. If it does not exist, an error is directly returned. If it exists, the reference count is reduced by 1, and the number of times the current process references the resource is increased by 1. If the number of times the current process references the resource is 0, the recorded process information is directly deleted;

[0119] S4, obtain the resource with a reference count of 0: loop through all resource addresses corresponding to the reference count, if the count is 0, return and delete the resource;

[0120] In addition, the resource information structure recorded in the kernel state includes the reference counts of each memory resource address and the number of references of each memory resource in each process, which may include but is not limited to those shown in Table 1:

[0121] Table 1

[0122]

[0123] In an exemplary embodiment, Fig. 9 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application, such as Fig. 9As shown, in the related technology, the service process has a service management module and various service modules, which can provide the client with services for obtaining memory resources, or the client uses the acquired memory resources to perform other services, such as using YUV data resources to perform encoding services. For the latter, the application process first obtains data from the server through the SDK, and then returns the data to the server, which then uses the data to complete the corresponding business. However, during the service process using data, the application process sends a request to release resources. Therefore, if the server directly releases resources, it will inevitably affect the service process business processing, which may cause the service process to exit abnormally. The specific operations of the related technical solution include:

[0124] S1, the client application process wants to obtain data A through the SDK interface. After receiving the service request, service S_A executes service 1, completes the collection of data A, and returns the physical address of data A. After receiving data A, SDK maps the physical address corresponding to data A and provides it to the client application process to execute its own service;

[0125] S2, the client application process wants to use data A to execute service 2 through the SDK interface. After receiving the service request, service S_B needs to execute service 2 asynchronously because service 2 takes a long time to execute.

[0126] S3, after the client completes sending, it hopes that service S_A will release data A through the SDK interface. However, service S_B is currently using data A to execute business 2. If it is released directly, the service process will crash abnormally.

[0127] Therefore, in order to avoid the problem that the client and server processes use the same memory space, when the server uses a certain memory, the client suddenly releases it or exits abnormally, resulting in early recycling of resources, causing abnormalities in the service process, the embodiment of the present application combines actual business scenarios (business scenarios where the client obtains memory from the server and releases it immediately after use), and can solve the above problem by deploying a counting management driver, the specific contents include but are not limited to:

[0128] S1, the client obtains the memory DATA_A storing business data from the server. After receiving the request, the server first collects data. After the collection is completed, the reference count of DATA_A is increased by 1, and then DATA_A is returned to the client;

[0129] S2: After the client obtains DATA_A, it requests the server to execute service B based on DATA_A. Before the client sends the request, it first increases the reference count of DATA_A by 1, then sends the request to the server, and after the request is completed, it decreases the reference count of DATA_A by 1.

[0130] S3: After receiving the request to execute service B, the server executes service B asynchronously because service B takes a long time to execute. Before executing service B asynchronously, the reference count of DATA_A is increased by 1. After service B is executed, the reference count of DATA_A is decreased by 1.

[0131] S4: After the client has finished using DATA_A, it calls the interface to release DATA_A. After receiving the request, the server reduces the reference count of DATA_A by 1.

[0132] S5, the reference count management module thread loop checks the memory address with a reference count of 0. At this time, the reference count of DATA_A is 0, and the release interface corresponding to DATA_A is called to complete the memory release.

[0133] In yet another exemplary embodiment, Fig.10 is a schematic diagram of another optional memory resource management method according to an embodiment of the present application, such as Fig.10 As shown, in the related technology, in the scenario of high concurrent client requests, the server cannot effectively guarantee the security of memory resources. The reason is that after the client request is sent to the server, it will be sent to each service processing in the thread pool in sequence. However, when there are many concurrent requests, the server will assign the business request to different threads in the thread pool to complete the business execution, resulting in the inability to guarantee that the requests of the same client are executed in sequence. Specifically, when the application process calls the SDK interface, the business interface of using the memory storing data_A and releasing the memory storing data_A is executed sequentially. The SDK will send requests to the server sequentially. At this time, since the thread pool of the service management module cannot guarantee that these two businesses can be executed sequentially, if a business request for executing and releasing the memory storing data_A in advance is provided, the release will cause the business request using data_A to be abnormal, and will also cause the service process to be abnormal.

[0134] Therefore, considering that in actual usage scenarios, the stability of the client development stage is poor and there may be abnormal exit scenarios, if the client abnormally exits after adding 1 to the reference count of a memory address, the reference count management driver module needs to clear the number of references to the process and subtract the number of references to the process from the total number of references, resulting in inaccurate reference counts in memory management, which may cause memory leaks or incorrect memory release problems. Therefore, the embodiment of the present application also provides a resource recovery mechanism in the scenario of abnormal process exit, including but not limited to:

[0135] After the client obtains data DATA_A, it needs to add 1 to the reference count of DATA_A before sending a request to execute business B to the server. After the reference count is added to 1, the client exits abnormally. In this scenario, the server first detects that the client connection is disconnected, and will reduce the reference count of the corresponding resource DATA_A by 1; because when the client initializes the reference management module, it first obtains the file descriptor of the reference count management driver through the open function. After the client exits abnormally, the Linux kernel will call the driver's release callback function, and the driver obtains the process ID of the current abnormal exit, and obtains the reference count of DATA_A through the process ID. Finally, the total number of references corresponding to DATA_A is subtracted from the number of references by the client process, that is, the number is subtracted by 1. When the server thread loop checks that the reference count of this resource is 0, the resource release callback function is triggered.

[0136] In another exemplary embodiment, in the related technology, the resources requested by the client process are used for multiple processes. The exit of the process that requests memory resources will cause abnormalities in other processes that use this memory. For the client, the user can execute multiple business processes according to their own business needs. Each business process performs different functions. The communication between the two processes can also use the memory resources requested from the server. Specifically, the P_B process requests memory from the server through the SDK interface, and then maps this memory to the requested memory in the current process. After the mapping is completed, the business data is written to the memory, such as YUV data and Jpeg data; the P_B process sends the physical address to the P_A process through the socket, and P_A accesses the data in this memory; if the P_B process exits abnormally when the P_A process is accessing this memory, the memory requested by the P_B process cannot be recovered in time.

[0137] Therefore, considering that in an actual usage scenario, if there are two processes (P_A, P_B) on the client, P_B obtains memory resources, and P_A and P_B use this resource at the same time, if P_B ​​exits abnormally during use, it will cause abnormal use management of memory resources, resulting in unnecessary resource loss and abnormal business execution. Therefore, the embodiment of the present application also provides a client multi-process resource sharing mechanism, including but not limited to:

[0138] S1, after the P_B process obtains the memory resource DATA_A, the server adds monitoring of the number of references to DATA_A. The total number of references is 1, and the P_B process then sends the physical address corresponding to the data to the P_A process;

[0139] S2, after the P_A process receives the physical address, it needs to use the SDK interface to complete the memory mapping operation. After the memory mapping, the reference count of DATA_A will be increased by 1, and the number of references will become 2;

[0140] S3, if P_B ​​exits abnormally at this time, after the server receives the exception, the reference count of DATA_A decreases by 1, and the number of references becomes 1;

[0141] S4, after the P_A process finishes using DATA_A, it demaps it, and the reference count of DATA_A decreases by 1, and the total number of references becomes 0. After the server thread finds that the number of references to DATA_A is 0, it calls the corresponding release interface.

[0142] Through the embodiments of the present application, the problem that after the client obtains the memory resource for storing business data from the server, it releases the memory while other processes are still using it, resulting in abnormal business operation of other processes is effectively solved. Specifically, through a unified reference counting module, reference counting is performed for the memory to be monitored, and the memory data is released after all users' references are released, so as to ensure the normal execution of the business of the client and the server, including but not limited to the following implementation:

[0143] S1, implement reference counting management driver in kernel state, record the reference count of each resource and the reference count of each resource in each process in the driver, where the reference count of each resource by the process is recorded so that after the process exits abnormally, the driver's release function will subtract the total reference count of the resources used by the process from the reference count added in the process to avoid memory leaks.

[0144] S2, in order to ensure the real-time nature of resource references in multiple processes, the kernel records the number of references of each resource, and the driver supports adding resource memory addresses to be monitored in the application state, adding / subtracting 1 from the reference count of a certain resource, and supporting the query of all resources with reference records of 0.

[0145] S3, completes the reference counting operation related functions of the adapter driver in the application state, and at the same time, starts an independent thread loop to obtain resources with a reference count of 0, and then triggers the release function corresponding to the resource according to the callback function pointer passed in when the resource producer calls the add monitoring interface.

[0146] S4, when there are multiple processes on the client that reuse the same memory block provided by the server, when the process uses this memory for mapping, the reference count of this memory block is increased by 1, and the demapping operation then decreases the reference count of this memory block by 1.

[0147] It is understandable that in the specific implementation of this application, related data such as user information is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.

[0148] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0149] According to another aspect of the embodiments of the present application, a memory resource management device for implementing the above-mentioned memory resource management method is also provided. Fig.12 As shown, the device comprises:

[0150] A start module 1202 is used to initialize a target interface of the target process in response to the start of the target process, wherein the target process is deployed on the server side, and the target interface is used to update the reference count of the memory resource from the server side;

[0151] A first updating module 1204 is configured to increase the target reference count by a preset value through a target interface in response to receiving a first message sent by a first process, wherein the first process is deployed on a client, the client and the server are configured to use the same memory space, the target reference count indicates the number of times the target memory resource is referenced, and the first message is used to indicate that the target memory resource needs to be used;

[0152] A second updating module 1206 is configured to reduce the target reference count by a preset value through a target interface in response to receiving a second message, wherein the second message is used to indicate that the target memory resource has been used up;

[0153] The release module 1208 is used to release the target memory resource when the target reference count meets a preset condition.

[0154] As an optional solution, the above-mentioned device is used to increase the target reference count by a preset value through the target interface in response to receiving a first message sent by the first process in the following manner: in response to receiving the first message, collecting target memory resources from the memory space; increasing the target reference count by a preset value through the target interface, and sending the target memory resources to the first process.

[0155] As an optional solution, the above-mentioned device is used to respond to receiving a first message sent by a first process in the following manner, and increase the target reference count by a preset value through a target interface, including at least one of the following: when the first message indicates that the first process requests to obtain target memory resources, the target reference count is increased by a preset value through the target interface; when the first message indicates that the first process requests to execute a target business based on the target memory resources, asynchronously implements execution of the target business through the target process and increase of the target reference count by a preset value through the target interface, wherein when the first process requests to execute the target business based on the target memory resources, the first process increases the target reference count by a preset value through the first interface, and the first interface is used to update the reference count of the memory resource from the client deployed by the first process.

[0156] As an optional scheme, the above-mentioned device is used to respond to receiving the second message by reducing the target reference count by a preset value through the target interface in the following manner: when the second message indicates that the first process requests to release the target memory resources, the target reference count is reduced by a preset value through the target interface, wherein when the first process requests to release the target memory resources, the first process reduces the target reference count by a preset value through the first interface; when the second message indicates that the target business execution is completed, the target reference count is reduced by a preset value through the target interface.

[0157] As an optional solution, the above-mentioned device is used to release the target memory resource when the target reference count meets the preset conditions in the following manner: periodically query the reference count corresponding to each memory resource in the memory space through a thread; determine the memory resources whose reference counts meet the preset conditions as memory resources to be released, and release the memory resources to be released by calling a preset callback function.

[0158] As an optional solution, the above-mentioned device is also used to: in response to receiving a first message sent by the first process, after increasing the target reference count by a preset value through the target interface, in response to receiving a third message sent by the first process, reduce the target reference count by a preset value through the target interface, wherein the third message is used to indicate that there is an abnormality in the first process, when the first process requests to execute the target business based on the target memory resource, the first process increases the target reference count by a preset value through the first interface, when there is an abnormality in the first process, the first process clears the reference sub-count to zero through the first interface, the target reference count includes the reference sub-count, the reference sub-count indicates the number of times the target memory resource is referenced by the first process, and the first interface is used to update the reference count of the memory resource from the client deployed by the first process.

[0159] As an optional solution, the above-mentioned device is also used to: in response to receiving a first message sent by the first process, after increasing the target reference count by a preset value through the target interface, in response to receiving a fourth message sent by the first process, reduce the target reference count by a preset value through the target interface, wherein the fourth message is used to indicate that the first process has sent the physical address corresponding to the target memory resource to the second process, and there is an exception in the first process, when the second process requests to execute the target business based on the target memory resource, the second process increases the target reference count by a preset value through the second interface; when the second process requests to release the target memory resource, the second process reduces the target reference count by a preset value through the second interface, and the second interface is used to update the reference count of the memory resource from the client deployed by the second process.

[0160] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.

[0161] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0162] According to one aspect of the present application, a computer program product is provided. The computer program product includes a computer program.

[0163] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0164] Fig.13 The structure block diagram of a computer system for implementing an electronic device according to an embodiment of the present application is schematically shown.

[0165] It should be noted that Fig.13 The computer system 1300 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0166] like Fig.13As shown, the computer system 1300 includes a central processing unit 1301 (CPU), which can perform various appropriate actions and processes according to the program stored in the read-only memory 1302 (ROM) or the program loaded from the storage part 1308 to the random access memory 1303 (RAM). Various programs and data required for system operation are also stored in the random access memory 1303. The central processing unit 1301, the read-only memory 1302 and the random access memory 1303 are connected to each other through a bus 1304. The input / output interface 1305 (Input / Output interface, i.e., I / O interface) is also connected to the bus 1304.

[0167] The following components are connected to the input / output interface 1305: an input section 1306 including a keyboard, a mouse, etc.; an output section 1307 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1308 including a hard disk, etc.; and a communication section 1309 including a network interface card such as a LAN card, a modem, etc. The communication section 1309 performs communication processing via a network such as the Internet. A drive 1310 is also connected to the input / output interface 1305 as needed. A removable medium 1311, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1310 as needed so that a computer program read therefrom is installed into the storage section 1308 as needed.

[0168] In particular, according to an embodiment of the present application, the process described in each method flow chart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer readable medium, and the computer program contains a program code for executing the method shown in the flow chart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1309, and / or installed from the removable medium 1311. When the computer program is executed by the central processor 1301, various functions defined in the system of the present application are executed.

[0169] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1309, and / or installed from the removable medium 1311. When the computer program is executed by the central processor 1301, various functions provided by the embodiments of the present application are performed.

[0170] According to another aspect of the embodiment of the present application, an electronic device for implementing the above-mentioned memory resource management method is also provided. The electronic device may be Figure 1 The terminal device or server shown in the figure. This embodiment is described by taking the electronic device as a terminal device as an example. Fig.14 As shown, the electronic device includes a memory 1402 and a processor 1404. The memory 1402 stores a computer program, and the processor 1404 is configured to execute the steps in any of the above method embodiments through the computer program.

[0171] Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices of a computer network.

[0172] Optionally, in this embodiment, the above-mentioned processor can be configured to execute the methods in each embodiment of the present application through a computer program.

[0173] Alternatively, a person skilled in the art may understand that: Fig.14 The structure shown is for illustration only. Fig.14 The structure of the electronic device is not limited. Fig.14 More or fewer components (such as network interfaces, etc.) as shown in, or with Fig.14 Different configurations are shown.

[0174] Among them, the memory 1402 can be used to store software programs and modules, such as the program instructions / modules corresponding to the memory resource management method and device in the embodiment of the present application. The processor 1404 executes various functional applications and data processing by running the software programs and modules stored in the memory 1402, that is, realizing the above-mentioned memory resource management method. The memory 1402 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 1402 may further include a memory remotely located relative to the processor 1404, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Among them, the memory 1402 can be specifically, but not limited to, used to store information such as target memory resources. As an example, such as Fig.14 As shown, the memory 1402 may include, but is not limited to, the startup module 1202, the first update module 1204, the second update module 1206, and the release module 1208 in the memory resource management device. In addition, other module units in the memory resource management device may also be included but are not limited to, which will not be repeated in this example.

[0175] Optionally, the transmission device 1406 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wired network and a wireless network. In one example, the transmission device 1406 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 1406 is a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0176] In addition, the electronic device further includes: a display 1408 for displaying the target memory resource; and a connection bus 1410 for connecting various module components in the electronic device.

[0177] In other embodiments, the terminal device or server may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting the multiple nodes through network communication. The nodes may form a peer-to-peer network, and any form of computing device, such as a server, terminal or other electronic device, may become a node in the blockchain system by joining the peer-to-peer network.

[0178] According to one aspect of the present application, a computer-readable storage medium is provided, and a processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device executes the memory resource management method provided in various optional implementation methods of the above-mentioned memory resource management.

[0179] Optionally, in this embodiment, the above-mentioned computer-readable storage medium can be configured to store data for executing the methods in various embodiments of the present application.

[0180] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0181] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0182] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for one or more electronic devices to execute all or part of the steps of the methods described in each embodiment of the present application.

[0183] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0184] In the several embodiments provided in the present application, it should be understood that the disclosed application can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0185] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0186] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0187] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for managing memory resources, characterized in that: include: In response to the target process being started, a target interface of the target process is initialized, wherein the target process is deployed on a server, and the target interface is used to update the number of references of a memory resource from the server; In response to receiving a first message sent by a first process, increasing a target reference count by a preset value through the target interface, wherein the first process is deployed on a client, the client and the server are configured to use the same memory space, the target reference count indicates the number of times a target memory resource is referenced, and the first message is used to indicate that the target memory resource needs to be used; In response to receiving a second message, reducing the target reference count by the preset value through the target interface, wherein the second message is used to indicate that the target memory resource has been used up; When the target reference count meets a preset condition, the target memory resource is released.

2. The method according to claim 1, characterized in that In response to receiving the first message sent by the first process, increasing the target reference count by a preset value through the target interface includes: In response to receiving the first message, collecting the target memory resource from the memory space; The target reference count is increased by a preset value through the target interface, and the target memory resource is sent to the first process.

3. The method according to claim 1, characterized in that In response to receiving the first message sent by the first process, increasing the target reference count by a preset value through the target interface includes at least one of the following: In a case where the first message indicates that the first process requests to obtain the target memory resource, increasing the target reference count by the preset value through the target interface; In a case where the first message indicates that the first process requests to execute the target business based on the target memory resources, the target business is executed through the target process and the target reference count is increased by the preset value through the target interface asynchronously, wherein when the first process requests to execute the target business based on the target memory resources, the first process increases the target reference count by the preset value through the first interface, and the first interface is used to update the reference count of the memory resource from the client deployed by the first process.

4. The method according to claim 3, characterized in that In response to receiving the second message, reducing the target reference count by the preset value through the target interface includes: In a case where the second message indicates that the first process requests to release the target memory resource, reducing the target reference count by the preset value through the target interface, wherein when the first process requests to release the target memory resource, the first process reduces the target reference count by the preset value through the first interface; When the second message indicates that the target service is executed successfully, the target reference count is reduced by the preset value through the target interface.

5. The method according to claim 1, characterized in that When the number of target references meets a preset condition, releasing the target memory resource comprises: Periodically querying the number of references corresponding to each memory resource in the memory space through a thread; The memory resource whose reference count meets the preset condition is determined as the memory resource to be released, and the memory resource to be released is released by calling a preset callback function.

6. The method according to claim 1, characterized in that After the target reference count is increased by a preset value through the target interface in response to receiving the first message sent by the first process, the method further includes: In response to receiving a third message sent by the first process, reducing the target reference count by the preset value through the target interface, wherein the third message is used to indicate that an exception exists in the first process, when the first process requests to execute the target business based on the target memory resource, the first process increases the target reference count by the preset value through the first interface, when an exception exists in the first process, the first process clears the reference sub-count to zero through the first interface, the target reference count includes the reference sub-count, and the reference sub-count indicates the number of times the target memory resource is referenced by the first process, and the first interface is used to update the reference count of the memory resource from the client deployed by the first process.

7. The method according to claim 1, characterized in that After the target reference count is increased by a preset value through the target interface in response to receiving the first message sent by the first process, the method further includes: In response to receiving a fourth message sent by the first process, reducing the target reference count by the preset value through the target interface, wherein the fourth message is used to indicate that the first process has sent the physical address corresponding to the target memory resource to the second process, and that an exception has occurred in the first process, and when the second process requests to execute the target business based on the target memory resource, the second process increases the target reference count by the preset value through the second interface; when the second process requests to release the target memory resource, the second process reduces the target reference count by the preset value through the second interface, and the second interface is used to update the reference count of the memory resource from the client deployed by the second process.

8. A memory resource management device, characterized in that: include: A startup module, configured to initialize a target interface of the target process in response to the target process being started, wherein the target process is deployed on a server, and the target interface is used to update the number of references of a memory resource from the server; A first updating module is configured to increase the target reference count by a preset value through the target interface in response to receiving a first message sent by a first process, wherein the first process is deployed on a client, the client and the server are configured to use the same memory space, the target reference count indicates the number of times a target memory resource is referenced, and the first message is used to indicate that the target memory resource needs to be used; A second updating module, configured to reduce the target reference count by the preset value through the target interface in response to receiving a second message, wherein the second message is used to indicate that the target memory resource has been used up; The release module is used to release the target memory resource when the target reference count meets a preset condition.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein the computer program can be executed by an electronic device to perform the method described in any one of claims 1 to 7.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 7 are implemented.

11. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.