CN116049024A - Memory page recycling optimization method and system, electronic equipment and storage medium thereof - Google Patents

Memory page recycling optimization method and system, electronic equipment and storage medium thereof Download PDF

Info

Publication number
CN116049024A
CN116049024A CN202310016809.2A CN202310016809A CN116049024A CN 116049024 A CN116049024 A CN 116049024A CN 202310016809 A CN202310016809 A CN 202310016809A CN 116049024 A CN116049024 A CN 116049024A
Authority
CN
China
Prior art keywords
memory page
page
accessed
memory
linked list
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310016809.2A
Other languages
Chinese (zh)
Inventor
丁伟杰
彭伟林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Jiangxinchuang Technology Co ltd
Original Assignee
Guangzhou Jiangxinchuang Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangzhou Jiangxinchuang Technology Co ltd filed Critical Guangzhou Jiangxinchuang Technology Co ltd
Priority to CN202310016809.2A priority Critical patent/CN116049024A/en
Publication of CN116049024A publication Critical patent/CN116049024A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0253Garbage collection, i.e. reclamation of unreferenced memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/12Replacement control
    • G06F12/121Replacement control using replacement algorithms
    • G06F12/123Replacement control using replacement algorithms with age lists, e.g. queue, most recently used [MRU] list or least recently used [LRU] list
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/10Providing a specific technical effect
    • G06F2212/1041Resource optimization
    • G06F2212/1044Space efficiency improvement
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

The invention discloses a memory page recycling optimization method and system, electronic equipment and a storage medium. Wherein the method comprises the following steps: querying a page identifier of the accessed memory page under the condition that the accessed memory page is positioned in the inactive linked list; under the condition that the value of the page identifier of the accessed memory page is 0, adding the memory page to the head of the inactive linked list; setting a page identifier 1 of the accessed memory page; the page identifier is used for indicating whether the memory page is accessed in the latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1. The embodiment of the invention can optimize the management and recovery mechanism of the memory page by improving the processing process when the memory page is accessed, thereby improving the recovery efficiency of the memory page.

Description

