Memory region determination method and apparatus, electronic device, and computer readable medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
- Filing Date
- 2022-09-06
- Publication Date
- 2026-07-03
AI Technical Summary
Existing technologies are inefficient at finding hotspots in the physical address space of memory, especially in large electronic devices, where the accuracy and efficiency are insufficient when randomly selecting virtual or physical address spaces for lookups.
By dividing the virtual address space into a specified number of first-level page tables, if multiple target virtual address segments exist in the first-level page table and the corresponding physical address segments cannot be obtained, the physical address segments are rematched, thereby directly determining the hot segmentation.
This method quickly and effectively identifies hotspot segments, improving the efficiency and accuracy of hotspot searches in the physical address space of memory and reducing the time wasted due to invalid random selections.
Smart Images

Figure CN115587053B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and more specifically, to a method, apparatus, electronic device, and computer-readable medium for determining a memory region. Background Technology
[0002] Currently, with the development of electronic information technology, electronic devices are equipped with increasingly larger amounts of memory. Although it is possible to locate frequently used physical address spaces in memory and mark them as hot areas, existing methods for locating hot areas in the physical address space of memory are inefficient. Summary of the Invention
[0003] This application discloses a method, apparatus, electronic device, and computer-readable medium for determining a memory region.
[0004] In a first aspect, embodiments of this application provide a method for determining a memory region, applied to an electronic device. The method includes: when the electronic device executes a process, obtaining the virtual address space of the electronic device, the virtual address space including at least one virtual address segment; dividing the virtual address space into a specified number of virtual address segments to obtain at least one first-level page table; if there are at least two target virtual address segments in the first-level page table, using the first-level page table as the target page table, the data stored in the physical address segment of the target virtual address segment cannot be successfully retrieved; if there is no corresponding physical address segment for the target virtual address segment, then re-matching a physical address segment for the target virtual address; and using the physical address segment corresponding to each virtual address segment in the target page table as a hot segment.
[0005] Secondly, embodiments of this application also provide a memory region determination apparatus, the apparatus comprising: an acquisition unit, configured to acquire the virtual address space of the electronic device when the electronic device executes a process, the virtual address space including at least one virtual address segment; a processing unit, configured to divide the virtual address space into a specified number of virtual address segments to obtain at least one first-level page table; a first judgment unit, configured to, if at least two target virtual address segments exist in the first-level page table, use the first-level page table as the target page table, and the data stored in the physical address segment of the target virtual address segment cannot be successfully acquired; a second judgment unit, configured to, if the target virtual address segment does not have a corresponding physical address segment, re-match a physical address segment for the target virtual address; and a determination unit, configured to, use the physical address segment corresponding to each virtual address segment in the target page table as a hot segment.
[0006] Thirdly, embodiments of this application also provide an electronic device, including: one or more processors; a memory; the one or more processors for executing instructions; the memory for providing physical addresses; the bus for providing data transmission; and the one or more processors for performing the above-described method.
[0007] Fourthly, embodiments of this application also provide a computer-readable medium storing processor-executable program code, which, when executed by the processor, causes the processor to perform the above-described method.
[0008] Fifthly, embodiments of this application also provide a computer program product, including a computer program / instructions that, when executed by a processor, implement the above-described method.
[0009] This application provides a method, apparatus, electronic device, and computer-readable medium for determining memory regions. When the electronic device executes a process, the method can obtain the virtual address space of the electronic device, then divide the virtual address space into a specified number of virtual address segments to obtain at least one first-level page table. If at least two target virtual address segments exist in the first-level page table, the first-level page table is used as the target page table. If the target virtual address segment does not have a corresponding physical address segment, a new physical address segment is matched for the target virtual address. Thus, the physical address segment corresponding to each virtual address segment in the target page table can be used as a hot segment. However, if a portion is randomly selected from a large virtual address space, and the search for the corresponding hot segment is based on whether the selected portion of the virtual address space has been accessed, it may take a long time to find the hot segment if the randomly selected portion of the virtual address space has never been accessed. The method provided in this application divides the virtual address space into at least one first-level page table. When there are at least two target virtual address segments in the first-level page table, the physical address segments corresponding to all virtual address segments in the first-level page table can be directly identified as hot segments, thereby quickly and effectively finding hot segments.
[0010] Other features and advantages of the embodiments of this application will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the embodiments of this application. The objects and other advantages of the embodiments of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description
[0011] 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.
[0012] Figure 1 A structural block diagram of the electronic device provided in an embodiment of this application is shown;
[0013] Figure 2 A flowchart of the memory region determination method provided in an embodiment of this application is shown;
[0014] Figure 3 A schematic diagram of a first-level page table provided in an embodiment of this application is shown;
[0015] Figure 4 A flowchart of a memory region determination method provided in another embodiment of this application is shown;
[0016] Figure 5 A flowchart of a memory region determination method provided in another embodiment of this application is shown;
[0017] Figure 6 It shows Figure 5 One implementation of step S340;
[0018] Figure 7 It shows Figure 5 One implementation of step S350;
[0019] Figure 8 A schematic diagram of a second-level page table provided in an embodiment of this application is shown;
[0020] Figure 9 A unit block diagram of the memory region determination device provided in an embodiment of this application is shown;
[0021] Figure 10 A schematic diagram of an electronic device provided in an embodiment of this application is shown;
[0022] Figure 11 This paper shows a structural block diagram of a computer-readable storage medium provided in an embodiment of this application;
[0023] Figure 12 A structural block diagram of a computer program product provided in an embodiment of this application is shown. Detailed Implementation
[0024] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, and not all of them. The components of the embodiments of the present application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of the present application. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without inventive effort are within the scope of protection of the present application.
[0025] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0026] Currently, with the development of electronic information technology, electronic devices are equipped with increasingly larger amounts of memory. Although frequently used physical address spaces in memory can be identified and marked as "hot zones," existing methods for locating hot zones in memory's physical address space are inefficient. Improving the efficiency of locating hot zones in memory's physical address space is a problem that urgently needs to be solved.
[0027] Currently, any portion of the virtual address space can be randomly selected to form the first part of the virtual address space. This virtual address space can include multiple virtual address segments, and therefore, the first part of the virtual address space can also include multiple virtual address segments. Then, a virtual address segment within this first part of the virtual address space is randomly selected, and it is determined whether the selected virtual address segment has been accessed by a process. If it has been accessed, the corresponding physical address segment can be determined to be a frequently accessed segment, thus identifying it as a hot segment.
[0028] For example, if the virtual address space is 1GB in size, where GB stands for gigabyte, and each virtual address segment is 4KB in size, where KB stands for kilobyte, then a simple division operation can be performed to determine that the virtual address space can include 1GB / 4KB = 262144 virtual address segments.
[0029] Determining the corresponding physical address segment through virtual address segments can be achieved through mapping. For example, if the virtual address segments include 0x0, 0x1, and 0x2, and the physical address segments include 0x8001, 0x8002, 0x8003, 0x8004, 0x8005, and 0x8006, and address segments 0x8002, 0x8003, and 0x8004 are already occupied by data, while the free physical address segments are 0x8001, 0x8005, and 0x8006, then the virtual address segments can be mapped to the free physical address segments. Specifically, the mapping relationship could be: virtual address segment 0x0 mapped to physical address segment 0x8001, virtual address segment 0x1 mapped to physical address segment 0x8005, and virtual address segment 0x2 mapped to physical address segment 0x8006. This mapping relationship allows us to determine the corresponding physical address segment through virtual address segmentation.
[0030] Alternatively, any portion of the physical address space can be randomly selected to form the first part of the physical address space. The physical address space can include multiple physical address segments, and therefore the first part of the physical address space can also include multiple physical address segments. Then, a physical address segment within this first part of the physical address space is randomly selected, and it is determined whether the selected physical address segment has been accessed by a process. If it has been accessed, then the physical address segment can be determined to be a frequently accessed segment, thus identifying it as a hot segment.
[0031] However, the inventors discovered in their research that the aforementioned method for finding hot segmentation based on virtual address space involves randomly selecting a portion of the virtual address space and then randomly sampling within that selected portion to check for process calls. Since the virtual address space in existing electronic devices is relatively large, this method results in low accuracy and efficiency in finding hot segmentation. Similarly, the method for finding hot segmentation based on physical address space also suffers from low accuracy and efficiency.
[0032] Therefore, to overcome the above-mentioned defects, this application provides a method, apparatus, electronic device, and computer-readable medium for determining memory regions. When the electronic device executes a process, the method can obtain the virtual address space of the electronic device, then divide the virtual address space into a specified number of virtual address segments to obtain at least one first-level page table. If at least two target virtual address segments exist in the first-level page table, the first-level page table is used as the target page table. If the target virtual address segment does not have a corresponding physical address segment, a new physical address segment is matched for the target virtual address. Thus, the physical address segment corresponding to each virtual address segment in the target page table can be used as a hot segment. However, if a portion is randomly selected from a large virtual address space, and the search for the corresponding hot segment is based on whether the selected portion of the virtual address space has been accessed, it may take a long time to find the hot segment if the randomly selected portion of the virtual address space has never been accessed. The method provided in this application divides the virtual address space into at least one first-level page table. When there are at least two target virtual address segments in the first-level page table, the physical address segments corresponding to all virtual address segments in the first-level page table can be directly identified as hot segments, thereby quickly and effectively finding hot segments.
[0033] Please see Figure 1 , Figure 1 This diagram illustrates a structural block diagram of an electronic device 100 according to an embodiment of this application. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130.
[0034] In some implementations, the processor 110 can be used to run system programs installed on the electronic device 100. These system programs can be of different types, such as system programs for portable electronic devices (e.g., smartphone system programs, in-vehicle computer system programs, or smart tablet system programs), desktop computer system programs, or server system programs. Furthermore, while the system program on the electronic device 100 is running, the electronic device 100 can also execute processes initiated by applications. Specifically, the processor 110 in the electronic device 100 can also be used to execute applications, and more specifically, to execute processes initiated by applications. An application can initiate a process request, and the processor 110 can respond to the process request by executing the process corresponding to that request. For example, if an application initiates a process request, the processor 110 can respond to the process corresponding to that request. In another example, the application can also initiate multiple process requests, and the processor 110 can respond to the process corresponding to each process request. For example, application A can initiate three process requests, namely process request A1, process request A2 and process request A3. The processor 110 can respond to process request A1, process request A2 and process request A3 respectively, and execute the process corresponding to each process request.
[0035] Furthermore, when the electronic device 100 is executing a process, the processor 110 can also be used to locate frequently used portions of the physical address space, or portions of the physical address space that are likely to be used frequently. The physical address space can be divided into multiple segments of a certain size. Each segment can be assigned a marker, which can be an address. This address can be used to determine the specific location of the segment within the physical address space; therefore, the address can also be considered the identification information of different segments within the physical address space. For example, if the physical address space can be divided into four segments, the first segment can be assigned an address of 0x01, the second segment 0x02, the third segment 0x03, and the fourth segment 0x04. Thus, the physical address space can include multiple physical address segments. Therefore, when the processor 110 locates frequently used portions of the physical address space, it can search for the frequently used physical address segments within that physical address space, which are more likely to be used in subsequent process execution. It should be noted that if a segment of a physical address has been used frequently, such as within a specified time range, then that segment of the physical address can be identified as a hot segment.
[0036] Furthermore, when executing a process, the electronic device 100 typically places the process in a virtual address space and then uses a virtual physical address mapping table to map the virtual address space to the physical address space. This allows the process to access data stored in the physical address space through the virtual address space, or to store generated data in the physical address space. Specifically, when determining hot segmentation, the processor 110 can determine the access patterns of the physical address space through the virtual address space. Detailed methods can be found in the descriptions in subsequent embodiments.
[0037] The processor 110 may include one or more processing cores. The processor 110 can connect to various parts within the electronic device 100 using various interfaces and lines, obtain different requests from system programs and application programs, and execute the processes corresponding to different requests. Then, based on the process's calls to the virtual address space, it searches for hot segments existing in the physical address space. Optionally, the processor 110 may be implemented using at least one of the following hardware forms: Microcontroller Unit (MCU), Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA).
[0038] In some implementations, the memory 120 may store the system program corresponding to the electronic device 100. For example, if the electronic device 100 is a smartphone, the memory 120 may store the smartphone system program; if the electronic device 100 is a desktop computer, the memory 120 may store the desktop computer system program. The electronic device 100 can run the system program stored in the memory 120, specifically through the processor 110. The memory 120 may also store different application programs, which can run within the system program running on the electronic device 100. The application program may include at least one process, as detailed above, and will not be repeated here. In some implementations, the memory 120 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM.
[0039] In some implementations, memory 130 may include physical memory, which generally has a higher read speed, while the speed of memory 120 is generally lower than that of memory 130. Therefore, memory 130 can pre-read data stored in memory 120 and store it in memory 130. When the processor 110 executes the process of an application, it can directly interact with data through memory 130, thereby minimizing direct data exchange between the processor 110 and memory 120 and affecting the overall operating speed of electronic device 100. Furthermore, since the physical memory in memory 130 is generally small, storing all application processes in the physical memory of memory 130 will affect the number of processes that can be executed simultaneously, and may also cause mutual interference between processes. Therefore, memory 130 may also include virtual memory. The processes executed in electronic device 100 can be first placed in the virtual memory of memory 130 by the processor 110. The virtual memory then accesses the corresponding physical memory through a virtual physical address mapping table, specifically accessing data stored in physical memory or writing data generated during the process to physical memory. Virtual memory can have a larger space than physical memory, so the number of processes that can be executed simultaneously when placed in virtual memory is greater than the number of processes that can be placed directly in physical memory.
[0040] In some implementations, memory 130 may be synchronous dynamic random access memory (SDRAM) or double data rate synchronous dynamic random access memory (DDRSDRAM), etc.
[0041] Please see Figure 2 , Figure 2 This application illustrates a method for determining a memory region, which can be applied to the electronic device 100 described in the foregoing embodiments. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130. Specifically, the method includes steps S110 to S150.
[0042] Step S110: When the electronic device executes a process, the virtual address space of the electronic device is obtained, the virtual address space including at least one virtual address segment.
[0043] In some implementations, the electronic device can respond to a process request initiated by an application, thereby executing the process corresponding to that process request; the electronic device can also respond to a process request initiated by a system process within a currently running system program, thereby executing the process corresponding to that process request; the system program currently running the electronic device can also pre-set process requests triggered based on trigger conditions. When such a process request is triggered, the system program issues the process request, and the electronic device can respond to the process request, thereby executing the process corresponding to that process request. For example, if the application is a music playback application, the music playback application can issue a music playback process request, and the electronic device can respond to this music playback process request and execute the music playback process.
[0044] In some implementations, when an electronic device executes a process, its processor typically interacts with memory, requiring the process to be loaded into memory first. However, directly loading the process into physical memory can be problematic. Since the physical memory space in an electronic device is generally limited, exceeding the physical memory limit could cause the system program running on the device to crash, impacting the entire device. Therefore, when executing a process, the electronic device can load the corresponding program into virtual memory and then map it to physical memory. This allows the virtual memory to be used to determine the corresponding physical memory location, enabling data reading and writing. The size of virtual memory can be significantly larger than the physical memory, allowing for the loading of more processes, including those requiring larger memory spaces.
[0045] The virtual memory may include a virtual address space, which can be divided into multiple segments of a certain size. Each segment can be assigned a marker, which can be an address. This address can be used to determine the specific location of the segment within the virtual address space, and thus can also be considered as the identity information of different segments within the virtual address space. In one embodiment provided by this application, the virtual address space includes at least one virtual address segment. For example, if the virtual address space can be divided into four segments, the first segment can be assigned an address of 0x01, the second segment 0x02, the third segment 0x03, and the fourth segment 0x04. That is, the virtual address space can include multiple virtual address segments. It should be noted that the number of virtual address segments included in a virtual address space is generally large. The above description of including four virtual address segments is merely illustrative and does not constitute a limitation of the embodiments of this application.
[0046] Similarly, physical memory can also include a physical address space, as described above in the section on virtual memory, and will not be repeated here. Furthermore, the virtual address space can be mapped to the physical address space, allowing processes residing in the virtual address space to access the physical address space. For example, different virtual address segments in the virtual address space can be mapped to different physical address segments in the physical address space. For instance, the 0x0001 virtual address segment in the virtual address space can be mapped to the 0x0034 physical address segment in the physical address space, while the 0x0002 virtual address segment can be mapped to the 0x0064 physical address segment; and the 0x0003 virtual address segment can be mapped to the 0x00ea physical address segment. Another example is that different virtual address segments in the virtual address space can be mapped to the same physical address segments in the physical address space. For example, the 0x0001 virtual address segment in the virtual address space can be mapped to the 0x0034 physical address segment in the physical address space, while the 0x0002 virtual address segment in the virtual address space can be mapped to the 0x0034 physical address segment in the physical address space; and the 0x0003 virtual address segment in the virtual address space can be mapped to the 0x0034 physical address segment in the physical address space.
[0047] Therefore, when an electronic device executes a process, the process is loaded into the virtual address space, and then mapped to physical memory through the virtual address space, enabling interaction with the data stored in physical memory. Thus, to determine whether a physical address segment in physical memory is a "hot" segment, it's possible to monitor whether the virtual address segment in the virtual address space accesses data in the physical address space. Essentially, a hot segment is a physical address segment that is highly likely to be used in subsequent process execution. Specifically, a hot segment can be identified if a physical address segment has been accessed within a specified time period, or if it has been accessed multiple times within a specified time period, indicating a high probability of its use in subsequent process execution.
[0048] Step S120: Divide the virtual address space into segments according to a specified number of virtual addresses to obtain at least one first-level page table.
[0049] In some implementations, since the virtual address space in an electronic device is generally large, it typically includes a large number of virtual address segments. Therefore, the virtual address space can be divided first, for example, by dividing it into a specified number of virtual address segments. After dividing the virtual address space, at least one first-level page table can be obtained. The first-level page table can be used to store the various virtual address segments obtained after dividing the virtual address space. For example, if the virtual address space includes N virtual address segments, where the specified number can be N / 100, then 100 first-level page tables can be obtained, with each first-level page table including N / 100 virtual address segments.
[0050] It should be noted that the specified quantity in the above example is merely an example and is not a limitation of this embodiment. Therefore, different first-level page tables can be obtained by setting different specified quantities.
[0051] Step S130: If there are at least two target virtual address segments in the first-level page table, the first-level page table is used as the target page table, and the data stored in the physical address segment of the target virtual address segment cannot be successfully retrieved.
[0052] As the above analysis shows, in some implementations, the virtual address space is generally larger than the physical address space. Therefore, the data stored in the physical address space cannot satisfy the calls of every virtual address segment in the virtual address space. When a virtual address segment needs to retrieve data stored in the corresponding physical address segment, if the data stored in the physical address segment cannot be successfully retrieved, then that virtual address segment can be used as the target virtual address segment. Therefore, the target virtual address segment is the virtual address segment that initiated a call request for the data stored in the physical address segment but failed to retrieve the data stored in the physical address segment.
[0053] Furthermore, the inability to successfully retrieve data stored in a physical address segment within a target virtual address segment can be due to several factors. First, the target virtual address may not have a corresponding physical address segment. For example, the virtual physical address mapping table may not contain a mapping relationship between the target virtual address segment and the physical address segment. Second, the target virtual address segment may have a corresponding physical address segment, meaning the target virtual address segment can access the physical address segment, but the target virtual address segment lacks the permissions to read or write the data stored within that physical address segment, thus preventing successful retrieval of the data.
[0054] The aforementioned virtual physical address mapping table can store the mapping relationship between target virtual address segments and physical address segments. This physical virtual address mapping table can also be updated according to the needs of the process to add new mapping relationships or update existing ones.
[0055] Furthermore, since for the same first-level page table, if multiple virtual address segments in the page table need to retrieve data stored in the corresponding physical address segments, but the data stored in the physical address segments cannot be successfully retrieved, meaning that the page table contains multiple target virtual address segments, it indicates that the virtual address segments in the first-level page table are highly likely to call the data in the corresponding physical address segments again during subsequent process execution. Therefore, the first-level page table can be used as the target page table, and hot segmentation can be determined based on the target page table. In one embodiment provided by this application, the aforementioned multiple target virtual address segments can be two virtual address segments. That is, when there are at least two target virtual address segments in the first-level page table, the first-level page table is used as the target page table.
[0056] Step S140: If the target virtual address segment does not have a corresponding physical address segment, then a new physical address segment is matched for the target virtual address.
[0057] In some implementations, since a target virtual address segment may not have a corresponding physical address segment, a mapping relationship can first be established for the target virtual address segment in the first-level page table that does not have a corresponding physical address segment. For example, a physical address segment can be re-matched for the target virtual address, thus establishing a mapping relationship between the target virtual address and the re-matched physical address segment.
[0058] The reallocated physical address segment can be a physical address segment determined from the physical address space.
[0059] Step S150: The physical address segment corresponding to each virtual address segment in the target page table is used as a hot segment.
[0060] Please see Figure 3 , Figure 3 A schematic diagram of a first-level page table is shown. The virtual address space 210 can be divided into multiple first-level page tables 220 according to a specified number of virtual address segments. When at least two target virtual address segments exist in a first-level page table, the first-level page table is designated as a target page table. This allows for the identification of hot segments within the target page table.
[0061] As can be seen from the foregoing analysis, in some implementation methods, there may be multiple target virtual address segments in the target page table. This indicates that the virtual address segments in the target page table are more likely to call the data in the corresponding physical address segments again during the subsequent process execution. Therefore, as an example, the physical address segment corresponding to each virtual address segment in the target page table can be determined as a hot segment.
[0062] This application provides a method, apparatus, electronic device, and computer-readable medium for determining memory regions. When the electronic device executes a process, the method can obtain the virtual address space of the electronic device, then divide the virtual address space into a specified number of virtual address segments to obtain at least one first-level page table. If at least two target virtual address segments exist in the first-level page table, the first-level page table is used as the target page table. If the target virtual address segment does not have a corresponding physical address segment, a new physical address segment is matched for the target virtual address. Thus, the physical address segment corresponding to each virtual address segment in the target page table can be used as a hot segment. However, if a portion is randomly selected from a large virtual address space, and the search for the corresponding hot segment is based on whether the selected portion of the virtual address space has been accessed, it may take a long time to find the hot segment if the randomly selected portion of the virtual address space has never been accessed. The method provided in this application divides the virtual address space into at least one first-level page table. When there are at least two target virtual address segments in the first-level page table, the physical address segments corresponding to all virtual address segments in the first-level page table can be directly identified as hot segments, thereby quickly and effectively finding hot segments.
[0063] Please see Figure 4 , Figure 4 This application illustrates a method for determining a memory region, which can be applied to the electronic device 100 described in the foregoing embodiments. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130. Specifically, the method includes steps S210 to S270.
[0064] Step S210: When the electronic device executes a process, the virtual address space of the electronic device is obtained, the virtual address space including at least one virtual address segment.
[0065] Step S220: Divide the virtual address space into segments according to a specified number of virtual addresses to obtain at least one first-level page table.
[0066] Steps S210 and S220 have been described in detail in the foregoing embodiments and will not be repeated here.
[0067] Step S230: Set the flag bit of each of the first-level page tables to the default state.
[0068] Step S240: When it is detected that there are at least two target virtual address segments in the first-level page table, the flag bit of the first-level page table is set to a specified state.
[0069] Step S250: Use the first-level page table whose flag is in the specified state as the target page table.
[0070] In some implementations, when there are multiple first-level page tables, there may be more than one first-level page table containing at least two target virtual address segments. Therefore, a flag bit can be set for each first-level page table to indicate whether at least two target virtual address segments exist in that first-level page table.
[0071] For example, the flag bit can be a specified location stored in multiple virtual address segments corresponding to the first-level page table, with different values representing different states of the flag bit. For instance, the flag bit can be the first address in the first-level page table, where "0" can be the default state and non-"0" represents the specified state. Thus, by detecting the data at the first address of each first-level page table, when the data stored at that address is "0", the flag bit of the first-level page table is in the default state; when the data stored at that address is non-"0", such as "0001" or "00ef", the flag bit of the first-level page table is in the specified state. Furthermore, based on whether the flag bit in each first-level page table is in the default or specified state, it can be determined whether the first-level page table is the target page table.
[0072] In one implementation method provided in this application, the flag bits in each first-level page table can be set to the default state first. Please refer to the example above. Then the data corresponding to the first address in each first-level page table can be set to "0". At this time, the flag bits in each first-level page table can be set to the default state.
[0073] Furthermore, when at least two target virtual address segments are detected in the first-level page table, the flag bit of the first-level page table is set to a specified state. Referring to the example above, the data at the first address of a first-level page table containing at least two target virtual address segments can be set to a non-zero value, such as "0001" or "00ec", thereby setting the flag bit of the first-level page table to the specified state.
[0074] Furthermore, the flag bits of each first-level page table can be detected, and the first-level page table whose flag bits are in the specified state can be used as the target page table. At this point, a first-level page table containing at least two target virtual address segments can be identified as the target page table.
[0075] Step S260: If the target virtual address segment does not have a corresponding physical address segment, then a new physical address segment is matched for the target virtual address.
[0076] Step S270: Take the physical address segment corresponding to each virtual address segment in the target page table as a hot segment.
[0077] Steps S260 and S270 have been described in detail in the foregoing embodiments and will not be repeated here.
[0078] Please see Figure 5 , Figure 5 This application illustrates a method for determining a memory region, which can be applied to the electronic device 100 described in the foregoing embodiments. The electronic device 100 includes a processor 110, a memory 120, and a memory 130. The processor 110 is connected to both the memory 120 and the memory 130, and the memory 120 is also connected to the memory 130. Specifically, the method includes steps S310 to S370.
[0079] Step S310: When the electronic device executes a process, the virtual address space of the electronic device is obtained, the virtual address space including at least one virtual address segment.
[0080] Step S320: Divide the virtual address space into segments according to a specified number of virtual addresses to obtain at least one first-level page table.
[0081] Steps S310 and S320 have been described in detail in the foregoing embodiments and will not be repeated here.
[0082] Step S330: Divide the virtual address corresponding to each first-level page table into segments according to the second specified number to obtain multiple second-level page tables.
[0083] Step S340: If a target virtual address segment is detected in the first-level page table, the first-level page table is used as an intermediate page table.
[0084] Step S350: If another target virtual address segment exists in one of the multiple second-level page tables of the intermediate page table, the second-level page table that includes the other target virtual address segment shall be used as the target page table.
[0085] In some implementations, since there may be a large number of virtual address segments in the first-level page table, the virtual address segments in each first-level page table can be further divided according to a second specified number to obtain multiple second-level page tables. The second-level page tables can be used to store the virtual address segments obtained after dividing each virtual address segment in the first-level page table according to the second specified number. For example, if each first-level page table includes M virtual address segments, where the second specified number can be M / 100, then 100 second-level page tables can be obtained, with each second-level page table including M / 100 virtual address segments.
[0086] It's easy to understand that since a second-level page table divides the virtual address segments included in each first-level page table, the number of virtual address segments in each second-level page table should not exceed the number of virtual address segments in each first-level page table. If the number of virtual address segments in each second-level page table equals the number in each first-level page table, then there is no difference between the second-level and first-level page tables. Therefore, the number of virtual address segments in the second-level page table should be less than the number in the first-level page table. Furthermore, the number of virtual address segments in the second-level page table is the second specified number, and the number of virtual address segments in the first-level page table is the specified number. Therefore, the specified number is greater than the second specified number. For example, if the specified number is N and the second specified number is M, then N is greater than M.
[0087] Furthermore, due to the existence of two levels of page tables, when a target virtual address segment is detected in the first-level page table, the first-level page table can be used as an intermediate page table. The target page table can then be determined using this intermediate page table. For details, please refer to [link to relevant documentation]. Figure 6 , Figure 6 One embodiment of step S340 is shown, including S341 and S342.
[0088] Step S341: If a target virtual address segment is detected in the first-level page table, the first-level page table is used as an intermediate page table.
[0089] Step S342: Set the flag bit of each of the second-level page tables in the intermediate page table to the default state.
[0090] In some implementations, when a target virtual address segment is detected in a first-level page table, the first-level page table is used as an intermediate page table. Then, the flag bits of each second-level page table in this intermediate page table are set to their default state. The flag bits for the second-level page tables are similar to those for the first-level page tables; please refer to the preceding description of the first-level page table flag bits, which will not be repeated here. Furthermore, the presence of the target virtual address in each second-level page table corresponding to the intermediate page table can be further monitored, thereby determining the target page table.
[0091] Since each virtual address segment in a first-level page table must contain a target virtual address segment for the first-level page table to be considered an intermediate page table, it is easy to see that each second-level page table in the intermediate page table contains a target virtual address present in the aforementioned first-level page table. Therefore, the target page table can also be determined by another target virtual address segment. Specifically, if another target virtual address segment exists in multiple second-level page tables of the intermediate page table, the second-level page table containing the other target virtual address segment is used as the target page table. This other target virtual address segment is a different virtual address segment from the one previously identified when determining the first-level page table as an intermediate page table.
[0092] For details, please refer to Figure 7 , Figure 7 A diagram illustrating one embodiment of step S350 is shown, including steps S351 and S352.
[0093] Step S351: If another target virtual address segment exists in one of the multiple second-level page tables of the intermediate page table, set the flag bit of the second-level page table of the other target virtual address segment from the default state to the specified state.
[0094] Step S352: The second-level page table whose flag bits satisfy the specified state is taken as the target page table.
[0095] In some implementations, if another target virtual address segment appears in multiple second-level page tables, the flag bit of the second-level page table containing the target virtual address segment is set from the default state to a specified state.
[0096] Furthermore, the flag bit of each second-level page table in the intermediate page table can be detected, and the second-level page table with the flag bit set to the specified state can be used as the target page table.
[0097] Please see Figure 8 , Figure 8A schematic diagram of a two-level page table is shown. The virtual address space 210 can be divided into multiple first-level page tables 220 according to a specified number of virtual address segments. Each first-level page table 220 is then divided into multiple second-level page tables 230 according to a second specified number of virtual address segments. When a target virtual address segment exists in a first-level page table, that first-level page table is designated as an intermediate page table. Furthermore, the second-level page table 230 in the intermediate page table that contains another target virtual address segment is designated as the target page table, thus allowing the hot segmentation of the target page table to be determined.
[0098] In some implementations, the first-level page table can be the Page Upper Directory (PUD), the second-level page table can be the Page Middle Directory (PMD), and the virtual address segment can be a page table entry (PTE).
[0099] Step S360: If the target virtual address segment does not have a corresponding physical address segment, then a new physical address segment is matched for the target virtual address.
[0100] Step S370: Take the physical address segment corresponding to each virtual address segment in the target page table as a hot segment.
[0101] Steps S360 and S370 have been described in detail in the foregoing embodiments and will not be repeated here.
[0102] This application provides a method, apparatus, electronic device, and computer-readable medium for determining a memory region. When the electronic device executes a process, the method can obtain the virtual address space of the electronic device, then divide the virtual address space into a specified number of virtual address segments to obtain at least one first-level page table; divide the virtual address segments corresponding to each first-level page table into a second specified number of second-level page tables; if a target virtual address segment is detected in the first-level page table, the first-level page table is used as an intermediate page table; if another target virtual address segment exists in the multiple second-level page tables of the intermediate page table, the second-level page table including the other target virtual address segment is used as the target page table; and if the target virtual address segment does not have a corresponding physical address segment, a new physical address segment is matched for the target virtual address; thereby, the physical address segment corresponding to each virtual address segment in the target page table can be used as a hot segment. The first-level page table may contain a large number of target virtual address segments. By further dividing each first-level page table into multiple second-level page tables, and then determining the target page table based on the second-level page tables, hot segmentation can be identified. This avoids identifying too many virtual address segments as hot segments, thereby improving the accuracy of hot segment identification.
[0103] Please see Figure 9 The diagram illustrates a structural block diagram of a memory region determination device 900 provided in an embodiment of this application, which is applied to an electronic device. The device includes: an acquisition unit 910, a processing unit 920, a first judgment unit 930, a second judgment unit 940, and a determination unit 950.
[0104] The acquisition unit 910 is used to acquire the virtual address space of the electronic device when the electronic device is executing a process, the virtual address space including at least one virtual address segment.
[0105] The processing unit 920 is used to divide the virtual address space into segments according to a specified number of virtual addresses to obtain at least one first-level page table.
[0106] The first judgment unit 930 is used to determine if there are at least two target virtual address segments in the first-level page table, and to use the first-level page table as the target page table, so that the data stored in the physical address segment of the target virtual address segment cannot be successfully obtained.
[0107] Furthermore, the first judgment unit 930 is also used to set the flag bit of each of the first-level page tables to the default state;
[0108] When it is detected that there are at least two target virtual address segments in the first-level page table, the flag bit of the first-level page table is set to a specified state; the first-level page table with the flag bit set to the specified state is used as the target page table.
[0109] Furthermore, the first judgment unit 930 is also used to divide the virtual address segment corresponding to each of the first-level page tables into multiple second-level page tables according to the second specified number; if a target virtual address segment is detected in the first-level page table, the first-level page table is used as an intermediate page table; if another target virtual address segment exists in the multiple second-level page tables of the intermediate page table, the second-level page table including the other target virtual address segment is used as the target page table.
[0110] Furthermore, the first judgment unit 930 is also configured to, if a target virtual address segment is detected in the first-level page table, use the first-level page table as an intermediate page table; set the flag bit of each second-level page table in the intermediate page table to a default state; and if another target virtual address segment exists in multiple second-level page tables of the intermediate page table, use the second-level page table containing the other target virtual address segment as the target page table, comprising: if another target virtual address segment exists in multiple second-level page tables of the intermediate page table, setting the flag bit of the second-level page table of the other target virtual address segment from the default state to a specified state; and using the second-level page table whose flag bit satisfies the specified state as the target page table. Wherein, the first-level page table includes a page table parent directory, the second-level page table includes a page table intermediate directory, and the virtual address segment includes page table entries.
[0111] The second judgment unit 940 is used to re-match a physical address segment for the target virtual address if the target virtual address segment does not have a corresponding physical address segment.
[0112] The determining unit 950 is used to treat the physical address segment corresponding to each virtual address segment in the target page table as a hot segment.
[0113] Furthermore, the determining unit 950 is also used to determine the physical address segment corresponding to each virtual address segment in the target page table based on the virtual physical address mapping table, and to treat the physical address segment as a hot segment.
[0114] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the above-described apparatus and unit can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0115] In the several embodiments provided in this application, the coupling between the units can be electrical, mechanical or other forms of coupling.
[0116] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0117] Please refer to Figure 10 This document illustrates a structural block diagram of an electronic device 100 provided in an embodiment of this application. The electronic device 100 can be a smartphone, tablet computer, e-reader, or other electronic device capable of running applications. The electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more applications, wherein the one or more applications can be stored in the memory 120 and configured to be executed by one or more processors 110, and the one or more applications are configured to perform the methods described in the foregoing method embodiments.
[0118] Processor 110 may include one or more processing cores. Processor 110 connects to various parts within the electronic device 100 using various interfaces and lines, and performs various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets, or instruction sets stored in memory 120, and by calling data stored in memory 120. Optionally, processor 110 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 110 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 processor 110 and may be implemented separately using a communication chip.
[0119] The memory 120 may include random access memory (RAM) or read-only memory (ROM). The memory 120 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 120 may include a program storage area and a data storage area. 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. The data storage area may also store data created by the electronic device 100 during use (such as phonebook data, audio and video data, chat log data, etc.).
[0120] Please refer to Figure 11 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 1100 stores program code that can be called by a processor to execute the methods described in the above method embodiments.
[0121] The computer-readable storage medium 1100 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 1100 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 1100 has storage space for program code 1110 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 1110 may, for example, be compressed in a suitable form.
[0122] Please refer to Figure 12 The diagram illustrates a structural block diagram 1200 of a computer program product provided in an embodiment of this application. The computer program product 1200 includes a computer program / instructions 1210, which, when executed by a processor, implements the steps of the aforementioned method.
[0123] 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 memory region determination method, characterized by, Applied to electronic devices, including: When the electronic device executes a process, it acquires the virtual address space of the electronic device, the virtual address space including at least one virtual address segment; The virtual address space is divided into segments according to a specified number of virtual addresses to obtain at least one first-level page table; If there are at least two target virtual address segments in the first-level page table, the first-level page table is used as the target page table. The data stored in the physical address segment of the target virtual address segment cannot be successfully retrieved. The inability to successfully retrieve the data stored in the physical address segment of the target virtual address segment includes the target virtual address segment not having a corresponding physical address segment, and also includes the target virtual address segment having a corresponding physical address segment, but the target virtual address segment does not have permission to read or write. If the target virtual address segment does not have a corresponding physical address segment, then a new physical address segment will be matched for the target virtual address segment; The physical address segment corresponding to each virtual address segment in the target page table is used as a hot segment.
2. The method of claim 1, wherein, The first-level page table includes multiple tables. The step of using the first-level page table as the target page table if at least two target virtual address segments exist in the first-level page table includes: Set the flag bit of each of the first-level page tables to the default state; When it is detected that there are at least two target virtual address segments in the first-level page table, the flag bit of the first-level page table is set to the specified state; The first-level page table whose flag is set to the specified state is used as the target page table.
3. The method of claim 1, wherein, The specified quantity also includes a second specified quantity, wherein the specified quantity is less than the second specified quantity, and the step of using the first-level page table as the target page table if at least two target virtual address segments exist in the first-level page table includes: The virtual address corresponding to each first-level page table is divided into segments according to the second specified number to obtain multiple second-level page tables; If a target virtual address segment is detected in the first-level page table, the first-level page table will be used as an intermediate page table. If another target virtual address segment exists in one of the multiple second-level page tables of the intermediate page table, the second-level page table that includes the other target virtual address segment will be used as the target page table.
4. The method of claim 3, wherein, If a target virtual address segment is detected in the first-level page table, the first-level page table is used as an intermediate page table, including: If a target virtual address segment is detected in the first-level page table, the first-level page table will be used as an intermediate page table. Set the flag bit of each of the second-level page tables in the intermediate page table to the default state; If another target virtual address segment exists in one of the multiple second-level page tables of the intermediate page table, the second-level page table containing the other target virtual address segment will be used as the target page table, including: If another target virtual address segment exists in one of the multiple second-level page tables of the intermediate page table, the flag bit of the second-level page table of the other target virtual address segment is set from the default state to the specified state; The second-level page table whose flag bits satisfy the specified state is used as the target page table.
5. The method according to claim 3 or 4, characterized in that, The first-level page table includes the page table parent directory, the second-level page table includes the page table intermediate directory, and the virtual address segment includes page table entries.
6. The method according to claim 1, characterized in that, The step of dividing the physical address segment corresponding to each virtual address segment in the target page table into hot segments includes: Based on the virtual physical address mapping table, the physical address segment corresponding to each virtual address segment in the target page table is determined, and the physical address segment is used as a hot segment.
7. A memory region determination device, characterized in that, The main control module used in electronic devices includes: The acquisition unit is used to acquire the virtual address space of the electronic device when the electronic device executes a process, the virtual address space including at least one virtual address segment; The processing unit is used to divide the virtual address space into segments according to a specified number of virtual addresses to obtain at least one first-level page table; The first judgment unit is used to determine if at least two target virtual address segments exist in the first-level page table, and to use the first-level page table as the target page table, and the data stored in the physical address segment of the target virtual address segment cannot be successfully retrieved. The inability to successfully retrieve the data stored in the physical address segment of the target virtual address segment includes the absence of a corresponding physical address segment for the target virtual address segment, and the presence of a corresponding physical address segment for the target virtual address segment, but the target virtual address segment does not have permission to read or write. The second judgment unit is used to re-match a physical address segment for the target virtual address segment if the target virtual address segment does not have a corresponding physical address segment. The determining unit is used to treat the physical address segment corresponding to each virtual address segment in the target page table as a hot segment.
8. An electronic device, characterized in that, include: One or more processors; Memory; One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, the one or more applications being configured to perform the method as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1-6.
10. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the method described in any one of claims 1-6.