Shared memory processing method and device and electronic equipment

By automatically releasing and restoring shared memory when the application state switches, the problem of excessive shared memory usage is solved, imperceptible memory management is achieved, and system performance and stability are improved.

CN120743528APending Publication Date: 2025-10-03VIVO MOBILE COMM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510868468.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-26
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

Shared memory occupies too high a proportion in electronic devices, resulting in high system memory pressure and affecting user experience.

Method used

The shared memory is released when the application switches from the foreground to the background, and is restored when the application switches back to the foreground. The virtual address association is released and established through the reverse mapping mechanism to ensure that the user is unaware.

Benefits of technology

It reduces physical memory pressure, reduces the overall system memory usage, improves system stability and performance, and avoids system freezes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120743528A_ABST
    Figure CN120743528A_ABST
Patent Text Reader

Abstract

The invention discloses a shared memory processing method and device and electronic equipment, and belongs to the technical field of shared memory processing. The method comprises the following steps: under the condition that a target application is switched from a foreground state to a background state, executing a release operation on a target shared memory corresponding to the target application; and under the condition that the target application is switched from the background state to the foreground state, executing a recovery operation on the target shared memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of shared memory processing technology, and specifically relates to a shared memory processing method, device and electronic device. Background Art

[0002] With the widespread adoption of electronic devices, the variety of applications is increasing, and their memory usage is also increasing. Currently, there are many solutions for reclaiming file pages and anonymous pages, and there are also solutions to support GPU memory reclamation. However, while shared memory can improve data access speed, with the increasing availability of electronic device hardware resources and performance requirements, shared memory has become a significant component of electronic device memory, placing significant memory pressure on the system.

[0003] Shared memory in the system kernel uses reference counting to determine whether it can be released. This means it's only released when no one is using it (the reference count reaches 0). However, users often leave applications in the background rather than killing them immediately. As applications accumulate, the shared memory used by these applications remains unreleased. This increases the proportion of shared memory in the system's resident memory, exacerbating memory pressure and causing system lag and frame drops, which in turn impacts the user experience. Summary of the Invention

[0004] The purpose of the embodiments of the present application is to provide a shared memory processing method, device and electronic device, which can solve the problem that the existing shared memory occupies a large proportion of the memory of the electronic device, resulting in a large memory pressure on the system.

[0005] In a first aspect, an embodiment of the present application provides a shared memory processing method, comprising:

[0006] When the target application switches from the foreground state to the background state, performing a release operation on the target shared memory corresponding to the target application;

[0007] When the target application switches from a background state to a foreground state, a recovery operation is performed on the target shared memory.

[0008] In a second aspect, an embodiment of the present application provides a shared memory processing device, comprising:

[0009] A release module, configured to release the target shared memory corresponding to the target application when the target application switches from a foreground state to a background state;

[0010] The recovery module is used to perform a recovery operation on the target shared memory when the target application switches from a background state to a foreground state.

[0011] In a third aspect, an embodiment of the present application provides an electronic device comprising a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the method described in the first aspect are implemented.

[0012] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0013] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface, the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the method described in the first aspect.

[0014] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the method described in the first aspect.

[0015] In an embodiment of the present application, when the target application switches from the foreground state to the background state, a release operation is performed on the target shared memory corresponding to the target application. After the target shared memory is released, the corresponding physical memory will also be released, thereby reducing the pressure on the physical memory and further reducing the overall memory pressure of the system. When the target application switches from the background state to the foreground state, a recovery operation is performed on the target shared memory, that is, when the target shared memory is needed, the use of the physical memory of the target shared memory is restored. The entire process automatically triggers the release operation or recovery operation of the target shared memory through the state that the target should be in the foreground and background, ensuring that the pressure on the physical memory is reduced while achieving user-unawareness. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 This is one of the flow charts of the shared memory processing method provided in the embodiment of the present application;

[0017] Figure 2 This is the second flow chart of the shared memory processing method provided in the embodiment of the present application;

[0018] Figure 3 This is the third flow chart of the shared memory processing method provided in the embodiment of the present application;

[0019] Figure 4 This is a fourth flow chart of the shared memory processing method provided in an embodiment of the present application;

[0020] Figure 5Schematic diagram of the structure of a shared memory processing device provided in an embodiment of the present application;

