Kernel cache release method and device
By acquiring and releasing the index nodes of specified cache objects, the cache is released in a targeted manner, which solves the impact of cache recycling on the performance of important processes in the existing technology, and improves system stability and performance.
Patent Information
- Application Number
- CN202410644358.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-21
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-05-21
AI Technical Summary
In the existing technology, when managing memory in the operating system, the cache recycling mechanism is released indiscriminately, which may affect the performance of important processes. In particular, when the cache is manually released in a production environment, it lacks pertinence, leading to performance problems.
By obtaining the identifier of the cache object to be released, determining its index node, and releasing the cache of the specified file or process based on the index node, it ensures that the performance of important processes is not affected and targeted cache release is achieved.
It achieves refined management of designated caches, avoids impact on the performance of important processes, and improves system stability and performance.
Smart Images

Figure CN118585322A
Abstract
Description
Technical Field
[0001] The present application relates to the field of server technology, and in particular to a kernel cache release method and device. Background Art
[0002] In the operating system, memory management is one of the key subsystems used to effectively manage and allocate the system's memory resources. Memory management involves many technologies, one of which is the management and maintenance of the operating system kernel cache.
[0003] The existing mechanism of the operating system kernel will automatically trigger cache recycling when the memory is about to be exhausted. In some special scenarios, the user can also manually perform cache recycling.
[0004] For example, the Linux kernel currently provides three cache clearing methods, including:
[0005] 1. echo 1> / proc / sys / vm / drop_caches# Clear page cache;
[0006] 2. echo 2> / proc / sys / vm / drop_caches#Clear directory entries and inodes;
[0007] 3.echo 3> / proc / sys / vm / drop_caches#Clear page cache, directory entries and inodes.
[0008] These three methods will traverse all super blocks of the operating system and all index nodes under the super blocks, and release the page cache corresponding to the index node indiscriminately when it is confirmed that it can be released. However, in production environments, in scenarios where manual cache release is required, indiscriminate cache release will affect the performance of important processes and may affect the performance of important processes. Summary of the invention
[0009] In view of this, an embodiment of the present application provides a kernel cache release method and device to achieve targeted release of the cache.
[0010] To solve the above problems, the technical solutions provided in the embodiments of the present application are as follows:
[0011] In a first aspect, an embodiment of the present application provides a kernel cache release method, the method comprising:
[0012] Obtaining an identifier of a cache object to be released; wherein the cache object to be released is not a cache object prohibited from being released; and the object to be released is a process or a file;
[0013] Determine the index node of the cache object to be released according to the identifier of the cache object to be released;
[0014] Determine the cache occupied by the file corresponding to the index node of the cache object to be released;
[0015] Release the cache occupied by the file corresponding to the index node of the cache object to be released.
[0016] In this way, the cache of the designated cache object to be released can be released in a targeted manner, ensuring that the release of the cache does not affect the performance of important processes.
[0017] In a possible implementation, the cache object to be released is a cache file to be released;
[0018] Determining the index node of the cache object to be released according to the identifier of the cache object to be released includes:
[0019] Extract the file identifier of the cache file to be released from the absolute address of the cache file to be released;
[0020] Determine the inode of the file identifier of the cache file to be released.
[0021] You can release the cache in a targeted manner based on the file granularity, customize the files to be released, and implement refined maintenance of the operating system cache to ensure the stability of the operating system operation.
[0022] In a possible implementation, the cache object to be released is a process to be released;
[0023] Determining the index node of the cache object to be released according to the identifier of the cache object to be released includes:
[0024] Determine the task structure corresponding to the process to be released according to the identifier of the process to be released;
[0025] Get the index node of the file used by the process to be released from the task structure corresponding to the process to be released.
[0026] The cache can be released in a targeted manner based on the process granularity, and the process to be released can be customized to implement refined maintenance of the operating system cache to ensure the stability of the operating system operation.
[0027] In a possible implementation, before releasing the cache occupied by the file corresponding to the index node of the cache object to be released, the method further includes:
[0028] Determine whether the target cache page is used; the target cache page is any cache page in the cache occupied by the file corresponding to the index node of the cache object to be released;
[0029] When the target cache page is not in use, the target cache page is released.
[0030] In this way, the file currently being used in the cache is not released to avoid affecting the process currently using the file.
[0031] In a possible implementation, before obtaining the identifier of the cache object to be released, the method further includes:
[0032] In response to a view request, determining an index node of a cache object; the view request is used to determine a cache occupied by the cache object;
[0033] Determine the cache occupied by the file corresponding to the index node of the cache object;
[0034] Based on the cache occupied by the file corresponding to the index node of the cache object, the cache object to be released is determined.
[0035] The cache objects to be released can be determined by checking the cache occupied by the files corresponding to the cache objects.
[0036] In a possible implementation, determining the cache object to be released based on the cache occupied by the file corresponding to the index node of the cache object includes:
[0037] Determine whether the cache occupied by the file corresponding to the index node of the cache object exceeds a preset threshold;
[0038] When the cache occupied by the file corresponding to the index node of the cache object exceeds a preset threshold, determining whether the cache object is a cache object that is prohibited from being released;
[0039] When the cache object does not belong to the cache objects prohibited from being released, the cache object is determined as a cache object to be released.
[0040] The determined cache objects to be released are cache objects that occupy more than a preset threshold and are not prohibited from being released, so that the cache objects that occupy too much cache are released without affecting important processes or files.
[0041] In a possible implementation, the cache object is a cache file;
[0042] In response to the view request, determining the index node of the cache object includes:
[0043] In response to the view request, the index node of the cache file is obtained from the super block structure.
[0044] Whether to release the cache file can be determined based on the cache file granularity, which makes it more convenient to accurately maintain the use of the cache.
[0045] In one possible implementation, the cache object is a process;
[0046] In response to the view request, determining the index node of the cache object includes:
[0047] In response to the viewing request, the index node of the file used by the process is obtained from the task structure corresponding to the process.
[0048] Whether to release files used by a cache process can be determined based on the granularity of the cache process, making it easier to accurately maintain the use of the cache.
[0049] In a possible implementation, determining the cache occupied by the file corresponding to the index node of the cache object includes:
[0050] Get the cache occupied by the file corresponding to the target index node;
[0051] The cache sizes occupied by the files corresponding to the target index nodes are accumulated to obtain the cache occupied by the files corresponding to the target index nodes; the target index node is any one of the index nodes of the cache object.
[0052] This makes it possible to more accurately determine the cache occupied by the file corresponding to each cache object.
[0053] In a second aspect, an embodiment of the present application provides a kernel cache release device, the device comprising:
[0054] An acquisition unit is used to acquire an identifier of a cache object to be released; wherein the cache object to be released is not a cache object prohibited from being released; and the object to be released is a process or a file;
[0055] A first determining unit, configured to determine an index node of the cache object to be released according to an identifier of the cache object to be released;
[0056] A second determining unit is used to determine the cache occupied by the file corresponding to the index node of the cache object to be released;
[0057] The release unit is used to release the cache occupied by the file corresponding to the index node of the cache object to be released.
[0058] In a third aspect, an embodiment of the present application provides a computing device, including: a memory and a processor;
[0059] The memory is used to store program instructions;
[0060] The processor is used to run program instructions so that the computing device implements the kernel cache release method involved in the above-mentioned first aspect and its possible implementation methods.
[0061] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a computing device, the computing device executes the kernel cache release method involved in the above-mentioned first aspect and its possible implementation methods.
[0062] In a fifth aspect, an embodiment of the present application provides a computer program product, including computer program instructions. When the computer program instructions are executed on a computing device, the computing device executes the kernel cache release method involved in the first aspect and its possible implementation methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 A schematic diagram of an exemplary application scenario provided for an embodiment of the present application;
[0064] Figure 2 A schematic diagram of a computing device provided in an embodiment of the present application;
[0065] Figure 3 A flowchart of a kernel cache release method provided in an embodiment of the present application;
[0066] Figure 4 A flowchart of a kernel cache release method provided in an embodiment of the present application;
[0067] Figure 5 A flowchart of another kernel cache release method provided in an embodiment of the present application;
[0068] Figure 6 A flowchart of a method for determining a cache object to be released provided in an embodiment of the present application;
[0069] Figure 7 A flowchart of another method for determining a cache object to be released provided in an embodiment of the present application;
[0070] Figure 8 A flowchart of another method for determining a cache object to be released provided in an embodiment of the present application;
[0071] Fig. 9 A schematic diagram of an exemplary kernel cache release method in an embodiment of the present application;
[0072] Fig.10 A schematic diagram of a kernel cache release device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0073] In order to make the above-mentioned purposes, features and advantages of the embodiments of the present application more obvious and easy to understand, the embodiments of the present application are further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0074] In order to facilitate the understanding and explanation of the technical solutions provided by the embodiments of the present application, the professional terms involved in the embodiments of the present application will be explained below.
[0075] Cache: used to store recently used data so that they can be accessed faster. Linux uses cache to store frequently accessed pages and files, mainly to solve the problem of performance mismatch between the two ends of the system. When an application needs to access data, if the data is already in the cache, it can read the data directly from the cache instead of from the disk, which can greatly improve access speed and performance.
[0076] Buffer: A special type of storage area. In Linux, the buffer is used to store data read from the disk or data to be written to the disk. When data is read from or written to the disk, the buffer can speed up the reading and writing speed.
[0077] Super block: It is the core data structure of the file system. It represents the entire file system and stores the metadata of the file system. The super block stores the file block size, operation functions, and information of all inodes set by the file system. Each file system has a super block, which contains global file information, such as hard disk used space, data block available space, inode node information, etc. A super block is connected to other super blocks through a linked list to form a bidirectional circular linked list. Each super block represents a file system on the Linux operating system. The Linux operating system can have multiple file systems.
[0078] Index node (inode for short): is a special data structure in the file system that is used to store metadata information about file system objects. Each file or directory in the file system has an associated inode. The inode contains the file's metadata, such as file size, file owner, file permissions, timestamps, etc. This information helps the operating system manage and access files.
[0079] LRU (least recently used): is a commonly used page replacement algorithm used to decide which pages should be discarded when memory is insufficient. In the Linux kernel, the LRU algorithm is used to manage pages in physical memory and swap space. In the Linux kernel, the LRU algorithm is mainly implemented through a pair of bidirectional linked lists: the active linked list and the inactive linked list. Each linked list contains all pages belonging to the process user address space or page cache. Among them, the active linked list stores the most recently accessed pages, while the inactive linked list stores pages that have not been accessed for a period of time. This partition management method improves efficiency and reduces the number of page transfers. When performing cache recycling, the Linux kernel will start recycling from the end of the inactive linked list.
[0080] The following is a description of the background technology involved in the embodiments of the present application.
[0081] In an operating system, such as the Linux operating system, memory management is one of the key subsystems used to effectively manage and allocate the system's memory resources. Memory management involves many technologies, one of which is the management and maintenance of cache and buffer. Cache and buffer are technologies used by the operating system to increase data access speed.
[0082] In the Linux operating system, cache and buffer are integrated when implemented in the system, especially in the IO (input / output) system, and have the functions of both buffer and cache. For example, the kernel buffer has the functions of both cache and buffer, which improves the file access rate and avoids frequent writing of data to the disk, thus protecting the disk and increasing the file writing speed.
[0083] In the subsequent embodiments of the present application, cache and buffer are not specifically distinguished and are collectively referred to as kernel cache or cache. Since cache usually stores data in units of pages, it can also be called page cache.
[0084] In order to solve the problem that the manual release of cache by the operating system is non-targeted and will affect the performance of important processes, the embodiments of the present application provide a kernel cache release method and device, which can release the cache of a specified process or a specified file in a targeted manner.
[0085] In order to facilitate understanding of the kernel cache release method provided in the embodiment of the present application, Figure 1See the example scenario shown in the figure. Figure 1 As shown, this figure is a schematic diagram of an exemplary application scenario provided in an embodiment of the present application.
[0086] The embodiments of the present application can be applied to an operating system kernel, and the Linux operating system kernel is used as an example for explanation below.
[0087] It should be noted that, in addition to the Linux operating system, the above operating system may also be other types of operating systems, for example, the above operating system may also be a Fusion operating system (operating system, OS), etc. The embodiment of the present application does not specifically limit the type of operating system, and all operating systems applicable to the method proposed in the embodiment of the present application are within the protection scope of the present application.
[0088] The embodiment of the present application provides a kernel cache release method. When the system memory is tight, generally due to excessive cache occupancy, the cache usage can be quickly located and the cache can be released in a targeted manner. In the embodiment of the present application, the specific usage of the cache in the current operating system can be obtained, that is, the file cache information and the process cache information can be obtained, and the processes and files that occupy a lot of cache in the operating system can be clearly understood. In order not to affect the performance of important processes of the current operating system, when releasing the cache, ordinary processes can be specified to release the cache, thereby ensuring that the performance of important processes will not be affected by the release of the cache, thereby improving the stability of system performance. If it is found that a special file occupies too much cache, it can also be specified to release the cache occupied by the file to maximize the guarantee that the operating system performance is not affected.
[0089] It should be noted that the above-mentioned important processes and ordinary processes can be determined by the user according to actual operation requirements, and the division of the important processes and ordinary processes can be changed.
[0090] Those skilled in the art will understand that Figure 1 The framework diagram shown is only an example in which the embodiments of the present application can be implemented. The scope of application of the embodiments of the present application is not limited by any aspect of the framework.
[0091] The kernel cache release method provided in the embodiment of the present application can be applied to an operating system kernel, and the operating system kernel can be run on a computing device. The computing device can be, for example, a server. Figure 2 As shown in FIG. 1 , the figure is a schematic diagram of a computing device provided in an embodiment of the present application. The computing device 1000 includes: a bus 1002 , a processor 1004 , a memory 1006 and a communication interface 1008 .
[0092] The processor 1004, the memory 1006 and the communication interface 1008 communicate with each other via the bus 1002. The computing device 1000 may be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the computing device 1000.
[0093] The bus 1002 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. Figure 8 The bus 1002 may include a path for transmitting information between various components of the computing device 1000 (eg, the memory 1006, the processor 1004, and the communication interface 1008).
[0094] The processor 1004 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0095] The memory 1006 may include a volatile memory, such as a random access memory (RAM). The memory 1006 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).
[0096] The memory 1006 stores executable program codes, and the processor 1004 executes the executable program codes to implement the kernel cache release method provided in the embodiment of the present application. Specifically, the memory 1006 stores instructions for executing the kernel cache release method.
[0097] The communication interface 1008 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 1000 and other devices or a communication network.
[0098] To facilitate understanding of the embodiments of the present application, a kernel cache release method provided by the embodiments of the present application is described below in conjunction with the accompanying drawings.
[0099] See also Figure 3 As shown in FIG. 1 , this figure is a flow chart of a kernel cache release method provided by an embodiment of the present application, such as Figure 3 As shown, the method may include S301-S304:
[0100] S301: Obtain the identifier of the cache object to be released.
[0101] In a possible implementation, a computing device obtains an identifier of a cache object to be released; the cache object to be released is a cache object that occupies a cache exceeding a preset threshold, and the cache object is not an object that is prohibited from being released. The cache object to be released is a process or a file. The cache object to be released has an identifier, and each identifier uniquely corresponds to a cache object to be released.
[0102] In a possible implementation, the computing device may first obtain the occupancy status of the cache, and then identify the files or processes that occupy the cache exceeding a preset threshold as cache objects to be released.
[0103] S302: Determine the index node of the cache object to be released according to the identifier of the cache object to be released.
[0104] Releasing the cache object to be released actually means releasing the cache occupied by the cache object to be released. When the cache object to be released is a cache file to be released, the cache occupied by the cache file to be released is released. When the cache object to be released is a process to be released, the cache occupied by the file used by the process to be released is released.
[0105] In actual applications, an index node is a special data structure that stores the metadata of a file, and the index node has a corresponding relationship with the file. One of the contents in the index node is whether the file is stored in the cache. If it is stored in the cache, it also includes information such as the location and size in the cache. In order to find the files of the cache object to be released, it is necessary to first determine the index nodes corresponding to these files. When the cache object to be released is a cache file to be released, the index node of the cache object to be released can be one; when the cache object to be released is a process to be released, the index node of the cache object to be released can be one or more. By obtaining the identifier of the cache object to be released, the index node of the cache object to be released can be determined. As for the specific implementation method of S302 determining the index node of the cache object to be released by the identifier of the cache object to be released, please refer to the description in the subsequent embodiments.
[0106] S303: Determine the cache occupied by the file corresponding to the index node of the cache object to be released.
[0107] After obtaining the index node of the cache object to be released, the files corresponding to the index node of the cache object to be released can be found, and these files can be determined as the cache object file to be released or the files used by the process. The cache occupied by these files can be determined through the index node of the cache object to be released, such as which cache pages are occupied, the addresses of the occupied cache pages, etc.
[0108] S304: Release the cache occupied by the file corresponding to the index node of the cache object to be released.
[0109] From the above description, it can be known that the cache occupied by the files corresponding to the index node of the cache object to be released is the cache occupied by the files of the cache object to be released. These files need to be released to achieve targeted release of the cache occupied by the cache object to be released.
[0110] In a possible implementation, before S304 releases the cache occupied by the file corresponding to the index node of the cache object to be released, the following may also be included:
[0111] Determine whether the target cache page is used; the target cache page is any cache page in the cache occupied by the file corresponding to the index node of the cache object to be released.
[0112] When the target cache page is not in use, the target cache page is released.
[0113] Files are generally stored in the cache in units of pages. The file corresponding to the index node of the cache object to be released can occupy one or more cache pages in the cache. If the file corresponding to the index node of the cache object to be released is currently in use in the cache, the release may affect the process currently using the file. Therefore, all cache pages corresponding to the file are traversed, and the cache page is released when it is not in use.
[0114] In an embodiment of the present application, a computing device obtains an identifier of a cache object to be released, and determines an index node through the identifier. The index node corresponds to a file and may include whether the file is stored in the cache and the location of the file. The file corresponding to the index node in the cache can be found through the index node of the cache object to be released, and these files are files that need to be released in the cache. In this way, the cache of the specified cache object to be released can be released in a targeted manner, ensuring that the release of the cache will not affect the performance of important processes.
[0115] The following takes the cache object to be released as a cache file to be released as an example to further explain the kernel cache release method provided by the embodiment of the present application, see Figure 4 As shown, the figure is a flowchart of a kernel cache release method provided by an embodiment of the present application, which may include:
[0116] S401: Obtain the absolute address of the cache file to be released.
[0117] When the computing device needs to release the cache file to be released that occupies the cache, the computing device can obtain the absolute address of the cache file to be released, which can be understood as the address of the cache file to be released stored in the hard disk. At this time, the identifier of the cache object to be released is included in the absolute address of the cache file to be released.
[0118] S402: Determine the index node of the cache file to be released based on the absolute address of the cache file to be released.
[0119] In one achievable manner, the computing device extracts the file identifier of the cache file to be released from the absolute address of the cache file to be released; and determines the index node of the file identifier of the cache file to be released, which is the index node of the cache file to be released.
[0120] It should be noted that S402 is a possible implementation method of S302 to determine the index node corresponding to the cache object to be released according to the identifier of the cache object to be released. The absolute address of the cache file to be released contains the file identifier of the cache file to be released, such as the file name of the cache file to be released. The file identifier of the cache file to be released can be used to find the index node corresponding to the cache file to be released in the kernel.
[0121] S403: Determine the cache occupied by the file corresponding to the index node of the cache file to be released.
[0122] The occupancy status of the cache file to be released in the cache can be found through the index node, such as which cache pages are occupied, the addresses of the occupied cache pages, etc.
[0123] S404: Release the cache occupied by the file corresponding to the index node of the cache file to be released.
[0124] The implementation process of S303 - S304 is similar to that of S403 - S404 , and the related descriptions can be found in the above embodiment, which will not be repeated here.
[0125] In the embodiment of the present application, the cache can be released in a targeted manner based on the granularity of files, the files to be released can be customized, and the operating system cache can be finely maintained to ensure the stability of the operating system operation.
[0126] The following takes the cache object to be released as the process to be released as an example to continue to explain the kernel cache release method provided by the embodiment of the present application, see Figure 5 As shown, the figure is a flowchart of another kernel cache release method provided by an embodiment of the present application, which may include:
[0127] S501: Obtain the identifier of the process to be released.
[0128] The identifier of the process to be released is obtained on the computing device, wherein the identifier of the process to be released may be a process number or a process name. At this time, the identifier of the cache object to be released is the identifier of the process to be released.
[0129] S502: Determine the index node of the process to be released based on the identifier of the process to be released.
[0130] In one achievable manner, the computing device determines a task structure corresponding to the process to be released according to an identifier of the process to be released; and obtains an index node of a file used by the process to be released from the task structure corresponding to the process to be released.
[0131] S502 is a possible implementation method of S302 to determine the index node of the cache object to be released according to the identifier of the cache object to be released. Among them, the task structure task_struct corresponding to the process to be released can be obtained through the identifier of the process to be released, and the task structure contains the file structure of the file used by the process to be released, from which the index node of the file used by the process to be released can be obtained, that is, the index node corresponding to the process to be released. It can be understood that the file used by the process to be released can be one or more, and each file used by the process to be released corresponds to an index node.
[0132] S503: Determine the cache occupied by the file corresponding to the index node of the process to be released.
[0133] Through the index nodes of each process to be released, the occupancy status of the files used by the process to be released in the cache can be found, such as which cache pages are occupied, the addresses of the occupied cache pages, etc.
[0134] S504: Release the buffer occupied by the file corresponding to the index node of the process to be released.
[0135] The implementation process of S303 - S304 is similar to that of S503 - S504 . For related descriptions, please refer to the above embodiment and will not be repeated here.
[0136] In the embodiment of the present application, the cache can be released in a targeted manner based on the process granularity, the released process can be customized, and the operating system cache can be finely maintained to ensure the stability of the operating system operation.
[0137] In the embodiment of the present application, before obtaining the identifier of the cache object to be released, the cache object to be released may also be determined. Figure 6 As shown, the figure of the present application is a flow chart of a method for determining a cache object to be released provided by an embodiment of the present application, which may include:
[0138] S601: In response to a query request, determine an index node of a cache object.
[0139] When the computing device obtains the cache occupied by the cache object, a viewing request may be generated; the viewing request is used to determine the cache occupied by the cache object. In response to the viewing request for the cache object, the index node of the cache object may be determined first. The cache object may be a cache file or a process. When the cache object is a cache file, the index node of the cache object is the index node of the cache file; when the cache object is a process, the index node of the cache object is the index node of the file used by the process. The specific implementation method of S601 determining the index node of the cache object in response to the viewing request may refer to the description in the subsequent embodiments.
[0140] S602: Determine the cache occupied by the file corresponding to the index node of the cache object.
[0141] Through the index node corresponding to the cache object, you can find the occupancy of the corresponding file in the cache, such as which cache pages are occupied, the addresses of the occupied cache pages, etc.
[0142] In a possible implementation, S602 determines the cache occupied by the file corresponding to the index node of the cache object, which may include:
[0143] A1: Get the cache occupied by the file corresponding to the target index node.
[0144] A2: Accumulate the cache sizes occupied by the files corresponding to the target index nodes to obtain the cache occupied by the files corresponding to the target index nodes; the target index node is any one of the index nodes of the cache object.
[0145] The files corresponding to the same index node of the cache object may be stored in different locations in the cache. By accumulating the cache sizes occupied by the files corresponding to the same index node, the cache occupied by the files corresponding to the index node can be obtained, such as the size information of the cache occupied.
[0146] S603: Determine a cache object to be released based on the cache occupied by the file corresponding to the index node of the cache object.
[0147] After determining that the files corresponding to the index nodes of the cache objects occupy the cache, the cache occupancy status of each cache object can be obtained, and the cache objects to be released can be determined from each cache object.
[0148] In a possible implementation, S603 determines the object to be released based on the file occupying the cache corresponding to the index node of the cache object. Specifically, the implementation may include:
[0149] B1: Determine whether the cache occupied by the file corresponding to the index node of the cache object exceeds a preset threshold.
[0150] B2: When the cache occupied by the file corresponding to the index node corresponding to the cache object exceeds the preset threshold, determine whether the cache object is a cache object that is prohibited from being released.
[0151] B3: When the cache object does not belong to the cache objects prohibited from being released, the cache object is determined as a cache object to be released.
[0152] When the cache occupied by the file corresponding to the index node of a cache object exceeds the preset threshold, it means that the cache object occupies too much cache. If the cache object is not a cache object that is prohibited from being released, the cache object is determined as an object to be released to release the occupied cache. If the cache object is a cache object that is prohibited from being released, the cache occupied by the cache object will not be released, which can ensure that important files or processes are not affected. Among them, the preset threshold can be set according to actual conditions, and the embodiment of the present application does not limit the value of the preset threshold.
[0153] In one achievable method, cache objects that are prohibited from being released can be added to a whitelist. It is understandable that the cache objects in the whitelist are important processes or files. When the cache objects need to be released, the cache occupied by the cache objects in the whitelist should be retained. When determining whether a cache object is a cache object that is prohibited from being released, the whitelist can be searched. If the cache object is in the whitelist, the cache object is a cache object that is prohibited from being released. If the cache object is not in the whitelist, the cache object can be determined as a cache object to be released. In this way, the cache occupied by important processes or files can be retained through the whitelist mechanism.
[0154] In the embodiment of the present application, whether to release the cache object can be determined based on the granularity of the cache object, which makes it more convenient to accurately maintain the use of the cache.
[0155] The following takes the cache object as a cache file as an example to continue to explain the kernel cache release method provided by the embodiment of the present application, see Figure 7 As shown, the figure is a flowchart of another method for internally determining a cache object to be released provided by an embodiment of the present application, which may include:
[0156] S701: In response to a view request, read the index node of the cache file from the super block structure.
[0157] S701 is a possible implementation method of S601 determining the index node of the cache object in response to a viewing request. When you want to view the relevant information of a file in the cache, you can generate a viewing request, which is used to determine the cache occupied by the cache file. Traverse each superblock structure superblock in the kernel, and traverse each index node in each superblock structure superblock. The index node corresponds to the file, and may include whether the corresponding file is stored in the cache and the storage location. Then, through the content in each index node, if it is determined that the file corresponding to the index node exists in the cache, then the index node is the index node of the cache file. For example, index node 1 corresponds to file 1, index node 2 corresponds to file 2, and file 2 exists in the cache. By traversing each index node, it can be known that file 2 corresponding to index node 2 is in the cache, and the index node 2 of file 2 is obtained.
[0158] S702: Determine the cache occupied by the file corresponding to the index node of the cache file.
[0159] The file corresponding to the index node of each cache file is the cache file itself. The occupancy of the cache file in the cache can be found through the index node of the cache file, such as which cache pages are occupied and the addresses of the occupied cache pages.
[0160] S703: Determine a cache object to be released based on the cache occupied by the file corresponding to the index node of the cache file.
[0161] After determining that the files corresponding to the index nodes of the cache files occupy the cache, the cache occupancy status of each cache file can be obtained, and the cache files to be released can be determined from each cache file.
[0162] S703 is a possible implementation method of S603. The implementation process of S703 is similar to that of S603. For related descriptions, please refer to the above embodiment and will not be repeated here.
[0163] In the embodiment of the present application, the cache files may be used as the granularity, and files that occupy a large amount of cache may be determined as cache files to be released, so that the cache may be released more accurately.
[0164] The following takes the cache object as a process as an example to continue to explain the kernel cache release method provided by the embodiment of the present application, see Figure 8 As shown, this figure is a flowchart of another method for determining a cache object to be released provided by an embodiment of the present application, which may include:
[0165] S801: In response to a viewing request, obtaining an index node of a file used by the process from a task structure corresponding to the process.
[0166] S801 is a possible implementation method of determining the index node of the cache object in response to a viewing request in S601. When you want to view the relevant information of a process in the cache, you can generate a viewing request, which is used to determine the cache occupied by the process. Traverse all processes to obtain the task structure task_struck corresponding to the process. Each task structure has a file structure of the file used by the corresponding process, from which the index node of the file used by the process can be obtained.
[0167] S802: Determine the cache occupied by the file corresponding to the index node of the file used by the process.
[0168] The file corresponding to the index node of the file used by the process is the file used by the process. Through the index node of the file used by the process, the occupancy of the file used by the process in the cache can be found, such as which cache pages are occupied, the addresses of the occupied cache pages, etc. The cache occupied by the files corresponding to each index node in the task structure of a process is the cache occupied by the process. For example, process A uses file 1 and file 2. The task structure of process A includes index node 1 corresponding to file 1 and index node 2 corresponding to file 2. Through index node 1 and index node 2, the occupancy of file 1 and file 2 in the cache can be obtained, and the cache occupied by process A can be obtained.
[0169] S803: Determine a cache object to be released based on the file occupancy cache corresponding to the index node of the file used by the process.
[0170] After determining that the file occupancy cache corresponding to the index node of the file used by the process is determined, the cache occupancy status of the file used by the process can be obtained, and the process to be released can be determined from the process.
[0171] S803 is a possible implementation of S603. The implementation process of S803 is similar to that of S603. For related descriptions, please refer to the above embodiment, which will not be repeated here.
[0172] In the embodiment of the present application, the process that occupies a large amount of cache can be determined as the process to be released based on the process granularity, so that the cache can be released more accurately.
[0173] See also Fig. 9As shown, a schematic diagram of a kernel cache release method in practical applications is shown. In an embodiment of the present application, parameters can be obtained through the procfs interface. Including obtaining the absolute address of the cache file to be released to release the cache occupied by the specified file; or, obtaining the identifier of the process to be released to release the cache occupied by the specified process; or, obtaining a viewing request for the cache file to determine the cache file to be released according to the situation that each cache file occupies the cache; or, obtaining a viewing request for the process to determine the process to be released according to the situation that each process occupies the cache. In a specific implementation, the procfs interface can be one or more. Thereby, files or processes that occupy a large cache can be accurately located, and the cache of the specified file or specified process can be released in a targeted manner to ensure that the release of the cache will not affect the performance of important processes.
[0174] Based on a kernel cache releasing method provided by the above method embodiment, an embodiment of the present application further provides a kernel cache releasing device, which will be described below in conjunction with the accompanying drawings.
[0175] See also Fig.10 As shown in FIG. 1 , this figure is a schematic diagram of the structure of a kernel cache release device provided in an embodiment of the present application. Fig.10 As shown, the kernel cache release device includes:
[0176] The acquisition unit 1101 is used to acquire the identifier of the cache object to be released; wherein the cache object to be released is not a cache object prohibited from being released; and the object to be released is a process or a file;
[0177] A first determining unit 1102 is used to determine the index node of the cache object to be released according to the identifier of the cache object to be released;
[0178] The second determining unit 1103 is used to determine the cache occupied by the file corresponding to the index node of the cache object to be released;
[0179] The releasing unit 1104 is used to release the cache occupied by the file corresponding to the index node of the cache object to be released.
[0180] In a possible implementation, the cache object to be released is a cache file to be released; and the first determining unit is specifically configured to:
[0181] Extract the file identifier of the cache file to be released from the absolute address of the cache file to be released;
[0182] Determine the inode of the file identifier of the cache file to be released.
[0183] In a possible implementation, the cache object to be released is a process to be released; and the first determining unit is specifically configured to:
[0184] Determine the task structure corresponding to the process to be released according to the identifier of the process to be released;
[0185] Get the index node of the file used by the process to be released from the task structure corresponding to the process to be released.
[0186] In a possible implementation, the device further includes:
[0187] The third determination unit is used to determine whether the target cache page is used; the target cache page is any cache page in the cache occupied by the file corresponding to the index node of the cache object to be released;
[0188] The release unit is specifically used to release the target cache page when the target cache page is not used.
[0189] In a possible implementation, the device further includes:
[0190] A fourth determining unit is used to determine the index node of the cache object in response to the viewing request; the viewing request is used to determine the cache occupied by the cache object;
[0191] A fifth determining unit, used to determine the cache occupied by the file corresponding to the index node of the cache object;
[0192] The sixth determining unit is used to determine the cache object to be released based on the cache occupied by the file corresponding to the index node of the cache object.
[0193] In a possible implementation manner, the sixth determining unit is specifically configured to:
[0194] Determine whether the cache occupied by the file corresponding to the index node of the cache object exceeds a preset threshold;
[0195] When the cache occupied by the file corresponding to the index node of the cache object exceeds a preset threshold, determining whether the cache object is a cache object that is prohibited from being released;
[0196] When the cache object does not belong to the cache objects prohibited from being released, the cache object is determined as a cache object to be released.
[0197] In a possible implementation manner, the cache object is a cache file; and the fourth determining unit is specifically configured to:
[0198] In response to the view request, the index node of the cache file is obtained from the super block structure.
[0199] In a possible implementation manner, the cache object is a process; and the fourth determining unit is specifically configured to:
[0200] In response to the viewing request, the index node of the file used by the process is obtained from the task structure corresponding to the process.
[0201] In a possible implementation manner, the fifth determining unit is specifically configured to:
[0202] Get the cache occupied by the file corresponding to the target index node;
[0203] The cache sizes occupied by the files corresponding to the target index nodes are accumulated to obtain the cache occupied by the files corresponding to the target index nodes; the target index node is any one of the index nodes of the cache object.
[0204] The embodiment of the present application also provides a computing device, including: a memory and a processor; the memory and the processor are coupled;
[0205] The memory is used to store program instructions;
[0206] The processor is used to run program instructions to enable the computing device to implement the kernel cache release method as described above.
[0207] An embodiment of the present application also provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a computing device, the computing device executes the kernel cache release method as described above.
[0208] An embodiment of the present application also provides a computer program product, including computer program instructions. When the computer program instructions are executed on a computing device, the computing device executes the kernel cache release method as described above.
[0209] In an embodiment of the present application, the identifier of a cache object to be released can be obtained, and the index node of the cache object to be released can be determined through the identifier. The index node corresponds to a file and can include whether the file is stored in the cache and the location where it is stored. The file corresponding to the index node in the cache can be found through the index node, and these files are the files that need to be released in the cache. In this way, the cache of the specified cache object to be released can be released in a targeted manner to ensure that the release of the cache will not affect the performance of important processes. In addition, based on the cache occupancy of each cache object, the cache object to be released is determined to make the cache release more targeted.
[0210] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the system or device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0211] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0212] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0213] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0214] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A kernel cache release method, characterized in that: The method comprises: Obtaining an identifier of a cache object to be released; wherein the cache object to be released does not belong to a cache object prohibited from being released; and the object to be released is a process or a file; Determine the index node of the cache object to be released according to the identifier of the cache object to be released; Determine the cache occupied by the file corresponding to the index node of the cache object to be released; The cache occupied by the file corresponding to the index node of the cache object to be released is released.
2. The method according to claim 1, characterized in that The cache object to be released is a cache file to be released; The step of determining the index node of the cache object to be released according to the identifier of the cache object to be released includes: Extracting the file identifier of the cache file to be released from the absolute address of the cache file to be released; Determine the index node of the file identifier of the cache file to be released.
3. The method according to claim 1, characterized in that The cache object to be released is a process to be released; The step of determining the index node of the cache object to be released according to the identifier of the cache object to be released includes: Determine a task structure corresponding to the process to be released according to the identifier of the process to be released; The index node of the file used by the process to be released is obtained from the task structure corresponding to the process to be released.
4. The method according to any one of claims 1 to 3, characterized in that: Before releasing the cache occupied by the file corresponding to the index node of the cache object to be released, the method further includes: Determine whether the target cache page is used; the target cache page is any cache page in the cache occupied by the file corresponding to the index node of the cache object to be released; When the target cache page is not in use, the target cache page is released.
5. The method according to any one of claims 1 to 4, characterized in that: Before obtaining the identifier of the cache object to be released, the method further includes: In response to a viewing request, determining an index node of a cache object; the viewing request is used to determine a cache occupied by the cache object; Determine the cache occupied by the file corresponding to the index node of the cache object; Based on the cache occupied by the file corresponding to the index node of the cache object, a cache object to be released is determined.
6. The method according to claim 5, characterized in that The determining the cache object to be released based on the cache occupied by the file corresponding to the index node of the cache object includes: Determine whether the cache occupied by the file corresponding to the index node of the cache object exceeds a preset threshold; When the cache occupied by the file corresponding to the index node of the cache object exceeds the preset threshold, determining whether the cache object is a cache object that is prohibited from being released; In a case where the cache object does not belong to a cache object prohibited from being released, the cache object is determined as a cache object to be released.
7. The method according to claim 5, characterized in that The cache object is a cache file; The step of determining the index node of the cache object in response to the viewing request includes: In response to the viewing request, the index node of the cache file is obtained from the super block structure.
8. The method according to claim 5, characterized in that The cache object is a process; The step of determining the index node of the cache object in response to the viewing request includes: In response to the viewing request, an index node of a file used by the process is obtained from a task structure corresponding to the process.
9. The method according to any one of claims 5 to 8, characterized in that: The determining the cache occupied by the file corresponding to the index node of the cache object includes: Get the cache occupied by the file corresponding to the target index node; The cache sizes occupied by the files corresponding to the target index nodes are accumulated to obtain the cache occupied by the files corresponding to the target index nodes; the target index node is any one of the index nodes of the cache object.
10. A computing device, characterized in that include: Memory and processor; The memory is used to store program instructions; The processor is used to run the program instructions so that the computing device implements the kernel cache release method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Progress starting method, kernel and progress
CN102508713A
Cache cleaning method, device and client side
CN103714016A
File accessing method and related device
CN105378687A
Fine pitch connector socket
CN105830059A
Batch task processing method and device, computer equipment and storage medium
CN111078733A
