Memory page processing method, apparatus, and electronic device

By creating a memory pool in electronic devices and first searching for memory pages in the memory pool, the blocking problem in the memory reclamation process is solved, memory allocation efficiency is improved, and device smoothness is enhanced.

CN115827229BActive Publication Date: 2026-01-13GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211543262.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-02
Publication Date
2026-01-13
Estimated Expiration
2042-12-02

AI Technical Summary

Technical Problem

In existing technologies, the memory reclamation process carries the risk of blocking, which can prevent memory users from obtaining the required memory pages in a timely manner, causing electronic devices to lag or drop frames.

Method used

By pre-establishing a memory pool, the identifier of the memory allocation request is obtained, and a matching memory page is searched in the memory pool. If no matching page is found, the operating system memory reclamation is triggered, thus avoiding direct triggering of the operating system memory reclamation operation and reducing the probability of blocking during the memory reclamation operation.

Benefits of technology

It improves the efficiency of memory page allocation, reduces the probability that memory-using objects cannot obtain memory pages in a timely manner, and enhances the smoothness of electronic devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115827229B_ABST
    Figure CN115827229B_ABST
Patent Text Reader

Abstract

Embodiments of the present application disclose a memory page processing method and device and electronic equipment. The method comprises: in response to a memory allocation request triggered by a memory using object, obtaining an identifier of a memory page applied for allocation by the memory allocation request; if the memory pool has the memory page with the identifier, obtaining the memory page with the corresponding identifier from the memory pool and allocating the memory page to the memory using object, wherein the memory pages in the memory pool are obtained from an operating system of the electronic equipment in advance; and if the memory pool does not have the memory page with the identifier, triggering the operating system to perform a memory recovery operation, and allocating the memory page recovered by the memory recovery operation to the memory using object. Thus, the memory page required by the memory using object can be directly obtained from the memory pool, and the memory page required by the memory using object can be more timely and efficiently obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a method, apparatus, and electronic device for processing memory pages. Background Technology

[0002] Main memory, also known as RAM, is the storage space that the CPU can directly address, and it is made of semiconductor devices. The memory space in electronic devices is limited. To ensure that the system has enough memory available, electronic devices typically perform memory reclamation under certain circumstances. For example, when an application requests memory allocation, the electronic device can reclaim memory to satisfy the application's need. However, this memory reclamation process carries the risk of blocking, which can prevent the requesting application from obtaining the required memory pages in a timely manner. Summary of the Invention

[0003] In view of the above problems, this application proposes a memory page processing method, apparatus, and electronic device to improve the above problems.

[0004] In a first aspect, this application provides a memory page processing method applied to an electronic device. The method includes: in response to a memory allocation request triggered by a memory user, obtaining an identifier of the memory page requested for allocation in the memory allocation request; if a memory page with the identifier is present in a pre-established memory pool, obtaining the memory page corresponding to the identifier from the memory pool and allocating it to the memory user, wherein the memory pages in the memory pool are pre-requested from the operating system of the electronic device; if no memory page with the identifier is present in the pre-established memory pool, triggering the operating system to perform a memory reclamation operation to allocate the memory pages reclaimed by the memory reclamation operation to the memory user.

[0005] Secondly, this application provides a memory page processing apparatus, operating in an electronic device, the apparatus comprising: a memory identifier acquisition unit, configured to acquire an identifier of a memory page requested for allocation in response to a memory allocation request triggered by a memory user; and a memory processing unit, configured to, if a memory page with the identifier exists in a pre-established memory pool, acquire a memory page corresponding to the identifier from the memory pool and allocate it to the memory user, wherein the memory pages in the memory pool are pre-requested from the operating system of the electronic device; and if no memory page with the identifier exists in the pre-established memory pool, trigger the operating system to perform a memory reclamation operation to allocate the memory pages reclaimed by the memory reclamation operation to the memory user.

[0006] Thirdly, this application provides an electronic device including one or more processors and a memory; one or more programs are stored in the memory and configured to be executed by the one or more processors to implement the above-described method.

[0007] Fourthly, this application provides a computer-readable storage medium storing program code, wherein the above-described method is executed when the program code is run by a processor.

[0008] This application provides a memory page processing method, apparatus, and electronic device. Upon responding to a memory allocation request triggered by a memory user, the method first obtains the identifier of the memory page requested in the allocation request. If a pre-established memory pool contains a memory page with the identifier, the method retrieves the corresponding memory page from the memory pool and allocates it to the memory user. This allows for the pre-establishment of a memory pool and the pre-allocation of memory pages from the operating system. When a memory user requests a memory page, the required memory page can be directly retrieved from the memory pool. This avoids triggering memory reclamation operations when a memory user needs a memory page, further reducing the probability of memory reclamation blocking and preventing the memory user from obtaining the required memory page in a timely manner. This improves the efficiency of allocating required memory pages to memory users. Attached Figure Description

[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0010] Figure 1 A flowchart of a memory page processing method according to another embodiment of this application is shown;

[0011] Figure 2 A schematic diagram of a memory pool management interface according to an embodiment of this application is shown;

[0012] Figure 3 A flowchart of a memory page processing method according to another embodiment of this application is shown;

[0013] Figure 4 A schematic diagram of a memory pool according to an embodiment of this application is shown;

[0014] Figure 5A flowchart of a memory allocation process according to an embodiment of this application is shown;

[0015] Figure 6 A flowchart of a memory page processing method according to another embodiment of this application is shown;

[0016] Figure 7 A schematic diagram illustrating the parallel operation of the first memory reclamation method and the second memory reclamation method in an embodiment of this application is shown;

[0017] Figure 8 This illustration shows a schematic diagram of starting a second asynchronous thread based on the recycling time of the driver in an embodiment of this application;

[0018] Figure 9 A flowchart illustrating the workflow of the third asynchronous thread in an embodiment of this application is shown;

[0019] Figure 10 This document illustrates a flowchart of an embodiment of the present application that demonstrates memory page reclamation based on attempting to hold a lock on memory pages.

[0020] Figure 11 A flowchart of a third memory reclamation method according to an embodiment of this application is shown;

[0021] Figure 12 This paper shows a structural block diagram of a memory page processing apparatus according to an embodiment of the present application;

[0022] Figure 13 This invention illustrates a structural block diagram of an electronic device for performing a memory page processing method according to an embodiment of the present invention.

[0023] Figure 14 This application illustrates a storage unit for storing or carrying program code implementing a memory page processing method according to an embodiment of this application. Detailed Implementation