[0021] Figure 6 This is a structural block diagram of an electronic device provided in an embodiment of the present application;

[0022] Figure 7 This is a structural block diagram of another electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0023] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the embodiments described are 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 are within the scope of protection of this application.

[0024] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0025] The following describes the shared memory processing method provided by the embodiment of the present application through specific embodiments and application scenarios in conjunction with the accompanying drawings.

[0026] like Figure 1 As shown, the embodiment of the present application provides a shared memory processing method, which may specifically include the following steps:

[0027] Step 101 : When a target application switches from a foreground state to a background state, a release operation is performed on a target shared memory corresponding to the target application.

[0028] When the target application switches from the foreground state to the background state, it is equivalent to automatically triggering the release operation of the target shared memory, that is, performing the release operation on the target shared memory corresponding to the target application.

[0029] The target shared memory is the shared memory corresponding to the target application. Shared memory (DMA-BUF) is a core mechanism for efficiently sharing memory data. Its core function is to avoid data copies and directly allow different hardware (such as the Central Processing Unit (CPU), GPU, camera, etc.), upper-layer software, and the kernel to access the same physical memory.

[0030] Step 102 : When the target application switches from a background state to a foreground state, a recovery operation is performed on the target shared memory.

[0031] When the target application switches from the foreground state to the background state, it is equivalent to automatically triggering the recovery operation of the target shared memory, that is, performing the recovery operation on the target shared memory corresponding to the target application.

[0032] In an embodiment of the present application, when the target application switches from the foreground state to the background state, a release operation is performed on the target shared memory corresponding to the target application. After the target shared memory is released, the corresponding physical memory will also be released, thereby reducing the pressure on the physical memory and further reducing the overall memory pressure of the system. When the target application switches from the background state to the foreground state, a recovery operation is performed on the target shared memory, that is, when the target shared memory is needed, the use of the physical memory of the target shared memory is restored. The entire process automatically triggers the release operation or recovery operation of the target shared memory through the state that the target should be in the foreground and background, ensuring that the pressure on the physical memory is reduced while achieving user-unawareness.

[0033] In an optional specific embodiment, when the target application switches from a foreground state to a background state, step 101 of releasing the target shared memory corresponding to the target application includes:

[0034] When the target application switches from a foreground state to a background state, traversing virtual addresses corresponding to various users in the target shared memory by reverse mapping, and disassociating the virtual addresses corresponding to various users from the target shared memory; the users in the target shared memory include the target application and at least one of hardware and a kernel associated with the target application;

[0035] A release operation is performed on all physical memories corresponding to the target shared memory.

[0036] Each hardware, upper-layer software, and kernel needs to access the corresponding target shared memory through the corresponding virtual address. However, different modules accessing the target shared memory have different virtual addresses.

[0037] If the target application switches from the foreground state to the background state, the virtual addresses corresponding to all users in the target shared memory are traversed through reverse mapping, and the association between the virtual addresses corresponding to all users and the target shared memory is released. Without releasing any virtual address, the virtual address remains unchanged during subsequent recovery, achieving the unawareness of the upper-layer system.

[0038] Release all physical memory corresponding to the target shared memory and record the target application that uses the target shared memory to support the recovery of all released shared memory under the target application. This avoids the phenomenon of missing some shared memory when restoring all shared memory of the target application, which may cause application crash or system freeze.

[0039] Among them, reverse mapping refers to finding the virtual address referenced by the physical page to facilitate memory recovery.

[0040] Physical memory refers to the actual, directly accessible memory resources within an electronic device. Releasing all physical memory corresponding to the target shared memory frees up all physical memory resources associated with the target shared memory so that they can be reallocated or used for other purposes. This improves system resource utilization, avoids memory leaks, and enhances system stability and performance.

[0041] It should be noted that when using any upper-layer software or kernel, you first need to apply for the shared memory corresponding to the upper-layer software or kernel, and apply for the virtual address corresponding to the upper-layer software or kernel, establish an association between the virtual address and the shared memory, and save the virtual address to the corresponding shared memory.

