Same memory page merging method, apparatus, device and medium

CN117519986BActive Publication Date: 2026-10-30CHINA ELECTRONICS CLOUD DIGITAL INTELLIGENCE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311694489.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-08
Publication Date
2026-10-30
Estimated Expiration
2043-12-08

AI Technical Summary

Technical Problem

但是,采用KSM,存在消耗系统资源大的问题

Benefits of technology

[0037]本公开实施例提供的技术方案与现有技术相比具有如下优点:

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117519986B_ABST
    Figure CN117519986B_ABST
Patent Text Reader

Abstract

The present disclosure relates to the technical field of computer application, and particularly relates to a same memory page merging method and device, equipment and medium, which comprises the following steps: when a to-be-detected merging memory page is received, at least one initial merging memory page is determined from a plurality of preset memory pages according to a first sampling hash value corresponding to the to-be-detected merging memory page and a plurality of second sampling hash values corresponding to the plurality of preset memory pages included in a preset tree; a target merging memory page identical to the to-be-detected merging memory page is determined according to first data information corresponding to the to-be-detected merging memory page and second data information corresponding to each initial merging memory page; and the to-be-detected merging memory page is merged with the target merging memory page. By using the method, the consumption of system resources can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer application technology, and in particular to a method, apparatus, device and medium for merging identical memory pages. Background Technology

[0002] Currently, under high-load computing scenarios, intense competition for memory resources among multiple processes in a computer system can lead to insufficient system memory, making it impossible to cache data generated by application processes. This results in degraded system performance and compromised application stability. Therefore, to improve system performance and achieve effective utilization and management of memory resources, various computer systems offer different memory management technologies, such as virtual memory. Virtual memory can reduce memory usage and improve system performance by merging identical memory pages.

[0003] Existing operating systems offer a kernel samepage merging (KSM) technique, which merges shared memory pages between multiple processes running on the system. However, KSM suffers from high system resource consumption. Summary of the Invention

[0004] Therefore, it is necessary to provide a method, apparatus, device, and medium for merging identical memory pages to address the aforementioned technical problems. This method can utilize the first sampled hash value corresponding to the memory page to be merged and the second sampled hash value corresponding to a preset memory page, eliminating the need to calculate the hash value corresponding to either the memory page to be merged or the preset memory page. It first identifies at least one initial merged memory page that may be identical to the memory page to be merged from among multiple preset memory pages, thereby reducing system power consumption during computation. Furthermore, since at least one initial merged memory page that may be identical to the memory page to be merged is identified through pre-screening of multiple preset memory pages, and further, by using the data information (such as page size and code) of the selected initial merged memory page and the memory page to be merged, the target merged memory page identical to the memory page to be merged is identified and merged. This avoids scanning, judging, and merging a large number of memory pages in the system, thereby reducing system resource consumption.

[0005] A first aspect of this disclosure provides a method for merging identical memory pages, the method comprising: upon receiving a memory page to be merged, determining at least one initial merged memory page among the plurality of preset memory pages based on a first sampled hash value corresponding to the memory page to be merged and second sampled hash values ​​corresponding to a plurality of preset memory pages included in a preset tree;

[0006] Based on the first data information corresponding to the memory page to be merged and the second data information corresponding to each of the initial merged memory pages, a target merged memory page that is the same as the memory page to be merged is determined, and the memory page to be merged and the target merged memory page are merged.

[0007] In one embodiment, determining at least one initial merged memory page from the plurality of preset memory pages based on the first sampled hash value corresponding to the merged memory page to be detected and the second sampled hash values ​​corresponding to the plurality of preset memory pages included in the preset tree includes:

[0008] Compare whether the first sampled hash value is equal to each of the second sampled hash values;

[0009] The preset memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page;

[0010] The step of determining the target merged memory page that is the same as the target merged memory page based on the first data information corresponding to the merged memory page to be detected and the second data information corresponding to each of the initial merged memory pages includes:

[0011] Compare whether the first data information is equal to each of the second data information;

[0012] The initial merged memory page corresponding to the second data information that is equal to the first data information is determined as the target merged memory page.

[0013] In one embodiment, the preset tree includes a preset stable tree, the preset memory page includes a preset merged memory page, and the preset stable tree is used to store at least one preset merged memory page;

[0014] The step of comparing whether the first sampled hash value is equal to each of the second sampled hash values, and determining the preset memory page corresponding to the second sampled hash value that is equal to the first sampled hash value as the initial merged memory page, includes:

[0015] Compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset merged memory pages;

[0016] The preset merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page.