[0024] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0025] With the rapid development of mobile terminal technology, consumers' demands for electronic devices are no longer limited to simple functions; they expect smooth operation of multiple functions. Therefore, smoothness has become a necessary factor influencing users' purchasing decisions. Among these factors, memory performance has a significant impact on the smooth operation of electronic devices. Furthermore, the memory requirements of current electronic devices are increasing daily; for example, large mobile games may occupy 2GB of memory. Therefore, better managing memory performance mainly relies on memory reclamation technology.

[0026] For electronic devices, memory reclamation is a common mechanism because the amount of memory included is limited. There are two main reasons for memory reclamation: the operating system needs to provide sufficient memory for any sudden memory requests to prevent cache and other related memory usage from leaving the system with very little free memory for extended periods. Cache is a high-speed storage device located between the processor and main memory. Secondly, memory reclamation is triggered when a request for more free memory arrives. The core idea of ​​memory reclamation is that if some data can be saved to disk, it is written from memory to disk when memory is insufficient, thus freeing up the memory pages occupied by this data for the system to use.

[0027] In some cases, when a memory-using object (e.g., a user thread) makes a memory allocation request, the operating system will first reclaim the memory and then allocate the reclaimed memory pages to that object. However, this memory reclamation process carries the risk of blocking, which can prevent the requesting memory-using object from obtaining the required memory pages in a timely manner, potentially causing lag or even frame drops in electronic devices. For example, the operating system can perform memory reclamation using kswapd or direct_reclaim.

[0028] Among them, kswapd is a background memory reclamation thread. The operating system of the electronic device can detect the remaining allocatable memory. When it detects that the remaining allocatable memory is low (for example, below a preset threshold), it will start the kswapd thread to reclaim memory pages. direct_reclaim refers to the memory page reclamation being directly triggered by a user thread.

[0029] In both `kswapd` and `direct_reclaim`, the `shrink_lruvec` and `shrink_slab` operations are executed sequentially. `direct_reclaim` additionally performs a `pcppages` reclamation operation after `shrink_slab`. The goal of `shrink_lruvec` is to reclaim memory pages used by the application. The goal of `shrink_slab` is to call back the shrink callbacks of various drivers to reclaim memory pages used by those drivers. `pcppages` can be understood as memory pages allocated to processing devices; correspondingly, executing `pcppages` reclaims memory pages (used for caching data) from various processing devices. However, the inventors discovered that `shrink_lruvec`, `shrink_slab`, and `pcppages` are executed sequentially. Therefore, if any one of these operations blocks, the entire memory reclamation process will be blocked, preventing timely allocation of memory to memory-using objects.

[0030] Therefore, the inventors have proposed the memory page processing method, apparatus and electronic device of this application. After responding to a memory allocation request triggered by a memory user, the method can first obtain the identifier of the memory page requested by the memory allocation request, and then, if it is determined that there is an identifier in the pre-established memory pool, obtain the memory page with the corresponding identifier from the memory pool and allocate it to the memory user.

[0031] This method allows for the pre-establishment of a memory pool and the pre-allocation of memory pages from the operating system. When an object requests a memory page, the required memory page can be directly obtained from the memory pool. This avoids triggering memory reclamation operations by the operating system when an object needs a memory page, further reducing the probability of memory reclamation blocking and preventing the object from obtaining the required memory page in a timely manner. This improves the efficiency of allocating the required memory pages to objects.

[0032] The embodiments of this application will now be described in detail with reference to the accompanying drawings.

[0033] Please see Figure 1 This application provides a memory page processing method, which includes:

[0034] S110: In response to a memory allocation request triggered by a memory-using object, obtain the identifier of the memory page requested in the memory allocation request.

[0035] It's important to note that in electronic devices, a memory-using object can be understood as a thread or process corresponding to an application installed on the device. An application thread can also be understood as a user thread. During the execution of a memory-using object, it needs to process data using memory (memory pages), thus triggering a memory allocation request to acquire the required memory pages. This memory allocation request can be triggered at startup, or it can be triggered during runtime when it detects that the currently allocated memory pages are insufficient.

[0036] One approach is to include an identifier of the memory page to be allocated in the memory allocation request.

[0037] In the embodiments of this application, the identifier of a memory page can be implemented in several ways. In one approach, the identifier may include the type of the memory page. For example, the type may include a movable memory page, a non-movable memory page, a non-reclaimable memory page, and a reclaimable memory page, etc. In another approach, the identifier may include the size of the memory page, which may include 4Kbytes, 8Kbytes…4M bytes, etc. In yet another approach, the identifier of a memory page may include both the type and size of the memory page.

[0038] S120: If there are identified memory pages in the pre-established memory pool, obtain the corresponding identified memory page from the memory pool and allocate it to the memory user. The memory pages in the memory pool are obtained in advance from the operating system of the electronic device.

[0039] After obtaining the identifier of the requested memory page, a search can be conducted in the memory pool to find a memory page that matches that identifier. If a memory page matching the identifier exists in the memory pool, it is retrieved and allocated to the memory user who sent the memory allocation request. Here, "matching identifiers" can be understood as two identifiers being identical. For example, taking the identifier as the type of memory page, if a memory page of that type exists in the pre-established memory pool, it can be retrieved and allocated to the memory user.

[0040] In this embodiment of the application, the memory pool can be established by the electronic device at startup or by the electronic device when a specified event is detected.

[0041] Optionally, the specified event can be a user-triggered operation to create a memory pool. In this approach, the electronic device can be configured with a memory pool management interface, which can include a switch for the memory pool. If the user sets this switch to the "on" state, it is determined that the user has triggered the memory pool creation operation. The electronic device will then create the memory pool and request memory pages from the operating system to store in it. If the user sets the switch to the "off" state, the electronic device can delete the memory pool and release any unallocated memory pages within it. Figure 2 As shown, in Figure 2 The memory pool management interface 10 shown includes a switch 11 and an input control 12. Users can input the desired size of the memory pool in this input control 12. For example, if the user inputs a memory pool size of 100MB, the memory pool will request a total of 100MB of memory pages from the operating system after startup. Furthermore, after the memory pool has been created, the user can also change its size using the input control 12. Optionally, if a value is detected in the input control 12 when the memory pool has been created, the input value can be compared with the size of the already created memory pool. If the input value is greater than the size of the already created memory pool, memory pages can be requested from the operating system kernel based on the difference between the input value and the size of the already created memory pool to make up the difference. If the input value is less than the size of the already created memory pool, memory pages in the memory pool can be released based on the difference between the input value and the size of the already created memory pool, so that the size of the memory pool after releasing the memory pages is the same as the input value.