Memory page recycling optimization method and system, electronic equipment and storage medium thereof
Technical Field
The invention relates to the technical field of memory management, in particular to a memory page recycling optimization method and system, electronic equipment and a storage medium.
Background
In the linux system, the memory of the physical device is limited. With more and more running software, the software scale is larger and larger, and the problem of shortage of memory resources of the linux system occurs. In order to solve the problem of shortage of memory resources, modern operating systems generally use a page exchange mechanism. I.e. the program is run without loading the program code entirely into memory, but only with a part of the content. When the program runs and generates page fault abnormality, the program code is loaded into the memory. During the running process of the system, a part of memory is also recovered for loading the program or distributing the memory.
In the related art, an operating system may recycle recently unused physical pages according to a certain algorithm, for example: page reclamation is performed using a least recently used (Least Recently Used, LRU) algorithm. The LRU algorithm assumes that recently unused pages will not be used for some time in the future, and that these pages will be candidates for reclamation when memory is scarce. The LRU linked list is divided into two bidirectional linked lists in the kernel: active linked lists and inactive linked lists. In the existing kernel page exchange mechanism, when a memory page is recovered, if the memory page at the tail of the linked list of the inactive linked list is not recoverable, the memory page needs to be skipped, and the recoverable memory page is continuously searched forward. In the extreme case, the memory pages at the rear end of the linked list are not recyclable, so that the memory pages need to be skipped all the time, which greatly reduces the efficiency of page recycling.
Disclosure of Invention
The following is a summary of the subject matter described in detail herein.
The embodiment of the invention provides a memory page recycling optimization method and system, electronic equipment and storage medium, which can optimize management and recycling mechanisms of memory pages by improving the processing process when the memory pages are accessed, thereby improving the recycling efficiency of the memory pages.
In a first aspect, an embodiment of the present invention provides a memory page recovery optimization method, including:
querying a page identifier of the accessed memory page under the condition that the accessed memory page is positioned in an inactive linked list;
adding the memory page to the head of the inactive linked list under the condition that the value of the page identifier of the accessed memory page is 0;
setting 1 the page identifier of the accessed memory page;
the page identifier is used for indicating whether the memory page is accessed in a latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1.
In some embodiments, after the querying the page identifier of the memory page being accessed, further comprising:
adding the memory page to the head of an active linked list under the condition that the value of the page identifier of the accessed memory page is 1;
the page identifier of the memory page to be accessed is set to 0.
In some embodiments, the method further comprises: and in the case that the accessed memory page is positioned in an active linked list, setting the page identifier 1 of the accessed memory page.
In some embodiments, before the adding the memory page to the head of the inactive linked list, the method further includes:
obtaining a prev pointer and a next pointer of the memory page, wherein the prev pointer is used for pointing to a forward node of a current node, and the next pointer is used for pointing to a backward node of the current node;
searching a forward node and a backward node of the memory page according to the prev pointer and the next pointer of the memory page;
and adjusting a next pointer of the forward node to point to the backward node, adjusting a prev pointer of the backward node to point to the forward node, and removing the memory page from the current position of the inactive linked list.
In some embodiments, the adding the memory page to the head of the inactive linked list includes:
and adjusting the next pointer of the table head of the inactive linked list, the prev pointer of the memory page and the pointing direction of the next pointer, and adding the accessed memory page to the head of the inactive linked list.
In some embodiments, in a case that the accessed memory page is located in the inactive linked list, before querying the page identifier of the accessed memory page, the method further includes:
and under the condition that the memory page is accessed, querying that the memory page is positioned in the inactive linked list or in the active linked list.
In a second aspect, an embodiment of the present invention provides a memory page reclamation optimization system, including:
the page identifier query module is used for querying the page identifier of the accessed memory page under the condition that the accessed memory page is positioned in the inactive linked list;
a memory page processing module, configured to add the memory page to the head of the inactive linked list when the value of the page identifier of the accessed memory page is 0;
a page tag Fu Zhiwei module, configured to place the page tag of the accessed memory page at 1;
the page identifier is used for indicating whether the memory page is accessed in a latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1.
In some embodiments, the memory page reclamation optimization system further includes:
and the memory page query module is used for querying that the memory page is positioned in the inactive linked list or the active linked list under the condition that the memory page is accessed.
In a third aspect, an embodiment of the present invention provides an electronic device, including: a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the memory page reclamation optimization method according to the first aspect when executing the computer program.
In a fourth aspect, an embodiment of the present invention provides a computer readable storage medium storing computer executable instructions for implementing the memory page reclamation optimization method according to the first aspect when executed by a processor.
The embodiment of the invention comprises the following steps: querying a page identifier of the accessed memory page under the condition that the accessed memory page is positioned in the inactive linked list; under the condition that the value of the page identifier of the accessed memory page is 0, adding the memory page to the head of the inactive linked list; setting a page identifier 1 of the accessed memory page; the page identifier is used for indicating whether the memory page is accessed in a latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1. According to the scheme of the embodiment of the invention, when the accessed memory page is positioned in the inactive linked list, the memory page recovery optimization system is utilized to inquire the page identifier of the accessed memory page, when the value of the page identifier of the accessed memory page is 0, the memory page is added to the head of the inactive linked list, and the page identifier of the accessed memory page is positioned 1, namely, the memory page can be correspondingly processed according to different linked lists and different states of the accessed memory page, so that the tail part of the inactive linked list gathers the memory pages in a recoverable state, and the memory page at the tail part of the inactive linked list can be directly recovered in the process of recovering the memory page, thereby improving the recovery efficiency of the memory page. That is, the scheme of the embodiment of the invention can optimize the management and recovery mechanism of the memory page by improving the processing process when the memory page is accessed, thereby improving the recovery efficiency of the memory page.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention may be realized and attained by the structure particularly pointed out in the written description and drawings.
Drawings
The foregoing and/or additional aspects and advantages of the invention will become apparent and may be better understood from the following description of embodiments taken in conjunction with the accompanying drawings in which:
FIG. 1 is a schematic diagram of a process for reclaiming memory pages in the related art;
FIG. 2 is a flowchart illustrating a memory page reclamation optimization method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of processing an accessed memory page according to one embodiment of the present invention;
FIG. 4 is a flowchart illustrating a memory page reclamation optimization method according to another embodiment of the present invention;
FIG. 5 is a schematic diagram of processing an accessed memory page according to another embodiment of the present invention;
FIG. 6 is a flowchart illustrating a memory page reclamation optimization method according to another embodiment of the present invention;
FIG. 7 is a schematic overall flow chart of a memory page reclamation optimization method according to an embodiment of the present invention;
FIG. 8 is a schematic diagram of a memory page reclamation optimization system according to an embodiment of the present invention;
fig. 9 is a schematic hardware structure of an electronic device according to an embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
It should be noted that although a logical order is illustrated in the flowchart in the description of the present invention, in some cases, the steps illustrated or described may be performed in an order different from that in the flowchart. In the description of the present invention, a plurality means one or more, and a plurality means two or more. The description of "first" and "second" is used for the purpose of distinguishing between technical features only and is not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated or implicitly indicating the precedence of the technical features indicated.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein is for the purpose of describing embodiments of the invention only and is not intended to be limiting of the invention.
First, several terms involved in the present invention are explained:
the least recently used (Least Recently Used, LRU) algorithm, also known as the least recently used page replacement algorithm. The LRU algorithm is an algorithm that is applied in the page reclamation mechanism. The LRU algorithm assumes that memory pages that have not been used recently will not be used for some time in the future. In the event of insufficient memory, these pages will be candidates for eviction. The page reclamation algorithm employed in the kernel is a combination of the conventional LRU algorithm and the second chance method.
The LRU linked list is used for maintaining the memory pages in the operating system. For example: the Linux operating system maintains memory pages using a pair of LRU linked lists. Each node in the LRU chain table has a prev pointer and a next pointer; the prev pointer and the next pointer are used to point to a previous node and a next node, respectively, of the current node.
The LRU link list includes two bidirectional link lists, namely an active link list (active_list) and an inactive link list (inactive_list), wherein the active_list is used for storing frequently accessed memory pages in an active state, and the inactive_list is used for storing memory pages which are not frequently accessed. Each memory page in active_list and inactive_list has a page identifier pg_reference. The active_list and the inactive_list each have a head and a tail and include a plurality of nodes.
The page identifier pg_reference is used to identify whether the memory page has been accessed recently. Specifically, when the value of the page identifier pg_reference is 1, it indicates that the memory page has been accessed recently (or within the last preset period), and when the value of the page identifier pg_reference is 0, it indicates that the memory page has not been accessed recently (or within the last preset period). Therefore, the page identifier PG_reference is also commonly used to implement the second chance method. When the second opportunity method is applied, when page recycling is performed, if the value of the page identifier PG_reference of the memory page is 1, the memory page is given a second opportunity, and other memory pages are selected for recycling without performing page recycling.
During the memory management process, some functions or operations are called to facilitate the memory management. The embodiment of the invention comprises the following steps:
mark_page_accessed function: for marking that a memory page has been accessed.
PageActive function: and the method is used for judging whether the memory page is in the active_list linked list or not.
PageReferenced function: for determining whether pg_reference is set to 1.
Setpagereference operation: for setting pg_reference of the memory page to 1.
Clearpagereference operation: for setting pg_reference of the memory page to 0.
activate_page function: for adding memory pages to the active_list linked list.
At present, in the kernel, frequently accessed memory pages in an active state are placed in an active_list linked list, frequently accessed memory pages are placed in an inactive_list, and each memory page has a flag bit PG_reference. In the existing kernel page exchange mechanism, when a memory page is recovered, if the PG_reference value of the memory page is 1, the memory page is temporarily unrecoverable, a second opportunity is given to the memory page, and other memory pages are selected for recovery; if the PG_reference value of the memory page is 0, the memory page is recyclable. When a process newly applies for a memory page, the newly applied memory page is added to the header of the active_list, and PG_reference of the page is set to 0. When a certain memory page in the LRU linked list is accessed, different operations exist according to the LRU linked list: when the accessed memory page exists in the active_list linked list, setting PG_reference to 1; when the accessed memory page exists in the active_list linked list: if PG_reference is 0, PG_reference is set to 1; if PG_reference is 1, the memory page is transferred to the active_list header, and PG_reference is set to 0. When the memory is insufficient and page recovery is needed, recovery can only be performed from the inactive_list linked list.
As shown in fig. 1, fig. 1 is a schematic diagram of a process of reclaiming a memory page in the related art. The recovery process is as follows: and (3) starting to recover from the tail of an inactive linked list (inactive_list), if PG_reference of a memory page is 1, skipping the memory page, and setting PG_reference of the memory page to 0. If PG_reference of the memory page is 0, writing the memory page into the swap partition, unbinding all mappings related to the memory page, releasing the memory page, and completing recycling.
If the PG_reference value of the memory page at the tail of the inactive_list chain table is 1, the memory page needs to be skipped, and the memory page with PG_reference of 0 is continuously searched forward. In the extreme case, if pg_reference of the memory page at the back end of the linked list is all 1, the corresponding memory page needs to be skipped all the time, which greatly reduces the efficiency of page reclamation. In the existing page reclamation mechanism of the kernel, if the memory page in the inactive_list is accessed, the pg_reference is set to 1, but the position of the memory page in the linked list is not changed. When the page is recovered, if PG_reference of the memory page at the tail of the inactive_list linked list is 1, the memory page needs to be skipped, and the memory page with PG_reference of 0 is continuously searched forward. In the extreme case, if pg_reference of the memory page at the tail end of the inactive_list linked list is all 1, the corresponding memory page needs to be skipped all the time, which greatly reduces the recovery efficiency of the memory page.
Based on this, the embodiment of the invention provides a memory page reclaiming optimization method, a memory page reclaiming optimization system, an electronic device and a computer readable storage medium, which can query the page identifier of the accessed memory page by utilizing the memory page reclaiming optimization system under the condition that the accessed memory page is located in an inactive linked list, add the memory page to the head of the inactive linked list under the condition that the value of the page identifier of the accessed memory page is 0, and place the page identifier of the accessed memory page at 1, namely, the memory page can be correspondingly processed according to different linked lists and different states of the accessed memory page, so that the tail of the inactive linked list gathers the memory page in a recoverable state, and the memory page at the tail of the inactive linked list can be directly reclaimed in the process of reclaiming the memory page, thereby improving the reclaiming efficiency of the memory page. Therefore, the scheme of the embodiment of the invention can optimize the management and recovery mechanism of the memory page by improving the processing process when the memory page is accessed, thereby improving the recovery efficiency of the memory page.
Embodiments of the present invention will be further described below with reference to the accompanying drawings.
In a first aspect, referring to fig. 2, fig. 2 is a flowchart of a memory page reclaiming optimization method according to an embodiment of the present invention. The memory page recycling optimization method can be applied to a memory page recycling optimization system. Specifically, the memory page recycling optimization method can be applied to an operating system and electronic equipment based on a linux kernel. The memory page reclamation optimization method may include, but is not limited to, steps S110 to S130.
Step S110: and in the case that the accessed memory page is positioned in the inactive linked list, querying the page identifier of the accessed memory page.
In this step, when it is found that the accessed memory page is located in the inactive linked list, the value of the page identifier of the accessed memory page is then queried. And the method is beneficial to adopting different processing modes for the accessed memory pages according to the values of the page identifiers so as to optimize the management of the accessed memory pages.
Specifically, in the case that the accessed memory page is located in the inactive linked list, the pagereference function is called to determine the current value of the page identifier pg_reference of the accessed memory page.
In some embodiments, step S110: in the case that the accessed memory page is located in the inactive linked list, the method further includes, before querying the page identifier of the accessed memory page: and under the condition that the memory page is accessed, querying whether the memory page is positioned in an inactive linked list or in an active linked list.
It will be appreciated that the memory pages being accessed may be located in either an inactive linked list or an active linked list. In the embodiment of the invention, different processing modes are corresponding to the accessed memory pages in different linked lists, so that the judgment on which linked list the accessed memory pages are in is needed, the different processing modes are adopted according to the different linked lists in which the memory pages are in later, the management of the accessed memory pages is optimized, and the management efficiency is improved.
Specifically, when a memory page is accessed, the system calls the mark_page_accessed function to mark the memory page. And then, calling the PageActive function in the mark_page_accessed function to judge that the accessed memory page is positioned in the active linked list or the inactive linked list.
Step S120: and adding the memory page to the head of the inactive linked list under the condition that the value of the page identifier of the accessed memory page is 0.
In this step, if it is determined that the value of the page identifier of the accessed memory page is 0, the memory page is added to the head of the inactive linked list. When a memory page with the page identifier value of 0 in the inactive linked list is accessed, the memory page is not suitable as a recycling candidate object, so that the position of the memory page in the inactive linked list is adjusted, and the head of the inactive linked list gathers the memory page which is given a second opportunity and is not recycled temporarily. The method realizes more reasonable division and management of the inactive linked list, is beneficial to optimizing a recovery mechanism and improves the recovery efficiency of the memory pages.
In some embodiments, before adding the memory page to the head of the inactive linked list, further comprising:
firstly, obtaining a prev pointer and a next pointer of a memory page, wherein the prev pointer is used for pointing to a forward node of a current node, and the next pointer is used for pointing to a backward node of the current node;
then, searching a forward node and a backward node of the memory page according to the prev pointer and the next pointer of the memory page;
finally, the next pointer of the forward node is adjusted to point to the backward node, and the prev pointer of the backward node is adjusted to point to the forward node, so that the memory page is removed from the current position of the inactive linked list.
The memory page is removed from the current position of the inactive linked list by adjusting the prev pointer and the next pointer, so that the realization is convenient.
In some embodiments, further describing step S120, "adding a memory page to the head of an inactive linked list" includes, but is not limited to, the following steps:
and adjusting the next pointer of the table head of the inactive linked list, the prev pointer of the memory page and the pointing direction of the next pointer, and adding the accessed memory page to the head of the inactive linked list.
Specifically, the next pointer of the active_list table head is assigned to the next pointer of the accessed memory page, then the next pointer of the active_list table head points to the node of the accessed memory page, and then the prev pointer of the accessed memory page node points to the active_list table head.
Step S130: the page identifier of the memory page to be accessed is set to 1.
In this step, the page identifier 1 of the memory page to be accessed is set by calling the setpagereference operation. That is, when a memory page with a page identifier value of 0 in the inactive linked list is accessed, the memory page is adjusted to the head of the inactive linked list, and the page identifier of the memory page is set to 1, so that the memory page is given a second opportunity and is not recycled temporarily, so that the head of the inactive linked list aggregates memory pages which are not recycled temporarily, and the tail of the inactive linked list aggregates memory pages in a recyclable state. The management of the inactive linked list and the memory pages is improved, so that the recovery mechanism is optimized, and the recovery efficiency of the memory pages is improved.
The page identifiers involved in steps S110 to S130 are further described. The page identifier is used for indicating whether the memory page is accessed in a latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1.
Referring to fig. 3, fig. 3 is a schematic diagram illustrating processing of an accessed memory page according to an embodiment of the present invention. In the inactive link table (inactive_list), a first memory page with pg_reference=1, a second memory page with pg_reference=1, a third memory page with pg_reference=0, and a fourth memory page with pg_reference=0 are sequentially linked from the head to the tail. When the third memory page is accessed, the third memory page is moved to the head of the inactive linked list and the PG_reference value of the third memory page is set to 1.
In the embodiment of the invention, through step S110 to step S130, when the accessed memory page is located in the inactive linked list, firstly, the memory page recovery optimization system is utilized to query the page identifier of the accessed memory page, then, when the value of the page identifier of the accessed memory page is 0, the memory page is added to the head of the inactive linked list, and the page identifier of the accessed memory page is set to 1, namely, the memory page can be correspondingly processed according to different linked lists and different states of the accessed memory page, so that the tail of the inactive linked list gathers the memory pages in a recoverable state, and the memory page at the tail of the inactive linked list can be directly recovered in the process of recovering the memory page, thereby improving the recovery efficiency of the memory page. That is, the scheme of the embodiment of the invention can optimize the management and recovery mechanism of the memory page by improving the processing process when the memory page is accessed, thereby improving the recovery efficiency of the memory page.
Referring to fig. 4, fig. 4 is a flowchart illustrating a memory page reclaiming optimization method according to another embodiment of the invention.
In some embodiments, at step S110: in the case that the accessed memory page is located in the inactive linked list, after querying the page identifier of the accessed memory page, steps S210 to S220 may be included.
Step S210: and adding the memory page to the head of the active linked list under the condition that the value of the page identifier of the accessed memory page is 1.
Step S220: the page identifier of the memory page to be accessed is set to 0.
Specifically, in the embodiment of the present invention, when the page identifier of the accessed memory page is determined to be 1 through the pagereference function in steps S210 to S220, the memory page is added to the head of the active linked list through the activate_page function, and at the same time, the page identifier of the accessed memory page is set to 0 through the clearpagereference operation. And the memory page with the accessed page identifier value of 1 is moved out of the inactive linked list and added into the head of the active linked list, so that the efficiency of searching the recoverable memory page in the inactive linked list in the page recovery processing process is improved. The management of the inactive linked list, the active linked list and the memory pages is improved, so that the recovery mechanism is optimized, and the recovery efficiency of the memory pages is improved.
Referring to fig. 5, fig. 5 is a schematic diagram illustrating processing of an accessed memory page according to another embodiment of the present invention. In the inactive link table (inactive_list), a first memory page with pg_reference=1, a second memory page with pg_reference=1, a third memory page with pg_reference=1, and a fourth memory page with pg_reference=0 are sequentially linked from the head to the tail. In the original active list (active_list), a fifth memory page with pg_reference=1, a sixth memory page with pg_reference=1, and a seventh memory page with pg_reference=0 are sequentially linked from the head to the tail. In the case where a second memory page of pg_reference=1 in an inactive linked list (active_list) is accessed, the second memory page is added to the head of the active linked list (active_list), and the value of pg_reference of the second memory page is set to 0.
Fig. 6 is a flowchart of a memory page reclaiming optimization method according to another embodiment of the invention. In the case of a memory page being accessed, the possible memory pages being accessed are either in an inactive linked list or in an active linked list. In some embodiments, the method for optimizing memory page reclamation may further include, but is not limited to, step S310.
Step S310: in the case where the memory page being accessed is located in the active linked list, the page identifier of the memory page to be accessed is set to 1.
Specifically, in the embodiment of the present invention, in step S310, when the PageActive function queries that the accessed memory page is located in the active linked list, the page identifier of the memory page is directly set to 1 through the setpagereference operation. And the active linked list and the memory pages are managed, so that the recovery mechanism is optimized, and the recovery efficiency of the memory pages is improved.
As an example, as shown in fig. 7, fig. 7 is an overall flow chart of a memory page reclaiming optimization method according to an embodiment of the invention. When a memory page is accessed, firstly judging whether the memory page is positioned in an inactive_list linked list; on the one hand, under the condition that the memory page is not located in the inactive_list linked list, PG_reference is directly set to 1, and the processing is finished; on the other hand, if the memory page is located in the active_list linked list, judging whether PG_reference is 0, if PG_reference is not 0, adding the memory page into the active_list linked list, then setting PG_reference to 0, and ending the processing; and under the condition that PG_reference is 0, setting PG_reference to 1, moving the memory page out of the position of the current inactive_list linked list, adding the memory page into the head of the inactive_list linked list, and ending the processing. The memory page recovery optimization method provided by the embodiment of the invention can intensively place all the memory pages with PG_reference of 0 in the inactive_list linked list to the tail part of the linked list, and when the pages are recovered, the pages at the tail part can be recovered immediately. And aiming at different linked lists and different states of the accessed memory page, carrying out different treatments on the memory page. The management and recovery mechanism of the memory pages is optimized by improving the processing process when the memory pages are accessed, so that the recovery efficiency of the memory pages is improved.
In a second aspect, based on each embodiment of the memory page reclaiming optimization method, a memory page reclaiming optimization system capable of implementing the above embodiment is provided. Referring to fig. 8, fig. 8 is a schematic structural diagram of a memory page reclaiming optimization system according to an embodiment of the invention. The memory page reclamation optimization system 800 includes: a page identifier query module 810, a memory page processing module 820, and a page tag Fu Zhiwei module 830.
The page identifier query module 810 is configured to query the page identifier of the accessed memory page if the accessed memory page is in the inactive linked list.
The memory page processing module 820 is configured to add the memory page to the head of the inactive linked list if the value of the page identifier of the accessed memory page is 0.
The page tag Fu Zhiwei module 830 is configured to set a page tag of the accessed memory page to 1; the page identifier is used for indicating whether the memory page is accessed in a latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1.
In the memory page reclaiming optimization system 800 provided in the embodiment of the present invention, when the accessed memory page is located in the inactive linked list, firstly, the page identifier of the accessed memory page is queried by using the page identifier query module 810; then, in the case that the value of the page identifier of the accessed memory page is 0, adding the memory page to the head of the inactive linked list by using the memory page processing module 820; and sets the page identifier of the accessed memory page to 1 by using the page identifier Fu Zhiwei module 830; the page identifier is used for indicating whether the memory page is accessed in a latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1. The memory page recycling optimization system 800 can correspondingly process the memory pages according to different linked lists and different states of the accessed memory pages, so that the tail parts of the inactive linked lists gather the memory pages in a recyclable state, and the memory pages at the tail parts of the inactive linked lists can be directly recycled in the process of recycling the memory pages, thereby improving the recycling efficiency of the memory pages. Therefore, the memory page reclamation optimization system 800 of the embodiment of the invention can optimize the management and reclamation mechanism of the memory page by improving the processing procedure when the memory page is accessed, thereby improving the reclamation efficiency of the memory page.
In some embodiments, the memory page reclamation optimization system further comprises: and the memory page query module is used for querying whether the memory page is positioned in the inactive linked list or the active linked list under the condition that the memory page is accessed.
The specific implementation of the memory page reclamation optimization system 800 is substantially the same as the specific embodiment of the memory page reclamation optimization method described above, and will not be described herein.
It will be appreciated by persons skilled in the art that the system architecture shown in the figures is not limiting of the embodiments of the invention and may include more or fewer components than shown, or certain components may be combined, or a different arrangement of components.
The system embodiments described above are merely illustrative, in that the units illustrated as separate components may or may not be physically separate, i.e., may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
It can be appreciated that the memory page reclaiming optimization system 800 may be an operating system or an electronic device based on a Linux kernel, and can improve the reclaiming efficiency of the memory page by optimizing the management and reclaiming mechanism of the memory page, thereby improving the system performance.
It will be understood by those skilled in the art that the system architecture and the application scenario described in the embodiments of the present invention are for more clearly describing the technical solution of the embodiments of the present invention, and are not limited to the technical solution provided in the embodiments of the present invention, and those skilled in the art can know that, with the evolution of the system architecture and the appearance of the new application scenario, the technical solution provided in the embodiments of the present invention is equally applicable to similar technical problems.
In third aspect, referring to fig. 9, fig. 9 is a schematic hardware structure of an electronic device according to an embodiment of the present invention. The electronic device 900 includes: the memory 920, the processor 910 and a computer program stored on the memory 920 and executable on the processor, the processor 910 implementing the memory page reclamation optimization method as in the first aspect when executing the computer program.
The processor 910 and the memory 920 may be connected by a bus or other means.
The processor 910 may be implemented by a general purpose central processing unit, a microprocessor, an application specific integrated circuit, or one or more integrated circuits, etc. for executing related programs to implement the technical solutions provided by the embodiments of the present invention.
Memory 920 acts as a non-transitory computer readable storage medium that may be used to store non-transitory software programs as well as non-transitory computer executable programs. In addition, the memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, flash memory device, or other non-transitory solid state storage device. In some implementations, memory 920 may optionally include memory located remotely from the processor, which may be connected to the processor 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.
The non-transitory software programs and instructions required to implement the memory page reclamation optimization method of the above-described embodiments are stored in memory that, when executed by a processor, perform the memory page reclamation optimization method of the above-described embodiments, for example, perform the method steps shown in fig. 2, 4, 6, and 7 described above.
The apparatus embodiments or system embodiments described above are merely illustrative, in which elements illustrated as separate components may or may not be physically separate, i.e., may be located in one place, or may be distributed over multiple network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium storing computer-executable instructions that are executed by a processor or controller, for example, by one of the above-described embodiments of the apparatus, which may cause the above-described processor to perform the memory page reclamation optimization method in the above-described embodiments, for example, to perform the method steps shown in fig. 2, 4, 6, and 7 described above.
Those of ordinary skill in the art will appreciate that all or some of the steps, systems, and methods disclosed above may be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). The term computer storage media includes both volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data, as known to those skilled in the art. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital Versatile Disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by a computer. Furthermore, as is well known to those of ordinary skill in the art, communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media.
While the preferred embodiments of the present invention have been described in detail, the present invention is not limited to the above embodiments, and various equivalent modifications and substitutions can be made by those skilled in the art without departing from the spirit of the present invention, and these equivalent modifications and substitutions are intended to be included in the scope of the present invention.

