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

Method and device for regularly recycling linux cache Download PDF

Info

Publication number
CN113986540B
CN113986540B CN202111242077.6A CN202111242077A CN113986540B CN 113986540 B CN113986540 B CN 113986540B CN 202111242077 A CN202111242077 A CN 202111242077A CN 113986540 B CN113986540 B CN 113986540B
Authority
CN
China
Prior art keywords
cache
memory
behavior
linux
recovery
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.)
Active
Application number
CN202111242077.6A
Other languages
Chinese (zh)
Other versions
CN113986540A (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

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 recycling a linux cache; the method comprises the following steps: determining a recovery period; obtaining the sizes of a buffer memory and an idle physical memory in a linux system, and obtaining memory use parameters according to the idle physical memory and the buffer memory; 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 Linux system cache. The scheme of the application can recycle the cache in the system at regular time, can effectively prevent the condition of breakdown of the waterline caused by overlarge service pressure, can also prevent the condition of wasting the system memory caused by increasing the memory waterline, and can be used for replacing the stable operation of the system 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 important mechanisms in the linux system. From an operating system memory index perspective, caches mainly include page caches and kernel object caches (sleb caches). When page buffer memory, i.e. file read-write or memory mapping, the linux system will first write (read) data into the page buffer memory, so as to improve the read-write efficiency by reducing the system I/O times. The sleb cache is a cache pool for distributing small-block memory in the kernel, and can provide a quicker memory distribution path for a small-block data structure of the kernel.
However, in practical application, a situation that the cache occupies a large amount of physical memory often occurs, and at this time, if the service pressure suddenly increases, a large amount of memory allocation is required, which may cause breakdown of a memory waterline due to untimely memory recovery, and further cause problems of high system load or service delay jitter. How to better solve the recovery of the cache in the linux system is a problem to be solved in the field.
In the related art, the recovery of the current linux cache mainly depends on a page recovery mechanism, and mainly comprises two types: and (5) carrying out background recovery and direct recovery. The background recovery is to wake kswapd the kernel thread to perform asynchronous recovery when the system detects that the available memory is below the low waterline of the memory until the available memory of the system is increased to the high waterline, and the background recovery does not cause service delay. If the speed of asynchronously recovering the memory cannot meet the speed of the memory application at the moment, starting to directly recover the system; direct reclamation is synchronous blocking reclamation in the process of applying for memory by a 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 in the memory recovery process at this time, the problems of system load rising and service delay are caused.
Disclosure of Invention
To overcome at least some of the problems associated with the related art, the present application provides a method and apparatus for regularly reclaiming a linux cache.
According to a first aspect of an embodiment of the present application, there is provided a method for regularly recycling a linux cache, including:
Determining a recovery period;
Obtaining the sizes of a buffer memory and an idle physical memory in a linux system, and obtaining memory use parameters according to the idle physical memory and the buffer memory;
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 Linux system cache.
Further, the cache reclamation behavior is performed by a separate kernel thread;
the kernel thread is created when the linux system is initialized, 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 buffer includes:
And calculating the ratio of the idle physical memory to the cache to obtain the memory use parameter.
Further, the determining the corresponding cache reclamation behavior according to the memory usage parameter includes:
And when the memory use parameter is larger than a first preset proportion, executing a first cache recycling behavior.
Further, the first cache reclamation behavior includes:
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, releasing the index node cache.
Further, the determining the corresponding cache reclamation behavior according to the memory usage parameter further includes:
And when the memory usage parameter is smaller than the second preset proportion and larger than the third preset proportion, executing the second cache recycling behavior.
Further, the second cache reclamation act includes:
And calling a related kernel function in the linux kernel, and recovering the clean page of the page cache.
Further, the determining the corresponding cache reclamation behavior according to the memory usage parameter further includes:
And when the memory use parameter is smaller than a third preset proportion, executing a third cache recycling behavior.
Further, the third cache reclamation behavior includes:
And calling related kernel functions in the linux kernel, and recovering clean pages of the page cache and recoverable parts of the slab cache.
According to a second aspect of an embodiment of the present application, there is provided an apparatus for periodically reclaiming a linux cache, including:
A timer module for determining a recovery period;
the acquisition module is used for acquiring the sizes of the buffer memory and the idle physical memory in the linux system and acquiring memory use parameters according to the idle physical memory and the buffer memory;
the cache recycling module is used for determining corresponding cache recycling 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 recycle the cache in the system at regular time, can effectively prevent the condition of breakdown of the waterline caused by overlarge service pressure, can also prevent the condition of wasting the system memory caused by increasing the memory waterline, and can be used for replacing the stable operation of the system 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 as claimed.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
Fig. 1 is a flow chart illustrating a method of timing recovery of a linux cache according to an exemplary embodiment.
Fig. 2 is a block diagram illustrating an apparatus for timing recovery of a linux cache according to an exemplary embodiment.
Detailed Description
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary examples do not represent all implementations consistent with the application. Rather, they are merely examples of methods and apparatus consistent with aspects of the application as detailed in the accompanying claims.
In order to further detail the technical scheme of the 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 starts direct recovery, which can cause subsequent behavior of a process to be blocked, and the system may need long-time recovery; this again causes the subsequent behavior of the process to be blocked, which in turn causes problems with increased system load and traffic delays. Wherein kswapd is a linux kernel reclaim thread.
Although the configuration file in the system can trigger page reclamation earlier by increasing the memory water line, the method has a certain defect that after the memory water line is increased, the memory directly used by the upper application program is reduced, so that the waste of the system memory is caused.
It can be seen that the linux operating system has a certain defect in the recycle cache, which may cause a serious hysteresis problem of the upper layer traffic. The application aims at the problem and provides a method for periodically recycling a linux cache. The method provided by the application can be used in certain large service scenes, and the cache in the system is recovered at regular time, so that the situation that the service pressure is too high to break down the waterline can be effectively prevented, the situation that the memory waterline is increased to waste the system memory can be prevented, and the stable operation of the system is replaced with small cost.
Fig. 1 is a flow chart illustrating a method of timing recovery of a linux cache according to an exemplary embodiment. The method may comprise the steps of:
Step S1: determining a recovery period;
Step S2: obtaining the sizes of a buffer memory and an idle physical memory in a linux system, and obtaining memory use parameters according to the idle physical memory and the buffer memory;
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 Linux system cache.
The application provides a method for regularly recycling a linux cache, which can be applied to business scenes requiring a large number of read files or certain high-pressure scenes. The scheme of the application can recycle the cache in the system at regular time, can effectively prevent the condition of breakdown of the waterline caused by overlarge service pressure, can also prevent the condition of wasting the system memory caused by increasing the memory waterline, and can be used for replacing the stable operation of the system 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 strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in fig. 1 may include multiple sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor do the order in which the sub-steps or stages are performed necessarily performed in sequence, but may be performed alternately or alternately with at least a portion of other steps or sub-steps of other steps.
The scheme of the application is expanded and explained below by combining with specific application scenes.
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 a memory cannot be timely recycled under a large number of file read-write scenarios, resulting in serious blocking of an application program.
Step S1: a recovery period is determined.
Before determining the eviction period, it should be noted that the cache eviction function provided by the application is dynamically switchable. Because the cache reclamation mode of the application is different from the existing page reclamation thread of the kernel, the cache reclamation mode used in the application is a self-defined kernel thread. The kernel thread can be created when the linux system is initialized, can be created in a kernel module, and can be dynamically created through configuration files. Typically, the core thread will go to sleep directly when it is created.
The subsequent actions of the kernel thread are two, one is to wake up and recycle the cache when the timing time is up; the other is to exit the kernel thread when this cache reclamation function is to be shut down. The application adds configuration file/proc/sys/vm/cache_ reclaim _enable to control the switch of the function, the value is default to 0, which means that the cache recovery function is not started, the user can start the cache recovery function through echo1>/proc/sys/vm/cache_ reclaim _enable, when the function is started, the application preferably judges whether the kernel thread exists, if not, a kernel thread is created, and enters sleep, and waits for subsequent awakening. When the user executes echo0>/proc/sys/vm/cache_ reclaim _enable, the kernel thread is exited and resource recovery is performed. For the addition of the user mode configuration file, reference may be made to the existing document, and the present application will not be repeated.
The recovery period can be dynamically configured in a user mode, the new configuration file/proc/sys/vm/cache_ reclaim _time can be dynamically configured, the recovery period is 60 by default, namely the recovery period is 60 seconds by default, the kernel recovery thread is awakened once, the recovery of the cache is performed once, and the configuration can be performed by a user echox >/proc/sys/vm/cache_ reclaim _time (0 < x).
The implementation mode of the recovery period is realized through a timer mechanism of the linux kernel, and the kernel recovery thread is awakened to carry out recovery of the cache whenever the timing time is up. The implementation of the timer can refer to the prior art, and the application is not repeated.
Step 2: and obtaining the cache size and the idle physical memory size in the linux system.
The in-Linux system buffer memory is a page buffer memory of a file read by the system from a disk and a kernel data object buffer memory (a slot buffer memory), and the free physical memory is the sum of the memory which is not used currently and the unused exchange partition in the system. Wherein a slice is a linux kernel memory allocator.
It should be noted that the above-mentioned core data object cache is only a portion of the sleb cache, and the sleb cache may be divided into a recoverable portion and an unrecoverable portion, where the unrecoverable portion, that is, the portion of the memory cannot be recovered, so that the above-mentioned sleb cache refers to the recoverable portion in the sleb cache. It can be seen that the recoverable portions of the cache=page cache+slice Cache correspond to Cached and SReclaimable in the linux system lower/proc/meminfo file, i.e. cache= Cached + SReclaimable, respectively. Wherein Cached refers to the size of the cache in the linux system; SReclaimable is the recoverable portion of the sleb cache in the linux system.
The size of the free physical memory corresponds to the sum of MemFree and SwapFree values in the proc/meminfo file, i.e. free= MemFree + SwapFree, it is worth mentioning that the free physical memory described in this example contains the size (SwapFree) of the free swap partition, which is in fact not part of the physical memory, but rather virtualizes the hard disk space into memory use. Wherein MemFree is the size of the hollow memory in the linux system; swapFree is the size of the idle exchange in the linux system.
Step S3: and determining corresponding cache recovery 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 three proportion threshold values are divided: the first preset proportion, the second preset proportion and the third preset proportion. The above three preset proportions can be dynamically configured in a user mode, and configuration files cache_ reclaim _fir_ratio, cache_ reclaim _sec_ratio and cache_ reclaim _thi_ratio are newly added under the/proc/sys/vm/directory, and the default values are 80,50,30 respectively. That is, in the reclamation period, when the percentage of the size of the idle physical memory to the size of the cache is detected to be more than 80, executing a first cache reclamation behavior; when the percentage of the size of the idle physical memory to the size of the cache is detected to be more than 50 and less than 80, executing a second cache recycling behavior; and when the percentage of the free physical memory and the cache size is smaller than 30, executing a third cache recycling behavior.
Step S4: and executing different cache recovery behaviors according to the ratio of the idle physical memory to the cache size.
It is worth to be noted that, the recovery force of the first, second and third buffer recovery actions on the system buffer is in an increasing trend along with the decrease of the rest free physical memory in the linux system, and the influence on the performance of the operating system is also in an increasing trend, namely, the performance is replaced by the memory.
Step S401: and if the ratio of the idle physical memory to the cache is greater than a first preset ratio, executing a first cache recycling behavior. The first cache reclamation behavior reclaims the reclaimable portion SReclaimable of the above-described slab cache. The interface of the sleb function is already realized in the current linux kernel, so that the realization of the sleb cache recovery in the step can refer to kernel codes, and only certain modification is needed. The recovery of the slab cache realized by the kernel also comprises the indexing node cache of the disk file, when a process reads the file, the corresponding address space of the file is found through the indexing node, and then the corresponding physical page is found through the file offset. If the physical page exists indicating that the disk file has been cached in physical memory, then a read from disk is required if the physical page does not exist. The page cache and the inode cache are thus dependent. If the index node is released, the page buffer does not exist, which is equivalent to releasing the page buffer and the slab buffer at the same time, and the overall performance of the system can be influenced to a certain extent. The first cache reclamation action should not release those inodes that have a page cache present. Therefore, before the file system is scanned and the index node buffer is released, it should be firstly judged whether the index node has a corresponding page buffer, if so, the index node buffer should not be released. By the method, only the releasable sleb cache can be released, so that the influence on the performance of the system is reduced.
Step S402: and if the ratio of the idle physical memory to the cache is smaller than the second preset ratio and larger than the third preset ratio, executing the second cache recycling behavior.
The second cache recovery behavior recovers a clean page of the page cache, wherein the clean page is that the part of the memory of the page cache is synchronized with an external disk; the unsynchronized page caches are called dirty pages, which need to be written back to disk to be released, and the method provided by the application does not process the dirty pages. Instead, clean pages can be released directly. However, similarly, after the page buffer is released, if the page buffer needs to be read again from the disk to the memory next time, the physical memory occupied by the page buffer is relatively large, and thus, a slight delay of the service is also caused.
The function interface for recovering 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 recovering the page cache in the step. Reference is made in particular to the linux kernel related art and the present application will not be described.
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 reclamation behavior may reclaim both the clean pages of the page cache and the recyclable portion of the slab cache, since the system physical resource consumption is already substantial at this time, and therefore the recyclable portion may be fully reclaimed. At this point we will obviously feel the performance delay of the traffic.
Function interfaces for recycling clean pages in a page cache and recyclable parts of a slab cache are already realized in the current linux kernel, so that kernel functions can be directly called for recycling the page cache in the step. Reference is made in particular to the linux kernel related art and the present application will not be described. By this step of cache release, a large portion of the system cache can be reclaimed, although the performance of the system will drop significantly over 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; three different cache recovery behaviors are defined according to the memory state of the current system; the preset proportions for the three recycling behaviors can be dynamically configured to meet the needs of different scenes. The method can recycle the cache in the system at regular time, and three different recycling behaviors are provided according to the current system state, so that the requirement of the system physical memory can be met as much as possible under the condition that the service performance is not reduced as much as possible.
Fig. 2 is a schematic diagram of a linux cache reclaiming apparatus. As can be seen from the figure, the linux cache reclaiming apparatus 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 recycling period; a timer is created in the linux kernel that acts as a period for the system to reclaim the cache.
The parameter configuration module is used for realizing user-defined configuration, and comprises the following steps:
The proc/sys/vm/cache_ reclaim _enable is used for controlling the starting and closing of the cache recovery method;
The proc/sys/vm/cache_ reclaim _time is used for adjusting the timing time of the timer;
The cache_ reclaim _fir_ratio, the cache_ reclaim _sec_ratio and the cache_ reclaim _thi_ratio are used for adjusting the first preset proportion, the second preset proportion and the third preset proportion.
The acquisition module is used for acquiring the sizes of the buffer memory and the idle physical memory in the linux system and acquiring the memory use parameters according to the idle physical memory and the buffer memory.
The cache recycling module is used for determining corresponding cache recycling 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 specific steps in which the respective modules perform the operations in the apparatus of the above embodiments have been described in detail in the embodiments related to the method, and will not be explained in detail here. The modules in the cache reclaiming device can be realized in whole or in part by software, hardware and a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
It is to be understood that the same or similar parts in the above embodiments may be referred to each other, and that in some embodiments, the same or similar parts in other embodiments may be referred to.
It should be noted that in the description of the present application, the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. Furthermore, in the description of the present application, unless otherwise indicated, the meaning of "plurality" means at least two.
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 further implementations are included within the scope of the preferred embodiment of the present application 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 is to be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above-described embodiments, the various steps or methods may be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, may be implemented using any one or combination of the following techniques, as is well known in the art: discrete logic circuits having logic gates for implementing logic functions on data signals, application specific integrated circuits having suitable combinational logic gates, programmable Gate Arrays (PGAs), field Programmable Gate Arrays (FPGAs), and the like.
Those of ordinary skill in the art will appreciate that all or a portion of the steps carried out in the method of the above-described embodiments may be implemented by a program to instruct related hardware, where the program may be stored in a computer readable storage medium, and where the program, when executed, includes one or a combination of the steps of the method embodiments.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing module, or each unit may exist alone physically, or two or more units may be integrated in one module. The integrated modules may be implemented in hardware or in software functional modules. The integrated modules may also be stored in a computer readable storage medium if implemented in the form of software functional modules and sold or used as a stand-alone product.
The above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, or the like.
In the description of the present specification, a description referring to terms "one embodiment," "some embodiments," "examples," "specific examples," 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 present application. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiments or examples. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
While embodiments of the present application have been shown and described above, it will be understood that the above embodiments are illustrative and not to be construed as limiting the application, and that variations, modifications, alternatives and variations may be made to the above embodiments by one of ordinary skill in the art within the scope of the application.

Claims (4)

1. A method of timing recovery of a linux cache, comprising:
Determining a recovery period;
Obtaining the sizes of a buffer memory and an idle physical memory in a linux system, and obtaining memory use parameters according to the idle physical memory and the buffer memory;
determining corresponding cache recovery behaviors according to the memory use parameters;
The determined cache recovery behavior is executed at regular time according to the recovery period, and the cache of the linux system is recovered;
The determining the corresponding cache recycling behavior according to the memory usage parameter includes:
Executing a first cache reclamation behavior when the memory usage parameter is greater than a first preset proportion; the first cache reclamation behavior includes: 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, releasing the index node cache;
executing a second cache reclamation behavior when the memory usage parameter is smaller than the second preset proportion and larger than the third preset proportion; the second cache reclamation act includes: calling related kernel functions in a linux kernel, and recovering a clean page of a page cache;
When the memory usage parameter is smaller than a third preset proportion, executing a third cache recycling behavior; the third cache reclamation behavior includes: and calling related kernel functions in the linux kernel, and recovering clean pages of the page cache and recoverable parts of the slab cache.
2. The method of claim 1, wherein the cache reclamation behavior is performed by a separate kernel thread;
the kernel thread is created when the linux system is initialized, or is created in a kernel module, or is dynamically created through a configuration file.
3. The method of claim 1, wherein obtaining the memory usage parameter 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 parameter.
4. An apparatus for timing recovery of a linux cache, comprising:
A timer module for determining a recovery period;
the acquisition module is used for acquiring the sizes of the buffer memory and the idle physical memory in the linux system and acquiring memory use parameters according to the idle physical memory and the buffer memory;
The cache recycling module is used for determining corresponding cache recycling behaviors according to the memory use parameters; and according to the recovery period, the determined cache recovery behavior is executed regularly, and the cache of the linux system is recovered;
The determining the corresponding cache recycling behavior according to the memory usage parameter includes:
Executing a first cache reclamation behavior when the memory usage parameter is greater than a first preset proportion; the first cache reclamation behavior includes: 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, releasing the index node cache;
executing a second cache reclamation behavior when the memory usage parameter is smaller than the second preset proportion and larger than the third preset proportion; the second cache reclamation act includes: calling related kernel functions in a linux kernel, and recovering a clean page of a page cache;
When the memory usage parameter is smaller than a third preset proportion, executing a third cache recycling behavior; the third cache reclamation behavior includes: and calling related kernel functions in the linux kernel, and recovering clean pages of the page cache and recoverable parts of the slab cache.
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 CN113986540A (en) 2022-01-28
CN113986540B true 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)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115061944B (en) * 2022-06-24 2024-10-15 苏州浪潮智能科技有限公司 Memory optimization system, method and device based on memory sampling and storage medium