[0042] Optionally, the specified event can be the electronic device detecting that the number of currently running applications exceeds a specified threshold. It should be noted that as the number of running applications increases, the number of memory allocation requests in the electronic device will also increase. Therefore, to more efficiently handle the increased number of memory allocation requests, a memory pool can be activated to pre-allocate memory pages from the operating system and configure them into the memory pool.

[0043] S130: If there are no identified memory pages in the pre-established memory pool, the operating system is triggered to perform a memory reclamation operation to allocate the memory pages reclaimed by the memory reclamation operation to memory-using objects.

[0044] In the absence of a recognized memory page in the memory pool, the operating system can perform memory reclamation to acquire the necessary memory page for the memory-using object, ensuring that the object can still allocate the required memory page. In this embodiment, the memory pages reclaimed during reclamation may include file pages and / or anonymous pages. A file page can be understood as a page with a file background (i.e., a memory page mapped to a file on the disk). An anonymous page can be understood as a page without a file background.

[0045] This embodiment provides a memory page processing method. Upon responding to a memory allocation request triggered by a memory user, the method first obtains the identifier of the memory page requested in the allocation request. Then, if a pre-established memory pool contains the identified memory page, the method retrieves the corresponding memory page from the memory pool and allocates it to the memory user. This allows for the pre-establishment of a memory pool. After the memory pool is established, a memory request is sent to the operating system to pre-request memory pages from the operating system and store them in the memory pool. Therefore, when a memory user requests a memory page, the required memory page can be directly retrieved from the memory pool. This avoids the probability of triggering memory reclamation operations when a memory user needs a memory page, further reducing the probability of memory reclamation blocking during the operating system's memory reclamation process, which could prevent the memory user from obtaining the required memory page in a timely manner. This improves the efficiency of allocating the required memory pages to memory users.

[0046] Please see Figure 3 This application provides a memory page processing method, which includes:

[0047] S210: In response to a memory allocation request triggered by a memory-using object, obtain the identifier of the memory page requested in the memory allocation request.

[0048] S220: If a target linked list exists in the pre-established memory pool, retrieve the memory page with the corresponding identifier from the target linked list and allocate it to the memory user object. The identifier of the target linked list is the same as the identifier of the memory page to be allocated.

[0049] In this embodiment, memory pages can be stored in the memory pool using linked lists. The memory pool can include multiple linked lists, each with a different identifier. For example, taking the identifier representing a memory page as an example... Figure 4As shown, the memory pool contains linked lists A1, A2, A3, and A4. List A1 corresponds to movable memory pages, list A2 to non-movable memory pages, list A3 to non-reclaimable memory pages, and list A4 to reclaimable memory pages. If a memory allocation request requests a reclaimable memory page, then list A4 can be identified as the target list, and a memory page can be retrieved from list A4 and allocated to the memory-using object.

[0050] In this embodiment, the identifiers of memory pages used by the application can be pre-collected, and then linked lists can be built based on the identifiers of the memory pages frequently used by the application. Taking the type of memory page as an example, if it is pre-collected that the types of memory pages frequently used by the application are reclaimable memory pages and movable memory pages, then linked lists of type reclaimable memory pages and linked lists of type movable memory pages can be built. The identifiers of memory pages used by the application can be collected through experiments or large-scale data analysis.

[0051] To replenish memory pages in the linked list in a timely manner, one approach is to initiate an asynchronous thread to request corresponding memory pages from the operating system if the number of remaining memory pages in the target linked list falls below a first threshold. The requested memory pages are then configured into the target linked list. By requesting memory pages from the operating system asynchronously, the linked list is continuously replenished with memory pages, reducing the probability that there are no available memory pages in the linked list when memory allocation is needed. This also reduces the probability of the operating system triggering memory reclamation due to a lack of memory pages in the linked list, further preventing blocking during memory reclamation and ensuring that memory allocation for memory-using objects is not hindered.

[0052] It should be noted that the aforementioned first quantity threshold is the threshold that triggers asynchronous threads to allocate memory pages. This first quantity threshold can be configured by the developers before the electronic device leaves the factory, or it can be configured by the user of the electronic device.

[0053] Furthermore, in this embodiment, when it is necessary to retrieve memory pages from the linked list, the corresponding measures can be determined based on the number of remaining memory pages in the linked list. Optionally, if a target linked list exists in the pre-established memory pool, retrieving memory pages with corresponding identifiers from the target linked list and allocating them to memory users may include: if a target linked list exists in the pre-established memory pool, detecting whether the number of memory pages in the target linked list is greater than a second quantity threshold. If it is greater than the second quantity threshold, retrieving memory pages with corresponding identifiers from the target linked list and allocating them to memory users. If it is not greater than the second quantity threshold, waiting for a first specified time period and then detecting again whether the number of memory pages in the target linked list is greater than the second quantity threshold. If it is greater than the second quantity threshold, retrieving memory pages with corresponding identifiers from the target linked list and allocating them to memory users. If it is not greater than the second quantity threshold, triggering the operating system to perform a memory reclamation operation to allocate the memory pages reclaimed by the memory reclamation operation to memory users.

[0054] As described above, when the number of memory pages in a certain linked list is low (e.g., below a first threshold), memory pages are replenished via an asynchronous thread. Therefore, waiting for a first specified time when the remaining memory pages are no greater than a second threshold is to allow the asynchronous thread to complete the replenishment, thereby further preventing the operating system from performing memory reclamation. However, if, after waiting for the first specified time, the number of memory pages in the linked list is still no greater than the second threshold, the operating system will still be triggered to perform memory reclamation in order to allocate the necessary memory pages for the memory-using objects.

[0055] Next, we will proceed through... Figure 5 The process involved in this embodiment will be described below.

[0056] After obtaining the identifier through the memory allocation request of the memory-using object, the identifier is first matched. If the identifier matches successfully, the target linked list can be determined, and then it is checked whether there are enough memory pages in the target linked list. If the number of remaining memory pages in the target linked list is greater than a second threshold, memory pages can be directly retrieved from the target linked list. Then, it is checked whether the number of remaining memory pages in the target linked list after the memory pages were retrieved is lower than a first threshold. If it is lower than the first threshold, an asynchronous thread can be woken up, and the retrieved memory pages can be returned to the memory-using object. Furthermore, if the number of remaining memory pages in the target linked list is not greater than the second threshold, the process can be repeated after a first specified time. If the number of remaining memory pages in the target linked list is now greater than the second threshold, memory pages can be retrieved, and subsequent page judgment and allocation steps can be executed. Finally, if after the first specified time, the number of remaining memory pages in the target linked list is still not greater than the second threshold, the operating system kernel can be triggered to perform memory reclamation.