[0017] In one embodiment, the preset tree further includes a preset unstable tree, and the preset memory page further includes a preset unmerged memory page, wherein the preset unstable tree is used to store at least one preset unmerged memory page; the method further includes:

[0018] When the target merged memory page is not determined in at least one of the preset merged memory pages included in the preset stable tree, compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset non-merged memory pages;

[0019] The preset non-merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page.

[0020] In one embodiment, before comparing whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset merged memory pages, the method further includes:

[0021] Based on the first sampled hash value corresponding to the merged memory page to be detected, determine whether the merged memory page to be detected is a zero-to-zero memory page to be detected;

[0022] If so, compare whether the first sampled hash value is equal to the second sampled hash value corresponding to the preset all-zero merged memory page included in the multiple preset merged memory pages;

[0023] The preset all-zero merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page.

[0024] In one embodiment, the method further includes:

[0025] When the target merged memory page is determined in the preset unstable tree, a target stable node is established in the preset stable tree;

[0026] The target stable node is used to merge the memory page to be detected with the target memory page.

[0027] In one embodiment, before comparing whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset non-merged memory pages, the method further includes:

[0028] Calculate the third sample hash value corresponding to the currently detected merged memory page, and determine whether the third sample hash value is the same as the first sample hash value;

[0029] When it is determined that the third sample hash value is the same as the first sample hash value, compare whether the first sample hash value is equal to the second sample hash value corresponding to each preset non-merged memory page.

[0030] A second aspect of this disclosure provides an apparatus for merging identical memory pages. The apparatus includes an initial merged memory page determination module, configured to, upon receiving a memory page to be merged, determine at least one initial merged memory page from among the plurality of preset memory pages based on a first sampled hash value corresponding to the memory page to be merged and second sampled hash values ​​corresponding to the plurality of preset memory pages included in a preset tree.

[0031] The processing module is used to determine the target merged memory page that is the same as the target merged memory page based on the first data information corresponding to the target merged memory page and the second data information corresponding to each initial merged memory page, and to merge the target merged memory page with the target merged memory page.

[0032] A third aspect of this disclosure provides an electronic device, comprising:

[0033] One or more processors;

[0034] Storage device for storing one or more programs.

[0035] When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any of the first aspects.

[0036] A fourth aspect of this disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any of the first aspects.

[0037] The technical solution provided in this disclosure has the following advantages compared with the prior art:

[0038] This disclosure provides a method, apparatus, device, and medium for merging identical memory pages. Upon receiving a memory page to be merged, at least one initial merged memory page is determined from among multiple preset memory pages based on a first sampled hash value corresponding to the memory page to be merged and second sampled hash values ​​corresponding to multiple preset memory pages included in a preset tree. Based on first data information corresponding to the memory page to be merged and second data information corresponding to each initial merged memory page, a target merged memory page identical to the memory page to be merged is determined, and the memory page to be merged and the target merged memory page are merged. In the above process, by using the first sampled hash value corresponding to the memory page to be merged and the second sampled hash value corresponding to the preset memory page, it is possible to determine at least one initial merged memory page that may be the same as the memory page to be merged from multiple preset memory pages without calculating the hash value corresponding to the memory page to be merged or the preset memory page. This reduces the system power consumption during the calculation process. Furthermore, since multiple preset memory pages are pre-screened to determine at least one initial merged memory page that may be the same as the memory page to be merged, the target merged memory page that is the same as the memory page to be merged is determined by using the data information of the selected initial merged memory page and the memory page to be merged, such as page size and code, and then merged. This avoids scanning, judging and merging a large number of memory pages in the system, thereby reducing the consumption of system resources. Attached Figure Description

[0039] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0040] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0041] Figure 1 A flowchart illustrating a method for merging identical memory pages provided in an embodiment of this disclosure;

[0042] Figure 2 A flowchart illustrating another method for merging identical memory pages provided in this embodiment of the disclosure;

[0043] Figure 3 A flowchart illustrating another method for merging identical memory pages provided in this embodiment of the present disclosure;

[0044] Figure 4 A flowchart illustrating yet another method for merging identical memory pages provided in this embodiment of the disclosure;

[0045] Figure 5 A flowchart illustrating yet another method for merging identical memory pages provided in this embodiment of the disclosure;

[0046] Figure 6 This is a schematic diagram of the structure of an identical memory page merging device provided in an embodiment of the present disclosure;

[0047] Figure 7 This is an internal structural diagram of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0048] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.

[0049] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.

[0050] The terms "first," "second," etc., used in this disclosure and in the claims are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this disclosure can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0051] Currently, in order to improve system performance and achieve effective utilization and management of memory resources, existing operating systems provide a kernel samepage merging (KSM) technology, which means that when multiple processes running on the system have the same memory pages, KSM can merge them into a shared memory page.

[0052] Specifically, a stable tree is constructed for storing memory pages that can be merged (i.e., those with the same data information, such as code and runtime data corresponding to running processes), and an unstable tree is constructed for storing memory pages that cannot be merged. During the process of merging identical memory pages using KSM, each node of both the stable and unstable trees is traversed sequentially, and the hash value of the corresponding memory page for each node is calculated. Then, for a large number of memory pages, the page size corresponding to the entire memory page is compared to achieve the merging of identical memory pages, which results in the consumption of a large number of system resources.

[0053] Another example is when using KSM to merge identical memory pages. There may be a large number of all-zero memory pages. When determining whether a memory page is all-zero, it is necessary to calculate the hash value of the entire memory page of the all-zero memory page, which reduces the efficiency of merging identical memory pages and consumes a lot of system resources.

[0054] To address the aforementioned issues, this disclosure provides a method, apparatus, device, and medium for merging identical memory pages. This method utilizes a first sampled hash value corresponding to the memory page to be merged and a second sampled hash value corresponding to a preset memory page. Without calculating the hash value of either the memory page to be merged or the preset memory page, it first identifies at least one initial merged memory page from multiple preset memory pages that may be identical to the memory page to be merged. This reduces system power consumption during computation. Furthermore, by pre-screening multiple preset memory pages to identify at least one initial merged memory page that may be identical to the memory page to be merged, and further using data information such as page size and code between the screened initial merged memory page and the memory page to be merged, a target merged memory page identical to the memory page to be merged is identified and merged. This avoids scanning, judging, and merging a large number of memory pages in the system, thereby reducing system resource consumption.

[0055] In one embodiment, such as Figure 1 As shown, Figure 1 This is a flowchart illustrating a method for merging identical memory pages according to an embodiment of the present disclosure, specifically including the following steps:

[0056] S11: Upon receiving a memory page to be merged, determine at least one initial merged memory page from among the multiple preset memory pages based on the first sampled hash value corresponding to the memory page to be merged and the second sampled hash values ​​corresponding to the multiple preset memory pages included in the preset tree.

[0057] Among them, "to be detected and merged memory pages" refers to physical memory pages in a computer system that, in order to ensure system performance, need to be further detected for the existence of identical memory pages, and then merged or eliminated. Physical memory pages refer to the memory pages allocated by the system for the virtual address pages required by each process during process execution when memory management technologies such as virtual memory are used to manage memory resources.

[0058] The aforementioned preset tree refers to the preset tree constructed when merging identical memory pages using KSM technology. This preset tree can be, for example, a red-black tree, and different nodes in the preset tree correspond to a preset memory page.

[0059] The aforementioned sample hash value refers to the random generation of a sample index with a preset value of 4*1024 / 128 for a memory page, for example, a memory page with a size of 4kb. That is, 32 sample indices are randomly generated. The sample byte data corresponding to each of the 32 sample indices is obtained in the memory page, and the obtained sample byte data is hashed to obtain the sample hash value of the memory page.

[0060] Specifically, when a memory page to be merged is received, the first sample hash value of the memory page to be merged and the second sample hash values ​​corresponding to the multiple preset memory pages included in the preset tree are calculated. Based on the first sample hash value corresponding to the memory page to be merged and the second sample hash values ​​corresponding to the multiple preset memory pages, at least one initial merged memory page is determined among the multiple preset memory pages.

[0061] Optionally, based on the above embodiments, in some embodiments of this disclosure, such as... Figure 2 As shown, one implementation for determining at least one initial merged memory page from multiple preset memory pages based on the first sampled hash value corresponding to the memory page to be merged and the second sampled hash values ​​corresponding to the multiple preset memory pages included in the preset tree can be:

[0062] S21: Compare whether the first sampled hash value is equal to each of the second sampled hash values.

[0063] S22: Determine the preset memory page corresponding to the second sample hash value that is equal to the first sample hash value as the initial merged memory page.

[0064] Specifically, the first sample hash value corresponding to the memory page to be merged is compared with the second sample hash value corresponding to each preset memory page. It is determined whether the first sample hash value is equal to each second sample hash value. The preset memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page. In this way, one or more initial merged memory pages are determined from multiple preset memory pages.

[0065] S12: Based on the first data information corresponding to the memory page to be merged and the second data information corresponding to each of the initial merged memory pages, determine the target merged memory page that is the same as the memory page to be merged, and merge the memory page to be merged with the target merged memory page.

[0066] The first data information refers to the code, runtime data, or page size of the memory page to be merged, but is not limited to these. This disclosure does not impose specific limitations, and those skilled in the art can set it according to the actual situation.

[0067] The aforementioned second data information refers to the code, runtime data, or page size of the initial merged memory pages, but is not limited thereto. This disclosure does not impose specific limitations, and those skilled in the art can set it according to the actual situation.

[0068] Specifically, after determining one or more initial merged memory pages from multiple preset memory pages, for each initial merged memory page, the corresponding second data information is obtained, and for the merged memory page to be detected, the corresponding first data information is obtained. Based on the first data information corresponding to the merged memory page to be detected and the second data information corresponding to each initial merged memory page, the target merged memory page that is the same as the merged memory page to be detected is determined. After obtaining the target merged memory page, the merged memory page to be detected and the target merged memory page are merged.

[0069] Optionally, based on the above embodiments, reference may continue to be made to some embodiments of this disclosure. Figure 2 As shown, one implementation of determining the target merged memory page that is the same as the target merged memory page based on the first data information corresponding to the merged memory page to be detected and the second data information corresponding to each of the initial merged memory pages can be:

[0070] S23: Compare whether the first data information is equal to each of the second data information.

[0071] S24: Determine the initial merged memory page corresponding to the second data information that is equal to the first data information as the target merged memory page.

[0072] Specifically, the first data information corresponding to the memory page to be merged is compared with the second data information corresponding to each initial merged memory page. It is determined whether the first data information is equal to each second data information, and the initial merged memory page corresponding to the second data information that is equal to the first data information is determined as the target merged memory page corresponding to the memory page to be merged.

[0073] Optionally, based on the above embodiments, in some embodiments of this disclosure, the first data information corresponding to the merged memory page to be detected can be compared with the second data information corresponding to each initial merged memory page by calling the memcmp() function. However, this is not limited thereto, and this disclosure does not impose specific limitations. Those skilled in the art can set it according to the actual situation.

[0074] Thus, the method for merging identical memory pages provided in this embodiment determines at least one initial merged memory page from multiple preset memory pages upon receiving a memory page to be merged, based on the first sampled hash value corresponding to the memory page to be merged and the second sampled hash values ​​corresponding to multiple preset memory pages included in the preset tree. Then, based on the first data information corresponding to the memory page to be merged and the second data information corresponding to each initial merged memory page, a target merged memory page identical to the memory page to be merged is determined, and the memory page to be merged and the target merged memory page are merged. In the above process, by using the first sampled hash value corresponding to the memory page to be merged and the second sampled hash value corresponding to the preset memory page, it is possible to determine at least one initial merged memory page that may be the same as the memory page to be merged from multiple preset memory pages without calculating the hash value corresponding to the memory page to be merged or the preset memory page. This reduces the system power consumption during the calculation process. Furthermore, since multiple preset memory pages are pre-screened to determine at least one initial merged memory page that may be the same as the memory page to be merged, the target merged memory page that is the same as the memory page to be merged is determined by using the data information of the selected initial merged memory page and the memory page to be merged, such as page size and code, and then merged. This avoids scanning, judging and merging a large number of memory pages in the system, thereby reducing the consumption of system resources.

[0075] Optionally, based on the above embodiments, in some embodiments of this disclosure, the preset tree includes a preset stable tree, and the preset memory page includes a preset merged memory page. The preset merged memory page refers to a memory page in the system that has already undergone merging processing, and the preset stable tree is used to store at least one preset merged memory page. Based on this, as... Figure 3 As shown, one possible implementation of S21-S24 is:

[0076] S31: Compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset merged memory pages.

[0077] S32: Determine the preset merged memory page corresponding to the second sampled hash value that is equal to the first sampled hash value as the initial merged memory page.

[0078] S33: Compare whether the first data information is equal to each of the second data information.

[0079] S34: Determine the initial merged memory page corresponding to the second data information that is equal to the first data information as the target merged memory page.

[0080] Specifically, the first sampled hash value corresponding to the memory page to be detected and merged is compared with the second sampled hash values ​​corresponding to each preset merged memory page included in the preset stable tree. It is determined whether the first sampled hash value is equal to each of the second sampled hash values. The preset merged memory page corresponding to the second sampled hash value that is equal to the first sampled hash value is determined as the initial merged memory page. In this way, one or more initial merged memory pages are determined from multiple preset merged memory pages. The first data information corresponding to the memory page to be detected and merged is compared with the second data information corresponding to each of the initial merged memory pages. It is determined whether the first data information is equal to each of the second data information. The initial merged memory page corresponding to the second data information that is equal to the first data information is determined as the target merged memory page corresponding to the memory page to be detected and merged.

[0081] Optionally, based on the above embodiments, in some embodiments of this disclosure, the preset tree further includes a preset unstable tree, and the preset memory page further includes a preset unmerged memory page, wherein the preset unmerged memory page refers to a memory page in the system that has not been merged. The preset unstable tree is used to store at least one preset unmerged memory page. Based on this, such as Figure 4 As shown, it also includes:

[0082] S41: When the target merged memory page is not determined in at least one of the preset merged memory pages included in the preset stable tree.

[0083] S42: Compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset non-merged memory pages.

[0084] S43: Determine the preset non-merged memory page corresponding to the second sample hash value that is equal to the first sample hash value as the initial merged memory page.

[0085] S44: Compare whether the first data information is equal to each of the second data information.

[0086] S45: Determine the initial merged memory page corresponding to the second data information that is equal to the first data information as the target merged memory page.

[0087] Specifically, the first sampled hash value corresponding to the memory page to be merged is compared with the second sampled hash values ​​corresponding to each of the preset non-merged memory pages included in the preset unstable tree. It is determined whether the first sampled hash value is equal to each of the second sampled hash values. The preset non-merged memory page corresponding to the second sampled hash value that is equal to the first sampled hash value is determined as the initial merged memory page. In this way, one or more initial merged memory pages are determined from multiple preset non-merged memory pages. The first data information corresponding to the memory page to be merged is compared with the second data information corresponding to each of the initial merged memory pages. It is determined whether the first data information is equal to each of the second data information. The initial merged memory page corresponding to the second data information that is equal to the first data information is determined as the target merged memory page corresponding to the memory page to be merged.

[0088] Thus, the method for merging identical memory pages provided in this embodiment can, in the above process, first determine whether a target memory page exists in multiple preset merged memory pages by comparing the first sampled hash value corresponding to the memory page to be detected to be merged with the second sampled hash value of preset merged memory pages included in the preset stable tree. When no target merged memory page exists, it can further determine whether a target merged memory page exists in multiple preset non-merged memory pages by comparing the first sampled hash value corresponding to the memory page to be detected to be merged with the second sampled hash value of preset non-merged memory pages included in the preset unstable tree. In this way, the processing efficiency of merging memory pages is improved, and the consumption of system memory resources is reduced.

[0089] Optionally, based on the above embodiments, in some embodiments of this disclosure, before executing S31, the following steps are further included:

[0090] Step A1: Determine whether the merged memory page to be detected is a zero-based memory page to be detected based on the first sampled hash value corresponding to the merged memory page to be detected.

[0091] A zero-data page refers to a memory page where the corresponding data is zero, meaning that no code or runtime data is stored.

[0092] Step A2: When it is determined that the merged memory page to be detected is a zero-to-zero memory page to be detected, compare whether the first sampled hash value is equal to the second sampled hash value corresponding to the preset zero-to-zero merged memory page included in the multiple preset merged memory pages.

[0093] Step A3: Determine the preset all-zero merged memory page corresponding to the second sample hash value that is equal to the first sample hash value as the initial merged memory page.

[0094] Step A4: Compare whether the first data information is equal to each of the second data information.

[0095] Step A5: Determine the initial merged memory page corresponding to the second data information that is equal to the first data information as the target merged memory page.

[0096] Specifically, for the memory page to be merged, its corresponding first sample hash value is calculated. This first sample hash value is used to determine whether the memory page to be merged is a zero-based memory page. Once it is determined that the memory page to be merged is a zero-based memory page, a preset zero-based merged memory page is selected from multiple preset merged memory pages. The first sample hash value corresponding to the memory page to be merged is compared with the second sample hash value corresponding to the preset zero-based merged memory page. It is determined whether the first sample hash value is equal to the second sample hash value corresponding to each preset zero-based merged memory page. The preset zero-based merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is selected as the initial merged memory page. The first data information corresponding to the memory page to be merged is compared with the second data information corresponding to each preset zero-based merged memory page. It is determined whether the first data information is equal to each second data information. The preset zero-based merged memory page corresponding to the second data information that is equal to the first data information is selected as the target merged memory page corresponding to the memory page to be merged.

[0097] Thus, the method for merging identical memory pages provided in this embodiment, in the above process, can prioritize the processing of a large number of pre-defined all-zero memory pages by using the first sampled hash value corresponding to the memory page to be merged. When the memory page to be merged is determined to be a pre-defined all-zero memory page, the method compares the memory page to be merged with the second sampled hash value corresponding to the pre-defined all-zero memory pages in the pre-defined stable tree. In this way, a large number of pre-defined all-zero memory pages are processed first, thereby reducing the scanning and merging of a large number of pre-defined all-zero memory pages in the subsequent process, thereby reducing the consumption of system resources.