Citations (7)

* 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
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

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110413214B (en) * 2018-04-28 2023-07-18 伊姆西Ip控股有限责任公司 Method, apparatus and computer program product for storage management

Patent Citations (7)

* 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
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

Also Published As

Publication number Publication date
CN113986540A (en) 2022-01-28

Similar Documents

Publication Publication Date Title
JP4281421B2 (en) Information processing system, control method therefor, and computer program
CN108459898B (en) Resource recovery method and device
EP2495655B1 (en) Method for switching operating system and electronic apparatus using the same
US9021243B2 (en) Method for increasing free memory amount of main memory and computer therefore
US7831750B2 (en) Method, apparatus and software for processing input or output requests for a mirrored storage volume
JP6527577B2 (en) File system flushing
CN105630700B (en) A kind of storage system and reading/writing method with secondary cache structure
CN1658185A (en) Computer system with mutual independence symbiont multiple eperation system and its switching method
US11422860B2 (en) Optimizing save operations for OS/hypervisor-based persistent memory
CN102207881A (en) Quick operation system start-up method based on Android
CN113296880A (en) Container-based application management method and device
EP0751462A1 (en) A recoverable disk control system with a non-volatile memory
KR101826769B1 (en) Technologies for operating system transitions in multiple-operating-system environments
CN108694231A (en) Using NVM and by multiple log recording buffers come ahead log recording
CN113778662B (en) Memory recovery method and device
CN113986540B (en) Method and device for regularly recycling linux cache
CN109491592B (en) Storage device, data writing method thereof and storage device
TWI399637B (en) Fast switch machine method
CN114968839A (en) Hard disk garbage recycling method, device and equipment and computer readable storage medium
CN115328407A (en) Cache disk replacing method, device, equipment and storage medium
JP5166211B2 (en) Device using non-volatile memory as main memory
CN103383648A (en) Method and system for compressible virtual machine magnetic disk size recycling
CN102521173B (en) Method for automatically writing back data cached in volatile medium
CN114756355B (en) Method and device for automatically and quickly recovering process of computer operating system
US20140289486A1 (en) Information processing apparatus, information processing method, and recording medium

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