[0057] Furthermore, memory pages allocated to memory-using objects from the memory pool can also be released. For example, when a memory-using object is closed, the memory pages used by that object can be released. When a memory page is released, the linked list from which it originated can be retrieved first. Then, it is checked whether the number of memory pages in the source linked list is greater than a third threshold. If it is greater, the released memory page can be released back to the operating system kernel; if it is not greater, the memory page can be released back to the linked list in the memory pool from which it originated. This third threshold is greater than the aforementioned first threshold. For example, if the memory page to be released originates from... Figure 4 The linked list A4 shown can first check whether the number of memory pages in linked list A4 is greater than the third threshold. If it is greater, the memory page to be released can be released back into the operating system kernel. If it is not greater, the memory page to be released can be released back into linked list A4.

[0058] It should be noted that, in this embodiment, the memory allocation operations via the memory pool can be performed by a designated library of the operating system. In this case, upon receiving a memory allocation request triggered by a memory user, the designated library can be invoked to obtain the identifier of the memory page requested in the allocation request, and, if a target list exists in the pre-established memory pool, to retrieve the corresponding memory page from the target list and allocate it to the memory user. For example, the designated library can be based on an SO library. An SO library, also known as a dynamic library, is a file format in the Linux operating system. Instrumentation can be performed within the operating system to call the designated library and complete the above steps. Instrumentation within the operating system can be understood as inserting a piece of code into the operating system; this code, when run, can call the designated library to complete the above steps.

[0059] S230: If there is no target list in the pre-established memory pool, the operating system is triggered to perform a memory reclamation operation to allocate the memory pages reclaimed by the memory reclamation operation to the memory-using objects.

[0060] This embodiment provides a memory page processing method that allows for the pre-establishment of a memory pool and the pre-allocation of memory pages from the operating system. When a memory-using object requests a memory page, it can directly obtain the required memory page from the memory pool. This avoids triggering memory reclamation operations by the operating system when a memory-using object needs a memory page, further reducing the probability of memory reclamation blocking and preventing the memory-using object from obtaining the required memory page in a timely manner. This improves the efficiency of allocating required memory pages to memory-using objects. Furthermore, in this embodiment, multiple linked lists can be established in the memory pool, each storing different memory pages, allowing for more flexible management of the memory pages in the memory pool. Moreover, when the memory pages in the linked lists are insufficient, asynchronous threads can be started to request memory pages, further improving the efficiency of replenishing the memory pool. Furthermore, in this embodiment, some steps can be configured to be executed by a designated library instead of the operating system's own kernel, thereby realizing the memory reclamation process of the macro kernel (the operating system's kernel) by constructing a microkernel concept.

[0061] Please see Figure 6 This application provides a memory page processing method, which includes:

[0062] S310: In response to a memory allocation request triggered by a memory-using object, obtain the identifier of the memory page requested in the memory allocation request.

[0063] S320: If there are identified memory pages in the pre-established memory pool, obtain the corresponding identified memory page from the memory pool and allocate it to the memory user. The memory pages in the memory pool are obtained in advance from the operating system of the electronic device.

[0064] S330: If there are no identified memory pages in the pre-established memory pool, the operating system is triggered to execute the first memory reclamation method and the second memory reclamation method to reclaim memory and allocate the reclaimed memory pages to the memory users.

[0065] One method to trigger the operating system to perform memory reclamation includes: during the memory reclamation process, the operating system executes a first memory reclamation method and a second memory reclamation method in parallel. The first memory reclamation method reclaims memory pages of applications, while the second memory reclamation method reclaims memory pages of electronic device drivers. Since the first and second memory reclamation methods reclaim different objects, executing them in parallel improves memory reclamation efficiency and prevents them from blocking each other.

[0066] Furthermore, it should be noted that, in order for the operating system to support the parallel execution of the first and second memory reclamation methods, optionally, the first memory reclamation method can be executed by the operating system kernel, and the second memory reclamation method can be executed in parallel through a specified library set in the operating system, while preventing the operating system kernel from executing the second memory reclamation method. This can be understood as follows: by preventing the operating system from executing the second memory reclamation method, the operating system will not be blocked during its execution, thus preventing the entire memory reclamation process from being blocked; and by simultaneously executing the second memory reclamation method through the specified library, the parallel execution of the first and second memory reclamation methods can be achieved.

[0067] Optionally, memory reclamation can be triggered during the process using the `kswapd` and `direct_reclaim` methods. Each of the `kswapd` and `direct_reclaim` methods includes the first and second memory reclamation methods described above. The first memory reclamation method can be achieved by executing the `shrink_lruvec` operation, and the second memory reclamation method can be achieved by executing the `shrink_slab` operation. For example... Figure 7As shown, a first memory reclamation method can be executed through the operating system kernel when memory reclamation is needed, and a second memory reclamation method can be executed by calling an asynchronous reclamation thread. Optionally, an asynchronous thread can be woken up by calling a specified library, which can then be used to execute the second memory reclamation method. For example... Figure 7 As shown, if a blockage occurs during the execution of shrink_callback, it will only block the second memory reclamation method and will not block the first memory reclamation method.

[0068] As one approach, during the execution of the second memory reclamation method, if the reclamation time of the driver that performed memory page reclamation earlier exceeds a second specified time, a second asynchronous thread is started to begin reclamation of memory pages for the driver that performs memory page reclamation later. It should be noted that when there are multiple drivers for an electronic device, memory page reclamation for multiple drivers can be performed serially. This can be achieved by calling the individual `shrink_callback` of each driver. However, blocking may still occur during the reclamation of memory pages for each driver. In such cases, to avoid increasing the overall time consumption of the memory reclamation process, a second asynchronous thread can be started to begin reclamation of memory pages for the driver that performs memory page reclamation later.

[0069] Optional, such as Figure 8 As shown, the asynchronous garbage collection thread can start a timer to time the memory reclamation operation of the driver currently performing memory page reclamation. Based on the timeout duration, it can determine whether to activate a second asynchronous thread to skip the currently timed-out driver and begin memory page reclamation for the driver that will perform memory page reclamation later through this second asynchronous thread. For example, as... Figure 8 As shown, when it is determined that the garbage collection time corresponding to the called shrink_callback1 is greater than the second specified time, the second asynchronous thread is started to reclaim the memory pages of the driver that performs memory page reclamation later.