Claims (10)

1. The memory page recycling optimization method is characterized by comprising the following steps of:
querying a page identifier of the accessed memory page under the condition that the accessed memory page is positioned in an inactive linked list;
adding the memory page to the head of the inactive linked list under the condition that the value of the page identifier of the accessed memory page is 0;
setting 1 the page identifier of the accessed memory page;
the page identifier is used for indicating whether the memory page is accessed in a latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1.
2. The memory page reclamation optimization method as recited in claim 1, further comprising, after the querying the page identifier of the accessed memory page:
adding the memory page to the head of an active linked list under the condition that the value of the page identifier of the accessed memory page is 1;
the page identifier of the memory page to be accessed is set to 0.
3. The memory page reclamation optimization method as recited in claim 1, further comprising: and in the case that the accessed memory page is positioned in an active linked list, setting the page identifier 1 of the accessed memory page.
4. The method for memory page reclamation optimization of claim 1, further comprising, before adding the memory page to the head of the inactive linked list:
obtaining a prev pointer and a next pointer of the memory page, wherein the prev pointer is used for pointing to a forward node of a current node, and the next pointer is used for pointing to a backward node of the current node;
searching a forward node and a backward node of the memory page according to the prev pointer and the next pointer of the memory page;
and adjusting a next pointer of the forward node to point to the backward node, adjusting a prev pointer of the backward node to point to the forward node, and removing the memory page from the current position of the inactive linked list.
5. The method for memory page reclamation optimization as recited in claim 4, wherein the adding the memory page to the head of the inactive linked list comprises:
and adjusting the next pointer of the table head of the inactive linked list, the prev pointer of the memory page and the pointing direction of the next pointer, and adding the accessed memory page to the head of the inactive linked list.
6. The method for memory page reclamation optimization as recited in claim 1, wherein, in the case that the accessed memory page is located in the inactive linked list, the method further comprises, before querying the page identifier of the accessed memory page:
and under the condition that the memory page is accessed, querying that the memory page is positioned in the inactive linked list or in the active linked list.
7. A memory page reclamation optimization system, comprising:
the page identifier query module is used for querying the page identifier of the accessed memory page under the condition that the accessed memory page is positioned in the inactive linked list;
a memory page processing module, configured to add the memory page to the head of the inactive linked list when the value of the page identifier of the accessed memory page is 0;
a page tag Fu Zhiwei module, configured to place the page tag of the accessed memory page at 1;
the page identifier is used for indicating whether the memory page is accessed in a latest preset time period, and indicates that the memory page is not accessed in the latest preset time period under the condition that the value of the page identifier is 0, and indicates that the memory page is accessed in the latest preset time period under the condition that the value of the page identifier is 1.
8. The memory page reclamation optimization system as recited in claim 7, further comprising:
and the memory page query module is used for querying that the memory page is positioned in the inactive linked list or the active linked list under the condition that the memory page is accessed.
9. An electronic device, comprising: a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the memory page reclamation optimization method according to any of claims 1 to 6 when the computer program is executed.
10. A computer readable storage medium storing computer executable instructions for implementing the memory page reclamation optimization method according to any of claims 1 to 6 when executed by a processor.
CN202310016809.2A 2023-01-06 2023-01-06 Memory page recycling optimization method and system, electronic equipment and storage medium thereof Pending CN116049024A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310016809.2A CN116049024A (en) 2023-01-06 2023-01-06 Memory page recycling optimization method and system, electronic equipment and storage medium thereof

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310016809.2A CN116049024A (en) 2023-01-06 2023-01-06 Memory page recycling optimization method and system, electronic equipment and storage medium thereof