[0042] Reverse mapping allows the virtual address corresponding to the shared memory of upper-layer software to be found. Furthermore, different kernels access the same shared memory through the same kernel virtual address. When establishing a relationship between the kernel and shared memory, the shared memory also records this virtual address in the corresponding shared memory management structure. Therefore, when accessing shared memory, all virtual addresses corresponding to that shared memory are available to upper-layer software and the kernel. However, the virtual addresses of shared memory accessed by hardware are known only to the hardware, and without a reverse mapping mechanism, it is impossible to retrieve all virtual addresses corresponding to the hardware from a specific shared memory.

[0043] To address the problem of being unable to fully obtain all hardware virtual addresses of a specific shared memory, this application proposes recording the virtual addresses of each hardware module in the shared memory on a module-by-module basis when establishing an association with the shared memory. When the association with the shared memory is disassociated, the previously recorded virtual addresses are removed from the shared memory, thereby forming a hardware-specific shared memory reverse mapping mechanism to locate all hardware-related virtual addresses from the target shared memory.

[0044] Therefore, the user in the target shared memory refers to a subject that can access the target shared memory, including the target application, and may also include hardware associated with the target application and / or a kernel associated with the target application.

[0045] like Figure 2 As shown, taking the target application as an example: when using the target application, you first need to apply for the target shared memory corresponding to the target application, apply for the target application to access the virtual address of the target shared memory, establish an association between the virtual address and the target shared memory, and save the target application's virtual address module to the target shared memory management structure. When you need to actually release the target shared memory, you first disconnect the association between the virtual address and the target shared memory, remove the virtual address from the target shared memory, release the virtual address, and delete the data in the target shared memory to achieve the actual release of the target shared memory.

[0046] For the hardware that the target application depends on (i.e., the hardware associated with the target application), when using the hardware, it is necessary to apply for the target shared memory corresponding to the hardware, apply for the hardware to access the virtual address of the target shared memory, establish an association between the virtual address and the target shared memory, and save the hardware's virtual address modules in the target shared memory management structure. For the kernel that the target application depends on (i.e., the kernel associated with the target application), when using the kernel, it is necessary to apply for the target shared memory corresponding to the kernel, apply for the kernel to access the virtual address of the target shared memory, establish an association between the virtual address and the target shared memory, and save the kernel's virtual address modules in the target shared memory management structure.

[0047] Among them, module-based storage means that the virtual addresses corresponding to different hardware, upper-layer software, and kernel are stored in different modules of the target shared memory respectively.

[0048] Virtual address refers to the connection between each virtual address and the physical address of the corresponding shared memory established by hardware, upper-level software and kernel, so that the corresponding physical memory can be directly accessed through the virtual address.

[0049] In the above embodiment, the user includes not only the target application, but also the hardware associated with the target application and at least one item in the kernel, that is, the target shared memory not only stores the virtual address corresponding to the target application, but also stores the virtual address corresponding to the hardware and / or kernel. The virtual address corresponding to the target application, the virtual address corresponding to the hardware, and the virtual address corresponding to the kernel can be quickly found through the target shared memory, thereby achieving efficient reverse mapping and improving the stability and reliability of the system.

[0050] In an optional specific embodiment, in step 101, when the target application switches from a foreground state to a background state, before performing a release operation on the target shared memory corresponding to the target application, the method further includes:

[0051] When the target application switches from the foreground state to the background state, the request to establish an association relationship with the target shared memory is intercepted, and the data in the target shared memory is stored in the disk as a file or in other physical memory as a compressed cache.

[0052] If the target application switches from the foreground to the background, in order to prevent other users from requesting to establish an association with the target shared memory during the recovery process, all requests to establish an association with the target shared memory must be intercepted from the start of the release to the completion of the recovery. Because the release may need to be restored after the release, the data in the target shared memory must be temporarily stored in the form of a file on disk or in other physical memory as a compressed cache. This allows for direct access to the data when the target shared memory is restored. Saving the data in a file or compressed format can also save memory space.

[0053] It's important to note that the above solution only releases the physical memory corresponding to the target shared memory; the management structure and virtual address of the actual target shared memory remain. To truly release the target shared memory, simply release the management structure and the associated virtual address of the target shared memory and delete the data stored in the target shared memory.

[0054] The release process of the target shared memory is described below through a specific embodiment:

[0055] like Figure 3 As shown, step 301: detecting the state of the target application.

[0056] Step 302: If it is detected that the target application switches from the foreground state to the background state, a request to establish an association relationship with the target shared memory is intercepted.

[0057] Step 303: Store the data in the target shared memory into a disk in the form of a file or into other physical memory in the form of a compressed cache.

[0058] Step 304: traverse the virtual addresses corresponding to each user in the target shared memory.

[0059] Step 305: Disassociate the virtual address corresponding to each user from the target shared memory.

[0060] Step 306: Release all physical memories corresponding to the target shared memory.

[0061] In an optional specific embodiment, when the target application switches from a background state to a foreground state, step 102 of performing a recovery operation on the target shared memory includes:

[0062] When the target application switches from a background state to a foreground state, acquiring a target shared memory corresponding to the target application that has been released;

[0063] Apply for a physical memory corresponding to the target shared memory, and restore the file data corresponding to the target shared memory in the disk and the compressed data corresponding to the target shared memory in other physical memories to the physical memory corresponding to the target shared memory;

[0064] By means of reverse mapping, the virtual addresses corresponding to the various users in the target shared memory are traversed, and an association relationship is re-established between the virtual addresses corresponding to the various users and the target shared memory.

[0065] If it is detected that the target application switches from the background state to the foreground state, in order to avoid the shared memory under the name of the target application from being missed, all shared memories related to the target application (including the target shared memory) are found from the released shared memory, and then each released shared memory related to the target application is restored one by one.

[0066] The following uses the target shared memory as an example to illustrate the recovery process. The recovery process for other shared memories is the same as that for the target shared memory:

[0067] Obtain the target shared memory corresponding to the released target application, apply for physical memory of the same size as the target shared memory, and hand over the physical memory to the target shared memory for management. Restore the file data corresponding to the target shared memory in the disk and the compressed data corresponding to the target shared memory in other physical memories to the physical memory corresponding to the target shared memory in order. Through reverse mapping, traverse the virtual addresses corresponding to all users in the target shared memory, and re-associate the virtual addresses corresponding to each user with the target shared memory to avoid problems such as address access errors.

[0068] It should be noted that the purpose of obtaining all virtual addresses mentioned above is: if you want to make the hardware, kernel, and upper-level software using the target shared memory unaware of the release and recovery of the target shared memory, you need to reserve all virtual addresses corresponding to the target shared memory in advance and use these virtual addresses for recovery. After recovery, the hardware, kernel, and upper-level software using the target shared memory can still access the original target shared memory through the previously applied virtual addresses.

[0069] In an optional specific embodiment, in step 102, when the target application switches from a background state to a foreground state, after performing a recovery operation on the target shared memory, the method further includes:

[0070] Unblocking the request for establishing an association relationship with the target shared memory.

[0071] After re-associating the virtual addresses corresponding to each user with the target shared memory, it is also necessary to release the interception of the shared memory when it is released, that is, to release the interception of the request to establish an association with the target shared memory to ensure that other users can establish an association with the target shared memory.

[0072] The following describes the recovery process of the target shared memory through a specific embodiment:

[0073] like Figure 4 As shown, step 401: detecting the state of the target application.

[0074] Step 402: If it is detected that the target application switches from the background state to the foreground state, the released shared memory is traversed.

[0075] Step 403 : Determine whether the current target shared memory has been released and is related to the target application. If so, execute step 404 ; if not, return to step 402 .

[0076] Step 404: Apply for physical memory of the same size as the target shared memory, and hand it over to the target shared memory for management.

[0077] Step 405: restore the file data corresponding to the target shared memory in the disk and the compressed data corresponding to the target shared memory in other physical memories to the physical memory corresponding to the target shared memory.

[0078] Step 406: traverse the virtual addresses corresponding to each user in the target shared memory by means of reverse mapping.

[0079] Step 407: re-associate the virtual addresses corresponding to each user with the target shared memory.

[0080] In an optional specific embodiment, if it is detected that the target application switches from the foreground state to the background state, it is necessary to first determine whether the type of the target shared memory matches (or is consistent with) the type of the preset shared memory. If the type of the target shared memory is consistent with the type of the preset shared memory, it means that the target shared memory is applicable to the above-mentioned shared memory release scheme, and the target shared memory is automatically released according to the release process to reduce the proportion of shared memory in the system resident memory and reduce the overall memory pressure of the system.

[0081] If it is detected that the target application switches from the background state to the foreground state, it is necessary to first determine whether the type of the target shared memory matches (or is consistent with) the type of the preset shared memory. If the type of the target shared memory is consistent with the type of the preset shared memory, it means that the target shared memory is applicable to the above-mentioned shared memory recovery solution, and the target shared memory is automatically recovered according to the recovery process.

[0082] In an optional specific embodiment, the type of the preset shared memory is determined in the following manner:

[0083] For any type of shared memory, when an application corresponding to the shared memory enters a background state, if the application does not have an access requirement for the shared memory, the type of the shared memory is determined to be a preset shared memory type.

[0084] The underlying layer provides the function of dynamically releasing and restoring shared memory, but it is necessary to confirm what type of shared memory is applicable to this function, that is, to confirm in what scenarios it can be safely released and restored.

[0085] To address this issue, we've chosen scenarios where apps are in the foreground and background. This feature applies if an app doesn't access shared memory after it's in the background. Conversely, if an app still accesses shared memory after it's in the background, it doesn't. We've set the shared memory type by function, such as video, audio, or display.

[0086] To more clearly observe whether an application accesses shared memory when switching to the background, an offline test is conducted. For each type of shared memory, the application is forced to release the shared memory when it switches to the background. After the application is restored to the foreground, the application is observed to see if any abnormalities occur, such as application crashes, abnormal display, or no sound. If the application does not exhibit any abnormalities after multiple tests, it indicates that the shared memory type is suitable for this function and is determined as the preset shared memory type.

[0087] In summary, the implementation of the hardware shared memory reverse mapping mechanism in the embodiment of the present application can fully obtain the virtual addresses of all hardware, upper-layer software, and kernel in the shared memory. When the target application is in the background, the target shared memory under its name is automatically released, and when the target application is in the foreground, the target shared memory that has been released under its name is automatically restored. This not only makes the user of the target shared memory unaware, but also reduces the proportion of the target shared memory in the system resident memory, reduces the overall memory pressure of the system, and solves problems such as system freezes caused by insufficient memory.

[0088] The shared memory processing method provided in the embodiment of the present application can be executed by a shared memory processing device. In the embodiment of the present application, the shared memory processing device provided in the embodiment of the present application is described by taking the shared memory processing device executing the shared memory processing method as an example.

[0089] like Figure 5 As shown, the embodiment of the present application further provides a shared memory processing device 500, specifically comprising:

[0090] A release module 501 is configured to release a target shared memory corresponding to a target application when the target application switches from a foreground state to a background state;

[0091] The recovery module 502 is configured to perform a recovery operation on the target shared memory when the target application switches from a background state to a foreground state.

[0092] Optionally, the release module 501 is specifically configured to:

[0093] When the target application switches from a foreground state to a background state, traversing virtual addresses corresponding to various users in the target shared memory by reverse mapping, and disassociating the virtual addresses corresponding to various users from the target shared memory; the users in the target shared memory include the target application and at least one of hardware and a kernel associated with the target application;

[0094] A release operation is performed on all physical memories corresponding to the target shared memory.

[0095] Optionally, the device further comprises:

[0096] The processing module is used to intercept the request to establish an association relationship with the target shared memory when the target application switches from the foreground state to the background state, and store the data in the target shared memory in the form of a file on the disk or in other physical memory in the form of a compressed cache.

[0097] Optionally, the recovery module 502 is specifically configured to:

[0098] When the target application switches from a background state to a foreground state, acquiring a target shared memory corresponding to the target application that has been released;

[0099] Apply for a physical memory corresponding to the target shared memory, and restore the file data corresponding to the target shared memory in the disk and the compressed data corresponding to the target shared memory in other physical memories to the physical memory corresponding to the target shared memory;

[0100] By means of reverse mapping, the virtual addresses corresponding to the various users in the target shared memory are traversed, and an association relationship is re-established between the virtual addresses corresponding to the various users and the target shared memory.

[0101] Optionally, the device further comprises:

[0102] The release module is used to release the interception of the request to establish an association relationship with the target shared memory.