[0070] For example, the electronic device includes drivers D1, D2, D3, and D4. Driver D1 is reclaimed first, followed by drivers D2, D3, and D4 in that order. When the asynchronous reclamation thread starts calling driver D1's `shrink_callback` to begin reclamation of driver D1, a timer can be started synchronously. If, after a second specified time interval, driver D1's `shrink_callback` has not completed its reclamation operation, a second asynchronous thread will be started to begin reclamation of drivers D2, D3, and D4. Similarly, if driver D2's `shrink_callback` has not completed its reclamation operation after a second specified time interval (the timer starts from the call to driver D2's `shrink_callback`), a second asynchronous thread will be started to begin reclamation of drivers D3 and D4.

[0071] It should be noted that, in order to control the number of second asynchronous threads started, a thread threshold can be configured. Before starting a second asynchronous thread each time, it is first checked whether the number of second asynchronous threads already started is less than the thread threshold. If it is less, it is allowed to start a new second asynchronous thread. If it is not less, no new second asynchronous thread will be started. Instead, it will continue to wait for the currently working second asynchronous threads to complete the memory reclamation operation.

[0072] As a way, such as Figure 9 As shown, during the execution of the first memory reclamation method, the memory pages to be reclaimed are traversed, and the current memory page to be reclaimed is obtained from the list of memory pages to be reclaimed. In response to obtaining the current memory page to be reclaimed, an attempt is made to acquire a lock on it. If the lock acquisition attempt fails, a third asynchronous thread is started to reclaim the current memory page and attempt to acquire locks on the memory pages ordered after it. This allows waiting for successful lock acquisition of the current memory page and attempting to acquire locks on the next memory page to be reclaimed to proceed concurrently, ensuring that the operation of waiting for successful lock acquisition of the current memory page does not affect the overall memory reclamation process and prevents the overall memory reclamation process from being blocked.

[0073] Optionally, if the lock acquisition attempt fails, check if there is any remaining space in the shared linked list. The shared linked list stores memory pages that need to be reclaimed by a third asynchronous thread. If there is remaining space, add the memory page to be reclaimed to the shared linked list and start the third asynchronous thread to reclaim the current memory page. If there is no remaining space, wait until the current memory page to be reclaimed becomes lockable, then acquire the lock on the current memory page to be reclaimed and reclaim it.

[0074] Next, we will proceed through... Figure 9 The workflow of the third asynchronous thread will be explained below. For example... Figure 9 As shown, when the third asynchronous thread is in a sleep state, it can detect whether there is a notification to wake it up. If so, the third asynchronous thread can be woken up from its sleep state, allowing it to check if there are any remaining memory pages in the shared linked list. If so, a memory page can be retrieved from the shared linked list, and a lock can be attempted on the retrieved memory page until it is successfully locked. After successfully locking the retrieved memory page, it is checked whether the memory page can be reclaimed. If it can be reclaimed, the retrieved memory page is reclaimed, and the lock is released after reclamation. If it is determined that the memory page cannot be reclaimed, the memory page is returned to the operating system.

[0075] Optionally, if the lock acquisition attempt is successful, the system can further check whether the current memory page to be reclaimed can be reclaimed. If it can be reclaimed, the current memory page to be reclaimed is reclaimed, and then the lock on the reclaimed memory page is released. Conversely, if it is detected that the current memory page to be reclaimed cannot be reclaimed, the lock is released directly. The electronic device can determine whether a memory page can be reclaimed through reverse mapping. Reverse mapping refers to checking whether a user (e.g., an application) has recently accessed the memory page. If no user has recently accessed the memory page, it is determined that the memory page can be reclaimed; otherwise, the memory page is considered a frequently used page and cannot be reclaimed.

[0076] It should be noted that some steps in this embodiment can be executed by the operating system kernel, while other steps can be executed by the aforementioned specified library. Optionally, Figure 10 The steps shown—attempting to acquire a lock on the current memory page to be reclaimed, checking if the shared list is full, storing the page in the shared list, and waking up the third asynchronous thread—can be performed by a specified library. In this case, it can be instrumented in the operating system kernel so that the specified library can be called to perform the corresponding steps.

[0077] In this embodiment, triggering the operating system to perform memory reclamation may include: triggering the operating system to execute a third memory reclamation method, which involves reclamating the memory pages corresponding to the processing device. The processing device may be a processor (CPU) or a core of a multi-core processor.

[0078] Optionally, there may be multiple processor devices in an electronic device. In this case, triggering the operating system to execute the third memory reclamation method may include: triggering memory reclamation on multiple processor devices; if the target processor among the multiple processor devices completes memory page reclamation, allocating the reclaimed memory pages to memory-using objects, wherein the number of reclaimable memory pages corresponding to the target processor is greater than a third threshold. Optionally, the priority of the memory reclamation thread corresponding to the target processor may be increased.

[0079] In scenarios with multiple processing devices, the amount of reclaimable memory pages may differ for each device. After memory reclamation begins across multiple devices, the process synchronously waits for each device to complete its reclamation before returning the reclaimed memory pages. However, as mentioned earlier, different processing devices have varying amounts of reclaimable memory pages (e.g., ppppages). If a particular processing device has few reclaimable memory pages but its reclamation operation is slow, waiting for that device becomes unwise. Therefore, by pre-determining the amount of reclaimable memory pages for each processing device, it's possible to identify which devices require waiting, thus achieving a balance between waiting time and the gained benefits (reclaimed memory pages).

[0080] For example, the electronic device includes processing device C1, processing device C2, processing device C3, and processing device C4. The amount of reclaimable memory pages in processing device C1 is P1, in processing device C2 is P2, in processing device C3 is P3, and in processing device C4 is P4. If P3 and P4 are greater than a third threshold, then processing devices C3 and C4 can be used as target processing devices. During the execution of the third memory reclamation method, if it is detected that processing devices C3 and C4 have completed their memory page reclamation operations, the reclaimed memory pages will be returned to the memory user, instead of continuing to wait for processing devices C1 and C2 to complete their reclamation operations.

[0081] Furthermore, it should be noted that the processing device performs memory page reclamation by triggering a corresponding memory reclamation thread. However, the priority of the memory reclamation thread corresponding to the processing device is usually low. Therefore, when the processing device needs to handle data processing tasks and perform memory page reclamation at the same time, the memory reclamation thread will be delayed, which may cause the processing device to fail to complete the memory page reclamation in a timely manner. This may result in a situation where a high-priority user thread waits for a low-priority user thread. For example, if the memory user that triggers the memory allocation request is user thread A, and the memory reclamation operation is triggered according to the method provided in this application embodiment, during the execution of the third memory reclamation method, if a processing device needs to handle user thread B (which has a lower priority than user thread A) and also needs to perform memory page reclamation, then the higher-priority user thread A may have to wait for the lower-priority user thread B. Therefore, in this embodiment, by increasing the priority of the memory reclamation thread corresponding to the target processing device, the target processing device can perform memory page reclamation operations with higher priority. This improves the efficiency of memory reclamation, enabling faster allocation of the required memory pages to memory-using objects, while also ensuring that memory-using objects with higher priority can run before memory-using objects with lower priority.

[0082] For example, taking a CPU as the processing device, such as Figure 11 As shown, in the case of multiple CPUs, the electronic device can first traverse each CPU to determine whether the ppppages inventory of each CPU is greater than a third threshold. Then, the CPU with the ppppages inventory greater than the third threshold is designated as the target CPU. The priority of the memory reclamation thread of the target CPU is dynamically adjusted to elevate its priority. Afterwards, the memory reclamation threads of multiple CPUs are awakened to begin memory reclamation. Once the target CPU has completed the reclamation of its ppppages inventory, the reclaimed memory pages can be allocated to memory-using objects.

[0083] It should be noted that, in order for the relevant operating system to support the third memory reclamation method provided in this embodiment, code that supports the third memory reclamation method provided in this embodiment is written into a designated library. In this case, if the aforementioned third memory reclamation method needs to be executed, the steps included in the third memory reclamation method can be performed by calling the designated library.

[0084] It should be noted that if no corresponding memory page is identified in the memory pool, the operating system will be triggered to perform a memory reclamation operation. During this memory reclamation operation, the first memory reclamation method, the second memory reclamation method, and the third memory reclamation method can be executed in parallel.

[0085] Furthermore, even when there are first, second, and third memory reclamation methods available, the operation can be triggered to execute only one method during the memory reclamation process. For example, only the first memory reclamation method or only the second memory reclamation method can be executed.

[0086] This embodiment provides a memory page processing method that enables the pre-establishment of a memory pool and the pre-allocation of memory pages from the operating system into the memory pool. When a memory-using object requests a memory page, the required memory page can be directly obtained from the memory pool. This avoids triggering memory reclamation operations by the operating system when a memory-using object needs a memory page, further reducing the probability of memory reclamation blocking during the operation and preventing the memory-using object from obtaining the required memory page in a timely manner. This improves the efficiency of allocating the required memory pages to memory-using objects.

[0087] Furthermore, in this embodiment, if there are no memory pages required by the memory-using object in the memory pool, the memory reclamation operation via the operating system has not yet been triggered, so that the required memory pages can be allocated to the memory-using object. Moreover, when the memory reclamation operation includes a first memory reclamation method, a second memory reclamation method, and a third memory reclamation method, optimizations have been made for the first, second, and third memory reclamation methods respectively, improving their respective reclamation efficiency and effectiveness. This further enables more efficient memory reclamation when the memory reclamation operation is initiated, thereby improving the efficiency of allocating memory to the memory-using object.

[0088] Furthermore, in this embodiment, asynchronous optimizations were performed on the driver's memory reclamation interface, page locking, and thread priorities. This effectively solves the performance lag issues caused by slow memory reclamation and memory-using object blocking due to these factors. It also effectively reduces the processor load caused by memory reclamation.

[0089] Please see Figure 12 This application provides a memory page processing apparatus 400, which includes:

[0090] The memory identifier acquisition unit 410 is used to acquire the identifier of the memory page requested by the memory allocation request in response to a memory allocation request triggered by a memory user object.

[0091] The memory processing unit 420 is used to obtain the corresponding identified memory page from the memory pool and allocate it to the memory user if there is an identified memory page in the pre-established memory pool. The memory pages in the memory pool are obtained in advance from the operating system of the electronic device.

[0092] In one approach, the identifier includes the type of the memory page. Specifically, the memory identifier acquisition unit 410 is used to acquire a memory page of the type from a pre-established memory pool and allocate it to the memory-using object if a memory page of that type exists in the pool.

[0093] In one approach, the memory pool includes multiple linked lists, each with a different identifier. Specifically, the memory processing unit 420, if a target linked list exists in the pre-established memory pool, retrieves the memory page with the corresponding identifier from the target linked list and allocates it to the memory-using object. The identifier of the target linked list is the same as the identifier of the requested memory page.

[0094] Optionally, the memory processing unit 420 is further configured to, if the number of remaining memory pages in the target linked list is lower than a first quantity threshold, start a first asynchronous thread to request the corresponding memory pages from the operating system and configure the requested memory pages into the target linked list.

[0095] Optionally, the memory processing unit 420 is further configured to, if a target linked list exists in the pre-established memory pool, detect whether the number of memory pages in the target linked list is greater than a second quantity threshold; if it is greater than the second quantity threshold, retrieve the memory page with the corresponding identifier from the target linked list and allocate it to the memory user. If it is not greater than the second quantity threshold, wait for a first specified time period and then detect again whether the number of memory pages in the target linked list is greater than the second quantity threshold; if it is greater than the second quantity threshold, retrieve the memory page with the corresponding identifier from the target linked list and allocate it to the memory user; if it is not greater than the second quantity threshold, trigger the operating system to perform a memory reclamation operation to allocate the memory pages reclaimed by the memory reclamation operation to the memory user.

[0096] In one manner, the memory processing unit 420 is also used to trigger the operating system to perform a memory reclamation operation if there are no identified memory pages in the pre-established memory pool, so as to allocate the memory pages reclaimed by the memory reclamation operation to the memory-using object.

[0097] In one manner, the memory processing unit 420 is also used to trigger the operating system to execute a first memory reclamation method and a second memory reclamation method in parallel during the memory reclamation process. The first memory reclamation method is used to reclaim the memory pages of the application, and the second memory reclamation method is used to reclaim the memory pages of the electronic device's driver.

[0098] Optionally, the memory processing unit 420 is specifically configured to execute a first memory reclamation method through the operating system kernel, and to execute a second memory reclamation method in parallel through a specified library set in the operating system. The memory processing unit 420 is also specifically configured to prevent the operating system kernel from executing the second memory reclamation method.

[0099] In one approach, an electronic device may have multiple drivers, and these drivers may be reclaimed in different orders. Specifically, the memory processing unit 420 is further configured to, during the execution of the second memory reclamation method, if the reclamation time of the driver that performed memory page reclamation earlier exceeds a second specified time, then start a second asynchronous thread to begin reclamation of memory pages for the driver that performed memory page reclamation later.

