Cache method and device of memory page, electronic equipment and storage medium
By setting page slots of different sizes in virtual memory and caching them to match the size of the pages to be swapped out, the problem of insufficient memory allocation is solved, efficient compression and decompression of large pages are achieved, and the overhead of memory swapping is reduced.
Patent Information
- Application Number
- CN202211065256.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2042-08-31
AI Technical Summary
Electronic devices have limited memory space, leading to insufficient memory allocation. Existing memory reclamation technologies only support reading and writing small pages, resulting in low efficiency in disassembling and compressing large pages, and increased reverse mapping and lock contention.
Caching is performed using page slots of different sizes to match the size of the page to be swapped out. Compressed caching of large pages is supported, reducing reverse mapping and lock contention during the swapping process.
It improves the compression ratio, reduces reverse mapping and lock contention in the swapping process, and enhances memory utilization efficiency.
Smart Images

Figure CN115509958B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of electronic devices, and more particularly, to a memory page caching method and device, an electronic device, and a storage medium. BACKGROUND
[0002] With the development of science and technology, electronic devices are increasingly widely used and have more and more functions, and have become one of the necessities in people's daily life. In the running process of an electronic device, an operating system will cache a large amount of data in the memory of the electronic device in order to speed up the running of the electronic device, so as to facilitate the fast reading and writing of the cached data. However, the memory space of the electronic device is limited, and caching all data in the memory will cause insufficient memory allocation, resulting in abnormal running of the electronic device. SUMMARY
[0003] In view of the above problems, the present application provides a memory page caching method and device, an electronic device, and a storage medium to solve the above problems.
[0004] In a first aspect, an embodiment of the present application provides a memory page caching method, which comprises: in the case of page swapping from a physical memory to a virtual memory, obtaining a page to be swapped out, wherein the virtual memory comprises a plurality of page slots of at least two different sizes; and compressing the page to be swapped out to a first page slot in the plurality of page slots for caching, wherein the size of the first page slot matches the size of the page to be swapped out.
[0005] In a second aspect, an embodiment of the present application provides a memory page caching device, which comprises: a page to be swapped out obtaining module configured to obtain a page to be swapped out in the case of page swapping from a physical memory to a virtual memory, wherein the virtual memory comprises a plurality of page slots of at least two different sizes; and a page caching module configured to compress the page to be swapped out to a first page slot in the plurality of page slots for caching, wherein the size of the first page slot matches the size of the page to be swapped out.
[0006] In a third aspect, an embodiment of the present application provides an electronic device, which comprises a memory and a processor, wherein the memory is coupled to the processor, and the memory stores instructions, which, when executed by the processor, cause the processor to perform the above method.
[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores program codes, and the program codes can be invoked by a processor to perform the above method.
[0008] The memory page caching method and device, the electronic device, and the storage medium provided by the embodiments of the present application can obtain a page to be swapped out in the case of swapping out the page from a physical memory to a virtual memory, wherein the virtual memory comprises a plurality of page slots of at least two different sizes, and the page to be swapped out is compressed into a first page slot in the plurality of page slots for caching, wherein the size of the first page slot matches the size of the page to be swapped out, so that the compression caching of large pages is supported by setting page slots of different sizes, and the compression ratio can be increased, the reverse mapping in the swapping process can be reduced, and the lock contention can be reduced. BRIEF DESCRIPTION OF DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort.
[0010] Figure 1 A schematic diagram of the current memory page caching mode is shown;
[0011] Figure 2 A flowchart of the memory page caching method provided by an embodiment of the present application is shown;
[0012] Figure 3 A schematic diagram of the memory page caching mode provided by an embodiment of the present application is shown;
[0013] Figure 4 A flowchart of the memory page caching method provided by an embodiment of the present application is shown;
[0014] Figure 5 A flowchart of the memory page caching method provided by an embodiment of the present application is shown;
[0015] Figure 6 A flowchart of the memory page caching method provided by an embodiment of the present application is shown; Figure 5 A flowchart of step S320 of the memory page swapping method is shown;
[0016] Figure 7 A flowchart of step S330 of the memory page swapping method is shown; Figure 5 A flowchart of step S330 of the memory page swapping method is shown;
[0017] Figure 8 A flowchart of the memory page caching method provided by an embodiment of the present application is shown;
[0018] Figure 9 A flowchart of the memory page caching method provided by an embodiment of the present application is shown;
[0019] Figure 10 A flowchart of a memory page caching method according to an embodiment of the present application is shown;
[0020] Figure 11 A block diagram of a memory page caching apparatus according to an embodiment of the present application is shown;
[0021] Figure 12 A block diagram of an electronic device for implementing a memory page caching method according to an embodiment of the present application is shown;
[0022] Figure 13 A storage unit for storing or carrying program code for implementing a memory page caching method according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0023] 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 described clearly and completely below with reference to the accompanying drawings.
[0024] First, the terms involved in the embodiments of the present application are introduced:
[0025] Physical memory: is a memory space obtained through volatile memory. When an application is running, the code and data corresponding to the application are stored in a memory page, and the physical memory is used to store the memory page. During the running of the application, the central processor reads the corresponding memory page from the physical memory to realize the running of the code and data, thereby realizing the running of the application.
[0026] Virtual memory (Zram): is a technology of system memory management, which divides a part on a non-volatile memory and establishes a memory space through code. The virtual memory is a backup memory of the physical memory. When an application is running, the physical memory does not store or stores part of the memory page corresponding to the application, and the remaining available memory page of the physical memory reaches the water level specified by the physical memory. The central processor determines the memory page that needs to be put into the virtual memory according to the preset condition, that is, the memory page to be exchanged this time. The central processor exchanges the memory page to be exchanged this time from the physical memory into the virtual memory, thereby freeing up memory space for the new application to realize the running of the application. The water level specified by the physical memory refers to the ratio between the remaining available memory page of the physical memory and the total memory page of the physical memory. For example, if the physical memory is set to a specified water level of 40%, when the ratio of the remaining available memory page of the physical memory reaches 40%, part of the memory page in the physical memory needs to be put into the virtual memory.
[0027] Swapping refers to the process in an operating system where, when the memory page to be swapped is located in physical memory, the central processing unit (CPU) swaps the memory page from physical memory into virtual memory; conversely, when the memory page to be swapped is located in virtual memory, the CPU swaps the determined memory page from virtual memory into physical memory.
[0028] Page fault: When fetching instructions or data, the memory management unit needs to translate virtual addresses into physical addresses. If the virtual address does not have a corresponding physical address or the CPU does not have the necessary access permissions, the CPU will generate a page fault.
[0029] Large pages: In the Android system, regular small pages use 4K. If a page granularity larger than 4K is used, such as 64K or 2M, these granularity pages supported by the architecture are called large pages.
[0030] Anonymous pages: Physical pages without backup files are called anonymous pages, such as the program's heap and stack.
[0031] LRU (Least Recently Used) linked list: In Linux's memory reclamation algorithm, an LRU linked list is used to store the least recently used pages. When adding a page, it is added from the head of the list, and when reclaiming a page, it is removed from the tail of the list.
[0032] To avoid insufficient memory allocation caused by caching all data in memory, electronic devices began supporting memory reclamation mechanisms. However, the inventors discovered that current memory reclamation technology only supports reading and writing small pages (such as 4K). When the operating system's memory is insufficient, it writes recently infrequently used anonymous pages to the swap partition. When these anonymous pages in the swap partition are accessed again, a page fault occurs, and the anonymous pages in the swap partition are read into memory during exception handling. In embedded electronic devices such as mobile phones, flash memory is generally used as the storage device. Considering issues such as the lifespan of flash memory due to erasure, virtual memory ZRAM is used as the swap partition.
[0033] Among them, such as Figure 1 As shown, when the operating system's physical memory is tight, if the swapped-out page is a large page (e.g., 64K), it needs to be broken down into smaller pages (e.g., 4K). Each page is then compressed into ZRAM. Upon subsequent access, the corresponding page (a regular 4K page) is decompressed into the LRU list (these smaller pages need to be reassembled into larger pages to continue enjoying the benefits of larger pages). However, this method requires splitting large pages into smaller pages and compressing each page individually when swapping to ZRAM, and subsequent accesses cannot retrieve the entire page; each page also needs to be decompressed. This method has relatively low compression and increases reverse mapping and lock contention during the swapping process.
[0034] To address the aforementioned problems, the inventors, through extensive research, discovered and proposed a memory page caching method, apparatus, electronic device, and storage medium as provided in the embodiments of this application. By setting page slots of different sizes, compressed caching of large pages can be achieved, increasing the compression ratio, reducing reverse mapping during the swapping process, and reducing lock contention. The specific memory page caching method will be described in detail in subsequent embodiments.
[0035] Please see Figure 2 , Figure 2 A flowchart illustrating a memory page caching method according to an embodiment of this application is shown. This method supports compressed caching of large pages by setting page slots of different sizes, thereby increasing the compression ratio, reducing reverse mapping during swapping, and reducing lock contention. In a specific embodiment, this memory page swapping method is applied to, for example... Figure 8 The memory page cache device 200 shown and the electronic device 100 configured by the memory cache device 200 ( Figure 9 The following will use an electronic device as an example to illustrate the specific process of this embodiment. Of course, it is understood that the electronic device used in this embodiment may include smartphones, tablets, wearable electronic devices, etc., and is not limited thereto. The following will focus on... Figure 2 The process shown will be described in detail. The memory page caching method may specifically include the following steps:
[0036] Step S110: In the case of swapping pages from physical memory to virtual memory, obtain the page to be swapped out, wherein the virtual memory includes multiple page slots of at least two different sizes.
[0037] Memory pages are used to store the code and data corresponding to an application; physical memory is used to store memory pages that are frequently used during application runtime; virtual memory, also known as swap partition, is used to store memory pages of infrequently used applications, and / or memory pages of running applications that are not frequently used.
[0038] In some implementations, the virtual memory includes at least two different page slots of varying sizes. Each page slot can store a memory page, and each page slot can store a memory page whose size is no larger than the slot size. The virtual memory can have multiple page slots, and the slot sizes of these multiple page slots can be completely different or not completely the same. In this embodiment, the types of slot sizes for the multiple page slots can be set according to requirements and are not limited here. As one possible implementation, the multiple page slots refer to two or more page slots; for example, the multiple page slots can include at least two of the following: 4K, 16K, 32K, 64K, 128K, and 2M.
[0039] For example, a part of the plurality of page slots can have a first capacity, and another part of the plurality of page slots can have a second capacity. For another example, a first part of the plurality of page slots can have a first capacity, a second part of the plurality of page slots can have a second capacity, and a third part of the plurality of page slots can have a third capacity. For yet another example, each of the plurality of page slots can have a different capacity.
[0040] In this embodiment, it can be detected whether the electronic device meets the page swapping from the physical memory to the virtual memory. If it is detected that the electronic device meets the page swapping from the physical memory to the virtual memory, the to-be-swapped page can be obtained.
[0041] As a manner, it can be detected whether the physical memory of the electronic device is insufficient. If it is detected that the physical memory of the electronic device is insufficient, it can be determined that the electronic device meets the page swapping from the physical memory to the virtual memory.
[0042] As another manner, in response to a running instruction of a target application, it can be detected whether the physical memory caches a memory page corresponding to the target application. If it is detected that the physical memory does not cache the memory page corresponding to the target application, it can be detected whether the physical memory of the electronic device is insufficient. If it is detected that the physical memory of the electronic device is insufficient, it can be determined that the electronic device meets the page swapping from the physical memory to the virtual memory.
[0043] As still another manner, it can be determined that the electronic device meets the page swapping from the physical memory to the virtual memory when a memory recycling instruction is listened to. The memory recycling instruction can be triggered by a user of the electronic device through a touch operation or a voice input.
[0044] In some embodiments, the to-be-swapped page can be obtained from the physical memory. For example, the to-be-swapped page can be obtained according to a caching order of a plurality of memory pages in the physical memory. For another example, the to-be-swapped page can be obtained randomly from the physical memory. As a manner that can be implemented, the physical memory includes an lru list for storing memory pages. The memory page stored at a tail of the lru list can be obtained, and the obtained memory page stored at the tail of the lru list can be taken as the to-be-swapped memory page.
[0045] Step S120: compress the to-be-swap-out page to a first page slot in the plurality of page slots for caching, wherein a slot size of the first page slot matches a page size of the to-be-swap-out page.
[0046] In the embodiment, in a case where the to-be-swap-out page is obtained, the to-be-swap-out page can be compressed as a whole to a first page slot in the plurality of page slots for caching, wherein a slot size of the first page slot matches a page size of the to-be-swap-out page. Based on this, the whole compression caching of a large page can be implemented, which can increase the compression ratio on one hand, and reduce the overheads such as reverse mapping, lock contention and the like of the swap process (and can also reduce the utilization of the central processing unit during compression) on the other hand.
[0047] In some embodiments, in a case where the to-be-swap-out page is obtained, a page slot with a slot size matching the page size of the to-be-swap-out page can be obtained from the plurality of page slots in the virtual memory, and the page slot with the slot size matching the page size of the to-be-swap-out page is determined as the first page slot. Then, the to-be-swap-out page can be compressed as a whole to the first page slot in the plurality of page slots for caching.
[0048] In some embodiments, in a case where the to-be-swap-out page is obtained, the to-be-swap-out page can be compressed as a whole to obtain a to-be-swap-out data packet, and then the to-be-swap-out data packet can be cached to a first page slot in the plurality of page slots.
[0049] As an implementable manner, the slot size of the first page slot matching the page size of the to-be-swap-out page can include that the slot size of the first page slot is consistent with the page size of the to-be-swap-out page, for example, the slot size of the first page slot is 4K, and the page size of the to-be-swap-out page is 4K, or the slot size of the first page slot is 64K, and the page size of the to-be-swap-out page is 64K. At this time, the to-be-swap-out page can not be disassembled, but cached to one page slot by means of whole compression.
[0050] As another implementable manner, the slot size of the first page slot matching the page size of the to-be-swap-out page can include that the slot size of the first page slot is greater than the page size of the to-be-swap-out page, and the difference between the slot size of the first page slot and the page size of the to-be-swap-out page is less than a difference threshold, for example, the slot size of the first page slot is 4K, and the page size of the to-be-swap-out page is 3.5K, or the slot size of the first page slot is 64K, and the page size of the to-be-swap-out page is 60K. At this time, the to-be-swap-out page can not be disassembled, but cached to one page slot by means of whole compression.
[0051] Please refer toFigure 3 , Figure 3 A schematic diagram of a cache mode of a memory page provided by an embodiment of the present application is shown. As shown in Figure 3 , the virtual memory includes page slots with a slot size of 4K and page slots with a slot size of 64K. Assuming that the page size of a page to be swapped out is 64K, the page with the page size of 64K to be swapped out can be compressed into a corresponding page slot (the page slot with the slot size of 64K) in the virtual memory, and accordingly, when accessed again, the page with the page size of 64K to be swapped out can be decompressed into an lru linked list.
[0052] The cache method of a memory page provided by an embodiment of the present application, in the case of page swapping from a physical memory to a virtual memory, acquires a page to be swapped out, wherein the virtual memory includes a plurality of page slots with at least two different sizes, and the page to be swapped out is compressed into a first page slot in the plurality of page slots for caching, wherein the slot size of the first page slot matches the page size of the page to be swapped out, so that by setting page slots with different sizes, compression caching of large pages is supported, and the compression ratio can be increased, the reverse mapping in the swapping process can be reduced, and lock contention can be reduced.
[0053] Please refer to Figure 4 , Figure 4 A flowchart of a cache method of a memory page provided by an embodiment of the present application is shown. The cache method of a memory page will be described in detail below with respect to the flowchart shown in Figure 4 . The cache method of a memory page can specifically include the following steps:
[0054] Step S210: In the case of page swapping from a physical memory to a virtual memory, a page to be swapped out is acquired, wherein the virtual memory includes a plurality of page slots with at least two different sizes.
[0055] Step S220: The page to be swapped out is compressed into a first page slot in the plurality of page slots for caching, wherein the slot size of the first page slot matches the page size of the page to be swapped out.
[0056] The specific description of steps S210-S220 can be referred to steps S110-S120, which will not be described here again.
[0057] Step S230: In response to an access instruction for the page to be swapped out, the page to be swapped out is decompressed from the first page slot to the physical memory for caching.
[0058] In the embodiment, after the to-be-evicted page is cached in the first page slot in the virtual memory, it can be monitored whether an access instruction for the to-be-evicted page is received. In a case where it is determined that the access instruction for the to-be-evicted page is received, the to-be-evicted page can be decompressed from the first page slot and cached in the physical memory in response to the access instruction for the to-be-evicted page.
[0059] In some embodiments, the to-be-evicted data packet is cached in the first page slot. In response to the access instruction for the to-be-evicted page, the to-be-evicted data packet can be decompressed as a whole to obtain the to-be-evicted page, and then the to-be-evicted page can be decompressed from the first page slot and cached in the physical memory.
[0060] In some embodiments, the physical memory includes an lru list. In response to the access instruction for the to-be-evicted page, the to-be-evicted page can be decompressed from the first page slot and cached in the lru list. For example, the to-be-evicted page can be decompressed from the first page slot and cached at the head of the lru list.
[0061] As one way, an application associated with the to-be-evicted page can be determined, and it can be monitored whether the electronic device runs the application associated with the to-be-evicted page. In a case where it is monitored that the electronic device starts to run the application associated with the to-be-evicted page, an access instruction for the to-be-evicted page can be generated. Accordingly, the to-be-evicted page can be decompressed from the first page slot and cached in the physical memory in response to the access instruction for the to-be-evicted page. The application associated with the to-be-evicted page can include code and data of the application included in the to-be-evicted page.
[0062] As one example, if the to-be-evicted page has a page size of 4K, the to-be-evicted page with the page size of 4K can be directly decompressed in the physical memory. If the to-be-evicted page has a page size of 64K, the to-be-evicted page with the page size of 64K can be directly decompressed in the physical memory. Details are not described herein.
[0063] The memory page caching method provided by an embodiment of the present application includes: in a case where a to-be-evicted page is evicted from a physical memory to a virtual memory, obtaining the to-be-evicted page; the virtual memory includes at least two page slots with different sizes; the to-be-evicted page is compressed and cached in a first page slot in the at least two page slots; the first page slot has a slot size matching a page size of the to-be-evicted page; and in response to an access instruction for the to-be-evicted page, the to-be-evicted page is decompressed from the first page slot and cached in the physical memory. Figure 2The memory page caching method shown in this embodiment also decompresses the page to be swapped out from virtual memory to physical memory as a whole, which can support decompression caching of large pages, increase the compression ratio, reduce reverse mapping in the swapping process, and reduce lock contention.
[0064] Please see Figure 5 , Figure 5 A flowchart illustrating a memory page caching method according to an embodiment of this application is shown. The following will focus on... Figure 5 The process shown will be described in detail. The memory page caching method may specifically include the following steps:
[0065] Step S310: In the case of swapping pages from physical memory to virtual memory, obtain the page to be swapped out, wherein the virtual memory includes multiple page slots of at least two different sizes.
[0066] For a detailed description of step S310, please refer to step S110, which will not be repeated here.
[0067] Step S320: Obtain the page size of the page to be swapped out.
[0068] In this embodiment, if the page to be swapped out is obtained, the page size of the page to be swapped out can be obtained.
[0069] In some implementations, once the page to be swapped out is obtained, its page structure can be analyzed to determine its size. For example, the page size may include 4K, 64K, etc., and is not limited here.
[0070] Please see Figure 6 , Figure 6 This application shows Figure 5 The flowchart illustrates step S320 of the memory page swapping method. In this embodiment, the physical memory includes a swap list used to store the page to be swapped out. The following will focus on... Figure 6 The process shown will be described in detail, and the method may specifically include the following steps:
[0071] Step S321: Obtain the header page of the page to be swapped out from the swap list.
[0072] In this embodiment, the physical memory includes a swap list (lru list), which is used to store memory pages including the page to be swapped out.
[0073] In some embodiments, in the case that the to-be-evicted page is obtained, the head page of the to-be-evicted page can be obtained from the lru linked list. The head page of the to-be-evicted page can include specification information of the to-be-evicted page, and the specification information can be used to determine whether the to-be-evicted page is a large page.
[0074] Step S322: If it is determined according to the head page that the page size of the to-be-evicted page is greater than a preset size, the page size of the to-be-evicted page is obtained.
[0075] In this embodiment, in the case that the head page of the to-be-evicted page is obtained, the head page of the to-be-evicted page can be parsed to determine whether the page size of the to-be-evicted page is greater than a preset size. In the case that it is determined that the page size of the to-be-evicted page is greater than the preset size, it can be determined that the to-be-evicted page is a large page, indicating that there can be no page slot matching the page size in the virtual memory. In this case, the page size of the to-be-evicted page can be obtained for specific comparison and analysis. In the case that it is determined that the page size of the to-be-evicted page is less than or equal to the preset size, it can be determined that the to-be-evicted page is a small page (not a large page), indicating that there is definitely a page slot matching the page size in the virtual memory. In this case, the to-be-evicted page can be directly compressed and cached in the virtual memory.
[0076] In some embodiments, the preset size can be pre-set by the electronic device by default, or can be set by the user according to the needs during use, which is not limited herein. For example, the preset size can include 4K.
[0077] Step S330: If the plurality of page slots include a page slot whose slot size matches the page size, the page slot whose slot size matches the page size is determined as the first page slot.
[0078] In this embodiment, in the case that the page size of the to-be-evicted page is obtained, it can be determined whether the plurality of page slots include a page slot whose slot size matches the page size. In the case that it is determined that the plurality of page slots include a page slot whose slot size matches the page size, the page slot whose slot size matches the page size can be determined as the first page slot.
[0079] In some embodiments, the electronic device can pre-store the slot size of each of the plurality of page slots. Then, as one way, in the case of obtaining the page size of the page to be swapped out, the page size can be compared with the slot size of each of the plurality of page slots simultaneously to determine whether the plurality of page slots include a page slot whose slot size matches the page size. As another way, in the case of obtaining the page size of the page to be swapped out, the page size can be compared with the slot size of each of the plurality of page slots in turn until it is determined that the plurality of page slots include a page slot whose slot size matches the page size, at which point the comparison of the remaining page slots is stopped, or until all page slots have been compared.
[0080] Referring to Figure 7 , Figure 7 The present application is illustrated Figure 5 The flowchart of step S330 of the memory page swapping method is shown. The following will be described in detail with respect to the flowchart shown, and the method can specifically include the following steps: Figure 7
[0081] Step S331: If the plurality of page slots include a page slot whose slot size matches the page size, idle detection is performed on the page slot whose slot size matches the page size.
[0082] In some embodiments, in the case of obtaining the page size of the page to be swapped out, it is determined whether the plurality of page slots include a page slot whose slot size matches the page size. If it is determined that the plurality of page slots include a page slot whose slot size matches the page size, idle detection can be performed on the page slot whose slot size matches the page size.
[0083] As one implementable way, the idle detection on the page slot whose slot size matches the page size can include detecting whether the page slot whose slot size matches the page size caches a memory page. If it is detected that the page slot whose slot size matches the page size caches a memory page, it can be determined that the page slot whose slot size matches the page size is in a non-idle state. If it is detected that the page slot whose slot size matches the page size does not cache a memory page, it can be determined that the page slot whose slot size matches the page size is in an idle state.
[0084] As another implementable manner, the idle detection on the page slot with the slot size matching the page size can include: detecting whether the remaining slot size of the page slot with the slot size matching the page size is less than the capacity size thereof. In a case where it is detected that the remaining slot size of the page slot with the slot size matching the page size is less than the capacity size thereof, it can be determined that the page slot with the slot size matching the page size is in the non-idle state. In a case where it is detected that the remaining slot size of the page slot with the slot size matching the page size is equal to the capacity size thereof, it can be determined that the page slot with the slot size matching the page size is in the idle state.
[0085] Step S332: If it is detected that the page slot with the slot size matching the page size is in the idle state, the page slot with the slot size matching the page size is determined as the first page slot.
[0086] In some embodiments, in a case where it is determined that the page slot with the slot size matching the page size is detected in the idle state, it is represented that the page slot with the slot size matching the page size can be used for caching the to-be-evicted page, and the page slot with the slot size matching the page size can be determined as the first page slot.
[0087] In some embodiments, in a case where it is determined that the page slot with the slot size matching the page size is detected in the non-idle state, it is represented that the page slot with the slot size matching the page size cannot be used for caching the to-be-evicted page, and the remaining page slots in the plurality of page slots can be continuously detected whether including the page slot with the slot size matching the page size and continuously detected whether the page slot with the slot size matching the page size is in the idle state until the page slot with the slot size matching the page size is detected in the idle state, and the page slot with the slot size matching the page size is determined as the first page slot.
[0088] In some embodiments, in a case where it is determined that the page slot with the slot size matching the page size is detected in the non-idle state, it is represented that the page slot with the slot size matching the page size cannot be used for caching the to-be-evicted page, and the to-be-evicted page can be split into a plurality of to-be-evicted sub-pages according to the slot sizes of the plurality of page slots, and the plurality of to-be-evicted sub-pages are compressed into a plurality of second page slots in the plurality of page slots for caching, wherein the slot sizes of the plurality of second page slots match the page sizes of the respective cached to-be-evicted sub-pages.
[0089] Step S340: The to-be-evicted page is compressed into the first page slot for caching.
[0090] The specific description of step S340 can be referred to step S120, which will not be repeated here.
[0091] The memory page caching method provided by the embodiment of the present application, in the case of page swapping from a physical memory to a virtual memory, acquires a page to be swapped out, wherein the virtual memory comprises at least two kinds of page slots with different sizes, acquires a page size of the page to be swapped out, if the page slots comprise a page slot with a slot size matching the page size, determines the page slot with the slot size matching the page size as a first page slot, and compresses the page to be swapped out to the first page slot for caching. Compared with the memory page caching method shown in the prior art, the embodiment can guarantee the overall caching of the page to be swapped out and improve the caching effect of the page. Figure 2 The memory page caching method provided by the embodiment of the present application, in the case of page swapping from a physical memory to a virtual memory, acquires a page to be swapped out, wherein the virtual memory comprises at least two kinds of page slots with different sizes, acquires a page size of the page to be swapped out, if the page slots comprise a page slot with a slot size matching the page size, determines the page slot with the slot size matching the page size as a first page slot, and compresses the page to be swapped out to the first page slot for caching. Compared with the memory page caching method shown in the prior art, the embodiment can guarantee the overall caching of the page to be swapped out and improve the caching effect of the page.
[0092] Please refer to Figure 8 , Figure 8 The embodiment of the present application provides a memory page caching method. The flowchart of the memory page caching method is shown in the figure. The following will be described in detail with respect to the flowchart shown in the figure. The memory page caching method can specifically include the following steps: Figure 8
[0093] Step S410: In the case of page swapping from a physical memory to a virtual memory, a page to be swapped out is acquired, wherein the virtual memory comprises at least two kinds of page slots with different sizes.
[0094] The specific description of step S410 can be referred to step S110, which will not be repeated here.
[0095] Step S420: The page size of the page to be swapped out is acquired.
[0096] Step S430: If the page slots comprise a page slot with a slot size matching the page size, the page slot with the slot size matching the page size is determined as the first page slot.
[0097] The specific description of steps S420-S430 can be referred to steps S320-S330, which will not be repeated here.
[0098] Step S440: The page to be swapped out is compressed to the first page slot for caching.
[0099] The specific description of step S440 can be referred to step S120, which will not be repeated here.
[0100] Step S450: If there is no page slot whose size matches the size of the page to be swapped out in the plurality of page slots, the page to be swapped out is split into a plurality of sub-pages to be swapped out according to the sizes of the plurality of page slots.
[0101] In this embodiment, if the size of the page to be swapped out is obtained, it can be determined whether there is a page slot whose size matches the size of the page to be swapped out in the plurality of page slots. If it is determined that there is no page slot whose size matches the size of the page to be swapped out in the plurality of page slots, the page to be swapped out can be split into a plurality of sub-pages to be swapped out according to the sizes of the plurality of page slots.
[0102] In some embodiments, if it is determined that there is no page slot whose size matches the size of the page to be swapped out in the plurality of page slots, the page to be swapped out can be split into a plurality of sub-pages to be swapped out according to the sizes of the plurality of page slots. The sizes of the plurality of sub-pages to be swapped out match the sizes of the plurality of page slots.
[0103] As an implementable manner, if it is determined that there is no page slot whose size matches the size of the page to be swapped out in the plurality of page slots, the reference size (the smallest size) of the plurality of page slots can be obtained, and the page to be swapped out can be split into a plurality of sub-pages to be swapped out according to the reference size. For example, assuming that the reference size of the plurality of page slots is 4K, and the size of the page to be swapped out is 64K, the page to be swapped out with the size of 64K can be split into 16 sub-pages to be swapped out with the size of 4K.
[0104] As another implementable manner, if it is determined that there is no page slot whose size matches the size of the page to be swapped out in the plurality of page slots, the maximum size of the plurality of page slots can be obtained, and the page to be swapped out can be split into a plurality of sub-pages to be swapped out according to the maximum size. For example, assuming that the maximum size of the plurality of page slots is 32K, and the size of the page to be swapped out is 64K, the page to be swapped out with the size of 64K can be split into 2 sub-pages to be swapped out with the size of 32K.
[0105] As another implementable manner, in a case that it is determined that the page slot with the slot size matching the page size is not included in the plurality of page slots, then the slot size of each page slot in the plurality of page slots can be acquired, and the to-be-swapped-out page is split into a plurality of to-be-swapped-out sub-pages according to the slot size of each page slot in the plurality of page slots. For example, assuming that the plurality of page slots include a page slot with a slot size of 32K and a page slot with a slot size of 4K, and the page size of the to-be-swapped-out page is 64K, then the to-be-swapped-out page with a page size of 64K can be split into one to-be-swapped-out sub-page with a page size of 32K and eight to-be-swapped-out sub-pages with a page size of 4K.
[0106] Step S460: compressing the plurality of to-be-swapped-out sub-pages into a plurality of second page slots in the plurality of page slots respectively for caching, wherein the slot size of each second page slot matches the page size of the to-be-swapped-out sub-page cached in the second page slot.
[0107] In the embodiment, in a case that the plurality of to-be-swapped-out sub-pages are obtained, then the plurality of to-be-swapped-out sub-pages can be compressed into a plurality of second page slots in the plurality of page slots respectively for caching, wherein the slot size of each second page slot matches the page size of the to-be-swapped-out sub-page cached in the second page slot. Based on this, the success rate of the swap caching of the large page can be improved.
[0108] In some embodiments, in a case that the plurality of to-be-swapped-out sub-pages are obtained, then the plurality of page slots with the slot size matching the page size of the plurality of to-be-swapped-out sub-pages can be acquired from the plurality of page slots in the virtual memory, and the plurality of page slots with the slot size matching the page size of the plurality of to-be-swapped-out sub-pages are determined as a plurality of second page slots, and then the plurality of to-be-swapped-out sub-pages can be compressed into the second page slots matching the plurality of to-be-swapped-out sub-pages respectively for caching.
[0109] In some embodiments, in a case that the plurality of to-be-swapped-out sub-pages are obtained, then the plurality of to-be-swapped-out sub-pages can be compressed respectively to obtain a plurality of to-be-swapped-out data packets, and then the plurality of to-be-swapped-out data packets can be cached into the second page slots matching the plurality of to-be-swapped-out data packets.
[0110] As an implementable manner, the slot size of the second page slot matching the page size of the to-be-swapped-out sub-page can include that the slot size of the second page slot is consistent with the page size of the to-be-swapped-out sub-page, for example, the slot size of the second page slot is 4K, and the page size of the to-be-swapped-out sub-page is 4K.
[0111] As another implementable manner, the slot size of the second page slot matches the page size of the to-be-swapped sub-page can include that the slot size of the second page slot is greater than the page size of the to-be-swapped sub-page, and the difference between the slot size of the second page slot and the page size of the to-be-swapped sub-page is less than a difference threshold, for example, the slot size of the second page slot is 4K, and the page size of the to-be-swapped sub-page is 2K.
[0112] As an example, assuming that a to-be-swapped page with a page size of 64K is split into 16 to-be-swapped sub-pages with a page size of 4K, then 16 page slots with a slot size of 4K can be determined from the plurality of page slots as second page slots, wherein the 16 second page slots are respectively used to cache the 16 to-be-swapped sub-pages.
[0113] As another example, assuming that a to-be-swapped page with a page size of 64K is split into 2 to-be-swapped sub-pages with a page size of 32K, then 2 page slots with a slot size of 32K can be determined from the plurality of page slots as second page slots, wherein the 2 second page slots are respectively used to cache the 2 to-be-swapped sub-pages.
[0114] As another example, assuming that a to-be-swapped page with a page size of 64K is split into 1 to-be-swapped sub-page with a page size of 32K and 8 to-be-swapped sub-pages with a page size of 4K, then 1 page slot with a slot size of 32K and 8 page slots with a slot size of 4K can be determined from the plurality of page slots as second page slots, wherein the 1 second page slot with a slot size of 32K is used to cache the 1 to-be-swapped sub-page with a slot size of 32K, and the 8 second page slots with a slot size of 4K are respectively used to cache the 8 to-be-swapped sub-pages with a slot size of 4K.
[0115] The memory page caching method provided by an embodiment of the present application, in the case of page swapping from a physical memory to a virtual memory, acquires a to-be-swapped page, wherein the virtual memory includes at least two page slots with different sizes, acquires a page size of the to-be-swapped page, if the plurality of page slots include a page slot with a slot size matching the page size, determines the page slot with the slot size matching the page size as a first page slot, and compresses the to-be-swapped page to the first page slot for caching, if the plurality of page slots do not include a page slot with a slot size matching the page size, splits the to-be-swapped page into a plurality of to-be-swapped sub-pages according to the slot sizes of the plurality of page slots, and compresses the plurality of to-be-swapped sub-pages to a plurality of second page slots in the plurality of page slots for caching, wherein the slot sizes of the plurality of second page slots match the page sizes of the to-be-swapped sub-pages cached respectively. Compared with the prior art, the method provided by the embodiment of the present application has the advantages that the to-be-swapped page is cached in the second page slot with the slot size matching the page size, and the to-be-swapped page is split into the plurality of to-be-swapped sub-pages when the plurality of page slots do not include the page slot with the slot size matching the page size, thereby improving the cache efficiency of the to-be-swapped page. Figure 2The memory page caching method shown in the embodiment also acquires the page size of the page to be swapped out, and determines a page slot in which the slot size matches the page size as the first page slot, to cache the page to be swapped out, so that the overall caching of the page to be swapped out can be ensured, and the caching effect of the page is improved. In addition, when the page slots do not include a page slot in which the slot size matches the page size, the page to be swapped out is split and cached according to the slot sizes of the page slots, so that the caching success rate of the page to be swapped out can be improved.
[0116] Referring to Figure 9 , Figure 9 A flowchart of a memory page caching method provided by an embodiment of the application is shown. The following will be a detailed description of the flow shown in the figure. The memory page caching method can specifically include the following steps: Figure 9
[0117] Step S510: In the case of page swapping from a physical memory to a virtual memory, a page to be swapped out is acquired, wherein the virtual memory includes a plurality of page slots of at least two different sizes.
[0118] For a specific description of step S510, please refer to step S110, which will not be repeated here.
[0119] Step S520: The page size of the page to be swapped out is acquired.
[0120] Step S530: If the plurality of page slots include a page slot in which the slot size matches the page size, the page slot in which the slot size matches the page size is determined as the first page slot.
[0121] For a specific description of steps S520-S530, please refer to steps S320-S330, which will not be repeated here.
[0122] Step S540: The page to be swapped out is compressed to the first page slot for caching.
[0123] For a specific description of step S540, please refer to step S120, which will not be repeated here.
[0124] Step S550: If the plurality of page slots do not include a page slot in which the slot size matches the page size, the page to be swapped out is re-acquired from the plurality of pages in the physical memory according to the arrangement order of the plurality of pages.
[0125] In the embodiment, in the case that the page size of the to-be-evicted page is obtained, it can be determined whether the plurality of page slots include a page slot whose slot size matches the page size. If it is determined that the plurality of page slots do not include a page slot whose slot size matches the page size, the to-be-evicted page can be reacquired from the plurality of pages according to the arrangement order of the plurality of pages in the physical memory. In the case that it is determined that the plurality of page slots do not include a page slot whose slot size matches the page size, it can be considered that there is no page slot in the virtual memory that matches the to-be-evicted page, and the to-be-evicted page cannot be compressed into the virtual memory as a whole. Therefore, the to-be-evicted page can be reacquired from the plurality of pages according to the arrangement order of the plurality of pages in the physical memory, so as to attempt to acquire a page whose page size matches the slot size of the plurality of page slots as the to-be-evicted page.
[0126] In some embodiments, the physical memory includes an lru list, and the to-be-evicted page can be reacquired from the plurality of pages according to the arrangement order of the plurality of pages in the lru list. For example, if the initial to-be-evicted page is located at the tail of the lru list, a page located at the second tail of the lru list can be reacquired as the to-be-evicted page.
[0127] Step S560: compressing the reacquired to-be-evicted page into a third page slot of the plurality of page slots for caching, wherein the slot size of the third page slot matches the page size of the reacquired to-be-evicted page.
[0128] In the embodiment, in the case that the to-be-evicted page is reacquired, the reacquired to-be-evicted page can be compressed into a third page slot of the plurality of page slots for caching, wherein the slot size of the third page slot matches the page size of the reacquired to-be-evicted page. Based on this, the normal operation of the electronic device can be ensured.
[0129] In some embodiments, in the case that the to-be-evicted page is reacquired, a page slot whose slot size matches the page size of the reacquired to-be-evicted page can be acquired from the plurality of page slots in the virtual memory, and the page slot whose slot size matches the page size of the reacquired to-be-evicted page is determined as the third page slot. Then, the reacquired to-be-evicted page can be compressed into the third page slot of the plurality of page slots for caching.
[0130] In some embodiments, in the case that the to-be-evicted page is reacquired, the reacquired to-be-evicted page can be compressed as a whole to obtain a reacquired to-be-evicted data packet. Then, the reacquired to-be-evicted data packet can be cached into a third page slot of the plurality of page slots.
[0131] As an example, assuming that the page size of the plurality of page slots is 4K, and the page size of the initially obtained to-be-evicted page is 64K, it can be considered that the plurality of page slots do not include a page slot whose slot size matches the page size, and the to-be-evicted page can be reacquired. Assuming that the page size of the reacquired to-be-evicted page is 4K, the reacquired to-be-evicted page can be compressed into the third page slot of the plurality of page slots for caching.
[0132] The memory page caching method provided in an embodiment of the present application, in the case of page eviction from the physical memory to the virtual memory, acquires a to-be-evicted page, wherein the virtual memory includes at least two sizes of a plurality of page slots, acquires the page size of the to-be-evicted page, if the plurality of page slots include a page slot whose slot size matches the page size, determines the page slot whose slot size matches the page size as a first page slot, and compresses the to-be-evicted page into the first page slot for caching, if the plurality of page slots do not include a page slot whose slot size matches the page size, reacquires the to-be-evicted page from the plurality of pages according to the arrangement order of the plurality of pages in the physical memory, and compresses the reacquired to-be-evicted page into a third page slot of the plurality of page slots for caching, wherein the slot size of the third page slot matches the page size of the reacquired to-be-evicted page. Compared with the memory page caching method shown in Figure 2 The memory page caching method provided in an embodiment of the present application, in the case of page eviction from the physical memory to the virtual memory, acquires a to-be-evicted page, wherein the virtual memory includes at least two sizes of a plurality of page slots, acquires the page size of the to-be-evicted page, if the plurality of page slots include a page slot whose slot size matches the page size, determines the page slot whose slot size matches the page size as a first page slot, and compresses the to-be-evicted page into the first page slot for caching, if the plurality of page slots do not include a page slot whose slot size matches the page size, reacquires the to-be-evicted page from the plurality of pages according to the arrangement order of the plurality of pages in the physical memory, and compresses the reacquired to-be-evicted page into a third page slot of the plurality of page slots for caching, wherein the slot size of the third page slot matches the page size of the reacquired to-be-evicted page. Compared with the memory page caching method shown in
[0133] Please refer to Figure 10 , Figure 10 The flowchart of the memory page caching method provided in an embodiment of the present application is shown. The following will be a detailed description of the flowchart shown in Figure 10 The memory page caching method can specifically include the following steps:
[0134] Step S610: In the case of insufficient physical memory, perform page eviction from the physical memory to the virtual memory and acquire the to-be-evicted page.
[0135] In some embodiments, the electronic device can detect the remaining storage space of the physical memory, and if it is detected that the physical memory is insufficient, it is determined that the remaining storage space of the physical memory is insufficient and memory recycling needs to be performed. Therefore, if it is determined that the physical memory is insufficient, the electronic device can trigger page switching from the physical memory to the virtual memory and obtain the to-be-swapped-out page.
[0136] In some embodiments, the electronic device can have a memory threshold value pre-set and stored. The electronic device can detect the remaining storage space of the physical memory, and if it is detected that the physical memory is sufficient, the electronic device can compare the remaining storage space of the physical memory with the memory threshold value to determine whether the remaining storage space of the physical memory is less than the memory threshold value. If it is determined that the remaining storage space of the physical memory is less than the memory threshold value, it is determined that the physical memory is insufficient, and the electronic device can perform page swapping out from the physical memory to the virtual memory and obtain the to-be-swapped-out page. If it is determined that the remaining storage space of the physical memory is greater than or equal to the memory threshold value, it is determined that the physical memory is sufficient, and the electronic device can not perform page swapping out from the physical memory to the virtual memory.
[0137] Step S620: compressing the to-be-swapped-out page to a first page slot in the plurality of page slots for caching, wherein a slot size of the first page slot matches a page size of the to-be-swapped-out page.
[0138] The specific description of step S620 can be referred to step S120, which will not be repeated here.
[0139] The memory page caching method provided by the embodiment of the present application can perform page swapping out from the physical memory to the virtual memory and obtain the to-be-swapped-out page in the case of insufficient physical memory, and compress the to-be-swapped-out page to a first page slot in the plurality of page slots for caching, wherein a slot size of the first page slot matches a page size of the to-be-swapped-out page. Compared with the memory page caching method shown in Figure 2 The embodiment also triggers page swapping out in the case of insufficient physical memory, thereby ensuring the normal operation of the electronic device and improving the user experience.
[0140] Please refer to Figure 11 , Figure 11 A module block diagram of the memory page caching apparatus provided by the embodiment of the present application is shown. In the following, the block diagram shown in Figure 11 The memory page caching apparatus 200 includes a to-be-swapped-out page obtaining module 210 and a page caching module 220, wherein:
[0141] The to-be-evicted page obtaining module 210 is configured to obtain a to-be-evicted page in a case where page eviction is performed from a physical memory to a virtual memory, wherein the virtual memory comprises a plurality of page slots of at least two different sizes.
[0142] Further, the to-be-evicted page obtaining module 210 comprises a to-be-evicted page obtaining sub-module.
[0143] The to-be-evicted page obtaining sub-module is configured to perform page eviction from the physical memory to the virtual memory and obtain the to-be-evicted page in a case where the physical memory is insufficient.
[0144] The page caching module 220 is configured to compress the to-be-evicted page to a first page slot of the plurality of page slots for caching, wherein a slot size of the first page slot matches a page size of the to-be-evicted page.
[0145] Further, the page caching module 220 comprises a page size obtaining sub-module, a page slot determining sub-module, and a page caching sub-module.
[0146] The page size obtaining sub-module is configured to obtain the page size of the to-be-evicted page.
[0147] Further, the physical memory comprises a swap chain list configured to store the to-be-evicted page, and the page size obtaining sub-module comprises a head page obtaining unit and a page size obtaining unit.
[0148] The head page obtaining unit is configured to obtain a head page of the to-be-evicted page from the swap chain list.
[0149] The page size obtaining unit is configured to obtain the page size of the to-be-evicted page if the page size of the to-be-evicted page is determined to be greater than a preset size according to the head page.
[0150] The page slot determining sub-module is configured to determine a page slot of a slot size matching the page size as the first page slot if the plurality of page slots comprise a page slot of a slot size matching the page size.
[0151] Further, the page slot determining sub-module comprises an idle detection unit and a page slot determining unit.
[0152] The idle detection unit is configured to perform idle detection on the page slot of the slot size matching the page size if the plurality of page slots comprise a page slot of a slot size matching the page size.
[0153] The page slot determining unit is configured to determine the page slot with the slot size matching the page size as the first page slot if it is detected that the page slot with the slot size matching the page size is in an idle state.
[0154] The page cache submodule is configured to compress the to-be-evicted page to the first page slot for caching.
[0155] Further, the page cache module 220 comprises a page splitting submodule and a sub-page cache submodule, wherein:
[0156] The page splitting submodule is configured to split the to-be-evicted page into a plurality of to-be-evicted sub-pages according to the slot sizes of the plurality of page slots if the plurality of page slots do not comprise a page slot with a slot size matching the page size.
[0157] The sub-page cache submodule is configured to compress the plurality of to-be-evicted sub-pages to a plurality of second page slots in the plurality of page slots for caching, wherein the slot sizes of the plurality of second page slots match the page sizes of the respective cached to-be-evicted sub-pages.
[0158] Further, the page cache module 220 comprises a page reacquiring submodule and a reacquired page cache submodule, wherein:
[0159] The page reacquiring submodule is configured to reacquire a to-be-evicted page from the plurality of pages in the physical memory according to the arrangement order of the plurality of pages if the plurality of page slots do not comprise a page slot with a slot size matching the page size.
[0160] The reacquired page cache submodule is configured to compress the reacquired to-be-evicted page to a third page slot in the plurality of page slots for caching, wherein the slot size of the third page slot matches the page size of the reacquired to-be-evicted page.
[0161] Further, the memory page caching apparatus 200 further comprises a page decompression module, wherein:
[0162] The page decompression module is configured to decompress the to-be-evicted page from the first page slot to the physical memory for caching in response to an access instruction for the to-be-evicted page.
[0163] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described apparatuses and modules can refer to the corresponding processes in the foregoing method embodiments, which will not be described herein again.
[0164] The coupling between the modules may be electrical, mechanical, or in other forms in the embodiments of the present application.
[0165] In addition, the functional modules in the embodiments of the present application may be integrated in one processing module, or may be physically present individually, or two or more modules may be integrated in one module. The integrated module may be realized in the form of hardware or in the form of a software functional module.
[0166] Please refer to Figure 12 which shows a structural block diagram of an electronic device 100 provided by an embodiment of the present application. The electronic device 100 may be a smart phone, a tablet computer, an electronic book, or the like, which can run an application program. The electronic device 100 in the present application may include one or more of the following components: a processor 110, a memory 120, and one or more application programs, wherein the one or more application programs may be stored in the memory 120 and configured to be executed by the one or more processors 110, and the one or more programs are configured to perform the method as described in the foregoing method embodiments.
[0167] The processor 110 may include one or more processing cores. The processor 110 connects various parts in the entire electronic device 100 by various interfaces and lines, performs various functions of the electronic device 100 and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 120, and calling data stored in the memory 120. Optionally, the processor 110 may be realized in the form of at least one of digital signal processing (DSP), field programmable gate array (FPGA), programmable logic array (PLA). The processor 110 may be integrated with a combination of one or several of central processing unit (CPU), graphics processing unit (GPU), and modem. Among them, the CPU mainly processes operating systems, user interfaces, and application programs, etc.; the GPU is responsible for rendering and drawing the content to be displayed; and the modem is used for processing wireless communication. It can be understood that the above-mentioned modem may also not be integrated into the processor 110, but realized by a separate communication chip.
[0168] The memory 120 can include a random access memory (RAM) and can also include a read-only memory (ROM). The memory 120 can be used to store instructions, programs, codes, code sets, or instruction sets. The memory 120 can include a program storage area and a data storage area, where the program storage area can store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing each of the method embodiments described below, and the like. The data storage area can also store data created by the electronic device 100 in use (such as a phonebook, audio / video data, chat record data), and the like.
[0169] Referring to Figure 13 which shows a structural block diagram of a computer readable storage medium provided by an embodiment of the present application. The computer readable medium 300 stores program codes therein, which can be invoked by a processor to execute the methods described in the above method embodiments.
[0170] The computer readable storage medium 300 can be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Alternatively, the computer readable storage medium 300 includes a non-transitory computer readable medium. The computer readable storage medium 300 has a storage space for program codes 310 for executing any of the method steps described above. These program codes can be read from or written to one or more computer program products. The program codes 310 can be compressed in an appropriate form, for example.
[0171] To sum up, the memory page caching method, apparatus, electronic device, and storage medium provided by the embodiments of the present application, in the case of page swapping from a physical memory to a virtual memory, the to-be-swapped-out page is obtained, where the virtual memory includes a plurality of page slots of at least two different sizes, the to-be-swapped-out page is compressed into a first page slot of the plurality of page slots for caching, where the slot size of the first page slot matches the page size of the to-be-swapped-out page, thereby supporting compressed caching of large pages by setting page slots of different sizes, which can increase the compression ratio, reduce reverse mapping in the swapping process, and reduce lock contention.
[0172] Finally, it should be noted that the above examples are only used to illustrate the technical solutions of the present application, and are not intended to limit the same; although the present application has been described in detail with reference to the foregoing examples, those of ordinary skill in the art will understand that they can still modify the technical solutions described in the foregoing examples, or make equivalent replacements for some of the technical features; and these modifications or replacements 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 the present application.
Claims
1. A cache method of memory pages, characterized by, The method comprises: In the case of page swapping from the physical memory to the virtual memory, obtaining a to-be-swapped page, wherein the virtual memory comprises a plurality of page slots of at least two different sizes, and the virtual memory is obtained by dividing a part in the physical memory; From the plurality of page slots, obtaining a page slot whose slot size matches the page size of the to-be-swapped page, and determining the page slot whose slot size matches the page size of the to-be-swapped page as a first page slot; Without disassembling the to-be-swapped page, compressing the to-be-swapped page as a whole to the first page slot in the plurality of page slots for caching, wherein the slot size of the first page slot matches the page size of the to-be-swapped page.
2. The method of claim 1, wherein, After the to-be-swapped page is compressed to the first page slot in the plurality of page slots for caching, the method further comprises: In response to an access instruction for the to-be-swapped page, decompressing the to-be-swapped page from the first page slot to the physical memory for caching.
3. The method of claim 1, wherein, The compression of the to-be-swapped page to the first page slot in the plurality of page slots for caching comprises: Obtaining the page size of the to-be-swapped page; If the plurality of page slots include a page slot whose slot size matches the page size, determining the page slot whose slot size matches the page size as the first page slot; Compressing the to-be-swapped page to the first page slot for caching.
4. The method of claim 3, wherein, The method further comprises: If the plurality of page slots do not include a page slot whose slot size matches the page size, disassembling the to-be-swapped page into a plurality of to-be-swapped sub-pages according to the slot sizes of the plurality of page slots; Compressing the plurality of to-be-swapped sub-pages to a plurality of second page slots in the plurality of page slots for caching, respectively, wherein the slot sizes of the plurality of second page slots match the page sizes of the to-be-swapped sub-pages cached respectively.
5. The method of claim 3, wherein, The physical memory comprises a swap linked list for storing the to-be-swapped page, and the obtaining of the page size of the to-be-swapped page comprises: Obtaining a head page of the to-be-swapped page from the swap linked list; If it is determined according to the head page that the page size of the to-be-swapped page is greater than a preset size, obtaining the page size of the to-be-swapped page.
6. The method of claim 3, wherein, If the plurality of page slots include a page slot whose slot size matches the page size, the method further comprises: If the plurality of page slots include a page slot whose slot size matches the page size, performing idle detection on the page slot whose slot size matches the page size; If it is detected that the page slot whose slot size matches the page size is in an idle state, determining the page slot whose slot size matches the page size as the first page slot.
7. The method of claim 3, wherein, The method further comprises: If the page slot with the size matching the page size is not included in the plurality of page slots, a page to be swapped out is reacquired from the plurality of pages in the order of arrangement of the plurality of pages in the physical memory; The reacquired page to be swapped out is compressed and cached in a third page slot in the plurality of page slots, wherein the size of the third page slot matches the size of the reacquired page to be swapped out.
8. The method according to any one of claims 1 to 7, characterized in that, The acquiring the page to be swapped out in the case of swapping out the page from the physical memory to the virtual memory comprises: In the case of insufficient physical memory, swapping out the page from the physical memory to the virtual memory and acquiring the page to be swapped out.
9. A cache apparatus of memory pages, characterized by The apparatus comprises: A page to be swapped out acquiring module, configured to acquire the page to be swapped out in the case of swapping out the page from the physical memory to the virtual memory, wherein the virtual memory comprises a plurality of page slots with at least two different sizes, and the virtual memory is obtained by dividing a part in the physical memory; A page caching module, configured to acquire a page slot with a size matching the size of the page to be swapped out from the plurality of page slots, and determine the page slot as a first page slot; and compress and cache the page to be swapped out in the first page slot in the plurality of page slots without disassembling the page to be swapped out, wherein the size of the first page slot matches the size of the page to be swapped out.
10. An electronic device, comprising: A memory and a processor, the memory is coupled to the processor, the memory stores instructions, and when the instructions are executed by the processor, the processor executes the method according to any one of claims 1-8.
11. A computer readable storage medium, characterized in that, The computer readable storage medium stores program codes, and the program codes can be called and executed by the processor to execute the method according to any one of claims 1-8.
Citation Information
Patent Citations
Data storage method and device
CN104281528A
Page exchange method, storage system and electronic equipment
CN113590509A
Data reduction techniques for use with caching
US20210216475A1