CN113986540A - Method and device for regularly recycling linux cache - Google Patents

Method and device for regularly recycling linux cache Download PDF

Info

Publication number
CN113986540A
CN113986540A CN202111242077.6A CN202111242077A CN113986540A CN 113986540 A CN113986540 A CN 113986540A CN 202111242077 A CN202111242077 A CN 202111242077A CN 113986540 A CN113986540 A CN 113986540A
Authority
CN
China
Prior art keywords
cache
memory
linux
recovery
behavior
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.)
Granted
Application number
CN202111242077.6A
Other languages
Chinese (zh)
Other versions
CN113986540B (en
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.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent 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 Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202111242077.6A priority Critical patent/CN113986540B/en
Publication of CN113986540A publication Critical patent/CN113986540A/en
Application granted granted Critical
Publication of CN113986540B publication Critical patent/CN113986540B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the 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/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/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0877Cache access modes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Landscapes

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

Abstract

The application relates to a method and a device for regularly recovering a linux cache; the method comprises the following steps: determining a recovery period; acquiring the sizes of a cache and an idle physical memory in a linux system, and acquiring memory use parameters according to the idle physical memory and the cache; determining corresponding cache recovery behaviors according to the memory use parameters; and executing the determined cache recovery behavior at regular time according to the recovery period, and recovering the cache of the linux system. The scheme of the application can regularly recover the cache in the system, can effectively prevent the situation that the service pressure breaks through the waterline too much, and can also prevent the situation that the memory waterline is increased to waste the system memory, so that the stable operation of the system is obtained at a small cost.

Description

Method and device for regularly recycling linux cache
Technical Field
The application relates to the technical field of computer memories, in particular to a method and a device for regularly recycling a linux cache.
Background
Caching is one of the most important mechanisms in linux systems. From the aspect of operating system memory indexes, the cache mainly includes a page cache and a kernel object cache (slab cache). When the page cache is used for reading and writing files or mapping the memory, the linux system firstly writes (reads) data into the page cache so as to improve the reading and writing efficiency by reducing the I/O times of the system. The slab cache is a cache pool allocated to the small block data in the kernel, and can provide a faster memory allocation path for the small block data structure of the kernel.
However, in practical applications, a large amount of physical memory is often occupied by the cache, and at this time, if the service pressure is suddenly increased, a large amount of memory allocation is required, and there is a possibility that a memory pipeline is broken down due to untimely memory recovery, which further causes a problem of a violent system load or service delay jitter. How to better solve the recycling of the cache in the linux system is an urgent problem to be solved in the field.
In the related art, the current linux cache reclamation mainly depends on a page reclamation mechanism, which is mainly two types: background reclamation and direct reclamation. Background recovery is to wake up the kswapd kernel thread for asynchronous recovery when the system detects that the available memory is below the low water line of the memory until the available memory of the system is increased to the high water line, and the background recovery does not cause service delay. If the asynchronous memory recovery speed cannot meet the memory application speed at the moment, starting the system to start direct recovery; the direct recovery is synchronous blocking recovery in the process of applying for the memory by the process, which can cause the subsequent behavior of the process to be blocked; if a dirty page written back to the slow IO device is encountered during the memory recovery process, the problems of system load increase and service delay will be caused.
Disclosure of Invention
To overcome, at least to some extent, the problems in the related art, the present application provides a method and apparatus for timing eviction of a linux cache.
According to a first aspect of embodiments of the present application, there is provided a method for periodically evicting a linux cache, including:
determining a recovery period;
acquiring the sizes of a cache and an idle physical memory in a linux system, and acquiring memory use parameters according to the idle physical memory and the cache;
determining corresponding cache recovery behaviors according to the memory use parameters;
and executing the determined cache recovery behavior at regular time according to the recovery period, and recovering the cache of the linux system.
Further, the cache eviction behavior is performed by a separate kernel thread;
the kernel thread is created at the time of initialization of the linux system, or is created in a kernel module, or is dynamically created through a configuration file.
Further, the obtaining the memory usage parameter according to the idle physical memory and the cache includes:
and calculating the ratio of the idle physical memory to the cache to obtain the memory use parameters.
Further, the determining the corresponding cache recycling behavior according to the memory usage parameter includes:
and executing a first cache recycling behavior when the memory use parameter is larger than a first preset proportion.
Further, the first cache eviction action comprises:
scanning a file system;
judging whether the scanned index node has a corresponding page cache or not;
if so, not releasing the index node cache; otherwise, the index node cache is released.
Further, the determining the corresponding cache recycling behavior according to the memory usage parameter further includes:
and executing a second cache recycling behavior when the memory use parameter is smaller than a second preset proportion and larger than a third preset proportion.
Further, the second cache eviction action comprises:
and calling a related kernel function in the linux kernel, and recycling the clean page of the page cache.
Further, the determining the corresponding cache recycling behavior according to the memory usage parameter further includes:
and executing a third cache recycling behavior when the memory use parameter is smaller than a third preset proportion.
Further, the third cache eviction action comprises:
and calling related kernel functions in the linux kernel, and recycling the clean page of the page cache and the recyclable part of the slab cache.
According to a second aspect of the embodiments of the present application, there is provided an apparatus for timing eviction of a linux cache, including:
a timer module for determining a recovery period;
the device comprises an acquisition module, a storage module and a processing module, wherein the acquisition module is used for acquiring the sizes of a cache and an idle physical memory in the linux system and acquiring memory use parameters according to the idle physical memory and the cache;
the cache recovery module is used for determining corresponding cache recovery behaviors according to the memory use parameters; and executing the determined cache recovery behavior at regular time according to the recovery period, and recovering the cache of the linux system.
The technical scheme provided by the embodiment of the application has the following beneficial effects:
the scheme of the application can regularly recover the cache in the system, can effectively prevent the situation that the service pressure breaks through the waterline too much, and can also prevent the situation that the memory waterline is increased to waste the system memory, so that the stable operation of the system is obtained at a small cost.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and together with the description, serve to explain the principles of the application.
FIG. 1 is a flow diagram illustrating a method of timing eviction of a linux cache in accordance with an exemplary embodiment.
FIG. 2 is a block diagram illustrating an apparatus for timing eviction of a linux cache, according to an example embodiment.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of methods and apparatus consistent with certain aspects of the present application, as detailed in the appended claims.
To further detail the technical solution of the present application, firstly, the defects of the linux operating system are specifically explained. In the linux system, asynchronous recovery of kswapd kernel threads does not cause service delay, but if kswapd wakes up too late, the system enables direct recovery, which causes subsequent behaviors of the process to be blocked, and the system may need long recovery; this will again lead to the subsequent behavior of the process being blocked, which in turn causes problems with increased system load and traffic delay. Wherein kswapd is a linux kernel recycle thread.
Although the configuration file in the system can trigger page recovery earlier by increasing the memory water line, this method also has a certain defect, that is, after the memory water line is increased, the memory directly used by the upper application program is reduced, resulting in waste of the system memory.
It can be seen that the linux operating system has certain defects on the recycle cache, which may cause a serious delay problem of upper layer services. The present application addresses this problem by providing a method for periodically evicting a linux cache. The method can be used in some large-service scenes, and can be used for regularly recovering the cache in the system, so that the situation that the waterline is punctured due to overlarge service pressure can be effectively prevented, the situation that the memory of the system is wasted due to the fact that the memory waterline is improved can also be prevented, and the stable operation of the system is replaced by a tiny cost.
FIG. 1 is a flow diagram illustrating a method of timing eviction of a linux cache in accordance with an exemplary embodiment. The method may comprise the steps of:
step S1: determining a recovery period;
step S2: acquiring the sizes of a cache and an idle physical memory in a linux system, and acquiring memory use parameters according to the idle physical memory and the cache;
step S3: determining corresponding cache recovery behaviors according to the memory use parameters;
step S4: and executing the determined cache recovery behavior at regular time according to the recovery period, and recovering the cache of the linux system.
The method for regularly recycling the linux cache can be applied to service scenes needing a large number of read files or certain large-pressure scenes. The scheme of the application can regularly recover the cache in the system, can effectively prevent the situation that the service pressure breaks through the waterline too much, and can also prevent the situation that the memory waterline is increased to waste the system memory, so that the stable operation of the system is obtained at a small cost.
It should be understood that, although the steps in the flowchart of fig. 1 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in fig. 1 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
The following describes the scheme of the present application in an expanded manner with reference to a specific application scenario.
Fig. 1 is a schematic diagram of a method for regularly recycling a linux cache according to some embodiments of the present application, which can effectively solve the problem that an application program is seriously blocked due to the fact that a memory cannot be timely recycled in a large file read-write scene.
Step S1: the recovery period is determined.
Before determining the eviction period, it should be noted that the cache eviction function provided by the present application is dynamically switchable. Since the cache recovery method of the present application is different from a page recovery thread existing in the kernel, the cache recovery method used in the present application is a custom kernel thread. The kernel thread can be created when the linux system is initialized, can be created in the kernel module, and can also be dynamically created through the configuration file. Typically, when a cache kernel thread is created, it goes to sleep directly.
The subsequent behaviors of the kernel thread have two kinds, one is to wake up and recover the cache when the timing time is up; the other is to exit the kernel thread when the cache eviction function is to be turned off. The method is characterized in that a configuration file/proc/sys/vm/cache _ callback _ enable is newly added to control a switch of the function, the default value of the value is 0, the cache recovery function is not started, a user can start the cache recovery function through echo1>/proc/sys/vm/cache _ callback _ enable, when the function is started, whether the kernel thread exists is firstly judged, if the kernel thread does not exist, a kernel thread is created, the kernel thread is put into sleep, and the subsequent awakening is waited. When the user executes echo0>/proc/sys/vm/cache _ callback _ enable, the kernel thread is exited and the resource is recycled. For the increase of the user mode configuration file, the existing document can be referred to, and the description is not repeated in the application.
The above-mentioned recovery period can also be dynamically configured in a user mode, the newly added configuration file/proc/sys/vm/cache _ retrieval _ time in the present application can dynamically configure the recovery period, the default is 60, the unit is second, that is, the default 60s wakes up a kernel recovery thread and performs recovery of a cache, and a user can perform echo >/proc/sys/vm/cache _ retrieval _ time (0< x) configuration.
The above implementation manner of the recovery period is implemented by a timer mechanism of the linux kernel, and when the timing time is up, the kernel recovery thread is awakened to recover the cache. The implementation of the timer can refer to the prior art, and details are not repeated in this application.
Step 2: and obtaining the cache size and the free physical memory size in the linux system.
The Linux system internal cache is a page cache and a kernel data object cache (slab cache) for reading files from a disk by the system, and the idle physical memory is the sum of the current unused memory and the unused exchange partition in the system. Wherein the slab is a linux kernel memory allocator.
It should be noted that the above-mentioned core data object cache is only a part of the slab cache, the slab cache may be divided into a recoverable part and an unrecoverable part, and the unrecoverable part, that is, this part of the memory cannot be recovered, so the above-mentioned slab cache refers to the recoverable part in the slab cache. As can be seen, the Cache is the recoverable part of the page Cache + slab Cache, and corresponds to Cached and sreclailable in the linux system lower/proc/meminfo file, that is, the Cache is Cached + sreclailable. Wherein Cached refers to the size of a cache in the linux system; SReclailable is a reclaimable part in the slab cache in the linux system.
The size of the free physical memory corresponds to the sum of the values of MemFree and swapfee in the/proc/meminfo file, that is, free is MemFree + swapfee, it is worth mentioning that the free physical memory described in this example includes the size of the free swap partition (swapfee), and in fact, the swap partition is not a part of the physical memory, and only the hard disk space is virtualized to be used as the memory. Wherein, MemFree is the size of the free memory in the linux system; SwapFree is the size of the idle swap in the linux system.
Step S3: and determining corresponding cache recycling behaviors according to the memory use parameters.
The proportion threshold value in the application can represent the memory use condition of the current linux system, and is divided into three proportion threshold values: the first preset proportion, the second preset proportion and the third preset proportion. The three preset proportions can be dynamically configured in a user mode, and configuration files, namely cache _ replay _ fir _ ratio, cache _ replay _ sec _ ratio and cache _ replay _ thi _ ratio, are newly added under/proc/sys/vm/directory, wherein the default values are 80,50 and 30 respectively. In a recovery period, when the percentage of the idle physical memory to the size of the cache is detected to be larger than 80, executing a first cache recovery action; when the percentage of the idle physical memory to the cache size is detected to be more than 50 and less than 80, executing a second cache recycling behavior; and when the percentage of the size of the free physical memory to the size of the cache is less than 30, executing a third cache recycling behavior.
Step S4: and executing different cache recycling behaviors according to the ratio of the free physical memory to the cache size.
It is worth noting that the recycling strength of the first, second and third cache recycling behaviors of the present application to the system cache gradually increases as the remaining idle physical memory in the linux system decreases, and the influence on the performance of the operating system also gradually increases, that is, the performance is exchanged for the memory.
Step S401: and if the ratio of the idle physical memory to the cache is larger than a first preset ratio, executing a first cache recycling behavior. The first cache eviction action evicts an evictable portion, sreclairable, of the slab cache. The interface of the slab function is already realized in the current linux kernel, so that kernel codes can be referred to for realizing slab cache recycling in the step, and only certain modification is needed. The slab cache recycling realized by the kernel also comprises index node caching of the disk file, when the process reads the file, the address space corresponding to the file is found through the index node, and then the corresponding physical page is found through file migration. If the physical page exists, it indicates that the disk file has been cached in the physical memory, and if the physical page does not exist, it needs to be read from the disk. The page cache and the inode cache are thus dependent. If the index node is released, the page cache does not exist, which is equivalent to releasing the page cache and the slab cache at the same time, and the overall performance of the system may be affected to a certain extent at this time. Therefore, the first cache eviction action should not release those inodes that have a page cache present. Therefore, before scanning the file system and releasing the index node cache, it should be determined whether the index node has a corresponding page cache, and if so, the index node cache should not be released. By the method, only the slab cache which can be released, so that the performance influence on the system is reduced.
Step S402: and if the ratio of the idle physical memory to the cache is smaller than a second preset ratio and larger than a third preset ratio, executing a second cache recycling behavior.
The second cache recycling behavior is to recycle a clean page of the page cache, namely the part of the memory of the page cache is synchronized with an external disk; the page cache which is not synchronized is called a dirty page, the dirty page needs to be written back to a disk to be released, and the method provided by the application does not process the dirty page. Instead, clean pages are directly freed. Similarly, after the page buffer is released, if the page buffer needs to be read again next time, the page buffer needs to be read into the memory again from the disk, and the physical memory occupied by the page buffer is relatively large, so that a slight delay of the service is also caused.
The function interface for recycling the clean page in the page cache is already realized in the current linux kernel, so that the kernel function can be directly called for recycling the page cache in the step. Reference may be made in particular to linux kernel related art, which is not further described in this application.
Step S403: and if the ratio of the idle physical memory to the cache is smaller than a third preset ratio, executing a third cache recycling behavior.
The third cache eviction action evicts both the clean page of the page cache and the evictable portion of the slab cache, and as the system physical resource consumption is already high, the evictable portion is evicted completely. At this point we will experience a significant performance delay of the service.
The function interfaces for recovering the clean pages in the page cache and the recoverable part of the slab cache are already realized in the current linux kernel, so that the kernel function can be directly called for recovering the page cache in the step. Reference may be made in particular to linux kernel related art, which is not further described in this application. By the cache release of this step, most of the system cache can be recycled, and the performance of the system is obviously reduced in a period of time.
In summary, the scheme of the application can recycle the linux cache at regular time, and the timing time can be dynamically configured; defining three different cache recycling behaviors according to the memory state of the current system; the preset proportion aiming at the three recovery behaviors can be dynamically configured so as to meet the requirements of different scenes. The method can recycle the cache in the system at regular time, provides three different recycling behaviors according to the state of the current system, and can meet the requirement of the physical memory of the system as much as possible under the condition of not reducing the service performance as much as possible.
FIG. 2 is a schematic diagram of an implementation of a linux cache eviction device. As can be seen from the figure, the linux cache eviction device may include: the device comprises a timer module, a parameter configuration module, an acquisition module and a cache recovery module.
The timer module is used for determining a recovery period; a timer is created in the linux kernel, and the timer is used as the period of the system recovery cache.
The parameter configuration module is used for realizing user-defined configuration, and comprises:
the/proc/sys/vm/cache _ relaim _ enable is used for controlling the starting and the closing of the cache recovery method;
the/proc/sys/vm/cache _ callback _ time is used for adjusting the timing time of the timer;
the cache _ replay _ fir _ ratio, the cache _ replay _ sec _ ratio and the cache _ replay _ thi _ ratio are used for adjusting the first, second and third preset proportions.
The obtaining module is used for obtaining the sizes of the cache and the free physical memory in the linux system and obtaining the memory use parameters according to the free physical memory and the cache.
The cache recovery module is used for determining corresponding cache recovery behaviors according to the memory use parameters; and executing the determined cache recovery behavior at regular time according to the recovery period, and recovering the cache of the linux system.
With regard to the apparatus in the above embodiment, the specific steps in which the respective modules perform operations have been described in detail in the embodiment related to the method, and are not described in detail herein. The modules in the cache recovery apparatus may be implemented wholly or partially by software, hardware, or a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
It is understood that the same or similar parts in the above embodiments may be mutually referred to, and the same or similar parts in other embodiments may be referred to for the content which is not described in detail in some embodiments.
It should be noted that, in the description of the present application, the terms "first", "second", etc. are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. Further, in the description of the present application, the meaning of "a plurality" means at least two unless otherwise specified.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps of the process, and the scope of the preferred embodiments of the present application includes other implementations in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the present application.
It should be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
It will be understood by those skilled in the art that all or part of the steps carried by the method for implementing the above embodiments may be implemented by hardware related to instructions of a program, which may be stored in a computer readable storage medium, and when the program is executed, the program includes one or a combination of the steps of the method embodiments.
In addition, functional units in the embodiments of the present application may be integrated into one processing module, or each unit may exist alone physically, or two or more units are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium.
The storage medium mentioned above may be a read-only memory, a magnetic or optical disk, etc.
In the description herein, reference to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the application. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
Although embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present application, and that variations, modifications, substitutions and alterations may be made to the above embodiments by those of ordinary skill in the art within the scope of the present application.

Claims (10)

1. A method for periodically evicting a linux cache, comprising:
determining a recovery period;
acquiring the sizes of a cache and an idle physical memory in a linux system, and acquiring memory use parameters according to the idle physical memory and the cache;
determining corresponding cache recovery behaviors according to the memory use parameters;
and executing the determined cache recovery behavior at regular time according to the recovery period, and recovering the cache of the linux system.
2. The method of claim 1, wherein the cache eviction behavior is performed by a separate kernel thread;
the kernel thread is created at the time of initialization of the linux system, or is created in a kernel module, or is dynamically created through a configuration file.
3. The method of claim 1, wherein obtaining memory usage parameters from the free physical memory and the cache comprises:
and calculating the ratio of the idle physical memory to the cache to obtain the memory use parameters.
4. The method according to any of claims 1-3, wherein determining the corresponding cache eviction behavior according to the memory usage parameter comprises:
and executing a first cache recycling behavior when the memory use parameter is larger than a first preset proportion.
5. The method of claim 4, wherein the first cache eviction action comprises:
scanning a file system;
judging whether the scanned index node has a corresponding page cache or not;
if so, not releasing the index node cache; otherwise, the index node cache is released.
6. The method according to claim 4, wherein determining the corresponding cache eviction behavior according to the memory usage parameter further comprises:
and executing a second cache recycling behavior when the memory use parameter is smaller than a second preset proportion and larger than a third preset proportion.
7. The method of claim 6, wherein the second cache eviction action comprises:
and calling a related kernel function in the linux kernel, and recycling the clean page of the page cache.
8. The method according to claim 4, wherein determining the corresponding cache eviction behavior according to the memory usage parameter further comprises:
and executing a third cache recycling behavior when the memory use parameter is smaller than a third preset proportion.
9. The method of claim 3, wherein the third cache eviction action comprises:
and calling related kernel functions in the linux kernel, and recycling the clean page of the page cache and the recyclable part of the slab cache.
10. An apparatus for timing eviction of a linux cache, comprising:
a timer module for determining a recovery period;
the device comprises an acquisition module, a storage module and a processing module, wherein the acquisition module is used for acquiring the sizes of a cache and an idle physical memory in the linux system and acquiring memory use parameters according to the idle physical memory and the cache;
the cache recovery module is used for determining corresponding cache recovery behaviors according to the memory use parameters; and executing the determined cache recovery behavior at regular time according to the recovery period, and recovering the cache of the linux system.
CN202111242077.6A 2021-10-25 2021-10-25 Method and device for regularly recycling linux cache Active CN113986540B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111242077.6A CN113986540B (en) 2021-10-25 2021-10-25 Method and device for regularly recycling linux cache

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111242077.6A CN113986540B (en) 2021-10-25 2021-10-25 Method and device for regularly recycling linux cache

Publications (2)

Publication Number Publication Date
CN113986540A true CN113986540A (en) 2022-01-28
CN113986540B CN113986540B (en) 2024-05-10

Family

ID=79741083

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111242077.6A Active CN113986540B (en) 2021-10-25 2021-10-25 Method and device for regularly recycling linux cache

Country Status (1)

Country Link
CN (1) CN113986540B (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103593298A (en) * 2013-10-16 2014-02-19 北京航空航天大学 Memory recovery method and device
CN105446814A (en) * 2014-09-30 2016-03-30 青岛海信移动通信技术股份有限公司 Cache recovery method and device
CN105760225A (en) * 2016-01-27 2016-07-13 浪潮(北京)电子信息产业有限公司 Internal storage recovery method and system
CN106843756A (en) * 2017-01-13 2017-06-13 中国科学院信息工程研究所 Memory pages recovery method and system based on page classifications
US20190332544A1 (en) * 2018-04-28 2019-10-31 EMC IP Holding Company LLC Method, device and computer programme product for storage management
CN111078586A (en) * 2019-12-10 2020-04-28 Oppo(重庆)智能科技有限公司 Memory recovery method and device, storage medium and electronic equipment
CN111488316A (en) * 2020-04-12 2020-08-04 杭州迪普科技股份有限公司 File cache recovery method and device
CN112035253A (en) * 2020-08-27 2020-12-04 浪潮商用机器有限公司 Linux system page cache recovery method and related device

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103593298A (en) * 2013-10-16 2014-02-19 北京航空航天大学 Memory recovery method and device
CN105446814A (en) * 2014-09-30 2016-03-30 青岛海信移动通信技术股份有限公司 Cache recovery method and device
CN105760225A (en) * 2016-01-27 2016-07-13 浪潮(北京)电子信息产业有限公司 Internal storage recovery method and system
CN106843756A (en) * 2017-01-13 2017-06-13 中国科学院信息工程研究所 Memory pages recovery method and system based on page classifications
US20190332544A1 (en) * 2018-04-28 2019-10-31 EMC IP Holding Company LLC Method, device and computer programme product for storage management
CN111078586A (en) * 2019-12-10 2020-04-28 Oppo(重庆)智能科技有限公司 Memory recovery method and device, storage medium and electronic equipment
CN111488316A (en) * 2020-04-12 2020-08-04 杭州迪普科技股份有限公司 File cache recovery method and device
CN112035253A (en) * 2020-08-27 2020-12-04 浪潮商用机器有限公司 Linux system page cache recovery method and related device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
BLUE SUMMER: "《vm内核参数之缓存回收drop_caches_Blue summer的博客-CSDN博客》", pages 1 - 6, Retrieved from the Internet <URL:https://blog.csdn.net/u010039418/article/details/108170523> *

Also Published As

Publication number Publication date
CN113986540B (en) 2024-05-10

Similar Documents

Publication Publication Date Title
TWI704496B (en) Electronic equipment, computer systems and their control methods
US8621144B2 (en) Accelerated resume from hibernation in a cached disk system
JP4281421B2 (en) Information processing system, control method therefor, and computer program
US6857047B2 (en) Memory compression for computer systems
JP6527577B2 (en) File system flushing
WO2015169145A1 (en) Memory management method and device
US9021243B2 (en) Method for increasing free memory amount of main memory and computer therefore
EP4239473A1 (en) Container-based application management method and apparatus
EP2733617A1 (en) Data buffer device, data storage system and method
US20140189198A1 (en) Memory allocation for fast platform hibernation and resumption of computing systems
US5752268A (en) Minimum-delay recoverable disk control system using checkpoints and nonvolatile memory
US11422860B2 (en) Optimizing save operations for OS/hypervisor-based persistent memory
CN113778662B (en) Memory recovery method and device
CN105630700B (en) A kind of storage system and reading/writing method with secondary cache structure
JP2004178016A (en) Cpu, information processor having it, and control method for cpu
US20110087901A1 (en) Fast speed computer system power-on &amp; power-off method
US20080183922A1 (en) Method, Apparatus And Software For Processing Input Or Output Requests For A Mirrored Storage Volume
TW200538926A (en) Dynamic node partitioning utilizing sleep state
CN114546634A (en) Management of a synchronized restart of a system
TWI399637B (en) Fast switch machine method
CN114968839A (en) Hard disk garbage recycling method, device and equipment and computer readable storage medium
JP5166211B2 (en) Device using non-volatile memory as main memory
CN111427804A (en) Method for reducing missing page interruption times, storage medium and intelligent terminal
CN105740170B (en) Cache dirty page flashing method and device
WO2011131003A1 (en) System for realizing mobile phone buffer storage mechanism and method for loading mobile phone operating system

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
GR01 Patent grant
GR01 Patent grant