[0100] Optionally, the memory processing unit 420 is further configured, during the execution of the first memory reclamation method, to, in response to acquiring the current memory page to be reclaimed, attempt to lock the current memory page to be reclaimed; if the lock acquisition attempt fails, start a third asynchronous thread to reclaim the current memory page to be reclaimed, and attempt to lock the memory pages to be reclaimed that are sorted after the current memory page to be reclaimed. If the lock acquisition attempt fails, check if there is any remaining space in the shared linked list, which is used to store memory pages that need to be reclaimed by the third asynchronous thread; if there is remaining space, add the memory pages to be reclaimed to the shared linked list, and start the third asynchronous thread to reclaim the current memory page to be reclaimed. If there is no remaining space, wait until the memory page to be reclaimed becomes lockable, then lock the memory page to be reclaimed, and reclaim the memory page to be reclaimed.

[0101] Optionally, the memory processing unit 420 is further configured to trigger the operating system to execute a third memory reclamation method, which involves reclaiming the memory pages corresponding to the processing devices. Specifically, the memory processing unit 420 is configured to trigger memory reclamation for multiple processing devices; if the target processing device among the multiple processing devices completes memory page reclamation, the reclaimed memory pages are allocated to memory-using objects, wherein the number of reclaimable memory pages corresponding to the target processing device is greater than a third threshold. Optionally, the memory processing unit 420 is further configured to increase the priority of the memory reclamation thread corresponding to the target processing device.

[0102] The memory page processing device provided in this embodiment avoids the probability of triggering the operating system to perform memory reclamation when a memory user needs a memory page. This further reduces the probability of memory user being unable to obtain the required memory page in a timely manner due to memory reclamation blocking during the operating system's memory reclamation operation, thereby improving the efficiency of allocating the required memory page to the memory user.

[0103] It should be noted that the device embodiments in this application correspond to the aforementioned method embodiments. The specific principles in the device embodiments can be found in the content of the aforementioned method embodiments, and will not be repeated here.

[0104] The following will combine Figure 13 This application describes an electronic device.

[0105] Please see Figure 13 Based on the aforementioned memory page processing method and apparatus, this application embodiment also provides an electronic device 1000 capable of executing the aforementioned memory page processing method. The electronic device 1000 includes one or more (only one shown in the figure) processors 102, a memory 104, a network module 106, a sensor module 108, and an audio acquisition device 110, all coupled to each other. The memory 104 stores programs capable of executing the contents of the aforementioned embodiments, and the processor 102 can execute the programs stored in the memory 104.

[0106] The processor 102 may include one or more processing cores. The processor 102 connects to various parts within the electronic device 1000 using various interfaces and lines, and performs various functions and processes data of the electronic device 1000 by running or executing instructions, programs, code sets, or instruction sets stored in the memory 104, and by calling data stored in the memory 104. Optionally, the processor 102 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 102 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 102 and may be implemented separately using a communication chip.

[0107] The memory 104 may include random access memory (RAM) or read-only memory (ROM). The memory 104 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 104 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below.

[0108] The network module 106 is used to enable information interaction between the electronic device 1000 and other devices, such as transmitting device control commands, manipulation request commands, and status information acquisition commands. However, the network module 106 may differ depending on the specific device being played by the audio playback device 200.

[0109] Sensor module 108 may include at least one sensor. Specifically, sensor module 108 may include, but is not limited to, a light sensor, a motion sensor, a pressure sensor, an infrared thermal sensor, a distance sensor, an acceleration sensor, and other sensors.

[0110] The pressure sensor is a sensor that detects pressure generated by pressing on the electronic device 1000. Specifically, the pressure sensor detects pressure generated by contact or pressing between the user and the audio playback device, such as pressure generated by contact or pressing between the user's ear and the mobile terminal. Therefore, the pressure sensor can be used to determine whether contact or pressing has occurred between the user and the electronic device 1000, and the magnitude of the pressure.

[0111] The accelerometer can detect the magnitude of acceleration in various directions (generally three axes), and when stationary, it can detect the magnitude and direction of gravity. It can be used for applications such as identifying the posture of the electronic device 1000 (e.g., screen orientation switching, related games, magnetometer posture calibration), and vibration recognition functions (e.g., pedometer, tapping). Additionally, the electronic device 1000 can also be equipped with other sensors such as a gyroscope, barometer, hygrometer, and thermometer, which will not be elaborated upon here.

[0112] An audio acquisition device 110 is used to acquire audio signals. Optionally, the audio acquisition device 110 includes multiple audio acquisition components. These audio acquisition components can be microphones.

[0113] In one approach, the network module of the electronic device 1000 is a radio frequency (RF) module. This RF module is used to receive and transmit electromagnetic waves, converting electromagnetic waves into electrical signals, thereby enabling communication with a communication network or other devices. The RF module may include various existing circuit elements used to perform these functions, such as antennas, RF transceivers, digital signal processors, encryption / decryption chips, user identity modules (SIM cards), memory, etc. For example, the RF module can interact with external devices by transmitting or receiving electromagnetic waves, thereby receiving audio signals transmitted by external devices.

[0114] Furthermore, the electronic device 1000 may also include an image acquisition device for image acquisition. For example, the image acquisition device can be used to capture video, still images, or moving images.

[0115] Please refer to Figure 14 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 800 stores program code that can be called by a processor to execute the methods described in the above method embodiments.

[0116] The computer-readable storage medium 800 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 800 has storage space for program code 810 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 810 may be compressed, for example, in a suitable form.

[0117] In summary, the memory page processing method, apparatus, and electronic device provided in this application, upon responding to a memory allocation request triggered by a memory user, can first obtain the identifier of the memory page requested in the memory allocation request. Then, if a memory page with the identifier is found in a pre-established memory pool, the corresponding memory page is retrieved from the memory pool and allocated to the memory user. This method allows for the pre-establishment of a memory pool and the pre-allocation of memory pages from the operating system. When a memory user requests a memory page, the required memory page can be directly retrieved from the memory pool, thus avoiding the probability of triggering memory reclamation operations when a memory user needs a memory page. This further reduces the probability of memory reclamation blocking during the operating system's memory reclamation process, preventing the memory user from timely obtaining the required memory page, thereby improving the efficiency of allocating the required memory pages to the memory user.