[0103] The shared memory processing device in the embodiment of the present application can be an electronic device or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a mobile Internet device (MID), an augmented reality (AR) / virtual reality (VR) device, a robot, a wearable device, an ultra-mobile personal computer (UMPC), a netbook or a personal digital assistant (PDA), etc. It can also be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine or a self-service machine, etc., and the embodiment of the present application does not specifically limit it.

[0104] The shared memory processing device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0105] The shared memory processing device provided in the embodiment of the present application can realize Figures 1 to 4 To avoid repetition, the various processes implemented in the method embodiment are not described here.

[0106] Alternatively, as Figure 6 As shown, an embodiment of the present application also provides an electronic device 900, including a processor 901 and a memory 902, wherein the memory 902 stores a program or instruction that can be run on the processor 901, and when the program or instruction is executed by the processor 901, the various steps of the above-mentioned shared memory processing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0107] It should be noted that the electronic devices in the embodiments of the present application include the mobile electronic devices and non-mobile electronic devices mentioned above.

[0108] Figure 7 A schematic diagram of the hardware structure of an electronic device implementing an embodiment of the present application.

[0109] The electronic device 1000 includes but is not limited to components such as a radio frequency unit 1001 , a network module 1002 , an audio output unit 1003 , an input unit 1004 , a sensor 1005 , a display unit 1006 , a user input unit 1007 , an interface unit 1008 , a memory 1009 , and a processor 1010 .

[0110] Those skilled in the art will understand that the electronic device 1000 may also include a power source (such as a battery) to power each component, and the power source may be logically connected to the processor 1010 through a power management system, thereby implementing functions such as charging, discharging, and power consumption management through the power management system. Figure 7 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be repeated here.

[0111] The processor 1010 is configured to release the target shared memory corresponding to the target application when the target application switches from the foreground state to the background state;

[0112] When the target application switches from a background state to a foreground state, a recovery operation is performed on the target shared memory.

[0113] Optionally, when the target application switches from the foreground state to the background state, the processor 1010 is specifically configured to:

[0114] When the target application switches from a foreground state to a background state, traversing virtual addresses corresponding to various users in the target shared memory by reverse mapping, and disassociating the virtual addresses corresponding to various users from the target shared memory; the users in the target shared memory include the target application and at least one of hardware and a kernel associated with the target application;

[0115] A release operation is performed on all physical memories corresponding to the target shared memory.

[0116] Optionally, when the target application switches from the foreground state to the background state, the processor 1010 is further configured to:

[0117] When the target application switches from the foreground state to the background state, the request to establish an association relationship with the target shared memory is intercepted, and the data in the target shared memory is stored in the disk as a file or in other physical memory as a compressed cache.

[0118] Optionally, when the target application switches from a background state to a foreground state, the processor 1010, when performing a recovery operation on the target shared memory, is specifically configured to:

[0119] When the target application switches from a background state to a foreground state, acquiring a target shared memory corresponding to the target application that has been released;

[0120] Apply for a physical memory corresponding to the target shared memory, and restore the file data corresponding to the target shared memory in the disk and the compressed data corresponding to the target shared memory in other physical memories to the physical memory corresponding to the target shared memory;

[0121] By means of reverse mapping, the virtual addresses corresponding to the various users in the target shared memory are traversed, and an association relationship is re-established between the virtual addresses corresponding to the various users and the target shared memory.

[0122] Optionally, when the target application switches from a background state to a foreground state, the processor 1010 is further configured to:

[0123] Unblocking the request for establishing an association relationship with the target shared memory.

[0124] It should be understood that in an embodiment of the present application, the input unit 1004 may include a graphics processing unit (GPU) 10041 and a microphone 10042, and the graphics processor 10041 processes the image data of a static picture or video obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 1006 may include a display panel 10061, and the display panel 10061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1007 includes a touch panel 10071 and at least one of other input devices 10072. The touch panel 10071 is also called a touch screen. The touch panel 10071 may include two parts: a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and an operating stick, which will not be repeated here.

[0125] The memory 1009 can be used to store software programs and various data. The memory 1009 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, applications or instructions required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory 1009 may include a volatile memory or a non-volatile memory, or the memory 1009 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM), and a direct memory bus random access memory (DRRAM). The memory 1009 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.