Publications (1)

Publication Number Publication Date
CN116049024A true CN116049024A (en) 2023-05-02

Family

ID=86117974

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310016809.2A Pending CN116049024A (en) 2023-01-06 2023-01-06 Memory page recycling optimization method and system, electronic equipment and storage medium thereof

Country Status (1)

Country Link
CN (1) CN116049024A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111858393A (en) * 2020-07-13 2020-10-30 Oppo(重庆)智能科技有限公司 Memory page management method, memory page management device, medium and electronic device
CN112699060A (en) * 2019-10-23 2021-04-23 深圳市茁壮网络股份有限公司 Data block management method, system and storage medium
CN112817736A (en) * 2019-11-15 2021-05-18 荣耀终端有限公司 Memory management method and electronic equipment
WO2022089452A1 (en) * 2020-10-31 2022-05-05 华为终端有限公司 Memory management method and apparatus, and electronic device and computer-readable storage medium
CN114968543A (en) * 2021-02-24 2022-08-30 华为技术有限公司 Method for processing document page and related device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112699060A (en) * 2019-10-23 2021-04-23 深圳市茁壮网络股份有限公司 Data block management method, system and storage medium
CN112817736A (en) * 2019-11-15 2021-05-18 荣耀终端有限公司 Memory management method and electronic equipment
CN111858393A (en) * 2020-07-13 2020-10-30 Oppo(重庆)智能科技有限公司 Memory page management method, memory page management device, medium and electronic device
WO2022089452A1 (en) * 2020-10-31 2022-05-05 华为终端有限公司 Memory management method and apparatus, and electronic device and computer-readable storage medium
CN114968543A (en) * 2021-02-24 2022-08-30 华为技术有限公司 Method for processing document page and related device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
匿名: "(转)linux内存源码分析 - 内存回收(lru链表)", pages 1 - 23, Retrieved from the Internet <URL:《http://www.noobyard.com/article/p-tbkrqtsh-e.html》> *