[0098] Optionally, based on the above embodiments, in some embodiments of this disclosure, since a preset stable tree is used to store memory pages with the same memory in the storage system, and a preset unstable tree is used to store memory pages in the storage system that do not have the same data information such as code, runtime data, or size, the method further includes:

[0099] When the target merged memory page is determined in the preset unstable tree, a target stable node is established in the preset stable tree.

[0100] The target stable node is used to merge the memory page to be detected with the target memory page.

[0101] Specifically, after identifying a target merged memory page that is identical to the merged memory page to be detected in the preset unstable tree, a target stable node is established in the preset stable tree. Through the target stable node, the merged memory page to be detected is merged with the target merged memory page.

[0102] It should be noted that target merged memory pages that are identical to the merged memory pages to be detected in the preset unstable tree are eliminated.

[0103] Optionally, based on the above embodiments, in some embodiments of this disclosure, since the memory pages to be merged may change during the merge scan process, based on this, such as... Figure 5 As shown, before executing S42, the following steps are also included:

[0104] S51: Calculate the third sample hash value corresponding to the current merged memory page to be detected, and determine whether the third sample hash value is the same as the first sample hash value.

[0105] S42: When it is determined that the third sample hash value is the same as the first sample hash value, compare whether the first sample hash value is equal to the second sample hash value corresponding to each preset non-merged memory page.

[0106] Specifically, when no target merged memory is found in the preset stable tree, the third sample hash value corresponding to the current merged memory page to be detected is calculated. This third sample hash value is compared with the pre-acquired first sample hash value to determine if they are the same. If they are, it indicates that the current merged memory page to be detected has not changed, and the first sample hash value is then compared with the second sample hash values ​​corresponding to each preset non-merged memory page. Conversely, if the third sample hash value is different from the first sample hash value, it indicates that the current merged memory page to be detected has changed, and no further processing is performed on the current merged memory page.

[0107] Thus, the method for merging identical memory pages provided in this embodiment avoids page faults during subsequent memory page processing by comparing the third sample hash value corresponding to the current memory page to be merged with the first sample hash value during the above process.

[0108] This disclosure also provides an apparatus for merging identical memory pages, used to execute any of the identical memory page merging methods provided in the above embodiments, and possessing the corresponding beneficial effects of the identical memory page merging method.

[0109] Figure 6A schematic diagram of a device for merging identical memory pages provided in an embodiment of this disclosure includes: an initial memory page merging determination module 11 and a processing module 12.

[0110] The initial merged memory page determination module 11 is used to determine at least one initial merged memory page among the multiple preset memory pages when a merged memory page to be detected is received, based on the first sampled hash value corresponding to the merged memory page to be detected and the second sampled hash values ​​corresponding to the multiple preset memory pages included in the preset tree.

[0111] Processing module 12 is used to determine a target merged memory page that is the same as the target merged memory page based on the first data information corresponding to the target merged memory page and the second data information corresponding to each initial merged memory page, and to merge the target merged memory page with the target merged memory page.

[0112] In the above embodiments, the initial merged memory page determination module 11 is specifically used to compare whether the first sampled hash value is equal to each of the second sampled hash values; and determine the preset memory page corresponding to the second sampled hash value that is equal to the first sampled hash value as the initial merged memory page; the processing module 12 is specifically used to compare whether the first data information is equal to each of the second data information; and determine the initial merged memory page corresponding to the second data information that is equal to the first data information as the target merged memory page.

[0113] In the above embodiments, the preset tree includes a preset stable tree, the preset memory page includes a preset merged memory page, and the preset stable tree is used to store at least one preset merged memory page; the initial merged memory page determination module 11 is specifically used to compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each preset merged memory page;

[0114] The preset merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page.

[0115] In the above embodiments, the preset tree further includes a preset unstable tree, and the preset memory page further includes a preset non-merged memory page. The preset unstable tree is used to store at least one preset non-merged memory page. The initial merged memory page determination module 11 is specifically used to compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each preset non-merged memory page when the target merged memory page is not determined among the at least one preset merged memory page included in the preset stable tree; and to determine the preset non-merged memory page corresponding to the second sampled hash value that is equal to the first sampled hash value as the initial merged memory page.

[0116] In the above embodiments, the device further includes: a zero-to-be-detected memory page processing module, configured to determine whether the zero-to-be-detected merged memory page is a zero-to-be-detected memory page based on a first sampled hash value corresponding to the zero-to-be-detected merged memory page; if so, compare whether the first sampled hash value is equal to a second sampled hash value corresponding to a preset zero-to-be-detected merged memory page included in a plurality of preset merged memory pages; and determine the preset zero-to-be-detected merged memory page corresponding to the second sampled hash value that is equal to the first sampled hash value as the initial merged memory page.

[0117] In the above embodiments, the processing module 12 is specifically used to establish a target stable node in the preset stable tree when the target merged memory page is determined in the preset unstable tree; and to merge the memory page to be detected with the target merged memory page through the target stable node.

[0118] In the above embodiments, the device further includes: a judgment module, configured to calculate the third sample hash value corresponding to the current merged memory page to be detected, and determine whether the third sample hash value is the same as the first sample hash value; when it is determined that the third sample hash value is the same as the first sample hash value, compare whether the first sample hash value is equal to the second sample hash value corresponding to each preset non-merged memory page.

[0119] Thus, in this embodiment, when the initial merged memory page determination module receives a merged memory page to be detected, it determines at least one initial merged memory page among multiple preset memory pages based on the first sampled hash value corresponding to the merged memory page to be detected and the second sampled hash values ​​corresponding to the multiple preset memory pages included in the preset tree. The processing module 12 is used to determine the target merged memory page that is the same as the merged memory page to be detected based on the first data information corresponding to the merged memory page to be detected and the second data information corresponding to each initial merged memory page, and to merge the merged memory page to be detected and the target merged memory page. In the above process, by using the first sampled hash value corresponding to the memory page to be merged and the second sampled hash value corresponding to the preset memory page, at least one initial merged memory page that may be the same as the memory page to be merged can be determined from multiple preset memory pages. In this way, it is not necessary to calculate the hash value of the memory page to be merged or the preset memory page, thereby reducing the system power consumption during the calculation process. Furthermore, since multiple preset memory pages are pre-screened to determine at least one initial merged memory page that may be the same as the memory page to be merged, and further, the target merged memory page that is the same as the memory page to be merged is determined from at least one initial merged memory page and merged, the scanning, judgment and elimination of a large number of memory pages are avoided, thereby reducing the consumption of system resources.

[0120] Figure 7This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure, such as... Figure 7 As shown, the electronic device includes a processor 710, a memory 720, an input device 730, and an output device 740; the number of processors 710 in the computer device can be one or more. Figure 7 Taking a processor 710 as an example; the processor 710, memory 720, input device 730, and output device 740 in the electronic device can be connected via a bus or other means. Figure 7 Taking the example of a connection between China and Israel via a bus.

[0121] The memory 720, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and modules, such as the program instructions / modules corresponding to the method in the embodiments of the present invention. The processor 710 executes various functional applications of the computer device and merges identical memory pages by running the software programs, instructions, and modules stored in the memory 720, thereby implementing the method provided in the embodiments of the present invention.

[0122] The memory 720 may primarily include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a given function; the data storage area may store data created based on terminal usage. Furthermore, the memory 720 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory, or other non-volatile solid-state storage device. In some instances, the memory 720 may further include memory remotely located relative to the processor 710, which can be connected to the computer device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0123] Input device 730 can be used to receive input digital or character information, and to generate key signal inputs related to user settings and function control of the electronic device, and may include a keyboard, mouse, etc. Output device 740 may include display devices such as a display screen.

[0124] This disclosure also provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to implement the method provided in this embodiment of the invention. The method includes:

[0125] Upon receiving a memory page to be merged, at least one initial merged memory page is determined from the plurality of preset memory pages based on the first sampled hash value corresponding to the memory page to be merged and the second sampled hash values ​​corresponding to the plurality of preset memory pages included in the preset tree.

[0126] Based on the first data information corresponding to the memory page to be merged and the second data information corresponding to each of the initial merged memory pages, a target merged memory page that is the same as the memory page to be merged is determined, and the memory page to be merged and the target merged memory page are merged.

[0127] Of course, the computer-executable instructions provided in the embodiments of the present invention are not limited to the method operations described above, but can also perform related operations in the methods provided in any embodiment of the present invention.

