A memory optimization method and system thereof
By establishing a memory sharing layer and a dedicated sharing layer in the browser, and utilizing page similarity matching and address mapping to optimize memory usage, the problem of excessive memory usage when the browser has multiple pages is solved, and efficient memory reuse and state retention are achieved.
Patent Information
- Application Number
- CN202211106961.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-09
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2042-09-09
AI Technical Summary
When a browser opens multiple pages, the memory usage is too large. Existing technologies are difficult to effectively reduce memory usage, resulting in state loss when the page is refreshed.
By matching page similarities, a memory sharing layer is established, hooks are used to create memory byte blocks, thresholds are set, memory address mapping relationships are established, address conversion is performed when reading and modifying memory, and the mapping relationship is updated during preset periodic similarity scans.
It improves the memory reuse rate of similar web pages, reduces memory usage, and avoids the loss of memory state.
Smart Images

Figure CN115659077B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a memory optimization method and system thereof. Background Art
[0002] Currently, when a browser opens multiple pages, to ensure access speed, it generally stores a large number of pages in memory, resulting in excessive memory usage. Memory can generally only be freed by closing the page, saving only the link to the current page. This causes the page to be refreshed, and some of the actual state at the time will also be lost. The memory method proposed in the Chinese patent application number 20221066824.1 and publication number CN114756382A, entitled "A Memory Merging Optimization Method and System Server," first calculates the eigenvalue of the page, searches for memory pages with the same eigenvalue in the memory stable tree, and then performs a memory comparison. This avoids directly comparing memory pages when performing a memory scan to determine whether the memory pages are the same. Although this patent reduces the time spent on memory page comparison, memory usage is still relatively large. The present technology uses a different method to optimize memory by increasing the memory comparison time and reducing memory usage. Summary of the Invention
[0003] The present invention aims to provide a memory optimization method that can improve the memory usage of similar web pages, reduce memory occupancy, and solve memory loss.
[0004] To achieve the above object, the present invention provides the following technical solution: a memory optimization method, comprising the following steps:
[0005] Step 1: When accessing a page, the page similarity between the page and other pages opened by the browser is matched based on the js files and css files loaded on the page. When similar pages are matched, a memory sharing layer 1 is established;
[0006] Step 2: Count the number of created memory byte blocks 1 by hooking the memory creation method, set a threshold for creating memory byte 1, store the created memory byte block 1 in the memory shared layer 1, and establish a memory address mapping relationship between the shared memory and the virtual memory address 1 of the browser page;
[0007] Step 3: By hooking the memory read method, the memory address is converted according to the memory address mapping relationship when reading the memory; if the memory is not mapped to the memory shared layer 1, the read memory data is directly returned; if the read memory is mapped to the shared memory, the address is converted to the address of the memory shared layer 1 and the memory is read out;
[0008] Step 4: By hooking the memory modification method, the modified memory converts the memory address according to the memory address mapping relationship; if the memory is not mapped to the memory sharing layer 1, it is modified directly; if it is in the memory sharing layer 1, a dedicated sharing layer 2 is established for the current page memory, and the incremental modification content is recorded in the dedicated sharing layer 2.
[0009] Furthermore, the matching of similar pages in step 1 is achieved by segmenting the content of the page using non-alphanumeric text or Chinese characters, segmenting the words or Chinese characters, and counting the number of times the words are repeated. If the words or Chinese characters on two pages are the same for more than 50%, the page contents are determined to be similar.
[0010] Furthermore, step 2 is further specified as follows: when the number of memory byte blocks for creating memory byte 1 is greater than a threshold, a sha1 value of the type of memory byte block 1 is obtained, the sha1 value of the memory byte block is saved in list 1, and the mapping relationship between virtual memory address 1 and sha1 value is saved in list 2.
[0011] Furthermore, step 3 is further specified as follows: if the memory is not mapped to the memory sharing layer 1, read the sha1 value from list 2, read the memory address from list 1 through the sha1 value, and then read the memory data from the memory sharing layer 1; if the memory has been modified, read the incremental modified content from the dedicated shared layer 2 and merge it with the memory sharing layer 1 content and return it.
[0012] Furthermore, step 5 is included, wherein step 5 is to scan the memory shared layer 1 and the dedicated shared layer 2 at a preset periodic time, as well as the page similarity of the dedicated shared layer 2 between the memory shared layer 1 and other pages; wherein the page similarity between the memory shared layer 1 and the dedicated shared layer 2 is achieved by setting a threshold of the same number of bytes. If the same number of bytes is greater than the threshold, the same content in the dedicated shared layer 2 is moved into the memory shared layer 1, and the mapping relationship is updated.
[0013] A memory optimization system, comprising a similar page matching module, a memory creation module, a memory reading module, and a memory modification module;
[0014] The matching similar page module, when accessing a page, matches the page similarity between the page and other pages opened by the browser based on the js files and css files loaded on the page, and establishes a memory sharing layer 1 when a similar page is matched;
[0015] The memory creation module counts the number of memory byte blocks 1 created by hooking the memory creation method, sets a threshold for creating memory byte 1, stores the created memory byte block 1 in the memory sharing layer 1, and establishes a memory address mapping relationship between the shared memory and the virtual memory address 1 of the browser page;
[0016] The memory reading module converts the memory address according to the memory address mapping relationship when reading the memory by hooking the memory reading method; if the memory is not mapped to the memory sharing layer 1, it directly returns the read memory data; if the memory to be read is mapped to the shared memory, it converts the address to the address of the memory sharing layer 1 and reads the memory;
[0017] The memory modification module converts the memory address of the modified memory according to the memory address mapping relationship by hooking the memory modification method; if the memory is not mapped to the memory sharing layer 1, it is modified directly; if it is in the memory sharing layer 1, a dedicated sharing layer 2 for the current page memory is established, and the incremental modification content is recorded in the dedicated sharing layer 2.
[0018] Furthermore, the matching of similar pages in the similar page matching module is achieved by segmenting the content of the page using non-alphanumeric text or Chinese characters, segmenting the words or Chinese characters, and counting the number of times the words are repeated. If the words or Chinese characters on two pages are the same for more than 50%, the page contents are determined to be similar.
[0019] Furthermore, the memory creation module is further specified as follows: when the number of memory byte blocks for creating memory byte 1 is greater than a threshold, a sha1 value of the type of memory byte block 1 is obtained, the sha1 value of the memory byte block is saved in list 1, and the mapping relationship between virtual memory address 1 and sha1 value is saved in list 2.
[0020] Furthermore, the memory reading module is further specified as follows: if the memory is not mapped to the memory shared layer 1, the sha1 value is read from the list 2, the memory address is read from the list 1 through the sha1 value, and then the memory data is read from the memory shared layer 1; if the memory has been modified, the incremental modified content is read from the dedicated shared layer 2 and merged with the memory shared layer 1 content and returned.
[0021] Furthermore, it also includes a memory update module, which scans the memory shared layer 1 and the dedicated shared layer 2 at a preset regular time, as well as the similarity of the dedicated shared layer 2 between the memory shared layer 1 and other pages; wherein, the similarity of the memory shared layer 1 and the dedicated shared layer 2 pages is achieved by setting a threshold of the same number of bytes. If the same number of bytes is greater than the threshold, the same content in the dedicated shared layer 2 is moved into the memory shared layer 1, and the mapping relationship is updated.
[0022] Beneficial effects of the present invention: Compared with the prior art, the present invention improves the memory usage of similar web pages, allowing similar memory blocks to reuse the same memory, thereby reducing memory usage and solving memory loss. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a schematic flow chart of the method of the present invention;
[0024] Figure 2 It is a system principle block diagram of the present invention. DETAILED DESCRIPTION
[0025] The present invention will be further described below with reference to the accompanying drawings.
[0026] See also Figure 1 As shown, a memory optimization method of the present invention comprises the following steps:
[0027] Step 1: When accessing a page, the page similarity between the page and other pages opened by the browser is matched based on the js files and css files loaded on the page. When similar pages are matched, a memory sharing layer 1 is established;
[0028] Step 2: Count the number of created memory byte blocks 1 by hooking the memory creation method, set a threshold for creating memory byte 1, store the created memory byte block 1 in the memory shared layer 1, and establish a memory address mapping relationship between the shared memory and the virtual memory address 1 of the browser page;
[0029] Step 3: By hooking the memory read method, the memory address is converted according to the memory address mapping relationship when reading the memory; if the memory is not mapped to the memory shared layer 1, the read memory data is directly returned; if the read memory is mapped to the shared memory, the address is converted to the address of the memory shared layer 1 and the memory is read out;
[0030] Step 4: By hooking the memory modification method, the modified memory converts the memory address according to the memory address mapping relationship; if the memory is not mapped to the memory sharing layer 1, it is modified directly; if it is in the memory sharing layer 1, a dedicated sharing layer 2 is established for the current page memory, and the incremental modification content is recorded in the dedicated sharing layer 2.
[0031] The present invention will be further described below with reference to a specific embodiment:
[0032] A memory optimization method, which is:
[0033] 1. When accessing a page, the page similarity between the page and other pages opened by the browser is matched based on the js files and css files loaded on the page. When similar pages are matched, a memory sharing layer 1 is established;
[0034] 1.1 Matching similar pages is done by segmenting the page content using non-alphanumeric text or Chinese characters, separating the words or Chinese characters, and counting the number of word repetitions. If the two pages have more than 50% of the same words or Chinese characters, the pages are considered similar.
[0035] For example: 1.1 A page contains helloworld Among them, <> / space are not words and Chinese characters. After segmentation, the final words extracted are div, hello and world, div. The content of another page is hi world The extracted words are div,hi and world,div. The two pages have a total of four words, three of which are the same. Therefore, the similarity between the two pages reaches 75%, and they are considered similar pages. If the similarity between the two pages exceeds 50%, they are matched and a memory sharing layer 1 is established.
[0036] 2. By hooking the memory creation method, count the created memory byte block 1, set the threshold for creating memory byte 1, store the created memory byte block 1 in the memory shared layer 1, and establish a memory address mapping relationship between the shared memory and the virtual memory address 1 of the browser page;
[0037] 2.1 When the number of memory byte blocks for creating memory byte 1 is greater than the threshold, the sha1 value of the type of the created memory byte block 1 is obtained, the sha1 value of the created memory byte block is saved in list 1, and the mapping relationship between the virtual memory address 1 and the sha1 value is saved in list 2;
[0038] For example: 2.1. By intercepting the memory creation method, when creating memory to read the page content, page 1 loads the content through address 0x0001. helloworld If the byte threshold is greater than 2 bytes, the current page meets the conditions and hello world Stored in memory shared layer 1, its sha1 value is 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427,
[0039] Listing 2 stores the virtual address of page 1:
[0040] 0x0001 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427
[0041] List 2
[0042] The contents of the memory stored in List 1 are stored in memory shared layer 1, and the corresponding addresses are stored in List 1:
[0043] 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 0x1001
[0044] List 1
[0045] Memory sharing layer 1 is:
[0046] 0x1001 content: hello world
[0047] Memory sharing layer 1
[0048] You can then find 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 through 0x0001 and then find 0x1001 and then find the content: hello world ;
[0049] Page 2 is loaded into memory at address 0x0010 hi world Since it is an approximate page, it is saved in List 1. The contents of the incremental memory are saved in the dedicated shared layer 2, and the corresponding addresses are saved in List 2:
[0050] New list 2 is added:
[0051] 0x0010 57FD8D6EE2A8FD7CA4E27D8397271AB8CED268C2
[0052] New List 2
[0053] New list 1 is added:
[0054] 57FD8D6EE2A8FD7CA4E27D8397271AB8CED268C2 0x2001
[0055] New List 1
[0056] The dedicated shared layer 2 for page 2 is:
[0057]
[0058]
[0059] Dedicated shared layer 2 for page 2
[0060] 3. By hooking the memory read method, the memory address is converted according to the memory address mapping relationship when reading the memory; if the memory is not mapped to the memory shared layer 1, the read memory data is directly returned; if the memory is mapped to the shared memory, the address is converted to the address of the memory shared layer 1 and the memory is read out;
[0061] 3.1 If the memory is not mapped to memory shared layer 1, read the sha1 value from list 2, read the memory address from list 1 through the sha1 value, and then read the memory data from memory shared layer 1; if the memory has been modified, read the incremental modified content from dedicated shared layer 2, merge it with the content of memory shared layer 1, and return it.
[0062] For example: 3. When reading memory, read the memory address 0x0001. Because the memory is mapped, read the sha1 value 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 from list 2, and then read 0x1001 from list 1 through 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 and read from memory shared layer 1. helloworld ;
[0063] 3.1. When reading page 2, when reading 0x0010, first read 57FD8D6EE2A8FD7CA4E27D8397271AB8CED268C2 in list 2, and find that it depends on snapshot 1, so snapshot 1 is read out from 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 in list 1 hello world , and then perform the merge operation, which replaces 5 to 11 bytes with hi, and finally merges hi world Return to page 2.
[0064] 4. By hooking the memory modification method, the modified memory converts the memory address according to the memory address mapping relationship; if the memory is not mapped to the memory sharing layer 1, it is modified directly; if it is in the memory sharing layer 1, a dedicated sharing layer 2 is established for the current page memory, and the incremental modification content is recorded in the dedicated sharing layer 2.
[0065] For example: 4. Page 1 also modifies the memory. Click to change world to abc. At this time, the memory shared layer 1 is established;
[0066] List 2 modifies the sha1 value at address 0x0010 to the sha1 value of the new content, that is hi abc The sha1 value is 7E738A2F7D8B94DC1B44F91B1147E4D189AC29A4:
[0067] The modified list 2 is:
[0068] 0x0010 7E738A277D8B94DC1B44F91B1147E4D189AC29A4
[0069] Modified List 2
[0070] The modified new list 1 is:
[0071] 7E738A2F7D8B94DC1B44F91B1147E4D189AC29A4 0x3001
[0072] Modified new list 1
[0073] The modified memory sharing layer 1 is:
[0074] 0x1001 content: hello world
[0075] Memory sharing layer 1
[0076] The modified dedicated shared layer 2 of page 1 is:
[0077]
[0078] Modified dedicated shared layer 2 for page 1
[0079] In this way, querying the memory of 0x0010 will actually pass
[0080] 7E738A2F7D8B94DC1B44F91B1147E4D189AC29A4 to 0x3001 and then perform the merge operation, and finally get hi abc , achieving the effect of modifying memory.
[0081] 5. Scan the memory shared layer 1 and the dedicated shared layer 2 at preset regular time intervals, as well as the dedicated shared layer 2 similarity between the memory shared layer 1 and other pages; wherein, the page similarity between the memory shared layer 1 and the dedicated shared layer 2 is determined by setting a threshold for the number of identical bytes. If the number of identical bytes is greater than the threshold, the identical content in the dedicated shared layer 2 is moved to the memory shared layer 1, and the mapping relationship is updated.
[0082] For example: 5. Memory shared layer 1 memory address number
[0083] 1, 2, 3, 4, 5 save data respectively
[0084] a, b, c, d, e
[0085] Page 1 dedicated shared layer 2
[0086] 3, 4
[0087] H, K
[0088] Page 2 dedicated shared layer 2
[0089] 3, 4
[0090] H, H
[0091] At this time, the data at address 3 is found to be the same;
[0092] The memory mapping relationship is reorganized. Originally, address number 3 for accessing page 1 and page 2 is obtained from address 3 of their respective dedicated shared layer 2. Now, after the reorganization, address 3 is obtained from memory shared layer 1.
[0093] The memory status of memory sharing layer 1 is as follows:
[0094] 1, 2, 3, 4, 5 save data respectively
[0095] a, b, H, d, e
[0096] Page 1 dedicated shared layer 2 4
[0098] K
[0099] Page 2 dedicated shared layer 2 4
[0101] H.
[0102] See also Figure 2 As shown, the present invention also provides a memory optimization system, which includes a similar page matching module, a memory creation module, a memory reading module, and a memory modification module;
[0103] The module for matching similar pages, when accessing a page, matches the page similarity between the page and other pages opened by the browser based on the js files and css files loaded on the page. When a similar page is matched, a memory sharing layer 1 is established;
[0104] The matching of similar pages in the matching similar pages module is achieved by segmenting the content of the page using non-alphanumeric text or Chinese characters, segmenting the words or Chinese characters, and counting the number of times the words are repeated. If the words or Chinese characters on two pages are the same for more than 50%, the page contents are determined to be similar.
[0105] For example: 1.1 A page contains hello world Among them, <> / space are not words and Chinese characters. After segmentation, the final words extracted are div, hello and world, div. The content of another page is hi world The extracted words are div,hi and world,div. The two pages have a total of four words, three of which are the same. Therefore, the similarity between the two pages reaches 75%, and they are considered similar pages. If the similarity between the two pages exceeds 50%, they are matched and a memory sharing layer 1 is established.
[0106] Create a memory module, create memory by hooking the memory creation method, count the number of created memory byte blocks 1, set a threshold for creating memory byte 1, store the created memory byte block 1 in the memory shared layer 1, and establish a memory address mapping relationship between the shared memory and the virtual memory address 1 of the browser page;
[0107] The creation of the memory module is further specified as follows: when the number of memory byte blocks of the created memory byte 1 is greater than the threshold, the sha1 value of the created memory byte block 1 type is obtained, the sha1 value of the created memory byte block is saved in list 1, and the mapping relationship between the virtual memory address 1 and the sha1 value is saved in list 2:
[0108] For example: 2.1. By intercepting the memory creation method, when creating memory to read the page content, page 1 loads the content through address 0x0001. hello world If the byte threshold is greater than 2 bytes, the current page meets the conditions and hello world Stored in memory shared layer 1, its sha1 value is 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427:
[0109] Listing 2 stores the virtual address of page 1:
[0110] 0x0001 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427
[0111] List 2
[0112] The contents of the memory stored in List 1 are stored in memory shared layer 1, and the corresponding addresses are stored in List 1:
[0113] 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 0x1001
[0114] List 1
[0115] Memory sharing layer 1 is:
[0116] 0x1001 content: hello world
[0117] Memory sharing layer 1
[0118] You can then find 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 through 0x0001 and then find 0x1001 and then find the content: hello world ;
[0119] Page 2 is loaded into memory at address 0x0010 hi world Since it is an approximate page, it is saved in List 1. The contents of the incremental memory are saved in the dedicated shared layer 2, and the corresponding addresses are saved in List 2:
[0120] New list 2 is added:
[0121] 0x0010 57FD8D6EE2A8FD7CA4E27D8397271AB8CED268C2
[0122] New List 2
[0123] New list 1 is added:
[0124] 57FD8D6EE2A8FD7CA4E27D8397271AB8CED268C2 0x2001
[0125] New List 1
[0126] The dedicated shared layer 2 for page 2 is:
[0127]
[0128] Dedicated shared layer 2 for page 2
[0129] The memory reading module converts the memory address according to the memory address mapping relationship when reading the memory by hooking the memory reading method. If the memory is not mapped to the memory shared layer 1, the read memory data is directly returned. If the memory to be read is mapped to the shared memory, the address is converted to the address of the memory shared layer 1 and the memory is read out.
[0130] The memory reading module is further specified as follows: if the memory is not mapped to the memory shared layer 1, the sha1 value is read from list 2, the memory address is read from list 1 through the sha1 value, and then the memory data is read from the memory shared layer 1; if the memory has been modified, the incremental modified content is read from the dedicated shared layer 2 and merged with the content of the memory shared layer 1 and returned.
[0131] For example: 3. When reading memory, read the memory address 0x0001. Because the memory is mapped, read the sha1 value 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 from list 2, and then read 0x1001 from list 1 through 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 and read from memory shared layer 1. helloworld ;
[0132] 3.1 When reading page 2, when reading 0x0010, first read 57FD8D6EE2A8FD7CA4E27D8397271AB8CED268C2 in list 2, and find that it depends on snapshot 1, so snapshot 1 is read out from 1A7A0C1AA7FE1C6DE54DB55669CA1532C4D08427 in list 1 hello world , and then perform the merge operation, which replaces 5 to 11 bytes with hi, and finally merges hi world Return to page 2.
[0133] The memory modification module converts the memory address of the modified memory according to the memory address mapping relationship by hooking the memory modification method; if the memory is not mapped to the memory sharing layer 1, it is modified directly; if it is in the memory sharing layer 1, a dedicated sharing layer 2 is established for the current page memory, and the incremental modification content is recorded in the dedicated sharing layer 2.
[0134] For example: Page 1 also modifies the memory. Click to change world to abc. At this time, the memory sharing layer 1 is established;
[0135] List 2 modifies the sha1 value at address 0x0010 to the sha1 value of the new content, that is hi abc The sha1 value is 7E738A2F7D8B94DC1B44F91B1147E4D189AC29A4:
[0136] The modified list 2 is:
[0137] 0x0010 7E738A2F7D8B94DC1B44F91B1147E4D189AC29A4
[0138] Modified List 2
[0139] The modified new list 1 is:
[0140] 7E738A2F7D8B94DC1B44F91B1147E4D189AC29A4 0x3001
[0141] Modified new list 1
[0142] Memory sharing layer 1 is:
[0143] 0x1001 content: hello world
[0144] Modified memory sharing layer 1
[0145] The modified dedicated shared layer 2 of page 1 is:
[0146]
[0147] Modified dedicated shared layer 2 for page 1
[0148] In this way, querying the memory of 0x0010 will actually pass
[0149] 7E738A2F7D8B94DC1B44F91B1147E4D189AC29A4 to 0x3001 and then perform the merge operation, and finally get hi abc , achieving the effect of modifying memory.
[0150] The memory update module presets a regular time to scan the memory shared layer 1 and the dedicated shared layer 2, as well as the dedicated shared layer 2 similarity between the memory shared layer 1 and other pages; wherein, the page similarity between the memory shared layer 1 and the dedicated shared layer 2 is determined by setting a threshold for the number of identical bytes. If the number of identical bytes is greater than the threshold, the identical content in the dedicated shared layer 2 is moved to the memory shared layer 1, and the mapping relationship is updated.
[0151] For example: Memory shared layer 1 memory address number
[0152] 1, 2, 3, 4, 5 save data respectively
[0153] a, b, c, d, e
[0154] Page 1 dedicated shared layer 2
[0155] 3, 4
[0156] H, K
[0157] Page 2 dedicated shared layer 2
[0158] 3, 4
[0159] H, H
[0160] At this time, the data at address 3 is found to be the same;
[0161] The memory mapping relationship is reorganized. Originally, address number 3 for accessing page 1 and page 2 was obtained from address 3 of their respective dedicated layers. Now, after the reorganization, address 3 is obtained from memory shared layer 1.
[0162] The memory status of memory sharing layer 1 is as follows:
[0163] 1, 2, 3, 4, 5 save data respectively
[0164] a, b, H, d, e
[0165] Page 1 dedicated shared layer 2 4
[0167] K
[0168] Page 2 dedicated shared layer 2 4
[0170] H.
[0171] The above description is only a preferred embodiment of the present invention and should not be understood as limiting the present application. All equivalent changes and modifications made within the scope of the patent application of the present invention should fall within the scope of the present invention.
Claims
1. A memory optimization method, characterized in that: The following steps are involved: Step 1: When accessing a page, the page similarity between the page and other pages opened by the browser is matched based on the js files and css files loaded on the page. When similar pages are matched, a memory sharing layer 1 is established; Step 2: Count the number of memory byte blocks 1 created by hooking the memory creation method, set a threshold for creating memory byte blocks 1, store the created memory byte blocks 1 in the memory sharing layer 1, and establish a memory address mapping relationship between the shared memory and the virtual memory address 1 of the browser page; Step 3: By hooking the memory reading method, the memory address is converted according to the memory address mapping relationship when reading the memory; If the memory is not mapped to the memory sharing layer 1, the read memory data is returned directly; If the memory to be read is mapped to shared memory, the address is converted to the address of memory sharing layer 1 and the memory is read out; Step 4: By hooking the memory modification method, the modified memory converts the memory address according to the memory address mapping relationship; If the memory is not mapped into the memory sharing layer 1, modify it directly; If it is in memory shared layer 1, a dedicated shared layer 2 is created for the current page memory, and the incremental modification content is recorded in the dedicated shared layer 2; Step 2 is further specifically as follows: when the number of memory byte blocks for creating memory byte block 1 is greater than a threshold, obtaining a sha1 value of the type of the created memory byte block 1, saving the sha1 value of the created memory byte block into list 1, and saving a mapping relationship between the virtual memory address 1 and the sha1 value into list 2; The step 3 is further specified as follows: if the memory is mapped to the memory shared layer 1, the sha1 value is read from the list 2, the memory address is read from the list 1 through the sha1 value, and then the memory data is read from the memory shared layer 1; if the memory has been modified, the incremental modified content is read from the dedicated shared layer 2 and merged with the content of the memory shared layer 1 and returned.
2. A memory optimization method according to claim 1, characterized in that: The matching of similar pages in step 1 is performed by segmenting the content of the page using non-alphanumeric text or Chinese characters, segmenting the words or Chinese characters, and counting the number of times the words are repeated. If the words or Chinese characters on two pages are the same for more than 50%, the page contents are determined to be similar.
3. The memory optimization method according to claim 1, wherein: The method also includes step 5, wherein step 5 is to scan the memory shared layer 1 and the dedicated shared layer 2 at a preset periodic time, as well as the page similarity of the memory shared layer 1 and the dedicated shared layer 2 with other pages; wherein the page similarity of the memory shared layer 1 and the dedicated shared layer 2 is determined by setting a threshold value of the number of identical bytes. If the number of identical bytes is greater than the threshold value, the identical content in the dedicated shared layer 2 is moved into the memory shared layer 1, and the mapping relationship is updated.
4. A memory optimization system, characterized by: The system includes a similar page matching module, a memory creation module, a memory reading module, and a memory modification module; The matching similar page module, when accessing a page, matches the page similarity between the page and other pages opened by the browser based on the js files and css files loaded on the page, and establishes a memory sharing layer 1 when a similar page is matched; The memory creation module counts the number of memory byte blocks 1 created by hooking the memory creation method, sets a threshold for creating memory byte blocks 1, stores the created memory byte blocks 1 in the memory sharing layer 1, and establishes a memory address mapping relationship between the shared memory and the virtual memory address 1 of the browser page; The memory reading module converts the memory address according to the memory address mapping relationship when reading the memory by hooking the memory reading method; If the memory is not mapped to the memory sharing layer 1, the read memory data is returned directly; If the memory to be read is mapped to shared memory, the address is converted to the address of memory sharing layer 1 and the memory is read out; The memory modification module converts the memory address of the modified memory according to the memory address mapping relationship by hooking the memory modification method; If the memory is not mapped into the memory sharing layer 1, modify it directly; If it is in memory shared layer 1, a dedicated shared layer 2 is created for the current page memory, and the incremental modification content is recorded in the dedicated shared layer 2; The memory creation module is further specifically configured as follows: when the number of memory byte blocks of the created memory byte block 1 is greater than a threshold, a sha1 value of the type of the created memory byte block 1 is obtained, the sha1 value of the created memory byte block is saved in list 1, and a mapping relationship between the virtual memory address 1 and the sha1 value is saved in list 2; The memory reading module is further specified as follows: if the memory is mapped to the memory shared layer 1, the sha1 value is read from the list 2, the memory address is read from the list 1 through the sha1 value, and then the memory data is read from the memory shared layer 1; if the memory has been modified, the incremental modified content is read from the dedicated shared layer 2, merged with the content of the memory shared layer 1, and returned.
5. The memory optimization system according to claim 4, characterized in that: The matching of similar pages in the matching similar pages module is achieved by segmenting the content of the page using non-alphanumeric text or Chinese characters, segmenting the words or Chinese characters, and counting the number of times the words are repeated. If the words or Chinese characters on two pages are the same for more than 50%, the page contents are determined to be similar.
6. The memory optimization system according to claim 4, characterized in that: It also includes a memory update module, which scans the memory shared layer 1 and the dedicated shared layer 2 at preset regular time, as well as the dedicated shared layer 2 similarity between the memory shared layer 1 and other pages; wherein, the page similarity between the memory shared layer 1 and the dedicated shared layer 2 is achieved by setting a threshold for the number of identical bytes. If the number of identical bytes is greater than the threshold, the identical content in the dedicated shared layer 2 is moved into the memory shared layer 1, and the mapping relationship is updated.
Citation Information
Patent Citations
Memory page merging optimization method and system and server
CN114756382A
Method for supporting quick start of similar virtual machine
CN101697134A
Method and associated equipment for determining management mode of shared virtual memory page
CN103902459A