Memory page processing method, apparatus, and electronic device
By identifying the target object among multiple memory-using objects and performing fine-grained management, the problem of inflexible memory page replacement operations in existing technologies is solved, achieving more efficient memory space utilization and improved system performance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
- Filing Date
- 2023-09-27
- Publication Date
- 2026-04-10
AI Technical Summary
Existing technologies do not allow for flexible memory page replacement operations, making it impossible to manage memory usage in a fine and flexible manner when multiple memory-using objects are involved.
The method involves identifying the target object from multiple memory users and replacing candidate memory pages with the first storage area. Specifically, the target object is determined based on factors such as memory access latency requirements, user identification codes, and program grouping. The replacement page is selected based on the memory page usage and access frequency.
It enables fine-grained and flexible memory page replacement operations when multiple memory-using objects are involved, improving memory space utilization efficiency, avoiding uniform processing of all memory pages, and enhancing system performance.
Smart Images

Figure CN119718609B_ABST
Abstract
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] During the operation of an electronic device, the device can manage memory pages in memory. For example, the device can swap memory pages to free up memory space for other processes. However, the swapping operation of memory pages in this method is not flexible enough. 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: determining a target object from a plurality of memory-using objects; and replacing at least a portion of the memory pages in a candidate memory page region with memory pages in a first storage region corresponding to the target object, wherein the candidate memory pages are memory pages in a second storage region located in the memory of the electronic device.
[0005] Secondly, this application provides a memory page processing apparatus operating in an electronic device. The apparatus includes: a target determination unit for determining a target object from a plurality of memory usage objects; and a memory page processing unit for replacing at least a portion of candidate memory pages with memory pages in a first storage region, wherein the candidate memory pages are memory pages in a second storage region corresponding to the target object, and the second storage region is located in the memory of the electronic device.
[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. When multiple memory users exist, a target memory user can be identified from among them, and at least a portion of the candidate memory pages can be swapped to a first storage area. This allows for the selection of memory pages from a single memory user when swapping memory pages from a second storage area to the first storage area, instead of selecting pages from all memory pages in the second storage area. This makes the memory page swapping operation more precise and flexible. 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 an embodiment of this application is shown;
[0011] Figure 2 A schematic diagram illustrating one method of establishing program groups in an embodiment of this application is shown;
[0012] Figure 3 This illustration shows a schematic diagram of dividing memory into uncompressed and compressed memory regions in an embodiment of this application.
[0013] Figure 4 A schematic diagram illustrating the determination of candidate memory pages in an embodiment of this application is shown;
[0014] Figure 5 This illustration shows a schematic diagram of the moment when candidate memory pages are compared and replaced with memory compression regions in an embodiment of this application;
[0015] Figure 6 A flowchart of a memory page processing method according to another embodiment of this application is shown;
[0016] Figure 7 A flowchart of a memory page processing method according to another embodiment of this application is shown;
[0017] Figure 8 A flowchart of a memory page processing method according to another embodiment of this application is shown;
[0018] Figure 9 This illustration shows a schematic diagram of the first memory threshold following the increase in the number of programs in an embodiment of this application;
[0019] Figure 10 This paper shows a structural block diagram of a memory page processing apparatus according to an embodiment of the present application;
[0020] Figure 11 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.
[0021] Figure 12 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
[0022] 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.
[0023] Main memory, also known as RAM, is directly addressable storage space made of semiconductor devices. Programs (e.g., processes or threads) in electronic devices typically require memory to perform data processing during execution. For example, during program startup, it acquires corresponding memory for use during or after startup. Data in memory is usually managed through memory pages. During the operation of an electronic device, it can manage memory pages. For example, an electronic device can swap memory pages to free up memory space for other processes. However, this method of swapping memory pages is not flexible enough.
[0024] Therefore, the inventors have proposed the memory page processing method, apparatus, and electronic device of this application. When there are multiple memory users, a target object can be determined from among the multiple memory users, and then at least a portion of the candidate memory pages can be replaced to a first storage area. Thus, by means of the above method, when there are multiple memory users and it is necessary to replace memory pages from a second storage area to the first storage area, memory pages can be selected for replacement from the memory pages corresponding to a single memory user, instead of selecting replacement pages from all memory pages in the second storage area. This makes the memory page replacement operation more precise and flexible.
[0025] The embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0026] Please see Figure 1 This application provides a memory page processing method, which includes:
[0027] S110: Determine the target object from multiple memory-using objects.
[0028] In this embodiment, a memory-using object can be understood as an object that uses the memory of an electronic device. Optionally, a memory-using object can be a program, or it can be a group of programs divided by a program. The program grouping can be implemented based on the Memory Control Group (Memcg) technology of an operating system (e.g., Linux). When the memory-using object is a program group, each program group can include at least one program. In this embodiment, a program can be understood as a complete application, or as a process or thread included in an application.
[0029] In cases where there are multiple program groups, these groups can be obtained by dividing multiple programs. Optionally, the multiple program groups can be obtained by dividing the programs based on their target features, wherein the programs within the same program group share the same target features. In the embodiments of this application, the target features can be implemented in various ways.
[0030] Optionally, the target feature includes the program's User Identification (UID).
[0031] When programs are grouped based on user identifiers, programs within the same program group have the same user identifier. Specifically, if a program represents a process, then the same program group can include multiple processes with the same user identifier. For example, a single application may further include multiple programs (e.g., multiple processes), and because these multiple programs belong to the same application, their user identifiers can be the same. In this case, these multiple programs can be grouped into the same program group.
[0032] For example, such as Figure 2As shown, the electronic device includes application programs A1, A2, and A3. Application program A1 includes programs A11, A12, and A13. Application program A2 includes programs A21 and A22. Application program A3 includes programs A31, A32, A33, and A34. Since programs A11, A12, and A13 all belong to application program A1, they will have the same user identification code. Similarly, programs A21 and A22 will have the same user identification code, and programs A31, A32, A33, and A34 will also have the same user identification code. When programs with the same identifier code are grouped into the same group, programs A11, A12, and A13 can be grouped into the same program group G1, programs A21 and A22 can be grouped into the same program group G2, and programs A31, A32, A33, and A34 can be grouped into the same program group G3.
[0033] Alternatively, the target characteristics may include the program's memory access latency requirements.
[0034] In this embodiment, memory access latency requirement characterizes the timeliness requirement of a program when performing memory access. For example, some programs expect access requests to be responded to quickly. A quick response can be understood as the requested data being returned to the program quickly, or the requested computation in memory being returned with a quick result. Optionally, the memory access latency requirement can represent the maximum acceptable latency time for the program. Alternatively, it can represent the maximum number of memory access delays the program can accept within a specified time period. In this case, the application whose memory access latency requirement meets the specified condition can be used as the first target application. Optionally, the specified condition can be: the maximum latency time is less than the specified time period, or the maximum number of memory access delays is less than the specified number.
[0035] Optionally, the electronic device can group applications based on their memory access latency requirements, resulting in multiple application groups. Within the same application group, the applications included have the same or similar memory access latency requirements. In this case, one or more applications from these application groups can be selected as the first target application. For example, the application in the application group with the shortest maximum acceptable latency can be selected as the first target application. Alternatively, the application in the application group with the fewest possible maximum number of memory access latency occurrences can be selected as the first target application.
[0036] After obtaining the memory access latency requirements of the programs to be grouped, the corresponding program groups can be configured for the programs to be grouped.
[0037] One approach is to pre-configure multiple application groups and assign corresponding memory access latency requirements to each group. In this method, after obtaining the applications to be grouped, the memory access latency requirements of the applications to be grouped can be compared with the corresponding memory access latency requirements configured for each application group. Application groups whose memory access requirements are similar to or identical to those of the applications to be grouped are then assigned to those applications.
[0038] In this context, two similar memory access latency requirements can be understood as representing a close approximation of latency demands. For example, if a memory access latency requirement represents the maximum acceptable latency time for a program, then the close approximation of latency demands means the difference between the maximum acceptable latency times is less than a specified threshold. Similarly, if a memory access latency requirement represents the maximum number of memory access delays a program can accept within a specified time period, then the close approximation of latency demands means the difference between the maximum number of memory access delays is less than a specified threshold.
[0039] For example, the following table can be used to illustrate the grouping of multiple programs:
[0040] ID Grouping identifier Grouped memory access latency requirements 1 Group G1 T1 2 Group G2 T2 3 Group G3 T3
[0041] As shown in the table above, T1, T2, and T3 in the memory access latency requirements of the grouped applications represent the maximum acceptable latency time. T1, T2, and T3 can be non-negative numbers. For example, T1 can be 0.5 seconds, T2 can be 1 second, and T3 can be 2 seconds. Based on the table, after obtaining the applications to be grouped, if the maximum acceptable latency time represented by the memory access latency requirement of the application to be grouped is T1, then the application to be grouped will be assigned to group G1. If the maximum acceptable latency time represented by the memory access latency requirement of the application to be grouped is T3, then the application to be grouped will be assigned to group G3. If the maximum acceptable latency time represented by the memory access latency requirement of the application to be grouped is T4, and the difference between T4 and T1 is less than a specified threshold, then it is determined that the memory access latency requirement of the application to be grouped is similar to that of group G1, and therefore the application to be grouped will be assigned to group G1.
[0042] As one approach, if the memory access latency requirements of the program to be grouped are different from and dissimilar to the memory access latency requirements of each group, it can be first checked whether creating a new program group is allowed. If creating a new program group is allowed, a new program group is created, and the memory access requirements of the program to be grouped are used as the memory access requirements of the new program group. If creating a new program group is not allowed, then from the currently established program groups, the group whose corresponding memory access latency requirements are closest to those of the program to be grouped is determined, and this group is selected as the program group corresponding to the program to be grouped.
[0043] Optionally, electronic devices can determine whether to allow the creation of new program groups in a variety of ways.
[0044] As one approach, the user of the electronic device can configure whether or not to allow the creation of new application groups. In this method, a configuration interface can be displayed on the electronic device, showing options to disable or allow the creation of new application groups. The user can then select the desired option based on their needs.
[0045] As another method of determination, the electronic device can determine whether to allow the creation of a new application group based on the currently remaining storage space. It should be noted that when a new application group is created, corresponding storage space needs to be allocated for that new application group to store its corresponding data. This data may include the data of the application group itself, as well as the data stored within that application group. Therefore, each newly created application group consumes more storage space. In this case, the electronic device can determine that it will not allow the creation of a new application group if it detects insufficient remaining storage space, and conversely, it can determine that it will allow the creation of a new application group if it detects sufficient remaining storage space.
[0046] Optionally, if the remaining storage space is detected to be greater than a specified storage threshold, it can be determined that the remaining storage space is sufficient; otherwise, it can be determined that the remaining storage space is insufficient.
[0047] It should be noted that, in the embodiments of this application, the memory access latency requirements of the application can be pre-configured by the application developers or determined by the electronic device based on the application's category and / or running status. Correspondingly, when the application's memory access latency requirements can be characterized by memory access latency levels, the application's memory access latency level can be determined based on the application's category and / or running status.
[0048] For example, if an application is categorized as either a foreground application or a system application, then its memory access latency requirement indicates that its memory access needs should be responded to relatively quickly. Conversely, if an application is categorized as a background application, then its memory access latency requirement indicates that its memory access needs can be delayed for a certain period before being responded to.
[0049] In this context, "foreground operation" can be understood as the state of a program or process in an operating system, indicating that the program or process is executing and can be directly interacted with by the user. When a program is in the foreground running state, its window will be displayed in the foreground, and the user can directly interact with it, such as typing text or clicking buttons. In contrast, "background operation" indicates that the program or process is running in the background, and the user cannot directly interact with it. Background running programs typically perform tasks that do not require user interaction, such as data backup or file download.
[0050] It's important to note that the memory access requirements of the same application can vary depending on its running state. For example, for an audio player, in its initial state before audio playback, the operations performed may be less time-sensitive, such as page switching, music searching, or configuration. However, once the audio player begins playing audio, it retrieves audio data from the network in real time, loads it into memory for decoding and playback. Therefore, the audio playback operations performed by the audio player are highly time-sensitive.
[0051] For example, in a game program, the operations performed during startup but before entering the game's control panel can include those with low time sensitivity. These low-time sensitivity operations can include page switching, game configuration, or purchasing in-game items. Once the game program is running and the control panel is displayed, it retrieves game data from the network in real time (e.g., data from other players or real-time map data) and loads it into memory for processing. Therefore, during this state, the game program needs to respond quickly to memory access requests. While the control panel is displayed, the game objects within it can be controlled.
[0052] In this embodiment of the application, programs in a program group can also be deleted. As mentioned above, there are multiple ways to determine the programs to be grouped, and in this case, there are also multiple ways to delete programs in a program group.
[0053] The identified target object can be understood as a memory-using object that requires memory page replacement, and this memory page to be replaced exists in the memory buffer area. Specifically, if the memory-using object is a program group, the identified target object can be the target program group. If the memory-using object is a program, the target object is the target program.
[0054] In the embodiments of this application, there are multiple ways to determine the target object. For example, when the memory-using object is a program group, the target program group (a target object) can be determined based on the overall memory buffer area occupied by each program group. Alternatively, the target program group can be determined based on the running status of the programs within each program group. Furthermore, when the memory-using object is a program, the target program (a target object) can be determined directly based on the program's running status.
[0055] S120: Replace at least a portion of the candidate memory pages with the first storage area, wherein the candidate memory pages are the memory pages in the second storage area that correspond to the target object, and the second storage area is located in the memory of the electronic device.
[0056] One approach is to directly swap memory pages in memory to the electronic device's hard drive, external storage device, or network. Alternatively, the swapped memory pages can be moved to a compressed memory region within memory. Furthermore, memory pages within a compressed memory region can also be further swapped to the electronic device's hard drive, external storage device, or network.
[0057] In this scenario, loading memory pages from the first storage area into memory is slower than loading memory pages from the second storage area. Optionally, the first storage area can be a disk of an electronic device, an external storage device, or a network, and the second storage area can be a compressed memory area. Alternatively, the first storage area can be a compressed memory area within memory, and the second storage area can be an uncompressed area within memory.
[0058] It's important to note that the memory of an electronic device can be divided into uncompressed and compressed memory regions. Memory pages in the uncompressed region are not compressed, while those in the compressed region are compressed. In this case, memory pages in the uncompressed region can be directly used by memory objects. However, if memory pages in the compressed region are needed, they must first be decompressed before being loaded into the uncompressed region. In essence, swapping memory pages from the uncompressed region to the compressed region can be understood as compressing memory pages from the uncompressed region and then swapping them into the compressed region. For example,... Figure 3 As shown, the memory of the electronic device is divided into an uncompressed region and a compressed region. Memory pages P1 and P2 in the uncompressed region are uncompressed memory pages. Memory pages P4 and P5 in the compressed region are compressed memory pages.
[0059] Optionally, a memory compression region can be established using zram. Memory pages swapped into the memory compression region are compressed to reduce their storage space usage. It's important to note that memory pages swapped out of memory may be reused and then need to be loaded back into memory. Memory pages swapped into the memory compression region can be loaded back into memory much faster than those swapped out of memory. However, the size of the memory compression region is limited. Therefore, in some cases, it may be necessary to swap memory pages within the memory compression region to locations outside of memory to ensure sufficient space within the memory compression region.
[0060] After identifying the target object, the memory pages in the second storage area corresponding to the target object can be used as candidate memory pages. Here, the memory pages corresponding to the target object can be understood as the memory pages where the recorded data belongs to the target object. For example, such as... Figure 4 As shown, the second storage area includes at least memory pages P1, P2, P3, P4, P5, and P6. The data recorded in memory pages P2, P3, and P4 belongs to memory user object D1. Therefore, if memory user object D1 is determined to be the target object, memory pages P2, P3, and P4 can be identified as candidate memory pages.
[0061] Once candidate memory pages are identified, memory pages can be selected from subsequent memory pages to be swapped into the first storage region. Optionally, some candidate memory pages can be swapped into the first storage region, or all candidate memory pages can be swapped into the first storage region.
[0062] It should be noted that, in the embodiments of this application, there are multiple ways to determine the memory page to be replaced from the candidate memory pages.
[0063] As one method, the number of memory pages to be swapped into the first storage region can be configured to a specified value. This specified value can be understood as a fixed value. In this method, when determining candidate memory pages, memory pages of the specified value can be selected from the candidate memory pages and swapped into the first storage region. Specifically, if the number of candidate memory pages is greater than the specified value, memory pages of the specified value can be selected from the kernel candidate memory pages and swapped into the first storage region. If the number of candidate memory pages is not greater than the specified value, all candidate memory pages can be swapped to a location outside of memory.
[0064] As another method of determination, when the first storage area is outside of memory and the second storage area is a memory compression area, the memory pages to be swapped out of memory can be determined based on the time it takes for candidate memory pages to be added to the second storage area. It should be noted that memory pages swapped out to the second storage area can be understood as memory pages that will not be accessed temporarily. Furthermore, the longer a memory page has been swapped out of the second storage area, the lower the probability of it being used again recently. Therefore, memory pages among the candidate memory pages whose time between being swapped out of the second storage area and the current time is greater than a specified time can be swapped out of memory. For example, ... Figure 5 As shown, if the candidate memory pages include memory pages P2, P3, and P4, where memory page P2 is swapped into the second storage area at time T1, memory page P3 at time T2, and memory page P4 at time T3, and the time elapsed between the current time and the time when memory page P2 is swapped into the second storage area is T0-T1, the time elapsed between the current time and the time when memory page P3 is swapped into the second storage area is T0-T2, and the time elapsed between the current time and the time when memory page P4 is swapped into the second storage area is T0-T3, if T0-T1 and T0-T2 are greater than a specified time elapsed, then it will be determined that memory pages P2 and P3 will be swapped to a location outside of memory.
[0065] As another approach, when the first storage area is located outside of main memory and the second storage area is a memory compression area, the memory pages to be swapped out of main memory can be determined based on their access frequency within a recently specified time period. It should be noted that some memory pages in the second storage area may be frequently swapped between main memory and the second storage area. If these memory pages, which frequently swap back and forth between main memory and the second storage area, are swapped to the first storage area, it may impact the performance of the objects using those memory pages. Therefore, optionally, memory pages whose access frequency within the recently specified time period is below a specified frequency threshold can be selected for swapping to the first storage area. Optionally, the recently specified time period can be one hour, one day, or one week.
[0066] In cases where there are multiple ways to determine the memory page to be swapped into the first storage area from the candidate memory pages, the specific method to determine the memory page to be swapped can be determined based on the current situation.
[0067] Optionally, the memory pages to be replaced can be determined based on the category of the memory usage object to which the candidate memory pages belong. It should be noted that some memory usage objects may be more likely to repeatedly process the same or similar data, such as document editing programs or image editing programs. However, some memory usage objects may be more likely to process new data, such as video playback programs or game programs.
[0068] The higher probability of processing the same or similar data repeatedly can be understood as processing the same or similar data more likely than processing new data. Conversely, the higher probability of processing new data can be understood as processing new data more likely than processing the same or similar data repeatedly.
[0069] Therefore, as one approach, when the first storage area is located outside of memory and the second storage area is a memory compression area, if the memory user of the candidate memory page repeatedly processes the same or similar data, the memory page to be replaced outside of memory can be determined based on the access frequency of the candidate memory page within the most recent specified time period. If the memory user of the candidate memory page is more likely to process new data, the memory page to be replaced outside of memory can be determined based on the time when the candidate memory page was added to the second storage area.
[0070] Optionally, in electronic devices, the category of memory-using objects can be determined by creating an object list. For example, a first object list can be created for memory-using objects that repeatedly process the same or similar data. A second object list can be created for memory-using objects that are more likely to process new data. In this approach, once the target object is identified, its category can be determined by querying the list in which it belongs, thus providing a method for selecting a memory page from the candidate memory pages.
[0071] This embodiment provides a memory page processing method. When there are multiple memory users, a target object can be determined from among the multiple memory users, and then at least a portion of the candidate memory pages can be swapped to a first storage area. Therefore, by means of the above method, when there are multiple memory users and it is necessary to swap memory pages from a second storage area to the first storage area, memory pages can be selected for swapping from the memory pages corresponding to a single memory user, instead of selecting memory pages to be swapped from all memory pages in the second storage area. This makes the memory page swapping operation more precise and flexible.
[0072] Please see Figure 6 This application provides a memory page processing method, which includes:
[0073] S210: Among multiple memory usage objects, the memory usage object whose corresponding memory page occupies storage space in the second storage area that meets the target space conditions is taken as the target memory usage object.
[0074] One approach is to configure a corresponding memory usage limit for each memory-using object. This limit represents the maximum storage space that the corresponding memory-using object can use in the second storage area. For example, if the second storage area is a memory-compressed area, the memory usage limit represents the maximum storage capacity that the corresponding memory-using object can occupy in the memory-compressed area. In addition to configuring a memory usage limit, a memory usage threshold can also be configured. This threshold can be less than the limit, such that when the storage space occupied by the memory pages corresponding to the memory-using object in the second storage area exceeds the threshold, it indicates that the storage capacity of the memory-using object in the second storage area is about to be exhausted, and at least some memory pages need to be swapped to the first storage space. Therefore, as a possible approach, the target space condition can include: the storage space occupied by the memory pages corresponding to the memory-using object in the second storage area is greater than the memory usage threshold corresponding to that memory-using object.
[0075] In this embodiment, the memory usage limit for each memory-using object can be the same or different. Furthermore, there are multiple ways to determine the usage limit for each memory-using object.
[0076] As a definitive method, users of electronic devices can configure corresponding memory usage limits for each memory-using object according to their needs. In this approach, the electronic device can have a dedicated memory configuration interface. This interface allows users to configure corresponding memory usage limits for different memory-using objects.
[0077] As another method, electronic devices can configure corresponding memory usage limits based on the characteristics of each memory-using object. It should be noted that different memory-using objects may have different memory requirements during operation. For example, programs running in the foreground have relatively higher timeliness requirements, while programs running in the background have relatively lower timeliness requirements. In this case, if the memory-using object is a program running in the foreground, or if the memory usage is a program group that includes programs running in the foreground, a larger memory usage limit can be configured. Conversely, if the memory-using object is a program running in the background, or if the memory-using object is a program group that includes programs running entirely in the background, a smaller memory usage limit can be configured.
[0078] Another approach is to determine the memory usage limit for each memory-using object based on its priority. Specifically, higher-priority programs can have a higher memory usage limit, while lower-priority programs can have a lower memory usage limit.
[0079] It should be noted that the storage space in the second storage area is limited. If a new memory user is created (e.g., a new program group is created, or a new program is installed on the electronic device), a corresponding memory usage limit needs to be configured for that new memory user. When configuring this limit, there may be situations where the remaining storage space in the second storage area is insufficient to meet the memory usage limit of the new memory user. In such cases, the electronic device can detect whether a specified usage condition is met. If the specified usage condition is met, the sum of the individual memory usage limits of all memory users is allowed to exceed the overall storage capacity of the second storage area. If the specified usage condition is not met, the sum of the individual memory usage limits of all memory users is not allowed to exceed the overall storage capacity of the second storage area.
[0080] If the specified usage conditions are met, the corresponding memory usage limit can be configured for the new memory-using object in a predetermined manner. This predetermined manner can be any of the aforementioned methods for determining the corresponding memory usage limit. If the specified usage conditions are not met, the memory usage limit for all memory-using objects (including original and new memory-using objects) needs to be reconfigured to ensure that the configuration result satisfies the currently used configuration principles and that the sum of the individual memory usage limits of all memory-using objects does not exceed the overall storage capacity of the second storage area.
[0081] Optionally, the electronic device can also configure a corresponding memory usage address for each memory user object so that the memory addresses of memory pages belonging to the same memory user object can be contiguous.
[0082] S220: Replace at least a portion of the candidate memory pages with the first storage area, wherein the candidate memory pages are memory pages in the second storage area that correspond to the target object, and the second storage area is located in the memory of the electronic device.
[0083] This embodiment provides a memory page processing method that, in the case of multiple memory users, when it is necessary to replace memory pages from the second storage area to the first storage area, memory pages can be selected for replacement from the memory pages corresponding to a single memory user, instead of selecting memory pages to be replaced from all memory pages in the second storage area. This makes the memory page replacement operation more precise and flexible. Furthermore, in this embodiment, with a memory usage threshold configured for each memory user, if the storage space occupied by a memory page of a memory user in the second storage area is detected to be greater than the corresponding memory usage threshold, the replacement of that memory page is triggered, which helps to avoid situations where the memory user cannot use the second storage area.
[0084] Please see Figure 7 This application provides a memory page processing method, which includes:
[0085] S310: Among multiple memory usage objects, the memory usage object whose program state satisfies the target state condition is taken as the target object.
[0086] As one approach, the target state conditions include at least one of the following: the program is running in the background; the program is in a prohibited startup state (e.g., the program is frozen); the program's resource usage is below a threshold; the storage space occupied by the program in the second storage area meets the target space condition, wherein meeting the target space condition means that the storage space occupied by the memory page corresponding to the program in the second storage area is greater than the memory usage threshold of the memory usage object to which the program belongs. Where there is only one program in the memory usage object, the memory usage threshold of the memory usage object can be understood as the memory usage threshold of the programs within the memory usage object. Where the memory usage object includes multiple programs, the memory usage threshold of the memory usage object can be determined based on the multiple programs included.
[0087] It's important to note that when a program is running in the background, its memory requirements are relatively lower. Therefore, the memory pages corresponding to the background program can be swapped to the first storage area, making the second storage area available for other memory users. Conversely, when a program is disabled from running, it may not use memory at all, allowing its corresponding memory pages to be swapped to the first storage area, making the second storage area available for other memory users.
[0088] In this embodiment, processing resources can be understood as resources such as CPU (Central Processing Unit), GPU (graphics processing unit), or NPU (Neural Processing Unit). When the program's usage of processing resources is below a certain threshold, it indicates that the program currently does not have many tasks to process, thus relatively reducing the usage of the second storage area. This threshold can be pre-configured by the developers or dynamically configured by the electronic device based on actual conditions.
[0089] S320: Replace at least a portion of the candidate memory pages with the first storage area, wherein the candidate memory pages are memory pages in the second storage area that correspond to the target object, and the second storage area is located in the memory of the electronic device.
[0090] This embodiment provides a memory page processing method that, in the case of multiple memory users, when it is necessary to replace memory pages from a second storage area to a first storage area, can select memory pages for replacement from the memory pages corresponding to a single memory user, instead of selecting memory pages to be replaced from all memory pages in the second storage area. This makes the memory page replacement operation more precise and flexible. Furthermore, in this embodiment, when each memory user includes at least one program, the target object can be determined based on the state of the program in each memory user, further improving the flexibility of target object determination.
[0091] Please see Figure 8 This application provides a memory page processing method, which includes:
[0092] S410: If the remaining memory of the electronic device is lower than the first memory threshold, at least two of the multiple memory-using objects are selected as the target objects.
[0093] One approach is to obtain the difference between the remaining memory of the electronic device and a first memory threshold; based on the difference, determine the number of memory-using objects that serve as the target object among multiple memory-using objects, wherein the larger the difference, the larger the number.
[0094] The first memory threshold represents the minimum threshold at which an electronic device can function properly. If the remaining memory of the electronic device falls below the first memory threshold, the device is more likely to experience lag or stuttering. Therefore, when the remaining memory of the electronic device is below the first memory threshold, memory pages can be swapped from the second storage area to the first storage area.
[0095] In this embodiment, the first memory threshold can be pre-configured by the developer of the electronic device. Alternatively, it can be dynamically determined by the electronic device based on actual conditions. For example, the more programs installed on an electronic device, the higher the probability of lag. In this approach, the electronic device can determine the first memory threshold based on the number of installed programs. The more programs installed, the higher the first memory threshold can be. For example, as shown... Figure 9 As shown, as the number of programs increases, the corresponding first memory threshold will also increase accordingly.
[0096] It's important to note that the first memory threshold can grow linearly or non-linearly with the increase in the number of programs. Alternatively, it can grow linearly in some stages and non-linearly in others. Linear and non-linear growth are two ways to describe the relationship between variables. Linear growth means that the relationship between the two variables (the number of programs and the first memory threshold) is a straight line, where one variable increases by a fixed step size as the other increases. Linear growth relationships are usually described by linear functions or linear equations. Non-linear growth, on the other hand, means that the relationship between the two variables is not linear, but rather exhibits a curve, surface, or uncertain complex relationship. Non-linear growth relationships typically require more complex mathematical models such as quadratic functions, polynomial equations, trigonometric functions, and exponential functions to describe them.
[0097] As one approach, when an electronic device has a small number of apps, any new apps added likely indicate that the user is likely to use them frequently. For example, when a user replaces their electronic device, the initial apps installed will likely be those they use frequently, such as payment apps and instant messaging apps. Conversely, when an electronic device has many apps installed, any new apps added are more likely to be those the user uses only occasionally. For example, an app installed at the last minute by the event organizer to participate in an activity. These occasionally used apps may remain on the device for a long time, but the probability of them being activated is low.
[0098] Therefore, to better and more accurately determine the variation range of the first memory threshold, at least one program threshold can be configured. If the number of programs in the electronic device increases, and the number of programs after the increase is less than the program threshold, the first memory threshold is increased linearly. If the number of programs in the electronic device increases, and the number of programs after the increase is greater than the program threshold, the first memory threshold is increased non-linearly. Furthermore, in the non-linear increase method, the magnitude of each increase in the first memory threshold is smaller than the magnitude in the linear increase method. For example, in the linear increase phase, the first memory threshold can increase by n each time it increases, and in the non-linear increase phase, the first memory threshold can increase by m each time it increases, where n is greater than m.
[0099] S420: Replace at least a portion of the candidate memory pages with the first storage area, wherein the candidate memory pages are memory pages in the second storage area that correspond to the target object, and the second storage area is located in the memory of the electronic device.
[0100] This embodiment provides a memory page processing method that, in the case of multiple memory users, when it is necessary to replace memory pages from a second storage area to a first storage area, memory pages can be selected for replacement from the memory pages corresponding to a single memory user, instead of selecting memory pages to be replaced from all memory pages in the second storage area. This makes the memory page replacement operation more precise and flexible. Furthermore, in this embodiment, the number of target objects can be determined based on the difference between the remaining memory of the electronic device and a first memory threshold, thereby improving the flexibility of target object determination. It also allows for dynamic adjustment of the number of memory pages to be replaced from the second storage area.
[0101] It should be noted that, in the embodiments of this application, when replacing memory pages in the memory (uncompressed area), the memory pages can be replaced to the memory compressed area, or they can be directly replaced to a location outside the memory.
[0102] In this embodiment, a corresponding memory removal strategy can be configured for each program group. This strategy determines whether the memory pages corresponding to a program group are replaced from the uncompressed region to the compressed region or directly to a location outside memory. Once the memory removal strategy for each program group is determined, the memory pages of the programs within that group can be replaced according to the strategy. For memory pages corresponding to the same program group, they can be replaced either to the compressed region or to a location outside memory. Alternatively, memory pages of programs within some program groups may not require replacement.
[0103] In this embodiment of the application, when determining the memory pages that need to be replaced in each program group, the determination can be made based on the usage frequency of the memory pages of the programs in the corresponding program group; or, based on the time when the memory pages of the programs in the corresponding program group are added to memory.
[0104] Optionally, in this method of memory page replacement based on usage frequency, the time of the most recent use of a memory page can be obtained, and then the decision to replace it can be made based on the last usage time. Optionally, the interval between the last usage time of a memory page and the current time can be obtained; if the interval is longer than a specified interval, the memory page is determined to be replaceable. Optionally, the last usage times of multiple memory pages can be compared, and the memory page with the longest interval between its usage time and the current time can be replaced. These multiple memory pages can be memory pages of programs within the same program group, and the memory removal strategy corresponding to that program group is based on the usage frequency of the memory pages of the programs within that program group.
[0105] In this case, replacing memory pages based on the usage frequency of the program's memory pages in the corresponding program group can also be done using the LRU (Least Recently Used) method to determine which memory pages can be replaced.
[0106] For example, multiple program groups include group G1, group G2, and group G3. The memory removal strategy for group G2 is based on the usage frequency of memory pages of the programs within that group. The electronic device will then determine which memory pages in group G2 can be replaced based on the usage frequency of the memory pages corresponding to the programs in that group. For instance, if group G2 includes programs P5 and P6, the electronic device will determine the memory pages to be removed based on the usage frequency of the memory pages of programs P5 and P6.
[0107] Optionally, in the method of replacing memory pages based on the time they were loaded into memory within the corresponding program group, a FIFO (First Input First Output) approach can be used to determine which memory pages can be replaced. In this method, the loading times of multiple memory pages are compared, and the memory page with the longest loading time from the current time is determined to be eligible for replacement.
[0108] For example, multiple program groups include group G1, group G2, and group G3. The memory removal strategy for group G3 is based on the time when the memory pages of the programs in that group were loaded into memory. The electronic device then determines which memory pages can be replaced from the memory pages corresponding to the programs in group G3 based on the time these pages were loaded into memory. For instance, if group G3 includes programs P7, P8, and P9, the electronic device will determine the memory pages to be removed based on the time when the memory pages of programs P7, P8, and P9 were loaded into memory.
[0109] For example, in this embodiment, the multiple program groups include a first group, a second group, and a third group. The programs in the first group can be system programs, the programs in the second group are programs running in the foreground, and the programs in the third group can be programs running in the background. The memory removal strategy for the first group can be no replacement, the memory removal strategy for the second group can be replacement based on the usage frequency of memory pages in the corresponding program group, and the memory removal strategy for the third group can be replacement based on the time it takes for memory pages in the corresponding program group to be added to memory.
[0110] One approach is to determine the target location of the swapped memory pages based on the program grouping they correspond to. It's important to note that some memory pages, after being swapped out, may be reloaded into memory or returned to their original memory location. The loading speed of the memory pages within different target locations will vary. For example, some memory pages may be swapped to the hard drive, while others may only be swapped into compressed memory. Compressed memory can be loaded into memory after decompression, while pages swapped out to the hard drive need to be loaded from the hard drive into memory, thus requiring more time.
[0111] For example, the multiple program groups obtained in this application embodiment may include the aforementioned first group, second group, and third group. The target location corresponding to the first group can be a first location, the target location corresponding to the second group can be a second location, and the target location corresponding to the third group can be a third location. The memory pages in the first location are loaded back into memory faster than the memory pages in the second location, and the memory pages in the second location are loaded back into memory faster than the memory pages in the third location. Optionally, the first location can be a location in memory, the second location can be flash memory, and the third location can be a disk.
[0112] Please see Figure 10 This application provides a memory page processing device 500, which operates in an electronic device. The device 500 includes:
[0113] The target determination unit 510 is used to determine the target object from multiple memory-using objects.
[0114] The memory page processing unit 520 is used to replace at least a portion of the candidate memory pages with memory pages in a first storage area. The candidate memory pages are memory pages in a second storage area that correspond to the target object. The second storage area is located in the memory of the electronic device.
[0115] As one approach, memory usage objects are grouped into program groups, and target objects are grouped into target program groups. Multiple program groups are obtained by dividing programs based on their target characteristics, and programs within the same program group share the same target characteristics. Optionally, target characteristics include the program's user identifier code, or target characteristics include the program's memory access latency requirements.
[0116] In one approach, the memory-using object is the program, and the target object is the target program.
[0117] As one approach, the target determination unit 510 is specifically used to select, from among multiple memory-using objects, the memory-using object whose corresponding memory page occupies storage space in the second storage area that satisfies the target space condition as the target memory-using object. Optionally, the target space condition includes:
[0118] The memory page corresponding to the memory-using object occupies more storage space in the second storage area than the memory usage threshold corresponding to that memory-using object.
[0119] In one approach, the target determination unit 510 is specifically used to identify, among multiple memory usage objects, the memory usage objects whose program states satisfy the target state conditions as target objects. Optionally, the target state conditions include at least one of the following conditions: the program is running in the background; the program is in a prohibited startup state; the program's resource usage is below a threshold.
[0120] As one approach, the target determination unit 510 is specifically used to, if the remaining memory of the electronic device is lower than a first memory threshold, designate at least two memory-using objects from a plurality of memory-using objects as target objects. Optionally, the difference between the remaining memory of the electronic device and the first memory threshold is obtained; the number of memory-using objects designated as target objects from the plurality of memory-using objects is determined based on the difference, wherein the larger the difference, the larger the number.
[0121] This embodiment provides a memory page processing device that, when there are multiple memory users and it is necessary to replace memory pages from a second storage area to a first storage area, can select memory pages for replacement from the memory pages corresponding to a single memory user, instead of selecting memory pages to be replaced from all memory pages in the second storage area. This makes the memory page replacement operation more precise and flexible.
[0122] 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.
[0123] The following will combine Figure 11 This application describes an electronic device.
[0124] Please see Figure 11Based on the aforementioned audio processing method and apparatus, this application embodiment also provides another electronic device 200 capable of executing the aforementioned audio processing method. The electronic device 200 includes one or more (only one shown in the figure) processors 202, a memory 204, a network module 206, a sensor module 208, and an audio acquisition device 210, all coupled to each other. The memory 204 stores programs capable of executing the contents of the aforementioned embodiments, and the processor 202 can execute the programs stored in the memory 204.
[0125] The processor 202 may include one or more processing cores. The processor 202 connects to various parts within the electronic device 200 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 204, and by calling data stored in the memory 204. Optionally, the processor 202 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 202 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 202 and may be implemented separately using a communication chip.
[0126] The memory 204 may include random access memory (RAM) or read-only memory (ROM). The memory 204 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 204 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.
[0127] The network module 206 is used to enable information interaction between the electronic device 200 and other devices, such as transmitting device control commands, manipulation request commands, and status information acquisition commands. However, the network module 206 may differ depending on the specific device being used.
[0128] Sensor module 208 may include at least one sensor. Specifically, sensor module 208 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.
[0129] The pressure sensor is a sensor that detects pressure generated by pressing on the electronic device 200. That is, the pressure sensor detects pressure generated by contact or pressing between the user and the electronic device, such as the 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 200, and the magnitude of the pressure.
[0130] 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 electronic devices 200 (e.g., screen orientation switching, related games, magnetometer posture calibration), and vibration recognition functions (e.g., pedometer, tapping). In addition, electronic devices 200 can also be equipped with other sensors such as gyroscopes, barometers, hygrometers, and thermometers, which will not be elaborated upon here.
[0131] Audio acquisition device 210 is used for acquiring audio signals. Optionally, audio acquisition device 210 includes multiple audio acquisition devices. These audio acquisition devices can be microphones. For example, in one embodiment, audio acquisition device 210 may include two microphones, in which one microphone may correspond to one analog-to-digital converter (ADC), and the other microphone may correspond to two ADCs with different analog gains. In another embodiment, audio acquisition device 210 may include three microphones. In this embodiment, two microphones (e.g., a main microphone and a secondary microphone) may each correspond to one ADC, and the other microphone (e.g., a camera microphone) may correspond to two ADCs with different analog gains.
[0132] In one approach, the network module of the electronic device 200 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, 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.
[0133] Furthermore, the electronic device 200 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.
[0134] Please refer to Figure 12 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.
[0135] 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.
[0136] This application provides a memory page processing method, apparatus, and electronic device. When multiple memory users exist, a target memory user can be identified from among them, and at least a portion of the candidate memory pages can be swapped to a first storage area. This allows for the selection of memory pages from a single memory user when swapping memory pages from a second storage area to the first storage area, instead of selecting pages from all memory pages in the second storage area. This makes the memory page swapping operation more precise and flexible.
[0137] Furthermore, in this application, when the first storage area is a memory compression area and the second storage area is a storage location outside of memory (e.g., a FLASH device), memory pressure can be effectively addressed by dynamically adjusting the usage of the memory compression area and the storage location outside of memory. Moreover, this application provides customized memory management for each memory user, improving system response speed and operating efficiency. Additionally, by dynamically moving memory pages from the memory compression area to storage locations outside of memory, the problem of memory compression failing when the memory compression area is full is avoided, improving memory expansion capabilities. Finally, under high memory pressure, it can better ensure the operation of critical applications, improving system stability.
[0138] 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 of memory page processing, the method comprising: The method is applied to an electronic device, and the method comprises: determining a target object from a plurality of memory usage objects, the target object corresponding to a memory page occupying a memory space in a second storage area greater than a memory usage threshold corresponding to the target object, wherein the memory usage threshold of each memory usage object is lower than the memory usage upper limit corresponding to each memory usage object, and the memory usage upper limit corresponding to each memory usage object is different; replacing at least part of the memory pages in the candidate memory pages to the first storage area, the candidate memory pages being the memory pages corresponding to the target object in the second storage area, and the second storage area being in the memory of the electronic device, wherein the memory usage object is a program group, and the target object is a target program group, wherein the plurality of program groups each comprises a plurality of programs, and the plurality of program groups are obtained by dividing programs according to target characteristics of the programs, wherein the programs in the same program group have the same target characteristics, and the target characteristics include memory access delay requirements of the programs; The method further comprises: in the case of obtaining a program to be grouped, grouping programs having similar or identical memory access requirements to the memory access requirements of the program to be grouped as the program group to which the program to be grouped is divided. If the memory access delay requirements of the program to be grouped are not similar to and different from the memory access delay requirements of each group, and new program groups are not allowed to be created at present, the program group having the most similar memory access delay requirements to the memory access delay requirements of the program to be grouped is determined from the program groups that have been established at present as the program group corresponding to the program to be grouped.
2. The method of claim 1, wherein, Each memory usage object comprises at least one program, and the determination of the target object from the plurality of memory usage objects comprises: determining, as the target object, a memory usage object comprising a program satisfying a target state condition from the plurality of memory usage objects.
3. The method of claim 2, wherein, The target state condition comprises at least one of the following conditions: the program is in a background running state; the program is in a prohibited start state; the program occupies a processing resource in an amount lower than an occupation threshold; the program occupies a memory space in the second storage area satisfying a target space condition.
4. The method of claim 1, wherein, The determination of the target object from the plurality of memory usage objects comprises: if the remaining memory of the electronic device is lower than a first memory threshold, determining at least two memory usage objects from the plurality of memory usage objects as the target object.
5. The method of claim 4, wherein, The method further comprises: obtaining a difference between the remaining memory of the electronic device and the first memory threshold; determining the number of memory usage objects as the target object from the plurality of memory usage objects based on the difference, wherein the larger the difference is, the larger the number is.
6. The method according to any one of claims 1 to 5, characterized in that, The first storage area is a storage area other than the memory, and the second storage area is a memory compression area.
7. The method of claim 6, wherein, The storage area other than the memory comprises a FLASH device, and the memory compression area is a ZRAM.
8. A memory page handling apparatus, characterized by comprising: The device runs on an electronic device, and the device comprises: The target determination unit is configured to determine a target object from a plurality of memory usage objects, the memory page corresponding to the target object occupying a memory space in the second storage area greater than a memory usage threshold corresponding to the target object, wherein the memory usage threshold of each memory usage object is lower than the memory usage upper limit corresponding to each memory usage object, and the memory usage upper limit corresponding to each memory usage object is different. The memory page processing unit is configured to replace at least part of the memory pages in the candidate memory pages to the first storage area, the candidate memory pages being the memory pages corresponding to the target object in the second storage area, and the second storage area being in the memory of the electronic device, wherein the memory usage object is a program group, and the target object is a target program group, wherein a plurality of program groups each include a plurality of programs, and the plurality of program groups are obtained by grouping programs according to target characteristics of the programs, wherein the programs in a same program group have the same target characteristics, and the target characteristics include memory access delay requirements of the programs. The target determination unit is further configured to, in a case where a program to be grouped is obtained, group a program group having similar or identical memory access requirements to the memory access requirements of the program to be grouped as a program group to which the program to be grouped is grouped; and in a case where the memory access delay requirements of the program to be grouped are neither identical nor similar to the memory access delay requirements of each group, and a new program group is not allowed to be established, determine, from the program groups that have been established, a program group having the most similar memory access delay requirements to the memory access delay requirements of the program to be grouped as a program group corresponding to the program to be grouped.
9. An electronic device, comprising: The computer readable storage medium stores one or more programs configured to be executed by one or more processors to perform the method of any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores one or more programs configured to be executed by one or more processors to perform the method of any one of claims 1-7.
Citation Information
Patent Citations
Page swap-out method
CN107766151A
Memory page processing method and device and electronic equipment
CN119576513A