[0126] Processor 1010 may include one or more processing units. Optionally, processor 1010 integrates an application processor and a modem processor. The application processor primarily handles operations related to the operating system, user interface, and application programs, while the modem processor primarily processes wireless communication signals, such as a baseband processor. It is understood that the modem processor may not be integrated into processor 1010.

[0127] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned shared memory processing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0128] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0129] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned shared memory processing method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0130] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.

[0131] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned shared memory processing method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0132] It should be noted that, in this article, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element. In addition, it should be noted that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in the opposite order according to the functions involved. For example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0133] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), including a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0134] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.

Claims

1. A shared memory processing method, characterized in that: include: When the target application switches from a foreground state to a background state, performing a release operation on the target shared memory corresponding to the target application; When the target application switches from a background state to a foreground state, a recovery operation is performed on the target shared memory.

2. The method according to claim 1, characterized in that When the target application switches from a foreground state to a background state, performing a release operation on the target shared memory corresponding to the target application includes: When the target application switches from a foreground state to a background state, traversing virtual addresses corresponding to various users in the target shared memory by reverse mapping, and disassociating the virtual addresses corresponding to various users from the target shared memory; the users in the target shared memory include the target application and at least one of hardware and a kernel associated with the target application; A release operation is performed on all physical memories corresponding to the target shared memory.

3. The method according to claim 1, characterized in that When the target application switches from the foreground state to the background state, before performing a release operation on the target shared memory corresponding to the target application, the method further includes: When the target application switches from the foreground state to the background state, the request to establish an association relationship with the target shared memory is intercepted, and the data in the target shared memory is stored in the disk as a file or in other physical memory as a compressed cache.

4. The method according to any one of claims 1 to 3, characterized in that When the target application switches from a background state to a foreground state, performing a recovery operation on the target shared memory includes: When the target application switches from a background state to a foreground state, acquiring a target shared memory corresponding to the target application that has been released; Apply for a physical memory corresponding to the target shared memory, and restore the file data corresponding to the target shared memory in the disk and the compressed data corresponding to the target shared memory in other physical memories to the physical memory corresponding to the target shared memory; By means of reverse mapping, the virtual addresses corresponding to the various users in the target shared memory are traversed, and an association relationship is re-established between the virtual addresses corresponding to the various users and the target shared memory.

5. The method according to claim 1, wherein When the target application switches from a background state to a foreground state, after performing a recovery operation on the target shared memory, the method further includes: Unblocking the request for establishing an association relationship with the target shared memory.

6. A shared memory processing device, characterized in that: include: A release module, configured to release the target shared memory corresponding to the target application when the target application switches from a foreground state to a background state; The recovery module is used to perform a recovery operation on the target shared memory when the target application switches from a background state to a foreground state.

7. The device according to claim 6, characterized in that The release module is specifically used to: When the target application switches from a foreground state to a background state, traversing virtual addresses corresponding to various users in the target shared memory by reverse mapping, and disassociating the virtual addresses corresponding to various users from the target shared memory; the users in the target shared memory include the target application and at least one of hardware and a kernel associated with the target application; A release operation is performed on all physical memories corresponding to the target shared memory.

8. The device according to claim 6, characterized in that The device further comprises: The processing module is used to intercept the request to establish an association relationship with the target shared memory when the target application switches from the foreground state to the background state, and store the data in the target shared memory in the form of a file on the disk or in other physical memory in the form of a compressed cache.

9. The device according to any one of claims 6 to 8, characterized in that The recovery module is specifically used to: When the target application switches from a background state to a foreground state, acquiring a target shared memory corresponding to the target application that has been released; Apply for a physical memory corresponding to the target shared memory, and restore the file data corresponding to the target shared memory in the disk and the compressed data corresponding to the target shared memory in other physical memories to the physical memory corresponding to the target shared memory; By means of reverse mapping, the virtual addresses corresponding to the various users in the target shared memory are traversed, and an association relationship is re-established between the virtual addresses corresponding to the various users and the target shared memory.

10. The device according to claim 6, characterized in that The device further comprises: The release module is used to release the interception of the request to establish an association relationship with the target shared memory.

11. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or instruction that can be run on the processor, and when the program or instruction is executed by the processor, the steps of the shared memory processing method according to any one of claims 1 to 5 are implemented.