[0118] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for handling memory pages, characterized in that, Applied to electronic devices, the method includes: In response to a memory allocation request triggered by a memory-using object, obtain the identifier of the memory page requested in the memory allocation request; If a memory page with the identifier is present in a pre-established memory pool, the memory page corresponding to the identifier is obtained from the memory pool and allocated to the memory user. The memory pages in the memory pool are obtained in advance from the operating system of the electronic device, and the memory pool stores multiple memory pages with the identifier. If the memory page identified by the identifier is not present in the pre-established memory pool, the operating system is triggered to perform a memory reclamation operation to allocate the memory page reclaimed by the memory reclamation operation to the memory-using object. Triggering the memory reclamation operation of the operating system includes: triggering the operating system to execute a first memory reclamation method through the kernel of the operating system and to execute a second memory reclamation method in parallel through a specified library set in the operating system, and preventing the kernel of the operating system from executing the second memory reclamation method. The first memory reclamation method is used to reclaim the memory pages of the application, and the second memory reclamation method is used to reclaim the memory pages of the driver of the electronic device.

2. The method according to claim 1, characterized in that, The identifier includes the type of memory page. The step of retrieving the memory page corresponding to the identifier from the memory pool and allocating it to the memory user if a pre-established memory pool contains a memory page with the identifier includes: If a memory pool of the specified type exists, a memory page of the specified type is retrieved from the memory pool and allocated to the memory user.

3. The method according to claim 1, characterized in that, The memory pool includes multiple linked lists, each with a different identifier; if a memory page with the specified identifier exists in the pre-established memory pool, retrieving the memory page corresponding to the identifier from the memory pool and allocating it to the memory user includes: If a target linked list exists in the pre-established memory pool, the memory page corresponding to the identifier is obtained from the target linked list and allocated to the memory user. The identifier corresponding to the target linked list is the same as the identifier of the memory page to be allocated.

4. The method according to claim 3, characterized in that, If a target linked list exists in the pre-established memory pool, after retrieving the memory page corresponding to the identifier from the target linked list and allocating it to the memory user object, the process further includes: If the number of remaining memory pages in the target linked list is less than a first quantity threshold, a first asynchronous thread is started to request the corresponding memory pages from the operating system, and the requested memory pages are configured into the target linked list.

5. The method according to claim 4, characterized in that, If a target linked list exists in the pre-established memory pool, retrieving the memory page corresponding to the identifier from the target linked list and allocating it to the memory user object includes: If a target linked list exists in the pre-established memory pool, check whether the number of memory pages in the target linked list is greater than the second quantity threshold. If the number exceeds the second threshold, the memory page corresponding to the identifier is retrieved from the target linked list and allocated to the memory user.

6. The method according to claim 5, characterized in that, The method further includes: If the number of memory pages in the target linked list is not greater than the second quantity threshold, then wait for a first specified time period and then check again whether the number of memory pages in the target linked list is greater than the second quantity threshold. If the number exceeds the second threshold, the memory page corresponding to the identifier is retrieved from the target linked list and allocated to the memory user. If the number is not greater than the second threshold, the operating system is triggered to perform a memory reclamation operation to allocate the memory pages reclaimed by the memory reclamation operation to the memory user.

7. The method according to claim 1, characterized in that, The electronic device has multiple drivers, and the recycling order of these drivers is different. The method further includes: During the execution of the second memory reclamation method, if the reclamation time of the driver that performed memory page reclamation earlier is greater than the second specified time, then the second asynchronous thread is started to reclamation the memory pages of the driver that performed memory page reclamation later.

8. The method according to claim 7, characterized in that, The method further includes: During the execution of the first memory reclamation method, in response to obtaining the current memory page to be reclaimed, an attempt is made to lock the current memory page to be reclaimed; If the attempt to hold the lock fails, a third asynchronous thread is started to reclaim the current memory page to be reclaimed, and to attempt to hold the lock on the memory pages to be reclaimed that are sorted after the current memory page to be reclaimed.

9. The method according to claim 8, characterized in that, If the attempt to hold the lock fails, a third asynchronous thread is started to reclaim the currently unclaimed memory pages, including: If the attempt to hold the lock fails, check if there is any remaining space in the shared linked list, which is used to store memory pages that need to be reclaimed by a third asynchronous thread; If there is remaining space, the memory pages to be reclaimed are added to the shared linked list, and a third asynchronous thread is started to reclaim the current memory pages to be reclaimed.

10. The method according to claim 9, characterized in that, The method further includes: If there is no remaining space, then when the memory page to be reclaimed becomes lockable, lock the memory page to be reclaimed and reclaim it.

11. The method according to claim 1 or 6, characterized in that, The step of triggering the operating system to perform memory reclamation also includes: The operating system is triggered to execute a third memory reclamation method, which involves reclaiming the memory pages corresponding to the processing device.

12. The method according to claim 11, characterized in that, The number of processing devices is multiple, and the method of triggering the operating system to execute the third memory reclamation includes: Trigger memory reclamation for multiple of the aforementioned processing devices; If the target processing device among the plurality of processing devices completes memory page reclamation, the reclaimed memory pages are allocated to the memory user, wherein the number of reclaimable memory pages corresponding to the target processing device is greater than the third threshold.

13. The method according to claim 12, characterized in that, The method further includes: Increase the priority of the memory reclamation thread corresponding to the target processing device.

14. A memory page processing apparatus, characterized in that, Operating in an electronic device, the device includes: The memory identifier acquisition unit is used to acquire the identifier of the memory page requested by the memory allocation request in response to a memory allocation request triggered by a memory user object. A memory processing unit is configured to, if a pre-established memory pool contains a memory page with the identified identifier, retrieve the corresponding memory page from the memory pool and allocate it to the memory user, wherein the memory pages in the memory pool are pre-allocated from the operating system of the electronic device, and the memory pool stores multiple identified memory pages; if the pre-established memory pool does not contain an identified memory page, trigger the operating system to perform a memory reclamation operation to allocate the reclaimed memory pages to the memory user, wherein triggering the operating system to perform a memory reclamation operation includes: triggering the operating system to execute a first memory reclamation method through the kernel of the operating system and to execute a second memory reclamation method in parallel through a designated library set in the operating system, and preventing the kernel of the operating system from executing the second memory reclamation method, wherein the first memory reclamation method is used to reclaim the memory pages of the application, and the second memory reclamation method is used to reclaim the memory pages of the driver of the electronic device.

15. An electronic device, characterized in that, It includes one or more processors and memory; one or more programs are stored in the memory and configured to be executed by the one or more processors according to any one of claims 1-13.

16. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program code, wherein the program code, when executed by a processor, performs the method according to any one of claims 1-13.

Citation Information

Patent Citations

  • Memory management method, device and equipment and storage medium

    CN111352863A

  • Memory allocation method and device

    CN113495789A