[0128] Based on the above description of the implementation methods, those skilled in the art can clearly understand that the present invention can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0129] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0130] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for merging identical memory pages, characterized in that, The method includes: Upon receiving a memory page to be merged, at least one initial merged memory page is determined from the plurality of preset memory pages based on the first sampled hash value corresponding to the memory page to be merged and the second sampled hash values ​​corresponding to the plurality of preset memory pages included in the preset tree; the preset tree includes a preset stable tree, the preset memory pages include preset merged memory pages, and the preset stable tree is used to store at least one preset merged memory page; Based on the first data information corresponding to the memory page to be merged and the second data information corresponding to each of the initial merged memory pages, a target merged memory page that is the same as the memory page to be merged is determined, and the memory page to be merged and the target merged memory page are merged. The step of determining at least one initial merged memory page from the plurality of preset memory pages based on the first sampled hash value corresponding to the memory page to be merged and the second sampled hash values ​​corresponding to the plurality of preset memory pages included in the preset tree includes: Compare whether the first sample hash value is equal to each of the second sample hash values; The preset memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page; The step of determining the target merged memory page that is the same as the target merged memory page based on the first data information corresponding to the merged memory page to be detected and the second data information corresponding to each of the initial merged memory pages includes: Compare whether the first data information is equal to each of the second data information; The initial merged memory page corresponding to the second data information that is equal to the first data information is determined as the target merged memory page; The step of comparing whether the first sampled hash value is equal to each of the second sampled hash values, and determining the preset memory page corresponding to the second sampled hash value that is equal to the first sampled hash value as the initial merged memory page, includes: Compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset merged memory pages; The preset merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page; Before comparing whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset merged memory pages, the method further includes: Based on the first sampled hash value corresponding to the merged memory page to be detected, determine whether the merged memory page to be detected is a zero-to-zero memory page to be detected; If so, compare whether the first sampled hash value is equal to the second sampled hash value corresponding to the preset all-zero merged memory page included in the multiple preset merged memory pages; The preset all-zero merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page.

2. The method according to claim 1, characterized in that, The preset tree also includes a preset unstable tree, and the preset memory page also includes a preset unmerged memory page. The preset unstable tree is used to store at least one preset unmerged memory page. The method further includes: When the target merged memory page is not determined in at least one of the preset merged memory pages included in the preset stable tree, compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset non-merged memory pages; The preset non-merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page.

3. The method according to claim 2, characterized in that, The method further includes: When the target merged memory page is determined in the preset unstable tree, a target stable node is established in the preset stable tree; The target stable node is used to merge the memory page to be detected with the target memory page.

4. The method according to claim 2, characterized in that, Before comparing whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset non-merged memory pages, the method further includes: Calculate the third sample hash value corresponding to the currently detected merged memory page, and determine whether the third sample hash value is the same as the first sample hash value; When it is determined that the third sample hash value is the same as the first sample hash value, compare whether the first sample hash value is equal to the second sample hash value corresponding to each preset non-merged memory page.

5. A device for merging identical memory pages, characterized in that, The device includes: An initial merged memory page determination module is used to determine at least one initial merged memory page from the plurality of preset memory pages when a merged memory page to be detected is received, based on the first sampled hash value corresponding to the merged memory page to be detected and the second sampled hash values ​​corresponding to the plurality of preset memory pages included in the preset tree; the preset tree includes a preset stable tree, the preset memory pages include preset merged memory pages, and the preset stable tree is used to store at least one preset merged memory page; The processing module is used to determine the target merged memory page that is the same as the target merged memory page based on the first data information corresponding to the target merged memory page and the second data information corresponding to each initial merged memory page, and to merge the target merged memory page with the target merged memory page. The initial merged memory page determination module is specifically used for: Compare whether the first sample hash value is equal to each of the second sample hash values; The preset memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page; The processing module is specifically used for: Compare whether the first data information is equal to each of the second data information; The initial merged memory page corresponding to the second data information that is equal to the first data information is determined as the target merged memory page; The initial merged memory page determination module is specifically used for: Compare whether the first sampled hash value is equal to the second sampled hash value corresponding to each of the preset merged memory pages; The preset merged memory page corresponding to the second sample hash value that is equal to the first sample hash value is determined as the initial merged memory page; The device further includes: a zero-to-be-detected memory page processing module, configured to determine whether the merged memory page to be detected is a zero-to-be-detected memory page based on a first sampled hash value corresponding to the merged memory page to be detected; if so, compare whether the first sampled hash value is equal to a second sampled hash value corresponding to a preset zero-to-be-detected merged memory page included in a plurality of preset merged memory pages; and determine the preset zero-to-be-detected merged memory page corresponding to the second sampled hash value that is equal to the first sampled hash value as the initial merged memory page.

6. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the steps of the same memory page merging method as described in any one of claims 1 to 4.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the identical memory page merging method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Low-cost efficient internal storage redundancy removing method and system

    CN104035822A

  • Merging method and device based on homogenous memory scanning

    CN106874119A