Similar Documents

Publication Publication Date Title
US10565075B2 (en) Storage device and block storage method based on the storage device
US8694472B2 (en) System and method for rebuilding indices for partitioned databases
CN105224546A (en) Data storage and query method and apparatus
CN109145163B (en) Block chain data capacity reduction method and device and storage medium
CN112506710B (en) Distributed file system data restoration method, device, equipment and storage medium
CN108984295B (en) Memory recovery method, computer device and computer readable storage medium
US6473842B1 (en) Virtual memory managing system for managing swap-outs by page units and a batch swap-out by task units
CN106445835A (en) Memory allocation method and apparatus
CN104933051B (en) File storage recovery method and device
CN108932271B (en) File management method and device
CN107025289A (en) The method and relevant device of a kind of data processing
CN111444147A (en) Data page creating method and device, terminal equipment and storage medium
CN105095495A (en) Distributed file system cache management method and system
CN104035928A (en) TCAM (telecommunication access method) table space recovery method and device
US20110078383A1 (en) Cache Management for Increasing Performance of High-Availability Multi-Core Systems
CN116049024A (en) Memory page recycling optimization method and system, electronic equipment and storage medium thereof
US11847116B2 (en) Distributed database preprocessing method, agent layer, system and storage medium
CN103714059A (en) Data updating method and device
CN112783688B (en) Erasure code data recovery method and device based on available partition level
CN112035253B (en) Linux system page cache recovery method and related device
CN112260948B (en) Multi-core SDN switch flow table management method and system based on batch updating
CN114020707B (en) Storage space recovery method, storage medium, and program product
CN112631741A (en) Transaction processing method, device and storage medium
CN113051081B (en) Event state management method, system and storage medium based on memory pool
CN117539409B (en) Query acceleration method and device based on data cache, medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination